blob: c0a1a662c61cfc50bfa2290762d8f18c342f3805 [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 Kupietz58270662017-12-04 12:10:06 +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 Kupietza6e08f02017-12-01 22:06:21 +010018
Marc Kupietz4abcd682017-11-28 20:51:08 +010019 $('#firstable').hide();
Marc Kupietz58270662017-12-04 12:10:06 +010020 $(document).ready(function() {
Marc Kupietz694610d2017-11-25 18:30:03 +010021
Marc Kupietz58270662017-12-04 12:10:06 +010022 $("input").bind("keydown", function(event) {
23 // track enter key
24 var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
25 if (keycode == 13) { // keycode for enter key
26 // force the 'Enter Key' to implicitly click the Update button
27 document.getElementById('SEARCH').click();
28 return false;
29 } else {
30 return true;
31 }});
Marc Kupietzdab9f222017-11-29 14:22:59 +010032
Marc Kupietz58270662017-12-04 12:10:06 +010033 $( "#tabs" ).on( "tabsactivate", function( event, ui ) {
34 if (localStorage) localStorage['tab'] = ui.newTab.index();
35 });
Marc Kupietz0af83e32017-11-27 09:31:37 +010036
Marc Kupietz58270662017-12-04 12:10:06 +010037 $(function(){
38 $("#SEARCH").click(function() {
39 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
40 });
41 });
Marc Kupietz2f6b74a2017-12-01 13:20:21 +010042
Marc Kupietz58270662017-12-04 12:10:06 +010043 function changeCharColor(txt, heat) {
44 var newText = "";
45 for (var i=0, l=txt.length; i<l; i++) {
46 newText += (i == 5 ? txt.charAt(i) : '<span style="background-color:'+getHeatColor(heat[i]/maxHeat)+'">'+txt.charAt(i)+'</span>');
47 }
48 return newText;
Marc Kupietzb6c615d2017-12-02 10:38:20 +010049 }
Marc Kupietzb6c615d2017-12-02 10:38:20 +010050
Marc Kupietz58270662017-12-04 12:10:06 +010051 function getHeatColor(value) {
52 var hue=((1-value)*120).toString(10);
53 return ["hsl(",hue,",90%,70%)"].join("");
Marc Kupietz0d4c0ca2017-12-04 09:18:56 +010054 }
Marc Kupietz0d4c0ca2017-12-04 09:18:56 +010055
Marc Kupietz58270662017-12-04 12:10:06 +010056 function bitvec2window(n, heat) {
57 var str = n.toString(2).padStart(10, "0")
58 .replace(/^([0-9]{5})/, '$1x')
59 .replace(/0/g, '·')
60 .replace(/1/g, '+');
61 return changeCharColor(str, heat);
Marc Kupietzddaba632017-12-02 17:30:56 +010062 }
Marc Kupietz6e2fc102017-12-01 22:07:23 +010063
Marc Kupietz58270662017-12-04 12:10:06 +010064 % use Mojo::ByteStream 'b';
Marc Kupietz58270662017-12-04 12:10:06 +010065 var paraResults = <%= b(Mojo::JSON::to_json($lists)) %>;
66 var urlprefix = new URLSearchParams(window.location.search);
Marc Kupietz451f8d82017-12-04 13:19:47 +010067 if (paraResults.length > 0 && paraResults[0] != null) {
Marc Kupietz58270662017-12-04 12:10:06 +010068 var nvecs = [],
69 nwords = [],
70 nranks = [],
71 nmarked = [];
72 for(var i = 0; i < paraResults.length; i++) {
73 nwords = nwords.concat(paraResults[i].map(function(a){return a.word;}));
74 nvecs = nvecs.concat(paraResults[i].map(function(a){return a.vector;}));
75 nranks = nranks.concat(paraResults[i].map(function(a){return a.rank;}));
76 nmarked = nmarked.concat(paraResults[i].map(function(a){return a.marked;}));
77 }
Marc Kupietz8f9c86a2017-12-04 17:17:13 +010078 showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: nvecs, ranks: nranks, marked: nmarked} );
Marc Kupietz58270662017-12-04 12:10:06 +010079 var t = $('#firsttable').DataTable({
80 data: paraResults[0],
81 "sScrollY": "780px",
82 "bScrollCollapse": true,
83 "bPaginate": false,
84 "bJQueryUI": true,
85 "dom": '<"top">rt<"bottom"flp><"clear">',
86 "columns": [
87 { "data": "rank", type: "allnumeric" },
88 { "data": "dist", render: function ( data, type, row ) {return data.toFixed(3) }},
89 { "data": "word", render: function ( data, type, row ) {urlprefix.set("word", data); return '<a href="?' + urlprefix + '">' + data + '</a>' }}
90 ],
91 "columnDefs": [
92 { className: "dt-right", "targets": [0,1] },
93 { "searchable": false,
94 "orderable": false,
95 "targets": 0
96 },
97 { "orderSequence": [ "desc" ], "targets": [ 1 ] },
98 { "orderSequence": [ "asc", "desc" ], "targets": [ 2 ] },
99 ],
Marc Kupietzd6b15442017-12-04 13:20:27 +0100100 "oLanguage": {
101 "sSearch": "Filter: "
102 },
Marc Kupietz58270662017-12-04 12:10:06 +0100103 "order": [[ 1, 'desc' ]],
104 } );
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100105
Marc Kupietz58270662017-12-04 12:10:06 +0100106 t.on( 'order.dt search.dt', function () {
107 t.column(0, {order:'applied'}).nodes().each( function (cell, i) {
108 cell.innerHTML = i+1;
109 } );
110 } ).draw();
Marc Kupietzdab9f222017-11-29 14:22:59 +0100111
Marc Kupietz58270662017-12-04 12:10:06 +0100112 $( "#first" ).clone().prependTo( "#tabs-2" );
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100113
Marc Kupietz58270662017-12-04 12:10:06 +0100114 }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100115
Marc Kupietz58270662017-12-04 12:10:06 +0100116 var collocatorData = <%= b(Mojo::JSON::to_json($collocators)) %>;
117 var maxHeat; // = Math.max.apply(Math,collocatorData.map(function(o){return o.cprob;}))
Marc Kupietz3305b0a2017-11-27 10:46:20 +0100118
Marc Kupietz58270662017-12-04 12:10:06 +0100119 if (collocatorData != null) {
120 maxHeat = Math.max.apply(Math,collocatorData.map(function(o){return Math.max.apply(Math,o.heat);}))
121 var t = $('#secondtable').DataTable({
122 data: collocatorData,
123 "sScrollY": "780px",
124 "bScrollCollapse": true,
125 "bPaginate": false,
126 "bJQueryUI": true,
127 "dom": '<"top">rt<"bottom"flp><"clear">',
128 "columns": [
129 { "data": "rank", type: "allnumeric" },
130 { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat) }},
131 { "data": "max", render: function ( data, type, row ) {return data.toFixed(3) }},
132 { "data": "conorm", render: function ( data, type, row ) {return data.toFixed(3) }},
133 { "data": "prob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
134 { "data": "cprob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
135 { "data": "overall", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
136 { "data": "word", sClass: "collocator" }
137 ],
138 "columnDefs": [
139 { className: "dt-right", "targets": [0,2,3,4,5,6] },
140 { className: "dt-center", "targets": [ 1] },
141 { "searchable": false,
142 "orderable": false,
143 "targets": 0
144 },
145 { "type": "scientific", targets: [2,3,4,5,6] },
146 { "orderSequence": [ "desc" ], "targets": [ 2, 3, 4, 5, 6 ] },
147 { "orderSequence": [ "asc", "desc" ], "targets": [ 1, 7 ] },
148 ],
Marc Kupietzd6b15442017-12-04 13:20:27 +0100149 "oLanguage": {
150 "sSearch": "Filter: "
151 },
Marc Kupietz58270662017-12-04 12:10:06 +0100152 "order": [[ 4, 'desc' ]],
153 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100154
Marc Kupietz58270662017-12-04 12:10:06 +0100155 t.on( 'order.dt search.dt', function () {
156 t.column(0, {order:'applied'}).nodes().each( function (cell, i) {
157 cell.innerHTML = i+1;
158 } );
159 } ).draw();
160
Marc Kupietz0ba5c812017-12-06 09:41:25 +0100161 if (localStorage && !window.location.hash) { // let's not crash if some user has IE7
Marc Kupietz58270662017-12-04 12:10:06 +0100162 var index = parseInt(localStorage['tab']||'0');
163 $("#tabs").tabs({ active: index });
164 }
165 }
166 $("#tabs").css("visibility", "visible"); // now we can show the tabs
167
168 });
169
170 $(function(){
171 $("#dropdownoptions").dialog({
172 title: "Options",
173 autoOpen: false,
174 modal: false,
175 draggable: false,
176 height: "auto",
177 width: "auto",
178 resizable: false,
179 buttons: {
180 "Cancel": function() {
181 $( this ).dialog( "close" );
182 },
183 "Apply": function() {
184 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
185 }
186 }
187 });
188 });
189
190 $(function(){
191 $("td.collocator").click(function(){
192 queryKorAPCII(this.textContent + " /w5 " + urlParams.get('word'));
193 });
194 });
195
196 $(function(){
197 $("#showoptions").click(function(){
198 $("#dropdownoptions").dialog("open");
199 var target = $(this);
200 $("#dropdownoptions").dialog("widget").position({
201 my: 'left bottom',
202 at: 'left bottom',
203 of: target
204 });
205 });
206 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100207
208 $( function() {
Marc Kupietz58270662017-12-04 12:10:06 +0100209 $( "#no_iterations" ).spinner({
210 spin: function( event, ui ) {
211 if ( ui.value < 1000 ) {
212 $( this ).spinner( "value", 1000 );
213 return false;
214 } else if ( ui.value > 10000 ) {
215 $( this ).spinner( "value", 10000 );
216 return false;
217 }
218 }
219 });
220 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100221
Marc Kupietz58270662017-12-04 12:10:06 +0100222 $( function() {
223 $( "#neighbours" ).spinner({
224 spin: function( event, ui ) {
225 if ( ui.value < 0 ) {
226 $( this ).spinner( "value", 0 );
227 return false;
228 } else if ( ui.value > 200 ) {
229 $( this ).spinner( "value", 200 );
230 return false;
231 }
232 }
233 });
234 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100235
Marc Kupietz58270662017-12-04 12:10:06 +0100236 $( function() {
237 $( "#cutoff" ).spinner({
238 spin: function( event, ui ) {
239 if ( ui.value < 100000 ) {
240 $( this ).spinner( "value", 100000 );
241 return false;
242 } else if ( ui.value > 2000000 ) {
243 $( this ).spinner( "value", 2000000 );
244 return false;
245 }
246 }
247 });
248 } );
249
250 $( function() {
251 $( "#tabs" ).tabs().addClass('tabs-min');
252 } );
253
254 $( function() {
255 $( ".controlgroup-vertical" ).controlgroup({
256 "direction": "vertical"
257 });
258 } );
259
260 $(function() {
261 $( document ).tooltip({
262 content: function() {
263 return $(this).attr('title');
264 }}
265 )
266 })
Marc Kupietz694610d2017-11-25 18:30:03 +0100267
Marc Kupietz83305222016-04-28 09:57:22 +0200268 </script>
Marc Kupietz58270662017-12-04 12:10:06 +0100269 <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
270 <script src="/derekovecs/js/tsne.js"></script>
271 <script src="/derekovecs/js/som.js"></script>
272 <script src="/derekovecs/js/labeler.js"></script>
Marc Kupietz83305222016-04-28 09:57:22 +0200273 <style>
274 body, input {
Marc Kupietz58270662017-12-04 12:10:06 +0100275 font-family: Lato, sans-serif;
276 font-size: 11pt;
Marc Kupietz83305222016-04-28 09:57:22 +0200277 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100278
Marc Kupietz58270662017-12-04 12:10:06 +0100279 h1, h2, h3 {
280 margin: 5px 10px 0 0;
281 color: rgb(246,168,0);
282 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;
283 font-weight: bold;
284 line-height: 1.35;
285 letter-spacing: normal;
286 text-transform: uppercase;
287 text-shadow: none;
288 word-wrap: break-word;
289 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100290
291
Marc Kupietz58270662017-12-04 12:10:06 +0100292 showoptions, #SEARCH {
293 margin-left: 10px;
294 margin-right: 10px;
295 }
Marc Kupietz6dbadd12017-11-29 16:43:33 +0100296
Marc Kupietz58270662017-12-04 12:10:06 +0100297 .tabs-left-vertical .ui-tabs-nav {
298 position: absolute;
299 width: 21em;
300 transform: translate(-100%,0%) rotate(-90deg);
301 transform-origin: 100% 0%;
302 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100303
Marc Kupietz58270662017-12-04 12:10:06 +0100304 .tabs-left-vertical .ui-tabs-nav li {
305 float: right;
306 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100307
Marc Kupietz58270662017-12-04 12:10:06 +0100308 .tabs-left-vertical .ui-tabs-panel {
309 padding-left: 3.5em;
310 }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100311
Marc Kupietz58270662017-12-04 12:10:06 +0100312 .tabs-left-vertical .ui-tabs-panel {
313 height: 20em;
314 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100315
Marc Kupietz58270662017-12-04 12:10:06 +0100316 .mono {
317 font-family: "DejaVu Sans Mono", Inconsolata, SourceCodePro, Courier;
318 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100319
Marc Kupietz58270662017-12-04 12:10:06 +0100320 .ui-tooltip-content {
321 font-size: 9pt;
322 color: #222222;
323 }
Marc Kupietzf4b49392016-04-28 10:49:56 +0200324
Marc Kupietz58270662017-12-04 12:10:06 +0100325 svg > .ui-tooltip-content {
326 font-size: 8pt;
327 color: #222222;
328 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100329
Marc Kupietz58270662017-12-04 12:10:06 +0100330 a.merged {
331 color: green;
332 fill: green;
333 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100334
Marc Kupietz58270662017-12-04 12:10:06 +0100335 #first a {
336 text-decoration: none;
337 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100338
Marc Kupietz58270662017-12-04 12:10:06 +0100339 a.marked, #first a.marked {
340 text-decoration: underline;
341 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100342
Marc Kupietz58270662017-12-04 12:10:06 +0100343 a.target {
344 color: red;
345 fill: red;
346 }
Marc Kupietz694610d2017-11-25 18:30:03 +0100347
Marc Kupietz58270662017-12-04 12:10:06 +0100348 table.display {
349 width: 40% important!;
350 margin: 1; /* <- works for me this way ****/
351 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100352
Marc Kupietz58270662017-12-04 12:10:06 +0100353 table.dataTable thead th, table.dataTable thead td, table.dataTable tbody td {
354 padding: 2px 2px;
355 // border-bottom: 1px solid #111;
356 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100357
Marc Kupietz58270662017-12-04 12:10:06 +0100358 #collocators {
359 margin-bottom: 15px;
360 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100361
Marc Kupietz58270662017-12-04 12:10:06 +0100362 #header {
363 width: 100%;
364 // border: 1px solid red;
365 overflow: hidden; /* will contain if #first is longer than #second */
366 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100367
Marc Kupietz58270662017-12-04 12:10:06 +0100368 #topwrapper {
369 width: 100%;
370 // border: 1px solid red;
371 overflow: hidden; /* will contain if #first is longer than #second */
372 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100373
Marc Kupietz58270662017-12-04 12:10:06 +0100374 #wrapper {
375 // border: 1px solid red;
376 overflow: hidden; /* will contain if #first is longer than #second */
377 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100378
Marc Kupietz58270662017-12-04 12:10:06 +0100379 #pagetitle {
380 max-width: 460px;
381 margin-right: 20px;
382 float: left;
383 overflow: hidden; /* if you don't want #second to wrap below #first */
384 // border: 1px solid green;
385 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100386
Marc Kupietz58270662017-12-04 12:10:06 +0100387 #options {
388 float: left;
389 width: 800px;
390 margin: 10px;
391 overflow: hidden; /* if you don't want #second to wrap below #first */
392 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100393
Marc Kupietz58270662017-12-04 12:10:06 +0100394 #word {
395 width: 50%;
396 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100397
Marc Kupietz58270662017-12-04 12:10:06 +0100398 #first {
399 margin-right: 20px;
400 float: left;
401 overflow: hidden; /* if you don't want #second to wrap below #first */
402 // border: 1px solid green;
403 }
404 #tabs {
405 margin-right: 20px;
406 overflow: hidden; /* if you don't want #second to wrap below #first */
407 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100408
Marc Kupietz58270662017-12-04 12:10:06 +0100409 .tabs-min {
410 background: transparent;
411 border: none;
412 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100413
Marc Kupietz58270662017-12-04 12:10:06 +0100414 .tabs-min .ui-widget-header {
415 background: transparent;
416 border: none;
417 border-bottom: 1px solid #c0c0c0;
418 -moz-border-radius: 0px;
419 -webkit-border-radius: 0px;
420 border-radius: 0px;
421 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100422
Marc Kupietz58270662017-12-04 12:10:06 +0100423 .tabs-min .ui-tabs-nav .ui-state-default {
424 background: transparent;
425 border: none;
426 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100427
Marc Kupietz58270662017-12-04 12:10:06 +0100428 .tabs-min .ui-tabs-nav .ui-state-active {
429 background: transparent url(derekovecs/img/uiTabsArrow.png) no-repeat bottom center;
430 border: none;
431 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100432
Marc Kupietz58270662017-12-04 12:10:06 +0100433 .tabs-min .ui-tabs-nav .ui-state-default a {
434 color: #c0c0c0;
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 a {
438 color: rgb(246,168,0);
439 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100440
Marc Kupietz58270662017-12-04 12:10:06 +0100441 #embed {
442 max-width: 802px;
443 border: 1px solid #333;
444 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100445
Marc Kupietz58270662017-12-04 12:10:06 +0100446 #second {
447 min-width: 800px;
448 // border: 1px solid #333;
449 overflow: hidden; /* if you don't want #second to wrap below #first */
450 }
451 #som2 svg {
452 border: 1px solid #333;
453 }
Marc Kupietz83305222016-04-28 09:57:22 +0200454
Marc Kupietz58270662017-12-04 12:10:06 +0100455 #cost {
456 font-size: 8pt;
457 color: #222222;
458 margin-top: 4px;
459 margin-bottom: 12px;
460 }
Marc Kupietz83305222016-04-28 09:57:22 +0200461
Marc Kupietz58270662017-12-04 12:10:06 +0100462 #sominfo1, #sominfo {
463 font-size: 8pt;
464 color: #222222;
465 margin-top: 0px;
466 }
Marc Kupietz83305222016-04-28 09:57:22 +0200467
Marc Kupietz58270662017-12-04 12:10:06 +0100468 #somcolor1, #somcolor2, #somcolor3 {
469 display: inline-block;
470 height: 10px;
471 width: 10px;
472 }
Marc Kupietz83305222016-04-28 09:57:22 +0200473
Marc Kupietz58270662017-12-04 12:10:06 +0100474 #third {
475 border: 1px solid #333;
476 }
Marc Kupietz83305222016-04-28 09:57:22 +0200477
478 </style>
479 <script>
480
481 var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>},
Marc Kupietz58270662017-12-04 12:10:06 +0100482 mapWidth = 800, // width map
483 mapHeight = 800,
484 jitterRadius = 7;
Marc Kupietz83305222016-04-28 09:57:22 +0200485
486 var T = new tsnejs.tSNE(opt); // create a tSNE instance
487
488 var Y;
489
490 var data;
491 var labeler;
492
493 function applyJitter() {
Marc Kupietz58270662017-12-04 12:10:06 +0100494 svg.selectAll('.tsnet')
495 .data(labels)
496 .transition()
497 .duration(50)
498 .attr("transform", function(d, i) {
499 T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20;
500 T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20;
501 return "translate(" +
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100502 (d.x) + "," +
503 (d.y) + ")";
Marc Kupietz58270662017-12-04 12:10:06 +0100504 });
Marc Kupietz83305222016-04-28 09:57:22 +0200505 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100506
Marc Kupietz83305222016-04-28 09:57:22 +0200507 function updateEmbedding() {
Marc Kupietz58270662017-12-04 12:10:06 +0100508 var Y = T.getSolution();
509 svg.selectAll('.tsnet')
510 .data(data.words)
511 .attr("transform", function(d, i) {
512 return "translate(" +
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100513 ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," +
514 ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; });
Marc Kupietz83305222016-04-28 09:57:22 +0200515 }
516
517 var svg;
518 var labels = [];
519 var anchor_array = [];
520 var text;
521
522 function drawEmbedding() {
Marc Kupietz58270662017-12-04 12:10:06 +0100523 var urlprefix = new URLSearchParams(window.location.search);
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100524 urlprefix.delete("word");
525 urlprefix.append("word","");
526
Marc Kupietz58270662017-12-04 12:10:06 +0100527 $("#embed").empty();
528 var div = d3.select("#embed");
Marc Kupietz34c08172017-11-29 17:08:47 +0100529
Marc Kupietz58270662017-12-04 12:10:06 +0100530 // get min and max in each column of Y
531 var Y = T.Y;
Marc Kupietz34c08172017-11-29 17:08:47 +0100532
Marc Kupietz58270662017-12-04 12:10:06 +0100533 svg = div.append("svg") // svg is global
534 .attr("width", mapWidth)
535 .attr("height", mapHeight);
Marc Kupietz34c08172017-11-29 17:08:47 +0100536
Marc Kupietz58270662017-12-04 12:10:06 +0100537 var g = svg.selectAll(".b")
538 .data(data.words)
539 .enter().append("g")
540 .attr("class", "tsnet");
Marc Kupietz34c08172017-11-29 17:08:47 +0100541
Marc Kupietz58270662017-12-04 12:10:06 +0100542 g.append("a")
543 .attr("xlink:href", function(word) {
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100544 return "?"+urlprefix+word; })
Marc Kupietz58270662017-12-04 12:10:06 +0100545 .attr("class", function(d, i) {
546 var res="";
547 if(data.marked[i]) {
548 res="marked ";
549 }
550 if(data.target.indexOf(" "+d+" ") >= 0) {
551 return res+"target";
552 } else if(data.ranks[i] < data.mergedEnd) {
553 return res+"merged";
554 } else {
555 return res;
556 }
557 })
558 .attr("title", function(d, i) {
559 if(data.mergedEnd > 0) {
560 if(data.ranks[i] >= data.mergedEnd) {
561 return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
562 } else {
563 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
564 }
565 } else {
566 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
567 }
568 })
569 .append("text")
570 .attr("text-anchor", "top")
571 .attr("font-size", 12)
572 .text(function(d) { return d; });
Marc Kupietz34c08172017-11-29 17:08:47 +0100573
Marc Kupietz58270662017-12-04 12:10:06 +0100574 var zoomListener = d3.behavior.zoom()
575 .scaleExtent([0.1, 10])
576 .center([0,0])
577 .on("zoom", zoomHandler);
578 zoomListener(svg);
Marc Kupietz83305222016-04-28 09:57:22 +0200579 }
580
581 var tx=0, ty=0;
582 var ss=1;
583 var iter_id=-1;
584
585 function zoomHandler() {
Marc Kupietz58270662017-12-04 12:10:06 +0100586 tx = d3.event.translate[0];
587 ty = d3.event.translate[1];
588 ss = d3.event.scale;
589 updateEmbedding();
Marc Kupietz83305222016-04-28 09:57:22 +0200590 }
591
592 var stepnum = 0;
593
594 function stopStep() {
Marc Kupietz58270662017-12-04 12:10:06 +0100595 clearInterval(iter_id);
596 text = svg.selectAll("text");
Marc Kupietz34c08172017-11-29 17:08:47 +0100597
Marc Kupietz58270662017-12-04 12:10:06 +0100598 // jitter function needs different data and co-ordinate representation
599 labels = d3.range(data.words.length).map(function(i) {
600 var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2;
601 var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2;
602 anchor_array.push({x: x, y: y, r: jitterRadius});
603 return {
604 x: x,
605 y: y,
606 name: data.words[i]
607 };
608 });
Marc Kupietz34c08172017-11-29 17:08:47 +0100609
Marc Kupietz58270662017-12-04 12:10:06 +0100610 // get the actual label bounding boxes for the jitter function
611 var index = 0;
612 text.each(function() {
613 labels[index].width = this.getBBox().width;
614 labels[index].height = this.getBBox().height;
615 index += 1;
616 });
Marc Kupietz83305222016-04-28 09:57:22 +0200617
Marc Kupietz34c08172017-11-29 17:08:47 +0100618
Marc Kupietz58270662017-12-04 12:10:06 +0100619 // setTimeout(updateEmbedding, 1);
620 // setTimeout(
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100621 labeler = d3.labeler()
622 .label(labels)
623 .anchor(anchor_array)
624 .width(mapWidth)
625 .height(mapHeight)
626 .update(applyJitter);
Marc Kupietz58270662017-12-04 12:10:06 +0100627 // .start(1000);
Marc Kupietz83305222016-04-28 09:57:22 +0200628
Marc Kupietz58270662017-12-04 12:10:06 +0100629 iter_id = setInterval(jitterStep, 1);
Marc Kupietz83305222016-04-28 09:57:22 +0200630 }
631
632 var jitter_i=0;
633
634 function jitterStep() {
Marc Kupietz58270662017-12-04 12:10:06 +0100635 if(jitter_i++ > 100) {
636 clearInterval(iter_id);
637 } else {
638 labeler.start2(10);
639 applyJitter();
640 }
Marc Kupietz83305222016-04-28 09:57:22 +0200641 }
642
643 var last_cost=1000;
644
645 function step() {
Marc Kupietz58270662017-12-04 12:10:06 +0100646 var i = T.iter;
Marc Kupietz34c08172017-11-29 17:08:47 +0100647
Marc Kupietz58270662017-12-04 12:10:06 +0100648 if(i > <%= $no_iterations %>) {
649 stopStep();
650 } else {
651 var cost = Math.round(T.step() * 100000) / 100000; // do a few steps
652 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5));
653 if(i % 250 == 0 && cost >= last_cost) {
654 stopStep();
655 } else {
656 last_cost = cost;
657 updateEmbedding();
658 }
659 }
Marc Kupietz83305222016-04-28 09:57:22 +0200660 }
661
662 function showMap(j) {
Marc Kupietz58270662017-12-04 12:10:06 +0100663 data=j;
664 T.iter=0;
665 T.initDataRaw(data.vecs); // init embedding
666 drawEmbedding(); // draw initial embedding
Marc Kupietz78114532017-11-29 17:00:16 +0100667
Marc Kupietz58270662017-12-04 12:10:06 +0100668 if(iter_id >= 0) {
669 clearInterval(iter_id);
670 }
671 //T.debugGrad();
672 iter_id = setInterval(step, 1);
673 if(true) { // (<%= $show_som %>) {
674 makeSOM(j, <%= $no_iterations %>);
675 }
Marc Kupietz83305222016-04-28 09:57:22 +0200676 }
Marc Kupietz39179ab2017-07-04 16:28:06 +0200677 var queryword;
678
679 function onload() {
Marc Kupietz58270662017-12-04 12:10:06 +0100680 queryword = document.getElementById('word');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200681 }
682
683 function queryKorAP() {
Marc Kupietz58270662017-12-04 12:10:06 +0100684 window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200685 }
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100686
687 function queryKorAPCII(query) {
Marc Kupietz58270662017-12-04 12:10:06 +0100688 window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP');
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100689 }
Marc Kupietz83305222016-04-28 09:57:22 +0200690 </script>
691 </head>
Marc Kupietz39179ab2017-07-04 16:28:06 +0200692 <body onload="onload()">
Marc Kupietz58270662017-12-04 12:10:06 +0100693 <div id="header">
694 <div id="pagetitle">
695 <h1>DeReKo-Vectors</h1>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100696 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100697 <div id="options" class="widget">
698 <form id="queryform">
699 <input id="word" type="text" name="word" placeholder="Word(s) to be searched" value="<%= $word %>"
700 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."/>
701 <input id="SEARCH" type="button" value="SEARCH">
702 <input type="button" id="showoptions" name="showoptions" value="Options" />
703 </form>
704 <div id="dropdownoptions" style="display: none">
705 <form id="optionsform">
706 <div class="controlgroup-vertical">
707 <label for="cutoff">cut-off</label>
708 <input id="cutoff" type="text" name="cutoff" size="10" value="<%= $cutoff %>" title="Only consider the most frequent x word forms.">
709 <label for="dedupe">dedupe</label>
710 <input id="dedupe" type="checkbox" name="dedupe" value="1" <%= ($dedupe ? "checked" : "") %> title="radically filter out any near-duplicates">
711 % if($mergedEnd > 0) {
712 <label for="sbf">backw.</label>
713 <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.">
714 % }
715 <label for="neighbours">max. neighbours:</label>
716 <input id="neighbours" size="4" name="n" value="<%= $no_nbs %>">
717 <label for="no_iterations">max. iterations</label>
718 <input id="no_iterations" name="N" size="4" value="<%= $no_iterations %>">
719 <!-- <label for="dosom">SOM</label>
720 <input id="dosom" type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> -->
721 % if($collocators) {
722 <label for="sortby">window/sort</label>
723 <select id="sortby" name="sort">
724 <option value="0" <%= ($sort!=1 && $sort!=2? "selected":"") %>>auto focus</option>
725 <!-- <option value="1" <%= ($sort==1? "selected":"") %>>any single position</option>
726 <option value="2" <%= ($sort==2? "selected":"") %>>whole window</option> -->
727 </select>
728 % }
729 <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/>
730 </div>
731 </form>
732 </div>
733 </div>
734 </div>
735 <div id="topwrapper">
736 <div style="visibility: hidden;" id="tabs">
737 <ul>
738 <li><a href="#tabs-1">Semantics (TSNE-map)</a></li>
739 <li><a href="#tabs-2">Semantics (SOM)</a></li>
740 <li><a href="#tabs-3">Syntagmatic (collocators)</a></li>
741 </ul>
742 <div id="tabs-1">
743 % if($lists && (@$lists) > 0 && (@$lists)[0]) {
744 <div id="wrapper">
745 <div id="first" style="width: 320px">
746 <table class="display compact nowrap" id="firsttable">
747 <thead>
748 <tr>
749 <th align="right">#</th><th align="right">cos</th><th align="left">similars</th>
750 </tr>
751 </thead>
752 <tbody>
753 <tr>
754 <td align="right">
755 </td>
756 <td align="right">
757 </td>
758 <td></td>
759 </tr>
760 </tbody>
761 </table>
762 </div>
763 <script>
764 </script>
765 <div id="second">
766 <div id="embed">
767 </div>
768 <div id="cost">
769 </div>
770 </div>
771 </div>
772 % } elsif($word !~ /^\s*$/) {
773 <div id="wrapper">
774 <div id="not-found-dialog" title="Not found">
775 <p>ERROR: "<%= $word %>" not found in vocabluary.</p>
776 <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>
777 </div>
778 <script>
779 $( function() {
780 $( "#not-found-dialog" ).dialog({
781 autoOpen: true,
782 modal: true,
783 draggable: false,
784 height: "auto",
785 width: "auto",
786 resizable: false,
787 buttons: {
788 "OK": function() {
789 $( this ).dialog( "close" );
790 },
791 "Apply": function() {
792 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
793 }
794 }
795 });
796 });
797 </script>
798 </div>
799 % }
800 </div>
801 <div id="tabs-2">
802 <div id="som2" style="width: 800; height: 800px">
803 </div>
804 <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div>
805 <div id="sominfo">SOM iteration <span id="iterations">0</span></div>
806 </div>
807 <div id="tabs-3">
808 <div style="width: 800px" id="secondt">
809 <table class="display compact nowrap" id="secondtable">
810 <thead>
811 <tr>
812 % if($collocators) {
813 <th>#</th>
814 <th align="center" title="The columns (c) around the target are considered for summation are marked with *.">w'</th>
815 <th align="right" title="Raw (max.) activation of the collocator in the output layers.">max(a)</th>
816 <th title="Co-normalized raw activation sum of the collocator in the selected columns." align="right">⊥Σa</th>
817 <th title="Sum of activations over the selected colunns normalized by the total activation sum of the selected columns." align="right">Σa/Σc</th>
818 <th title="Sum of the column normalized activations over the selected colunns." align="right">Σ(a/c)</th>
819 <th title="Sum of the activations over the whole window normalized by the total window sum (no auto-focus)." align="right">Σa/Σw</th>
820 <th align="left">collocator</th>
821 % }
822 </tr>
823 </thead>
824 <tbody>
825 <tr>
826 <td align="right">
827 </td>
828 <td align="right">
829 </td>
830 <td align="right">
831 </td>
832 <td align="right">
833 </td>
834 <td align="right">
835 </td>
836 <td align="right">
837 </td>
838 <script
839 src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
840 </td>
841 </tr>
842 </tbody>
843 </table>
844 </div> <!-- - tab2 -->
845 </div> <!-- tabs -->
846 </div>
847 </div> <!-- topwrapper -->
848 <div style="clear: both;"></div>
849 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100850 % if($training_args) {
851 <p>
852 Word vector model trained with <a href="https://code.google.com/p/word2vec/">word2vec</a> using the following parameters: <pre><%= $training_args %></pre>
853 </p>
Marc Kupietz83305222016-04-28 09:57:22 +0200854 % }
Marc Kupietz58270662017-12-04 12:10:06 +0100855 </body>
Marc Kupietz83305222016-04-28 09:57:22 +0200856</html>