blob: 6fa42103ef2077c7de73d5936c5faf56c1f0b0f2 [file] [log] [blame]
Marc Kupietz83305222016-04-28 09:57:22 +02001<!DOCTYPE html>
2<html>
3 <head>
4 <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 Kupietz6dbadd12017-11-29 16:43:33 +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 Kupietz4abcd682017-11-28 20:51:08 +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>
Marc Kupietz22796142017-12-01 13:19:15 +010010 <script src = "https://cdn.datatables.net/plug-ins/1.10.16/sorting/scientific.js"></script>
Marc Kupietz4abcd682017-11-28 20:51:08 +010011 <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 Kupietz6dbadd12017-11-29 16:43:33 +010013 src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
Marc Kupietzb6c615d2017-12-02 10:38:20 +010014 integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
15 crossorigin="anonymous"></script>
Marc Kupietz80bd7b92017-07-04 16:25:54 +020016 <script>
Marc Kupietza6e08f02017-12-01 22:06:21 +010017 var urlParams = new URLSearchParams(window.location.search);
18
Marc Kupietz4abcd682017-11-28 20:51:08 +010019 $('#firstable').hide();
20 $(document).ready(function() {
Marc Kupietz694610d2017-11-25 18:30:03 +010021
Marc Kupietzb6c615d2017-12-02 10:38:20 +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 Kupietzb2b7aa62017-12-02 14:41:46 +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 Kupietz896c9092017-12-02 14:40:43 +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 Kupietzb6c615d2017-12-02 10:38:20 +010043 $('#firsttable').DataTable({
44 "sScrollY": "780px",
45 "bScrollCollapse": true,
46 "bPaginate": false,
47 "bJQueryUI": true,
48 "dom": '<"top">rt<"bottom"flp><"clear">',
49 "aoColumnDefs": [
50 { "sWidth": "10%", "aTargets": [ -1 ] }
51 ]
52 } );
53
54 $( "#first" ).clone().prependTo( "#tabs-2" );
55
56 function changeCharColor(txt, heat) {
57 var newText = "";
58 for (var i=0, l=txt.length; i<l; i++) {
Marc Kupietz728b8ed2017-12-02 11:13:49 +010059 newText += (i == 5 ? txt.charAt(i) : '<span style="background-color:'+getHeatColor(heat[i]/maxHeat)+'">'+txt.charAt(i)+'</span>');
Marc Kupietzb6c615d2017-12-02 10:38:20 +010060 }
61 return newText;
62 }
63
64 function getHeatColor(value) {
65 var hue=((1-value)*120).toString(10);
Marc Kupietz728b8ed2017-12-02 11:13:49 +010066 return ["hsl(",hue,",90%,70%)"].join("");
Marc Kupietzb6c615d2017-12-02 10:38:20 +010067 }
68
69 function bitvec2window(n, heat) {
70 var str = n.toString(2).padStart(10, "0")
71 .replace(/^([0-9]{5})/, '$1x')
72 .replace(/0/g, '·')
73 .replace(/1/g, '+');
74 return changeCharColor(str, heat);
75 }
76
77 var collocatorData = <%= b(Mojo::JSON::to_json($collocators)) %>;
78 var maxHeat; // = Math.max.apply(Math,collocatorData.map(function(o){return o.cprob;}))
Marc Kupietzb6c615d2017-12-02 10:38:20 +010079
80 if (collocatorData != null) {
Marc Kupietz896c9092017-12-02 14:40:43 +010081 maxHeat = Math.max.apply(Math,collocatorData.map(function(o){return Math.max.apply(Math,o.heat);}))
Marc Kupietzb6c615d2017-12-02 10:38:20 +010082 var t = $('#secondtable').DataTable({
83 data: collocatorData,
84 "sScrollY": "800px",
85 "bScrollCollapse": true,
86 "bPaginate": false,
87 "bJQueryUI": true,
88 "dom": '<"top">rt<"bottom"flp><"clear">',
89 "columns": [
90 { "data": "rank", type: "allnumeric" },
91 { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat) }},
92 { "data": "max", render: function ( data, type, row ) {return data.toFixed(3) }},
93 { "data": "conorm", render: function ( data, type, row ) {return data.toFixed(3) }},
94 { "data": "prob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
95 { "data": "cprob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
96 { "data": "overall", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
97 { "data": "word", sClass: "collocator" }
98 ],
99 "columnDefs": [
100 { className: "dt-right", "targets": [0,2,3,4,5,6] },
101 { className: "dt-center", "targets": [ 1] },
102 { "searchable": false,
103 "orderable": false,
104 "targets": 0
105 },
106 { "type": "scientific", targets: [2,3,4,5,6] },
107 { "orderSequence": [ "desc" ], "targets": [ 2, 3, 4, 5, 6 ] },
108 { "orderSequence": [ "asc", "desc" ], "targets": [ 1, 7 ] },
109 ],
110 "order": [[ 4, 'desc' ]],
Marc Kupietz4abcd682017-11-28 20:51:08 +0100111 } );
Marc Kupietz0af83e32017-11-27 09:31:37 +0100112
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100113 t.on( 'order.dt search.dt', function () {
114 t.column(0, {order:'applied'}).nodes().each( function (cell, i) {
115 cell.innerHTML = i+1;
116 } );
117 } ).draw();
Marc Kupietzddaba632017-12-02 17:30:56 +0100118
119 if (localStorage) { // let's not crash if some user has IE7
120 var index = parseInt(localStorage['tab']||'0');
121 $("#tabs").tabs({ active: index });
122 }
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100123 }
124 $("#tabs").css("visibility", "visible"); // now we can show the tabs
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100125
Marc Kupietz4abcd682017-11-28 20:51:08 +0100126 });
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100127
Marc Kupietzdab9f222017-11-29 14:22:59 +0100128 $(function(){
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100129 $("#dropdownoptions").dialog({
130 title: "Options",
131 autoOpen: false,
132 modal: false,
133 draggable: false,
134 height: "auto",
135 width: "auto",
136 resizable: false,
137 buttons: {
138 "Cancel": function() {
139 $( this ).dialog( "close" );
140 },
141 "Apply": function() {
Marc Kupietzdab9f222017-11-29 14:22:59 +0100142 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100143 }
144 }
145 });
Marc Kupietzdab9f222017-11-29 14:22:59 +0100146 });
147
148 $(function(){
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100149 $("td.collocator").click(function(){
150 queryKorAPCII(this.textContent + " /w5 " + urlParams.get('word'));
151 });
152 });
153
154 $(function(){
155 $("#showoptions").click(function(){
156 $("#dropdownoptions").dialog("open");
157 var target = $(this);
158 $("#dropdownoptions").dialog("widget").position({
159 my: 'left bottom',
160 at: 'left bottom',
161 of: target
Marc Kupietzdab9f222017-11-29 14:22:59 +0100162 });
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100163 });
Marc Kupietzdab9f222017-11-29 14:22:59 +0100164 });
165
Marc Kupietz4abcd682017-11-28 20:51:08 +0100166 $( function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100167 $( "#no_iterations" ).spinner({
168 spin: function( event, ui ) {
169 if ( ui.value < 1000 ) {
170 $( this ).spinner( "value", 1000 );
171 return false;
172 } else if ( ui.value > 10000 ) {
173 $( this ).spinner( "value", 10000 );
174 return false;
175 }
176 }
177 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100178 } );
Marc Kupietz3305b0a2017-11-27 10:46:20 +0100179
Marc Kupietz4abcd682017-11-28 20:51:08 +0100180 $( function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100181 $( "#neighbours" ).spinner({
182 spin: function( event, ui ) {
183 if ( ui.value < 0 ) {
184 $( this ).spinner( "value", 0 );
185 return false;
186 } else if ( ui.value > 200 ) {
187 $( this ).spinner( "value", 200 );
188 return false;
189 }
190 }
191 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100192 } );
193
194 $( function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100195 $( "#cutoff" ).spinner({
196 spin: function( event, ui ) {
197 if ( ui.value < 100000 ) {
198 $( this ).spinner( "value", 100000 );
199 return false;
200 } else if ( ui.value > 2000000 ) {
201 $( this ).spinner( "value", 2000000 );
202 return false;
203 }
204 }
205 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100206 } );
207
208 $( function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100209 $( "#tabs" ).tabs().addClass('tabs-min');
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100210 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100211
212 $( function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100213 $( ".controlgroup-vertical" ).controlgroup({
214 "direction": "vertical"
215 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100216 } );
217
218 $(function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100219 $( document ).tooltip({
220 content: function() {
221 return $(this).attr('title');
222 }}
223 )
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100224 })
Marc Kupietz694610d2017-11-25 18:30:03 +0100225
Marc Kupietz83305222016-04-28 09:57:22 +0200226 </script>
227 <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
Marc Kupietz554aff52017-11-09 14:42:09 +0100228 <script src="/derekovecs/js/tsne.js"></script>
229 <script src="/derekovecs/js/som.js"></script>
230 <script src="/derekovecs/js/labeler.js"></script>
Marc Kupietz83305222016-04-28 09:57:22 +0200231 <style>
232 body, input {
Marc Kupietz6dbadd12017-11-29 16:43:33 +0100233 font-family: Lato, sans-serif;
Marc Kupietz83305222016-04-28 09:57:22 +0200234 font-size: 11pt;
235 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100236
Marc Kupietz6dbadd12017-11-29 16:43:33 +0100237 h1, h2, h3 {
238 margin: 5px 10px 0 0;
239 color: rgb(246,168,0);
240 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;
241 font-weight: bold;
242 line-height: 1.35;
243 letter-spacing: normal;
244 text-transform: uppercase;
245 text-shadow: none;
Marc Kupietz34c08172017-11-29 17:08:47 +0100246 word-wrap: break-word;
247 }
248
249
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100250 showoptions, #SEARCH {
251 margin-left: 10px;
252 margin-right: 10px;
Marc Kupietz6dbadd12017-11-29 16:43:33 +0100253 }
254
Marc Kupietzdab9f222017-11-29 14:22:59 +0100255 .tabs-left-vertical .ui-tabs-nav {
256 position: absolute;
257 width: 21em;
258 transform: translate(-100%,0%) rotate(-90deg);
259 transform-origin: 100% 0%;
260 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100261
Marc Kupietzdab9f222017-11-29 14:22:59 +0100262 .tabs-left-vertical .ui-tabs-nav li {
263 float: right;
264 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100265
Marc Kupietzdab9f222017-11-29 14:22:59 +0100266 .tabs-left-vertical .ui-tabs-panel {
267 padding-left: 3.5em;
268 }
269
270 .tabs-left-vertical .ui-tabs-panel {
271 height: 20em;
Marc Kupietz34c08172017-11-29 17:08:47 +0100272 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100273
Marc Kupietz34c08172017-11-29 17:08:47 +0100274 .mono {
275 font-family: "DejaVu Sans Mono", Inconsolata, SourceCodePro, Courier;
276 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100277
Marc Kupietz34c08172017-11-29 17:08:47 +0100278 .ui-tooltip-content {
279 font-size: 9pt;
280 color: #222222;
281 }
Marc Kupietzf4b49392016-04-28 10:49:56 +0200282
Marc Kupietz34c08172017-11-29 17:08:47 +0100283 svg > .ui-tooltip-content {
284 font-size: 8pt;
285 color: #222222;
286 }
287
288 a.merged {
289 color: green;
290 fill: green;
291 }
292
293 #first a {
294 text-decoration: none;
295 }
296
297 a.marked, #first a.marked {
298 text-decoration: underline;
299 }
300
301 a.target {
302 color: red;
303 fill: red;
304 }
Marc Kupietz694610d2017-11-25 18:30:03 +0100305
Marc Kupietz4abcd682017-11-28 20:51:08 +0100306 table.display {
307 width: 40% important!;
308 margin: 1; /* <- works for me this way ****/
309 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100310
Marc Kupietz4abcd682017-11-28 20:51:08 +0100311 table.dataTable thead th, table.dataTable thead td, table.dataTable tbody td {
312 padding: 2px 2px;
313 // border-bottom: 1px solid #111;
314 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100315
Marc Kupietz34c08172017-11-29 17:08:47 +0100316 #collocators {
317 margin-bottom: 15px;
318 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100319
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100320 #header {
321 width: 100%;
322 // border: 1px solid red;
323 overflow: hidden; /* will contain if #first is longer than #second */
324 }
325
Marc Kupietz34c08172017-11-29 17:08:47 +0100326 #topwrapper {
327 width: 100%;
328 // border: 1px solid red;
329 overflow: hidden; /* will contain if #first is longer than #second */
330 }
331
332 #wrapper {
333 // border: 1px solid red;
334 overflow: hidden; /* will contain if #first is longer than #second */
335 }
336
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100337 #pagetitle {
338 max-width: 460px;
339 margin-right: 20px;
340 float: left;
341 overflow: hidden; /* if you don't want #second to wrap below #first */
342 // border: 1px solid green;
343 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100344
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100345 #options {
346 float: left;
347 width: 800px;
348 margin: 10px;
349 overflow: hidden; /* if you don't want #second to wrap below #first */
350 }
351
352 #word {
353 width: 50%;
354 }
355
Marc Kupietz34c08172017-11-29 17:08:47 +0100356 #first {
357 margin-right: 20px;
358 float: left;
359 overflow: hidden; /* if you don't want #second to wrap below #first */
360 // border: 1px solid green;
361 }
362 #tabs {
363 margin-right: 20px;
364 overflow: hidden; /* if you don't want #second to wrap below #first */
365 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100366
367 .tabs-min {
368 background: transparent;
369 border: none;
370 }
371
372 .tabs-min .ui-widget-header {
373 background: transparent;
374 border: none;
375 border-bottom: 1px solid #c0c0c0;
376 -moz-border-radius: 0px;
377 -webkit-border-radius: 0px;
378 border-radius: 0px;
379 }
380
381 .tabs-min .ui-tabs-nav .ui-state-default {
382 background: transparent;
383 border: none;
384 }
385
386 .tabs-min .ui-tabs-nav .ui-state-active {
387 background: transparent url(img/uiTabsArrow.png) no-repeat bottom center;
388 border: none;
389 }
390
391 .tabs-min .ui-tabs-nav .ui-state-default a {
392 color: #c0c0c0;
393 }
394
395 .tabs-min .ui-tabs-nav .ui-state-active a {
396 color: rgb(246,168,0);
397 }
398
Marc Kupietz4abcd682017-11-28 20:51:08 +0100399 #embed {
400 max-width: 802px;
401 border: 1px solid #333;
402 }
403
Marc Kupietz34c08172017-11-29 17:08:47 +0100404 #second {
405 min-width: 800px;
Marc Kupietzdab9f222017-11-29 14:22:59 +0100406 // border: 1px solid #333;
Marc Kupietz34c08172017-11-29 17:08:47 +0100407 overflow: hidden; /* if you don't want #second to wrap below #first */
408 }
409 #som2 svg {
410 border: 1px solid #333;
411 }
Marc Kupietz83305222016-04-28 09:57:22 +0200412
Marc Kupietz34c08172017-11-29 17:08:47 +0100413 #cost {
414 font-size: 8pt;
415 color: #222222;
416 margin-top: 4px;
417 margin-bottom: 12px;
418 }
Marc Kupietz83305222016-04-28 09:57:22 +0200419
Marc Kupietz34c08172017-11-29 17:08:47 +0100420 #sominfo1, #sominfo {
421 font-size: 8pt;
422 color: #222222;
423 margin-top: 0px;
424 }
Marc Kupietz83305222016-04-28 09:57:22 +0200425
Marc Kupietz34c08172017-11-29 17:08:47 +0100426 #somcolor1, #somcolor2, #somcolor3 {
427 display: inline-block;
428 height: 10px;
429 width: 10px;
430 }
Marc Kupietz83305222016-04-28 09:57:22 +0200431
Marc Kupietz34c08172017-11-29 17:08:47 +0100432 #third {
433 border: 1px solid #333;
434 }
Marc Kupietz83305222016-04-28 09:57:22 +0200435
436 </style>
437 <script>
438
439 var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>},
440 mapWidth = 800, // width map
441 mapHeight = 800,
442 jitterRadius = 7;
443
444 var T = new tsnejs.tSNE(opt); // create a tSNE instance
445
446 var Y;
447
448 var data;
449 var labeler;
450
451 function applyJitter() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100452 svg.selectAll('.tsnet')
453 .data(labels)
454 .transition()
455 .duration(50)
456 .attr("transform", function(d, i) {
457 T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20;
458 T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20;
459 return "translate(" +
460 (d.x) + "," +
461 (d.y) + ")";
462 });
Marc Kupietz83305222016-04-28 09:57:22 +0200463 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100464
Marc Kupietz83305222016-04-28 09:57:22 +0200465 function updateEmbedding() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100466 var Y = T.getSolution();
467 svg.selectAll('.tsnet')
468 .data(data.words)
469 .attr("transform", function(d, i) {
470 return "translate(" +
471 ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," +
472 ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; });
Marc Kupietz83305222016-04-28 09:57:22 +0200473 }
474
475 var svg;
476 var labels = [];
477 var anchor_array = [];
478 var text;
479
480 function drawEmbedding() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100481 $("#embed").empty();
482 var div = d3.select("#embed");
Marc Kupietz34c08172017-11-29 17:08:47 +0100483
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100484 // get min and max in each column of Y
485 var Y = T.Y;
Marc Kupietz34c08172017-11-29 17:08:47 +0100486
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100487 svg = div.append("svg") // svg is global
488 .attr("width", mapWidth)
489 .attr("height", mapHeight);
Marc Kupietz34c08172017-11-29 17:08:47 +0100490
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100491 var g = svg.selectAll(".b")
492 .data(data.words)
493 .enter().append("g")
494 .attr("class", "tsnet");
Marc Kupietz34c08172017-11-29 17:08:47 +0100495
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100496 g.append("a")
497 .attr("xlink:href", function(word) {
498 return (data.urlprefix+word);})
499 .attr("class", function(d, i) {
500 var res="";
501 if(data.marked[i]) {
502 res="marked ";
503 }
504 if(data.target.indexOf(" "+d+" ") >= 0) {
505 return res+"target";
506 } else if(data.ranks[i] < data.mergedEnd) {
507 return res+"merged";
508 } else {
509 return res;
510 }
511 })
512 .attr("title", function(d, i) {
513 if(data.mergedEnd > 0) {
514 if(data.ranks[i] >= data.mergedEnd) {
515 return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
516 } else {
517 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
518 }
519 } else {
520 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
521 }
522 })
523 .append("text")
524 .attr("text-anchor", "top")
525 .attr("font-size", 12)
526 .text(function(d) { return d; });
Marc Kupietz34c08172017-11-29 17:08:47 +0100527
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100528 var zoomListener = d3.behavior.zoom()
529 .scaleExtent([0.1, 10])
530 .center([0,0])
531 .on("zoom", zoomHandler);
532 zoomListener(svg);
Marc Kupietz83305222016-04-28 09:57:22 +0200533 }
534
535 var tx=0, ty=0;
536 var ss=1;
537 var iter_id=-1;
538
539 function zoomHandler() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100540 tx = d3.event.translate[0];
541 ty = d3.event.translate[1];
542 ss = d3.event.scale;
543 updateEmbedding();
Marc Kupietz83305222016-04-28 09:57:22 +0200544 }
545
546 var stepnum = 0;
547
548 function stopStep() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100549 clearInterval(iter_id);
550 text = svg.selectAll("text");
Marc Kupietz34c08172017-11-29 17:08:47 +0100551
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100552 // jitter function needs different data and co-ordinate representation
553 labels = d3.range(data.words.length).map(function(i) {
554 var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2;
555 var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2;
556 anchor_array.push({x: x, y: y, r: jitterRadius});
557 return {
558 x: x,
559 y: y,
560 name: data.words[i]
561 };
562 });
Marc Kupietz34c08172017-11-29 17:08:47 +0100563
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100564 // get the actual label bounding boxes for the jitter function
565 var index = 0;
566 text.each(function() {
567 labels[index].width = this.getBBox().width;
568 labels[index].height = this.getBBox().height;
569 index += 1;
570 });
Marc Kupietz83305222016-04-28 09:57:22 +0200571
Marc Kupietz34c08172017-11-29 17:08:47 +0100572
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100573 // setTimeout(updateEmbedding, 1);
574 // setTimeout(
575 labeler = d3.labeler()
576 .label(labels)
577 .anchor(anchor_array)
578 .width(mapWidth)
579 .height(mapHeight)
580 .update(applyJitter);
581 // .start(1000);
Marc Kupietz83305222016-04-28 09:57:22 +0200582
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100583 iter_id = setInterval(jitterStep, 1);
Marc Kupietz83305222016-04-28 09:57:22 +0200584 }
585
586 var jitter_i=0;
587
588 function jitterStep() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100589 if(jitter_i++ > 100) {
590 clearInterval(iter_id);
591 } else {
592 labeler.start2(10);
593 applyJitter();
594 }
Marc Kupietz83305222016-04-28 09:57:22 +0200595 }
596
597 var last_cost=1000;
598
599 function step() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100600 var i = T.iter;
Marc Kupietz34c08172017-11-29 17:08:47 +0100601
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100602 if(i > <%= $no_iterations %>) {
603 stopStep();
604 } else {
605 var cost = Math.round(T.step() * 100000) / 100000; // do a few steps
606 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5));
607 if(i % 250 == 0 && cost >= last_cost) {
608 stopStep();
Marc Kupietz4abcd682017-11-28 20:51:08 +0100609 } else {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100610 last_cost = cost;
611 updateEmbedding();
Marc Kupietz4abcd682017-11-28 20:51:08 +0100612 }
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100613 }
Marc Kupietz83305222016-04-28 09:57:22 +0200614 }
615
616 function showMap(j) {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100617 data=j;
618 T.iter=0;
619 T.initDataRaw(data.vecs); // init embedding
620 drawEmbedding(); // draw initial embedding
Marc Kupietz78114532017-11-29 17:00:16 +0100621
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100622 if(iter_id >= 0) {
623 clearInterval(iter_id);
624 }
625 //T.debugGrad();
626 iter_id = setInterval(step, 1);
627 if(true) { // (<%= $show_som %>) {
628 makeSOM(j, <%= $no_iterations %>);
629 }
Marc Kupietz83305222016-04-28 09:57:22 +0200630 }
Marc Kupietz39179ab2017-07-04 16:28:06 +0200631 var queryword;
632
633 function onload() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100634 queryword = document.getElementById('word');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200635 }
636
637 function queryKorAP() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100638 window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200639 }
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100640
641 function queryKorAPCII(query) {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100642 window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP');
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100643 }
Marc Kupietz83305222016-04-28 09:57:22 +0200644 </script>
645 </head>
Marc Kupietz39179ab2017-07-04 16:28:06 +0200646 <body onload="onload()">
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100647 <div id="header">
648 <div id="pagetitle">
649 <h1>DeReKo-Vectors</h1>
650 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100651 <div id="options" class="widget">
Marc Kupietzdab9f222017-11-29 14:22:59 +0100652 <form id="queryform">
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100653 <input id="word" type="text" name="word" placeholder="Word(s) to be searched" value="<%= $word %>"
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100654 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."/>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100655 <input id="SEARCH" type="button" value="SEARCH">
656 <input type="button" id="showoptions" name="showoptions" value="Options" />
657 </form>
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100658 <div id="dropdownoptions" style="display: none">
Marc Kupietzdab9f222017-11-29 14:22:59 +0100659 <form id="optionsform">
Marc Kupietz4abcd682017-11-28 20:51:08 +0100660 <div class="controlgroup-vertical">
661 <label for="cutoff">cut-off</label>
662 <input id="cutoff" type="text" name="cutoff" size="10" value="<%= $cutoff %>" title="Only consider the most frequent x word forms.">
663 <label for="dedupe">dedupe</label>
664 <input id="dedupe" type="checkbox" name="dedupe" value="1" <%= ($dedupe ? "checked" : "") %> title="radically filter out any near-duplicates">
665 % if($mergedEnd > 0) {
Marc Kupietz78114532017-11-29 17:00:16 +0100666 <label for="sbf">backw.</label>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100667 <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.">
668 % }
669 <label for="neighbours">max. neighbours:</label>
670 <input id="neighbours" size="4" name="n" value="<%= $no_nbs %>">
Marc Kupietzc1e42c32017-11-29 16:47:56 +0100671 <label for="no_iterations">max. iterations</label>
672 <input id="no_iterations" name="N" size="4" value="<%= $no_iterations %>">
Marc Kupietz78114532017-11-29 17:00:16 +0100673 <!-- <label for="dosom">SOM</label>
674 <input id="dosom" type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> -->
Marc Kupietz4abcd682017-11-28 20:51:08 +0100675 % if($collocators) {
676 <label for="sortby">window/sort</label>
677 <select id="sortby" name="sort">
678 <option value="0" <%= ($sort!=1 && $sort!=2? "selected":"") %>>auto focus</option>
Marc Kupietza77acce2017-11-30 16:59:07 +0100679 <!-- <option value="1" <%= ($sort==1? "selected":"") %>>any single position</option>
680 <option value="2" <%= ($sort==2? "selected":"") %>>whole window</option> -->
Marc Kupietz4abcd682017-11-28 20:51:08 +0100681 </select>
682 % }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100683 <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100684 </div>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100685 </form>
686 </div>
Marc Kupietz0af83e32017-11-27 09:31:37 +0100687 </div>
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100688 </div>
689 <div id="topwrapper">
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100690 <div style="visibility: hidden;" id="tabs">
Marc Kupietz4abcd682017-11-28 20:51:08 +0100691 <ul>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100692 <li><a href="#tabs-1">Semantics (TSNE-map)</a></li>
693 <li><a href="#tabs-2">Semantics (SOM)</a></li>
694 <li><a href="#tabs-3">Syntagmatic (collocators)</a></li>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100695 </ul>
696 <div id="tabs-1">
Marc Kupietzdab9f222017-11-29 14:22:59 +0100697 % if($lists && (@$lists) > 0 && (@$lists)[0]) {
698 <div id="wrapper">
Marc Kupietzaaae0152017-12-01 23:31:56 +0100699 <div id="first" style="width: 320px">
Marc Kupietzdab9f222017-11-29 14:22:59 +0100700 <table class="display compact nowrap" id="firsttable">
701 <thead>
702 <tr>
Marc Kupietzaaae0152017-12-01 23:31:56 +0100703 <th align="right">#</th><th align="right">cos</th><th align="left">similars</th>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100704 </tr>
705 </thead>
706 <tbody>
707 % my $j=0; my @words; my @vecs; my @ranks; my @marked;
708 % for my $list (@$lists) {
709 % my $i=0; while($list) {
710 % my $item = (@$list)[$i];
711 % my $c = ($collocators? (@$collocators)[$i] : 0);
712 % last if(!$c && !$item);
713 <tr>
714 <td align="right">
715 <%= ++$i %>.
716 </td>
717 % if($item) {
Marc Kupietzdab9f222017-11-29 14:22:59 +0100718 <td align="right">
719 <%= sprintf("%.3f", $item->{dist}) %>
720 </td>
721 <td>
Marc Kupietz34c08172017-11-29 17:08:47 +0100722 % my $class = ($marked->{$item->{word}}? "marked " : "");
723 % my $r = $item->{rank};
Marc Kupietzdab9f222017-11-29 14:22:59 +0100724 % if($r < $mergedEnd) {
725 % $class .= "merged";
726 % $r .= " (merged vocab)";
727 % } elsif($mergedEnd!=0 && $r > $mergedEnd) {
728 % $r -= $mergedEnd;
729 % }
730 <a class="<%= $class =%>"
731 title="freq. rank: <%= $r =%>"
732 href="<%= url_with->query([word => $item->{word}]) =%>">
733 <%= $item->{word} =%>
734 </a>
735 </td>
736 % } else {
737 <td colspan="2"/>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100738 % }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100739 </tr>
Marc Kupietzaaae0152017-12-01 23:31:56 +0100740 % last if($i >= $no_nbs);
Marc Kupietzdab9f222017-11-29 14:22:59 +0100741 % }
742 % }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100743 </tbody>
744 </table>
745 </div>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100746 <script>
747 % use Mojo::ByteStream 'b';
748 % my $urlprefix = url_with->query([word=>'']);
749 $(window).load(function() {
Marc Kupietz52a3ec72017-12-02 16:59:56 +0100750 var result = <%= b(Mojo::JSON::to_json($lists)) %>;
751 var nvecs = [],
752 nwords = [],
753 nranks = [],
754 nmarked = [];
755 for(var i = 0; i < result.length; i++) {
756 nwords = nwords.concat(result[i].map(function(a){return a.word;}));
757 nvecs = nvecs.concat(result[i].map(function(a){return a.vector;}));
758 nranks = nranks.concat(result[i].map(function(a){return a.rank;}));
759 nmarked = nmarked.concat(result[i].map(function(a){return a.marked;}));
760 }
761 var urlprefix = new URLSearchParams(window.location.search);
762 urlprefix.set("word","");
763 showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: nvecs, ranks: nranks, marked: nmarked, urlprefix: "?"+urlprefix} );
764 // showMap(<%= b(Mojo::JSON::to_json({target => " $word ", mergedEnd=> $mergedEnd, words => \@words, vecs => \@vecs, ranks => \@ranks, marked => \@marked, urlprefix => "?"+$urlprefix})); %>);
Marc Kupietzdab9f222017-11-29 14:22:59 +0100765 });
766 </script>
Marc Kupietz896c9092017-12-02 14:40:43 +0100767 <div id="second">
768 <div id="embed">
769 </div>
770 <div id="cost">
771 </div>
772 </div>
773 </div>
774 % } elsif($word !~ /^\s*$/) {
775 <div id="wrapper">
776 <div id="not-found-dialog" title="Not found">
777 <p>ERROR: "<%= $word %>" not found in vocabluary.</p>
778 <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>
779 </div>
780 <script>
781 $( function() {
782 $( "#not-found-dialog" ).dialog({
783 autoOpen: true,
784 modal: true,
785 draggable: false,
786 height: "auto",
787 width: "auto",
788 resizable: false,
789 buttons: {
790 "OK": function() {
791 $( this ).dialog( "close" );
792 },
793 "Apply": function() {
794 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100795 }
Marc Kupietz896c9092017-12-02 14:40:43 +0100796 }
Marc Kupietz2f6b74a2017-12-01 13:20:21 +0100797 });
Marc Kupietz896c9092017-12-02 14:40:43 +0100798 });
799 </script>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100800 </div>
801 % }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100802 </div>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100803 <div id="tabs-2">
804 <div id="som2" style="width: 800; height: 800px">
805 </div>
806 <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div>
807 <div id="sominfo">SOM iteration <span id="iterations">0</span></div>
808 </div>
809 <div id="tabs-3">
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100810 <div style="width: 800px" id="secondt">
Marc Kupietz4abcd682017-11-28 20:51:08 +0100811 <table class="display compact nowrap" id="secondtable">
812 <thead>
813 <tr>
814 % if($collocators) {
Marc Kupietzdab9f222017-11-29 14:22:59 +0100815 <th>#</th>
Marc Kupietz22796142017-12-01 13:19:15 +0100816 <th align="center" title="The columns (c) around the target are considered for summation are marked with *.">w'</th>
Marc Kupietzd64f3f22017-11-30 12:07:42 +0100817 <th align="right" title="Raw (max.) activation of the collocator in the output layers.">max(a)</th>
Marc Kupietza77acce2017-11-30 16:59:07 +0100818 <th title="Co-normalized raw activation sum of the collocator in the selected columns." align="right">⊥Σa</th>
819 <th title="Sum of activations over the selected colunns normalized by the total activation sum of the selected columns." align="right">Σa/Σc</th>
820 <th title="Sum of the column normalized activations over the selected colunns." align="right">Σ(a/c)</th>
821 <th title="Sum of the activations over the whole window normalized by the total window sum (no auto-focus)." align="right">Σa/Σw</th>
822 <th align="left">collocator</th>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100823 % }
824 </tr>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100825 </thead>
826 <tbody>
Marc Kupietz22796142017-12-01 13:19:15 +0100827 <tr>
828 <td align="right">
829 </td>
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100830 <td align="right">
831 </td>
832 <td align="right">
833 </td>
834 <td align="right">
835 </td>
836 <td align="right">
837 </td>
838 <td align="right">
839 </td>
840 <td align="right">
841 </td>
842 <td align="left">
843 </td>
Marc Kupietz22796142017-12-01 13:19:15 +0100844 </tr>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100845 </tbody>
846 </table>
847 </div> <!-- - tab2 -->
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100848 </div> <!-- tabs -->
849 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100850 </div> <!-- topwrapper -->
851 <div style="clear: both;"></div>
Marc Kupietz0af83e32017-11-27 09:31:37 +0100852 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100853 % if($training_args) {
854 <p>
855 Word vector model trained with <a href="https://code.google.com/p/word2vec/">word2vec</a> using the following parameters: <pre><%= $training_args %></pre>
856 </p>
Marc Kupietz83305222016-04-28 09:57:22 +0200857 % }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100858 </body>
Marc Kupietz83305222016-04-28 09:57:22 +0200859</html>