blob: 5ede4fee63cbe401dd4377e680a0da07115134b6 [file] [log] [blame]
Marc Kupietz83305222016-04-28 09:57:22 +02001<!DOCTYPE html>
2<html>
3 <head>
Marc Kupietz58270662017-12-04 12:10:06 +01004 <title>DeReKo-Word-Vector-Distances: <%= $word %></title>
Marc Kupietz80bd7b92017-07-04 16:25:54 +02005 <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
Marc Kupietz58270662017-12-04 12:10:06 +01006 <link href="https://fonts.googleapis.com/css?family=Lato|Roboto+Condensed" rel="stylesheet">
Marc Kupietz80bd7b92017-07-04 16:25:54 +02007 <script src="http://code.jquery.com/jquery-latest.min.js"></script>
Marc Kupietz58270662017-12-04 12:10:06 +01008 <script src = "https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
9 <script src = "https://cdn.datatables.net/fixedcolumns/3.2.3/js/dataTables.fixedColumns.min.js"></script>
10 <script src = "https://cdn.datatables.net/plug-ins/1.10.16/sorting/scientific.js"></script>
11 <link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css">
Marc Kupietz80bd7b92017-07-04 16:25:54 +020012 <script
Marc Kupietz3eeb1022017-12-06 09:44:11 +010013 src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
14 integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
15 crossorigin="anonymous"></script>
Marc Kupietz80bd7b92017-07-04 16:25:54 +020016 <script>
Marc Kupietz58270662017-12-04 12:10:06 +010017 var urlParams = new URLSearchParams(window.location.search);
Marc Kupietz3eeb1022017-12-06 09:44:11 +010018 var currentWord = urlParams.get("word");
Marc Kupietza6e08f02017-12-01 22:06:21 +010019
Marc Kupietz4abcd682017-11-28 20:51:08 +010020 $('#firstable').hide();
Marc Kupietz58270662017-12-04 12:10:06 +010021 $(document).ready(function() {
Marc Kupietz694610d2017-11-25 18:30:03 +010022
Marc Kupietz58270662017-12-04 12:10:06 +010023 $("input").bind("keydown", function(event) {
24 // track enter key
25 var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
26 if (keycode == 13) { // keycode for enter key
27 // force the 'Enter Key' to implicitly click the Update button
28 document.getElementById('SEARCH').click();
29 return false;
30 } else {
31 return true;
32 }});
Marc Kupietzdab9f222017-11-29 14:22:59 +010033
Marc Kupietz58270662017-12-04 12:10:06 +010034 $( "#tabs" ).on( "tabsactivate", function( event, ui ) {
35 if (localStorage) localStorage['tab'] = ui.newTab.index();
36 });
Marc Kupietz0af83e32017-11-27 09:31:37 +010037
Marc Kupietz58270662017-12-04 12:10:06 +010038 $(function(){
39 $("#SEARCH").click(function() {
40 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
41 });
42 });
Marc Kupietz2f6b74a2017-12-01 13:20:21 +010043
Marc Kupietz3eeb1022017-12-06 09:44:11 +010044 function changeCharColor(txt, heat, word) {
Marc Kupietz58270662017-12-04 12:10:06 +010045 var newText = "";
46 for (var i=0, l=txt.length; i<l; i++) {
Marc Kupietz3eeb1022017-12-06 09:44:11 +010047 newText += (i == 5 ? txt.charAt(i) : '<a href="http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q=' +
48 currentWord + ' /' + (i > 5? '%2B' : '-') + 'w' +
49 Math.abs(i-5) + ':' + Math.abs(i-5) + ' ' + word +
50 '" target="korap"><span style="background-color:' +
51 getHeatColor(heat[i]/maxHeat)+'">'+txt.charAt(i)+'</span></a>');
Marc Kupietz58270662017-12-04 12:10:06 +010052 }
53 return newText;
Marc Kupietzb6c615d2017-12-02 10:38:20 +010054 }
Marc Kupietzb6c615d2017-12-02 10:38:20 +010055
Marc Kupietz58270662017-12-04 12:10:06 +010056 function getHeatColor(value) {
57 var hue=((1-value)*120).toString(10);
58 return ["hsl(",hue,",90%,70%)"].join("");
Marc Kupietz0d4c0ca2017-12-04 09:18:56 +010059 }
Marc Kupietz0d4c0ca2017-12-04 09:18:56 +010060
Marc Kupietz3eeb1022017-12-06 09:44:11 +010061 function bitvec2window(n, heat, word) {
Marc Kupietz58270662017-12-04 12:10:06 +010062 var str = n.toString(2).padStart(10, "0")
63 .replace(/^([0-9]{5})/, '$1x')
64 .replace(/0/g, '·')
65 .replace(/1/g, '+');
Marc Kupietz3eeb1022017-12-06 09:44:11 +010066 return changeCharColor(str, heat, word);
Marc Kupietzddaba632017-12-02 17:30:56 +010067 }
Marc Kupietz6e2fc102017-12-01 22:07:23 +010068
Marc Kupietz58270662017-12-04 12:10:06 +010069 % use Mojo::ByteStream 'b';
Marc Kupietz58270662017-12-04 12:10:06 +010070 var paraResults = <%= b(Mojo::JSON::to_json($lists)) %>;
71 var urlprefix = new URLSearchParams(window.location.search);
Marc Kupietz451f8d82017-12-04 13:19:47 +010072 if (paraResults.length > 0 && paraResults[0] != null) {
Marc Kupietz58270662017-12-04 12:10:06 +010073 var nvecs = [],
74 nwords = [],
75 nranks = [],
76 nmarked = [];
77 for(var i = 0; i < paraResults.length; i++) {
78 nwords = nwords.concat(paraResults[i].map(function(a){return a.word;}));
79 nvecs = nvecs.concat(paraResults[i].map(function(a){return a.vector;}));
80 nranks = nranks.concat(paraResults[i].map(function(a){return a.rank;}));
81 nmarked = nmarked.concat(paraResults[i].map(function(a){return a.marked;}));
82 }
Marc Kupietz8f9c86a2017-12-04 17:17:13 +010083 showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: nvecs, ranks: nranks, marked: nmarked} );
Marc Kupietz58270662017-12-04 12:10:06 +010084 var t = $('#firsttable').DataTable({
85 data: paraResults[0],
86 "sScrollY": "780px",
87 "bScrollCollapse": true,
88 "bPaginate": false,
89 "bJQueryUI": true,
90 "dom": '<"top">rt<"bottom"flp><"clear">',
91 "columns": [
92 { "data": "rank", type: "allnumeric" },
93 { "data": "dist", render: function ( data, type, row ) {return data.toFixed(3) }},
94 { "data": "word", render: function ( data, type, row ) {urlprefix.set("word", data); return '<a href="?' + urlprefix + '">' + data + '</a>' }}
95 ],
96 "columnDefs": [
97 { className: "dt-right", "targets": [0,1] },
98 { "searchable": false,
99 "orderable": false,
100 "targets": 0
101 },
102 { "orderSequence": [ "desc" ], "targets": [ 1 ] },
103 { "orderSequence": [ "asc", "desc" ], "targets": [ 2 ] },
104 ],
Marc Kupietzd6b15442017-12-04 13:20:27 +0100105 "oLanguage": {
106 "sSearch": "Filter: "
107 },
Marc Kupietz58270662017-12-04 12:10:06 +0100108 "order": [[ 1, 'desc' ]],
109 } );
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100110
Marc Kupietz58270662017-12-04 12:10:06 +0100111 t.on( 'order.dt search.dt', function () {
112 t.column(0, {order:'applied'}).nodes().each( function (cell, i) {
113 cell.innerHTML = i+1;
114 } );
115 } ).draw();
Marc Kupietzdab9f222017-11-29 14:22:59 +0100116
Marc Kupietz58270662017-12-04 12:10:06 +0100117 $( "#first" ).clone().prependTo( "#tabs-2" );
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100118
Marc Kupietz58270662017-12-04 12:10:06 +0100119 }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100120
Marc Kupietz58270662017-12-04 12:10:06 +0100121 var collocatorData = <%= b(Mojo::JSON::to_json($collocators)) %>;
122 var maxHeat; // = Math.max.apply(Math,collocatorData.map(function(o){return o.cprob;}))
Marc Kupietz3305b0a2017-11-27 10:46:20 +0100123
Marc Kupietz58270662017-12-04 12:10:06 +0100124 if (collocatorData != null) {
125 maxHeat = Math.max.apply(Math,collocatorData.map(function(o){return Math.max.apply(Math,o.heat);}))
126 var t = $('#secondtable').DataTable({
127 data: collocatorData,
128 "sScrollY": "780px",
129 "bScrollCollapse": true,
130 "bPaginate": false,
131 "bJQueryUI": true,
132 "dom": '<"top">rt<"bottom"flp><"clear">',
133 "columns": [
134 { "data": "rank", type: "allnumeric" },
Marc Kupietz3eeb1022017-12-06 09:44:11 +0100135 { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat, row.word) }},
Marc Kupietz58270662017-12-04 12:10:06 +0100136 { "data": "max", render: function ( data, type, row ) {return data.toFixed(3) }},
137 { "data": "conorm", render: function ( data, type, row ) {return data.toFixed(3) }},
138 { "data": "prob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
139 { "data": "cprob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
140 { "data": "overall", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
141 { "data": "word", sClass: "collocator" }
142 ],
143 "columnDefs": [
144 { className: "dt-right", "targets": [0,2,3,4,5,6] },
145 { className: "dt-center", "targets": [ 1] },
146 { "searchable": false,
147 "orderable": false,
148 "targets": 0
149 },
150 { "type": "scientific", targets: [2,3,4,5,6] },
151 { "orderSequence": [ "desc" ], "targets": [ 2, 3, 4, 5, 6 ] },
152 { "orderSequence": [ "asc", "desc" ], "targets": [ 1, 7 ] },
153 ],
Marc Kupietzd6b15442017-12-04 13:20:27 +0100154 "oLanguage": {
155 "sSearch": "Filter: "
156 },
Marc Kupietz58270662017-12-04 12:10:06 +0100157 "order": [[ 4, 'desc' ]],
158 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100159
Marc Kupietz58270662017-12-04 12:10:06 +0100160 t.on( 'order.dt search.dt', function () {
161 t.column(0, {order:'applied'}).nodes().each( function (cell, i) {
162 cell.innerHTML = i+1;
163 } );
164 } ).draw();
165
Marc Kupietz0ba5c812017-12-06 09:41:25 +0100166 if (localStorage && !window.location.hash) { // let's not crash if some user has IE7
Marc Kupietz58270662017-12-04 12:10:06 +0100167 var index = parseInt(localStorage['tab']||'0');
168 $("#tabs").tabs({ active: index });
169 }
170 }
171 $("#tabs").css("visibility", "visible"); // now we can show the tabs
172
173 });
174
175 $(function(){
176 $("#dropdownoptions").dialog({
177 title: "Options",
178 autoOpen: false,
179 modal: false,
180 draggable: false,
181 height: "auto",
182 width: "auto",
183 resizable: false,
184 buttons: {
185 "Cancel": function() {
186 $( this ).dialog( "close" );
187 },
188 "Apply": function() {
189 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
190 }
191 }
192 });
193 });
194
195 $(function(){
196 $("td.collocator").click(function(){
197 queryKorAPCII(this.textContent + " /w5 " + urlParams.get('word'));
198 });
199 });
200
201 $(function(){
202 $("#showoptions").click(function(){
203 $("#dropdownoptions").dialog("open");
204 var target = $(this);
205 $("#dropdownoptions").dialog("widget").position({
206 my: 'left bottom',
207 at: 'left bottom',
208 of: target
209 });
210 });
211 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100212
213 $( function() {
Marc Kupietz58270662017-12-04 12:10:06 +0100214 $( "#no_iterations" ).spinner({
215 spin: function( event, ui ) {
216 if ( ui.value < 1000 ) {
217 $( this ).spinner( "value", 1000 );
218 return false;
219 } else if ( ui.value > 10000 ) {
220 $( this ).spinner( "value", 10000 );
221 return false;
222 }
223 }
224 });
225 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100226
Marc Kupietz58270662017-12-04 12:10:06 +0100227 $( function() {
228 $( "#neighbours" ).spinner({
229 spin: function( event, ui ) {
230 if ( ui.value < 0 ) {
231 $( this ).spinner( "value", 0 );
232 return false;
233 } else if ( ui.value > 200 ) {
234 $( this ).spinner( "value", 200 );
235 return false;
236 }
237 }
238 });
239 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100240
Marc Kupietz58270662017-12-04 12:10:06 +0100241 $( function() {
242 $( "#cutoff" ).spinner({
243 spin: function( event, ui ) {
244 if ( ui.value < 100000 ) {
245 $( this ).spinner( "value", 100000 );
246 return false;
247 } else if ( ui.value > 2000000 ) {
248 $( this ).spinner( "value", 2000000 );
249 return false;
250 }
251 }
252 });
253 } );
254
255 $( function() {
256 $( "#tabs" ).tabs().addClass('tabs-min');
257 } );
258
259 $( function() {
260 $( ".controlgroup-vertical" ).controlgroup({
261 "direction": "vertical"
262 });
263 } );
264
265 $(function() {
266 $( document ).tooltip({
267 content: function() {
268 return $(this).attr('title');
269 }}
270 )
271 })
Marc Kupietz694610d2017-11-25 18:30:03 +0100272
Marc Kupietz83305222016-04-28 09:57:22 +0200273 </script>
Marc Kupietz58270662017-12-04 12:10:06 +0100274 <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
275 <script src="/derekovecs/js/tsne.js"></script>
276 <script src="/derekovecs/js/som.js"></script>
277 <script src="/derekovecs/js/labeler.js"></script>
Marc Kupietz83305222016-04-28 09:57:22 +0200278 <style>
279 body, input {
Marc Kupietz58270662017-12-04 12:10:06 +0100280 font-family: Lato, sans-serif;
281 font-size: 11pt;
Marc Kupietz83305222016-04-28 09:57:22 +0200282 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100283
Marc Kupietz58270662017-12-04 12:10:06 +0100284 h1, h2, h3 {
285 margin: 5px 10px 0 0;
286 color: rgb(246,168,0);
287 font-family: "Univers LT Std 47 Cn Lt", "Univers LT Std 67 Cn Lt", "Roboto Condensed", "Univers LT Std 67 Cn Bold", "UniversLTStd-BoldCn", "Times", 'League Gothic', Impact, sans-serif;
288 font-weight: bold;
289 line-height: 1.35;
290 letter-spacing: normal;
291 text-transform: uppercase;
292 text-shadow: none;
293 word-wrap: break-word;
294 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100295
296
Marc Kupietz58270662017-12-04 12:10:06 +0100297 showoptions, #SEARCH {
298 margin-left: 10px;
299 margin-right: 10px;
300 }
Marc Kupietz6dbadd12017-11-29 16:43:33 +0100301
Marc Kupietz58270662017-12-04 12:10:06 +0100302 .tabs-left-vertical .ui-tabs-nav {
303 position: absolute;
304 width: 21em;
305 transform: translate(-100%,0%) rotate(-90deg);
306 transform-origin: 100% 0%;
307 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100308
Marc Kupietz58270662017-12-04 12:10:06 +0100309 .tabs-left-vertical .ui-tabs-nav li {
310 float: right;
311 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100312
Marc Kupietz58270662017-12-04 12:10:06 +0100313 .tabs-left-vertical .ui-tabs-panel {
314 padding-left: 3.5em;
315 }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100316
Marc Kupietz58270662017-12-04 12:10:06 +0100317 .tabs-left-vertical .ui-tabs-panel {
318 height: 20em;
319 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100320
Marc Kupietz58270662017-12-04 12:10:06 +0100321 .mono {
322 font-family: "DejaVu Sans Mono", Inconsolata, SourceCodePro, Courier;
323 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100324
Marc Kupietz58270662017-12-04 12:10:06 +0100325 .ui-tooltip-content {
326 font-size: 9pt;
327 color: #222222;
328 }
Marc Kupietzf4b49392016-04-28 10:49:56 +0200329
Marc Kupietz58270662017-12-04 12:10:06 +0100330 svg > .ui-tooltip-content {
331 font-size: 8pt;
332 color: #222222;
333 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100334
Marc Kupietz58270662017-12-04 12:10:06 +0100335 a.merged {
336 color: green;
337 fill: green;
338 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100339
Marc Kupietz58270662017-12-04 12:10:06 +0100340 #first a {
341 text-decoration: none;
342 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100343
Marc Kupietz58270662017-12-04 12:10:06 +0100344 a.marked, #first a.marked {
345 text-decoration: underline;
346 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100347
Marc Kupietz58270662017-12-04 12:10:06 +0100348 a.target {
349 color: red;
350 fill: red;
351 }
Marc Kupietz694610d2017-11-25 18:30:03 +0100352
Marc Kupietz58270662017-12-04 12:10:06 +0100353 table.display {
354 width: 40% important!;
355 margin: 1; /* <- works for me this way ****/
356 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100357
Marc Kupietz58270662017-12-04 12:10:06 +0100358 table.dataTable thead th, table.dataTable thead td, table.dataTable tbody td {
359 padding: 2px 2px;
360 // border-bottom: 1px solid #111;
361 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100362
Marc Kupietz8f75b1f2017-12-06 09:42:13 +0100363 td.collocator {
364 cursor: pointer;
365 }
366
Marc Kupietz58270662017-12-04 12:10:06 +0100367 #collocators {
368 margin-bottom: 15px;
369 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100370
Marc Kupietz58270662017-12-04 12:10:06 +0100371 #header {
372 width: 100%;
373 // border: 1px solid red;
374 overflow: hidden; /* will contain if #first is longer than #second */
375 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100376
Marc Kupietz58270662017-12-04 12:10:06 +0100377 #topwrapper {
378 width: 100%;
379 // border: 1px solid red;
380 overflow: hidden; /* will contain if #first is longer than #second */
381 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100382
Marc Kupietz58270662017-12-04 12:10:06 +0100383 #wrapper {
384 // border: 1px solid red;
385 overflow: hidden; /* will contain if #first is longer than #second */
386 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100387
Marc Kupietz58270662017-12-04 12:10:06 +0100388 #pagetitle {
389 max-width: 460px;
390 margin-right: 20px;
391 float: left;
392 overflow: hidden; /* if you don't want #second to wrap below #first */
393 // border: 1px solid green;
394 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100395
Marc Kupietz58270662017-12-04 12:10:06 +0100396 #options {
397 float: left;
398 width: 800px;
399 margin: 10px;
400 overflow: hidden; /* if you don't want #second to wrap below #first */
401 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100402
Marc Kupietz58270662017-12-04 12:10:06 +0100403 #word {
404 width: 50%;
405 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100406
Marc Kupietz58270662017-12-04 12:10:06 +0100407 #first {
408 margin-right: 20px;
409 float: left;
410 overflow: hidden; /* if you don't want #second to wrap below #first */
411 // border: 1px solid green;
412 }
413 #tabs {
414 margin-right: 20px;
415 overflow: hidden; /* if you don't want #second to wrap below #first */
416 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100417
Marc Kupietz58270662017-12-04 12:10:06 +0100418 .tabs-min {
419 background: transparent;
420 border: none;
421 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100422
Marc Kupietz58270662017-12-04 12:10:06 +0100423 .tabs-min .ui-widget-header {
424 background: transparent;
425 border: none;
426 border-bottom: 1px solid #c0c0c0;
427 -moz-border-radius: 0px;
428 -webkit-border-radius: 0px;
429 border-radius: 0px;
430 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100431
Marc Kupietz58270662017-12-04 12:10:06 +0100432 .tabs-min .ui-tabs-nav .ui-state-default {
433 background: transparent;
434 border: none;
435 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100436
Marc Kupietz58270662017-12-04 12:10:06 +0100437 .tabs-min .ui-tabs-nav .ui-state-active {
438 background: transparent url(derekovecs/img/uiTabsArrow.png) no-repeat bottom center;
439 border: none;
440 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100441
Marc Kupietz58270662017-12-04 12:10:06 +0100442 .tabs-min .ui-tabs-nav .ui-state-default a {
443 color: #c0c0c0;
444 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100445
Marc Kupietz58270662017-12-04 12:10:06 +0100446 .tabs-min .ui-tabs-nav .ui-state-active a {
447 color: rgb(246,168,0);
448 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100449
Marc Kupietz58270662017-12-04 12:10:06 +0100450 #embed {
451 max-width: 802px;
452 border: 1px solid #333;
453 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100454
Marc Kupietz58270662017-12-04 12:10:06 +0100455 #second {
456 min-width: 800px;
457 // border: 1px solid #333;
458 overflow: hidden; /* if you don't want #second to wrap below #first */
459 }
460 #som2 svg {
461 border: 1px solid #333;
462 }
Marc Kupietz83305222016-04-28 09:57:22 +0200463
Marc Kupietz58270662017-12-04 12:10:06 +0100464 #cost {
465 font-size: 8pt;
466 color: #222222;
467 margin-top: 4px;
468 margin-bottom: 12px;
469 }
Marc Kupietz83305222016-04-28 09:57:22 +0200470
Marc Kupietz58270662017-12-04 12:10:06 +0100471 #sominfo1, #sominfo {
472 font-size: 8pt;
473 color: #222222;
474 margin-top: 0px;
475 }
Marc Kupietz83305222016-04-28 09:57:22 +0200476
Marc Kupietz58270662017-12-04 12:10:06 +0100477 #somcolor1, #somcolor2, #somcolor3 {
478 display: inline-block;
479 height: 10px;
480 width: 10px;
481 }
Marc Kupietz83305222016-04-28 09:57:22 +0200482
Marc Kupietz58270662017-12-04 12:10:06 +0100483 #third {
484 border: 1px solid #333;
485 }
Marc Kupietz83305222016-04-28 09:57:22 +0200486
487 </style>
488 <script>
489
490 var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>},
Marc Kupietz58270662017-12-04 12:10:06 +0100491 mapWidth = 800, // width map
492 mapHeight = 800,
493 jitterRadius = 7;
Marc Kupietz83305222016-04-28 09:57:22 +0200494
495 var T = new tsnejs.tSNE(opt); // create a tSNE instance
496
497 var Y;
498
499 var data;
500 var labeler;
501
502 function applyJitter() {
Marc Kupietz58270662017-12-04 12:10:06 +0100503 svg.selectAll('.tsnet')
504 .data(labels)
505 .transition()
506 .duration(50)
507 .attr("transform", function(d, i) {
508 T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20;
509 T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20;
510 return "translate(" +
Marc Kupietz3eeb1022017-12-06 09:44:11 +0100511 (d.x) + "," +
512 (d.y) + ")";
Marc Kupietz58270662017-12-04 12:10:06 +0100513 });
Marc Kupietz83305222016-04-28 09:57:22 +0200514 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100515
Marc Kupietz83305222016-04-28 09:57:22 +0200516 function updateEmbedding() {
Marc Kupietz58270662017-12-04 12:10:06 +0100517 var Y = T.getSolution();
518 svg.selectAll('.tsnet')
519 .data(data.words)
520 .attr("transform", function(d, i) {
521 return "translate(" +
Marc Kupietz3eeb1022017-12-06 09:44:11 +0100522 ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," +
523 ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; });
Marc Kupietz83305222016-04-28 09:57:22 +0200524 }
525
526 var svg;
527 var labels = [];
528 var anchor_array = [];
529 var text;
530
531 function drawEmbedding() {
Marc Kupietz58270662017-12-04 12:10:06 +0100532 var urlprefix = new URLSearchParams(window.location.search);
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100533 urlprefix.delete("word");
534 urlprefix.append("word","");
535
Marc Kupietz58270662017-12-04 12:10:06 +0100536 $("#embed").empty();
537 var div = d3.select("#embed");
Marc Kupietz34c08172017-11-29 17:08:47 +0100538
Marc Kupietz58270662017-12-04 12:10:06 +0100539 // get min and max in each column of Y
540 var Y = T.Y;
Marc Kupietz34c08172017-11-29 17:08:47 +0100541
Marc Kupietz58270662017-12-04 12:10:06 +0100542 svg = div.append("svg") // svg is global
543 .attr("width", mapWidth)
544 .attr("height", mapHeight);
Marc Kupietz34c08172017-11-29 17:08:47 +0100545
Marc Kupietz58270662017-12-04 12:10:06 +0100546 var g = svg.selectAll(".b")
547 .data(data.words)
548 .enter().append("g")
549 .attr("class", "tsnet");
Marc Kupietz34c08172017-11-29 17:08:47 +0100550
Marc Kupietz58270662017-12-04 12:10:06 +0100551 g.append("a")
552 .attr("xlink:href", function(word) {
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100553 return "?"+urlprefix+word; })
Marc Kupietz58270662017-12-04 12:10:06 +0100554 .attr("class", function(d, i) {
555 var res="";
556 if(data.marked[i]) {
557 res="marked ";
558 }
559 if(data.target.indexOf(" "+d+" ") >= 0) {
560 return res+"target";
561 } else if(data.ranks[i] < data.mergedEnd) {
562 return res+"merged";
563 } else {
564 return res;
565 }
566 })
567 .attr("title", function(d, i) {
568 if(data.mergedEnd > 0) {
569 if(data.ranks[i] >= data.mergedEnd) {
570 return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
571 } else {
572 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
573 }
574 } else {
575 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
576 }
577 })
578 .append("text")
579 .attr("text-anchor", "top")
580 .attr("font-size", 12)
581 .text(function(d) { return d; });
Marc Kupietz34c08172017-11-29 17:08:47 +0100582
Marc Kupietz58270662017-12-04 12:10:06 +0100583 var zoomListener = d3.behavior.zoom()
584 .scaleExtent([0.1, 10])
585 .center([0,0])
586 .on("zoom", zoomHandler);
587 zoomListener(svg);
Marc Kupietz83305222016-04-28 09:57:22 +0200588 }
589
590 var tx=0, ty=0;
591 var ss=1;
592 var iter_id=-1;
593
594 function zoomHandler() {
Marc Kupietz58270662017-12-04 12:10:06 +0100595 tx = d3.event.translate[0];
596 ty = d3.event.translate[1];
597 ss = d3.event.scale;
598 updateEmbedding();
Marc Kupietz83305222016-04-28 09:57:22 +0200599 }
600
601 var stepnum = 0;
602
603 function stopStep() {
Marc Kupietz58270662017-12-04 12:10:06 +0100604 clearInterval(iter_id);
605 text = svg.selectAll("text");
Marc Kupietz34c08172017-11-29 17:08:47 +0100606
Marc Kupietz58270662017-12-04 12:10:06 +0100607 // jitter function needs different data and co-ordinate representation
608 labels = d3.range(data.words.length).map(function(i) {
609 var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2;
610 var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2;
611 anchor_array.push({x: x, y: y, r: jitterRadius});
612 return {
613 x: x,
614 y: y,
615 name: data.words[i]
616 };
617 });
Marc Kupietz34c08172017-11-29 17:08:47 +0100618
Marc Kupietz58270662017-12-04 12:10:06 +0100619 // get the actual label bounding boxes for the jitter function
620 var index = 0;
621 text.each(function() {
622 labels[index].width = this.getBBox().width;
623 labels[index].height = this.getBBox().height;
624 index += 1;
625 });
Marc Kupietz83305222016-04-28 09:57:22 +0200626
Marc Kupietz34c08172017-11-29 17:08:47 +0100627
Marc Kupietz58270662017-12-04 12:10:06 +0100628 // setTimeout(updateEmbedding, 1);
629 // setTimeout(
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100630 labeler = d3.labeler()
631 .label(labels)
632 .anchor(anchor_array)
633 .width(mapWidth)
634 .height(mapHeight)
635 .update(applyJitter);
Marc Kupietz58270662017-12-04 12:10:06 +0100636 // .start(1000);
Marc Kupietz83305222016-04-28 09:57:22 +0200637
Marc Kupietz58270662017-12-04 12:10:06 +0100638 iter_id = setInterval(jitterStep, 1);
Marc Kupietz83305222016-04-28 09:57:22 +0200639 }
640
641 var jitter_i=0;
642
643 function jitterStep() {
Marc Kupietz58270662017-12-04 12:10:06 +0100644 if(jitter_i++ > 100) {
645 clearInterval(iter_id);
646 } else {
647 labeler.start2(10);
648 applyJitter();
649 }
Marc Kupietz83305222016-04-28 09:57:22 +0200650 }
651
652 var last_cost=1000;
653
654 function step() {
Marc Kupietz58270662017-12-04 12:10:06 +0100655 var i = T.iter;
Marc Kupietz34c08172017-11-29 17:08:47 +0100656
Marc Kupietz58270662017-12-04 12:10:06 +0100657 if(i > <%= $no_iterations %>) {
658 stopStep();
659 } else {
660 var cost = Math.round(T.step() * 100000) / 100000; // do a few steps
661 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5));
662 if(i % 250 == 0 && cost >= last_cost) {
663 stopStep();
664 } else {
665 last_cost = cost;
666 updateEmbedding();
667 }
668 }
Marc Kupietz83305222016-04-28 09:57:22 +0200669 }
670
671 function showMap(j) {
Marc Kupietz58270662017-12-04 12:10:06 +0100672 data=j;
673 T.iter=0;
674 T.initDataRaw(data.vecs); // init embedding
675 drawEmbedding(); // draw initial embedding
Marc Kupietz78114532017-11-29 17:00:16 +0100676
Marc Kupietz58270662017-12-04 12:10:06 +0100677 if(iter_id >= 0) {
678 clearInterval(iter_id);
679 }
680 //T.debugGrad();
681 iter_id = setInterval(step, 1);
682 if(true) { // (<%= $show_som %>) {
683 makeSOM(j, <%= $no_iterations %>);
684 }
Marc Kupietz83305222016-04-28 09:57:22 +0200685 }
Marc Kupietz39179ab2017-07-04 16:28:06 +0200686 var queryword;
687
688 function onload() {
Marc Kupietz58270662017-12-04 12:10:06 +0100689 queryword = document.getElementById('word');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200690 }
691
692 function queryKorAP() {
Marc Kupietz58270662017-12-04 12:10:06 +0100693 window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200694 }
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100695
696 function queryKorAPCII(query) {
Marc Kupietz58270662017-12-04 12:10:06 +0100697 window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP');
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100698 }
Marc Kupietz83305222016-04-28 09:57:22 +0200699 </script>
700 </head>
Marc Kupietz39179ab2017-07-04 16:28:06 +0200701 <body onload="onload()">
Marc Kupietz58270662017-12-04 12:10:06 +0100702 <div id="header">
703 <div id="pagetitle">
704 <h1>DeReKo-Vectors</h1>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100705 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100706 <div id="options" class="widget">
707 <form id="queryform">
708 <input id="word" type="text" name="word" placeholder="Word(s) to be searched" value="<%= $word %>"
709 title="When looking for multiple words use spaces as separators to search around the average vector and | as separator to get the neighbours for each word."/>
710 <input id="SEARCH" type="button" value="SEARCH">
711 <input type="button" id="showoptions" name="showoptions" value="Options" />
712 </form>
713 <div id="dropdownoptions" style="display: none">
714 <form id="optionsform">
715 <div class="controlgroup-vertical">
716 <label for="cutoff">cut-off</label>
717 <input id="cutoff" type="text" name="cutoff" size="10" value="<%= $cutoff %>" title="Only consider the most frequent x word forms.">
718 <label for="dedupe">dedupe</label>
719 <input id="dedupe" type="checkbox" name="dedupe" value="1" <%= ($dedupe ? "checked" : "") %> title="radically filter out any near-duplicates">
720 % if($mergedEnd > 0) {
721 <label for="sbf">backw.</label>
722 <input id="sbf" type="checkbox" name="sbf" value="1" <%= ($searchBaseVocabFirst ? "checked" : "") %> title="If checkecked base vocabulary will be searched first. Otherwise merged vocabulray will be searched first.">
723 % }
724 <label for="neighbours">max. neighbours:</label>
725 <input id="neighbours" size="4" name="n" value="<%= $no_nbs %>">
726 <label for="no_iterations">max. iterations</label>
727 <input id="no_iterations" name="N" size="4" value="<%= $no_iterations %>">
728 <!-- <label for="dosom">SOM</label>
729 <input id="dosom" type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> -->
730 % if($collocators) {
731 <label for="sortby">window/sort</label>
732 <select id="sortby" name="sort">
733 <option value="0" <%= ($sort!=1 && $sort!=2? "selected":"") %>>auto focus</option>
734 <!-- <option value="1" <%= ($sort==1? "selected":"") %>>any single position</option>
735 <option value="2" <%= ($sort==2? "selected":"") %>>whole window</option> -->
736 </select>
737 % }
738 <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/>
739 </div>
740 </form>
741 </div>
742 </div>
743 </div>
744 <div id="topwrapper">
745 <div style="visibility: hidden;" id="tabs">
746 <ul>
747 <li><a href="#tabs-1">Semantics (TSNE-map)</a></li>
748 <li><a href="#tabs-2">Semantics (SOM)</a></li>
749 <li><a href="#tabs-3">Syntagmatic (collocators)</a></li>
750 </ul>
751 <div id="tabs-1">
752 % if($lists && (@$lists) > 0 && (@$lists)[0]) {
753 <div id="wrapper">
754 <div id="first" style="width: 320px">
755 <table class="display compact nowrap" id="firsttable">
756 <thead>
757 <tr>
758 <th align="right">#</th><th align="right">cos</th><th align="left">similars</th>
759 </tr>
760 </thead>
761 <tbody>
762 <tr>
763 <td align="right">
764 </td>
765 <td align="right">
766 </td>
767 <td></td>
768 </tr>
769 </tbody>
770 </table>
771 </div>
772 <script>
773 </script>
774 <div id="second">
775 <div id="embed">
776 </div>
777 <div id="cost">
778 </div>
779 </div>
780 </div>
781 % } elsif($word !~ /^\s*$/) {
782 <div id="wrapper">
783 <div id="not-found-dialog" title="Not found">
784 <p>ERROR: "<%= $word %>" not found in vocabluary.</p>
785 <p>If you are sure you have spelled the word as intended, you can try to increase the cutoff parameter in the options menu.</p>
786 </div>
787 <script>
788 $( function() {
789 $( "#not-found-dialog" ).dialog({
790 autoOpen: true,
791 modal: true,
792 draggable: false,
793 height: "auto",
794 width: "auto",
795 resizable: false,
796 buttons: {
797 "OK": function() {
798 $( this ).dialog( "close" );
799 },
800 "Apply": function() {
801 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
802 }
803 }
804 });
805 });
806 </script>
807 </div>
808 % }
809 </div>
810 <div id="tabs-2">
811 <div id="som2" style="width: 800; height: 800px">
812 </div>
813 <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div>
814 <div id="sominfo">SOM iteration <span id="iterations">0</span></div>
815 </div>
816 <div id="tabs-3">
817 <div style="width: 800px" id="secondt">
818 <table class="display compact nowrap" id="secondtable">
819 <thead>
820 <tr>
821 % if($collocators) {
822 <th>#</th>
823 <th align="center" title="The columns (c) around the target are considered for summation are marked with *.">w'</th>
824 <th align="right" title="Raw (max.) activation of the collocator in the output layers.">max(a)</th>
825 <th title="Co-normalized raw activation sum of the collocator in the selected columns." align="right">⊥Σa</th>
826 <th title="Sum of activations over the selected colunns normalized by the total activation sum of the selected columns." align="right">Σa/Σc</th>
827 <th title="Sum of the column normalized activations over the selected colunns." align="right">Σ(a/c)</th>
828 <th title="Sum of the activations over the whole window normalized by the total window sum (no auto-focus)." align="right">Σa/Σw</th>
829 <th align="left">collocator</th>
830 % }
831 </tr>
832 </thead>
833 <tbody>
834 <tr>
835 <td align="right">
836 </td>
837 <td align="right">
838 </td>
839 <td align="right">
840 </td>
841 <td align="right">
842 </td>
843 <td align="right">
844 </td>
845 <td align="right">
846 </td>
847 <script
Marc Kupietz3eeb1022017-12-06 09:44:11 +0100848 src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
Marc Kupietz58270662017-12-04 12:10:06 +0100849 </td>
850 </tr>
851 </tbody>
852 </table>
853 </div> <!-- - tab2 -->
854 </div> <!-- tabs -->
855 </div>
856 </div> <!-- topwrapper -->
857 <div style="clear: both;"></div>
858 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100859 % if($training_args) {
860 <p>
861 Word vector model trained with <a href="https://code.google.com/p/word2vec/">word2vec</a> using the following parameters: <pre><%= $training_args %></pre>
862 </p>
Marc Kupietz83305222016-04-28 09:57:22 +0200863 % }
Marc Kupietz58270662017-12-04 12:10:06 +0100864 </body>
Marc Kupietz83305222016-04-28 09:57:22 +0200865</html>