blob: 7e5fb951f3169c5284e005280d72c260d7b5746c [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 Kupietzb6c615d2017-12-02 10:38:20 +010033 $(".selector").tabs({ active: 1 });
Marc Kupietz0af83e32017-11-27 09:31:37 +010034
Marc Kupietz2f6b74a2017-12-01 13:20:21 +010035
Marc Kupietzb6c615d2017-12-02 10:38:20 +010036 $('#firsttable').DataTable({
37 "sScrollY": "780px",
38 "bScrollCollapse": true,
39 "bPaginate": false,
40 "bJQueryUI": true,
41 "dom": '<"top">rt<"bottom"flp><"clear">',
42 "aoColumnDefs": [
43 { "sWidth": "10%", "aTargets": [ -1 ] }
44 ]
45 } );
46
47 $( "#first" ).clone().prependTo( "#tabs-2" );
48
49 function changeCharColor(txt, heat) {
50 var newText = "";
51 for (var i=0, l=txt.length; i<l; i++) {
52 newText += '<span style="background-color:'+getHeatColor(heat[i]/maxHeat)+'">'+txt.charAt(i)+'</span>';
53 }
54 return newText;
55 }
56
57 function getHeatColor(value) {
58 var hue=((1-value)*120).toString(10);
59 return ["hsl(",hue,",100%,50%)"].join("");
60 }
61
62 function bitvec2window(n, heat) {
63 var str = n.toString(2).padStart(10, "0")
64 .replace(/^([0-9]{5})/, '$1x')
65 .replace(/0/g, '·')
66 .replace(/1/g, '+');
67 return changeCharColor(str, heat);
68 }
69
70 var collocatorData = <%= b(Mojo::JSON::to_json($collocators)) %>;
71 var maxHeat; // = Math.max.apply(Math,collocatorData.map(function(o){return o.cprob;}))
72 maxHeat = Math.max.apply(Math,collocatorData.map(function(o){return Math.max.apply(Math,o.heat);}))
73
74 if (collocatorData != null) {
75 var t = $('#secondtable').DataTable({
76 data: collocatorData,
77 "sScrollY": "800px",
78 "bScrollCollapse": true,
79 "bPaginate": false,
80 "bJQueryUI": true,
81 "dom": '<"top">rt<"bottom"flp><"clear">',
82 "columns": [
83 { "data": "rank", type: "allnumeric" },
84 { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat) }},
85 { "data": "max", render: function ( data, type, row ) {return data.toFixed(3) }},
86 { "data": "conorm", render: function ( data, type, row ) {return data.toFixed(3) }},
87 { "data": "prob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
88 { "data": "cprob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
89 { "data": "overall", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
90 { "data": "word", sClass: "collocator" }
91 ],
92 "columnDefs": [
93 { className: "dt-right", "targets": [0,2,3,4,5,6] },
94 { className: "dt-center", "targets": [ 1] },
95 { "searchable": false,
96 "orderable": false,
97 "targets": 0
98 },
99 { "type": "scientific", targets: [2,3,4,5,6] },
100 { "orderSequence": [ "desc" ], "targets": [ 2, 3, 4, 5, 6 ] },
101 { "orderSequence": [ "asc", "desc" ], "targets": [ 1, 7 ] },
102 ],
103 "order": [[ 4, 'desc' ]],
Marc Kupietz4abcd682017-11-28 20:51:08 +0100104 } );
Marc Kupietz0af83e32017-11-27 09:31:37 +0100105
Marc Kupietzb6c615d2017-12-02 10:38:20 +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();
111 }
112 $("#tabs").css("visibility", "visible"); // now we can show the tabs
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100113
Marc Kupietz4abcd682017-11-28 20:51:08 +0100114 });
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100115
Marc Kupietzdab9f222017-11-29 14:22:59 +0100116 $(function(){
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100117 $("#dropdownoptions").dialog({
118 title: "Options",
119 autoOpen: false,
120 modal: false,
121 draggable: false,
122 height: "auto",
123 width: "auto",
124 resizable: false,
125 buttons: {
126 "Cancel": function() {
127 $( this ).dialog( "close" );
128 },
129 "Apply": function() {
Marc Kupietzdab9f222017-11-29 14:22:59 +0100130 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100131 }
132 }
133 });
Marc Kupietzdab9f222017-11-29 14:22:59 +0100134 });
135
136 $(function(){
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100137 $("#SEARCH").click(function() {
138 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
139 });
Marc Kupietz22796142017-12-01 13:19:15 +0100140 });
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100141
Marc Kupietz22796142017-12-01 13:19:15 +0100142 $(function(){
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100143 $("td.collocator").click(function(){
144 queryKorAPCII(this.textContent + " /w5 " + urlParams.get('word'));
145 });
146 });
147
148 $(function(){
149 $("#showoptions").click(function(){
150 $("#dropdownoptions").dialog("open");
151 var target = $(this);
152 $("#dropdownoptions").dialog("widget").position({
153 my: 'left bottom',
154 at: 'left bottom',
155 of: target
Marc Kupietzdab9f222017-11-29 14:22:59 +0100156 });
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100157 });
Marc Kupietzdab9f222017-11-29 14:22:59 +0100158 });
159
Marc Kupietz4abcd682017-11-28 20:51:08 +0100160 $( function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100161 $( "#no_iterations" ).spinner({
162 spin: function( event, ui ) {
163 if ( ui.value < 1000 ) {
164 $( this ).spinner( "value", 1000 );
165 return false;
166 } else if ( ui.value > 10000 ) {
167 $( this ).spinner( "value", 10000 );
168 return false;
169 }
170 }
171 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100172 } );
Marc Kupietz3305b0a2017-11-27 10:46:20 +0100173
Marc Kupietz4abcd682017-11-28 20:51:08 +0100174 $( function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100175 $( "#neighbours" ).spinner({
176 spin: function( event, ui ) {
177 if ( ui.value < 0 ) {
178 $( this ).spinner( "value", 0 );
179 return false;
180 } else if ( ui.value > 200 ) {
181 $( this ).spinner( "value", 200 );
182 return false;
183 }
184 }
185 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100186 } );
187
188 $( function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100189 $( "#cutoff" ).spinner({
190 spin: function( event, ui ) {
191 if ( ui.value < 100000 ) {
192 $( this ).spinner( "value", 100000 );
193 return false;
194 } else if ( ui.value > 2000000 ) {
195 $( this ).spinner( "value", 2000000 );
196 return false;
197 }
198 }
199 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100200 } );
201
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100202 var tabactivated = {}
Marc Kupietz4abcd682017-11-28 20:51:08 +0100203 $( function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100204 $( "#tabs" ).tabs().addClass('tabs-min');
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100205 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100206
207 $( function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100208 $( ".controlgroup-vertical" ).controlgroup({
209 "direction": "vertical"
210 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100211 } );
212
213 $(function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100214 $( document ).tooltip({
215 content: function() {
216 return $(this).attr('title');
217 }}
218 )
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100219 })
Marc Kupietz694610d2017-11-25 18:30:03 +0100220
Marc Kupietz83305222016-04-28 09:57:22 +0200221 </script>
222 <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
Marc Kupietz554aff52017-11-09 14:42:09 +0100223 <script src="/derekovecs/js/tsne.js"></script>
224 <script src="/derekovecs/js/som.js"></script>
225 <script src="/derekovecs/js/labeler.js"></script>
Marc Kupietz83305222016-04-28 09:57:22 +0200226 <style>
227 body, input {
Marc Kupietz6dbadd12017-11-29 16:43:33 +0100228 font-family: Lato, sans-serif;
Marc Kupietz83305222016-04-28 09:57:22 +0200229 font-size: 11pt;
230 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100231
Marc Kupietz6dbadd12017-11-29 16:43:33 +0100232 h1, h2, h3 {
233 margin: 5px 10px 0 0;
234 color: rgb(246,168,0);
235 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;
236 font-weight: bold;
237 line-height: 1.35;
238 letter-spacing: normal;
239 text-transform: uppercase;
240 text-shadow: none;
Marc Kupietz34c08172017-11-29 17:08:47 +0100241 word-wrap: break-word;
242 }
243
244
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100245 showoptions, #SEARCH {
246 margin-left: 10px;
247 margin-right: 10px;
Marc Kupietz6dbadd12017-11-29 16:43:33 +0100248 }
249
Marc Kupietzdab9f222017-11-29 14:22:59 +0100250 .tabs-left-vertical .ui-tabs-nav {
251 position: absolute;
252 width: 21em;
253 transform: translate(-100%,0%) rotate(-90deg);
254 transform-origin: 100% 0%;
255 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100256
Marc Kupietzdab9f222017-11-29 14:22:59 +0100257 .tabs-left-vertical .ui-tabs-nav li {
258 float: right;
259 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100260
Marc Kupietzdab9f222017-11-29 14:22:59 +0100261 .tabs-left-vertical .ui-tabs-panel {
262 padding-left: 3.5em;
263 }
264
265 .tabs-left-vertical .ui-tabs-panel {
266 height: 20em;
Marc Kupietz34c08172017-11-29 17:08:47 +0100267 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100268
Marc Kupietz34c08172017-11-29 17:08:47 +0100269 .mono {
270 font-family: "DejaVu Sans Mono", Inconsolata, SourceCodePro, Courier;
271 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100272
Marc Kupietz34c08172017-11-29 17:08:47 +0100273 .ui-tooltip-content {
274 font-size: 9pt;
275 color: #222222;
276 }
Marc Kupietzf4b49392016-04-28 10:49:56 +0200277
Marc Kupietz34c08172017-11-29 17:08:47 +0100278 svg > .ui-tooltip-content {
279 font-size: 8pt;
280 color: #222222;
281 }
282
283 a.merged {
284 color: green;
285 fill: green;
286 }
287
288 #first a {
289 text-decoration: none;
290 }
291
292 a.marked, #first a.marked {
293 text-decoration: underline;
294 }
295
296 a.target {
297 color: red;
298 fill: red;
299 }
Marc Kupietz694610d2017-11-25 18:30:03 +0100300
Marc Kupietz4abcd682017-11-28 20:51:08 +0100301 table.display {
302 width: 40% important!;
303 margin: 1; /* <- works for me this way ****/
304 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100305
Marc Kupietz4abcd682017-11-28 20:51:08 +0100306 table.dataTable thead th, table.dataTable thead td, table.dataTable tbody td {
307 padding: 2px 2px;
308 // border-bottom: 1px solid #111;
309 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100310
Marc Kupietz34c08172017-11-29 17:08:47 +0100311 #collocators {
312 margin-bottom: 15px;
313 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100314
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100315 #header {
316 width: 100%;
317 // border: 1px solid red;
318 overflow: hidden; /* will contain if #first is longer than #second */
319 }
320
Marc Kupietz34c08172017-11-29 17:08:47 +0100321 #topwrapper {
322 width: 100%;
323 // border: 1px solid red;
324 overflow: hidden; /* will contain if #first is longer than #second */
325 }
326
327 #wrapper {
328 // border: 1px solid red;
329 overflow: hidden; /* will contain if #first is longer than #second */
330 }
331
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100332 #pagetitle {
333 max-width: 460px;
334 margin-right: 20px;
335 float: left;
336 overflow: hidden; /* if you don't want #second to wrap below #first */
337 // border: 1px solid green;
338 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100339
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100340 #options {
341 float: left;
342 width: 800px;
343 margin: 10px;
344 overflow: hidden; /* if you don't want #second to wrap below #first */
345 }
346
347 #word {
348 width: 50%;
349 }
350
Marc Kupietz34c08172017-11-29 17:08:47 +0100351 #first {
352 margin-right: 20px;
353 float: left;
354 overflow: hidden; /* if you don't want #second to wrap below #first */
355 // border: 1px solid green;
356 }
357 #tabs {
358 margin-right: 20px;
359 overflow: hidden; /* if you don't want #second to wrap below #first */
360 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100361
362 .tabs-min {
363 background: transparent;
364 border: none;
365 }
366
367 .tabs-min .ui-widget-header {
368 background: transparent;
369 border: none;
370 border-bottom: 1px solid #c0c0c0;
371 -moz-border-radius: 0px;
372 -webkit-border-radius: 0px;
373 border-radius: 0px;
374 }
375
376 .tabs-min .ui-tabs-nav .ui-state-default {
377 background: transparent;
378 border: none;
379 }
380
381 .tabs-min .ui-tabs-nav .ui-state-active {
382 background: transparent url(img/uiTabsArrow.png) no-repeat bottom center;
383 border: none;
384 }
385
386 .tabs-min .ui-tabs-nav .ui-state-default a {
387 color: #c0c0c0;
388 }
389
390 .tabs-min .ui-tabs-nav .ui-state-active a {
391 color: rgb(246,168,0);
392 }
393
Marc Kupietz4abcd682017-11-28 20:51:08 +0100394 #embed {
395 max-width: 802px;
396 border: 1px solid #333;
397 }
398
Marc Kupietz34c08172017-11-29 17:08:47 +0100399 #second {
400 min-width: 800px;
Marc Kupietzdab9f222017-11-29 14:22:59 +0100401 // border: 1px solid #333;
Marc Kupietz34c08172017-11-29 17:08:47 +0100402 overflow: hidden; /* if you don't want #second to wrap below #first */
403 }
404 #som2 svg {
405 border: 1px solid #333;
406 }
Marc Kupietz83305222016-04-28 09:57:22 +0200407
Marc Kupietz34c08172017-11-29 17:08:47 +0100408 #cost {
409 font-size: 8pt;
410 color: #222222;
411 margin-top: 4px;
412 margin-bottom: 12px;
413 }
Marc Kupietz83305222016-04-28 09:57:22 +0200414
Marc Kupietz34c08172017-11-29 17:08:47 +0100415 #sominfo1, #sominfo {
416 font-size: 8pt;
417 color: #222222;
418 margin-top: 0px;
419 }
Marc Kupietz83305222016-04-28 09:57:22 +0200420
Marc Kupietz34c08172017-11-29 17:08:47 +0100421 #somcolor1, #somcolor2, #somcolor3 {
422 display: inline-block;
423 height: 10px;
424 width: 10px;
425 }
Marc Kupietz83305222016-04-28 09:57:22 +0200426
Marc Kupietz34c08172017-11-29 17:08:47 +0100427 #third {
428 border: 1px solid #333;
429 }
Marc Kupietz83305222016-04-28 09:57:22 +0200430
431 </style>
432 <script>
433
434 var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>},
435 mapWidth = 800, // width map
436 mapHeight = 800,
437 jitterRadius = 7;
438
439 var T = new tsnejs.tSNE(opt); // create a tSNE instance
440
441 var Y;
442
443 var data;
444 var labeler;
445
446 function applyJitter() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100447 svg.selectAll('.tsnet')
448 .data(labels)
449 .transition()
450 .duration(50)
451 .attr("transform", function(d, i) {
452 T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20;
453 T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20;
454 return "translate(" +
455 (d.x) + "," +
456 (d.y) + ")";
457 });
Marc Kupietz83305222016-04-28 09:57:22 +0200458 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100459
Marc Kupietz83305222016-04-28 09:57:22 +0200460 function updateEmbedding() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100461 var Y = T.getSolution();
462 svg.selectAll('.tsnet')
463 .data(data.words)
464 .attr("transform", function(d, i) {
465 return "translate(" +
466 ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," +
467 ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; });
Marc Kupietz83305222016-04-28 09:57:22 +0200468 }
469
470 var svg;
471 var labels = [];
472 var anchor_array = [];
473 var text;
474
475 function drawEmbedding() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100476 $("#embed").empty();
477 var div = d3.select("#embed");
Marc Kupietz34c08172017-11-29 17:08:47 +0100478
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100479 // get min and max in each column of Y
480 var Y = T.Y;
Marc Kupietz34c08172017-11-29 17:08:47 +0100481
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100482 svg = div.append("svg") // svg is global
483 .attr("width", mapWidth)
484 .attr("height", mapHeight);
Marc Kupietz34c08172017-11-29 17:08:47 +0100485
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100486 var g = svg.selectAll(".b")
487 .data(data.words)
488 .enter().append("g")
489 .attr("class", "tsnet");
Marc Kupietz34c08172017-11-29 17:08:47 +0100490
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100491 g.append("a")
492 .attr("xlink:href", function(word) {
493 return (data.urlprefix+word);})
494 .attr("class", function(d, i) {
495 var res="";
496 if(data.marked[i]) {
497 res="marked ";
498 }
499 if(data.target.indexOf(" "+d+" ") >= 0) {
500 return res+"target";
501 } else if(data.ranks[i] < data.mergedEnd) {
502 return res+"merged";
503 } else {
504 return res;
505 }
506 })
507 .attr("title", function(d, i) {
508 if(data.mergedEnd > 0) {
509 if(data.ranks[i] >= data.mergedEnd) {
510 return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
511 } else {
512 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
513 }
514 } else {
515 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
516 }
517 })
518 .append("text")
519 .attr("text-anchor", "top")
520 .attr("font-size", 12)
521 .text(function(d) { return d; });
Marc Kupietz34c08172017-11-29 17:08:47 +0100522
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100523 var zoomListener = d3.behavior.zoom()
524 .scaleExtent([0.1, 10])
525 .center([0,0])
526 .on("zoom", zoomHandler);
527 zoomListener(svg);
Marc Kupietz83305222016-04-28 09:57:22 +0200528 }
529
530 var tx=0, ty=0;
531 var ss=1;
532 var iter_id=-1;
533
534 function zoomHandler() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100535 tx = d3.event.translate[0];
536 ty = d3.event.translate[1];
537 ss = d3.event.scale;
538 updateEmbedding();
Marc Kupietz83305222016-04-28 09:57:22 +0200539 }
540
541 var stepnum = 0;
542
543 function stopStep() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100544 clearInterval(iter_id);
545 text = svg.selectAll("text");
Marc Kupietz34c08172017-11-29 17:08:47 +0100546
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100547 // jitter function needs different data and co-ordinate representation
548 labels = d3.range(data.words.length).map(function(i) {
549 var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2;
550 var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2;
551 anchor_array.push({x: x, y: y, r: jitterRadius});
552 return {
553 x: x,
554 y: y,
555 name: data.words[i]
556 };
557 });
Marc Kupietz34c08172017-11-29 17:08:47 +0100558
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100559 // get the actual label bounding boxes for the jitter function
560 var index = 0;
561 text.each(function() {
562 labels[index].width = this.getBBox().width;
563 labels[index].height = this.getBBox().height;
564 index += 1;
565 });
Marc Kupietz83305222016-04-28 09:57:22 +0200566
Marc Kupietz34c08172017-11-29 17:08:47 +0100567
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100568 // setTimeout(updateEmbedding, 1);
569 // setTimeout(
570 labeler = d3.labeler()
571 .label(labels)
572 .anchor(anchor_array)
573 .width(mapWidth)
574 .height(mapHeight)
575 .update(applyJitter);
576 // .start(1000);
Marc Kupietz83305222016-04-28 09:57:22 +0200577
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100578 iter_id = setInterval(jitterStep, 1);
Marc Kupietz83305222016-04-28 09:57:22 +0200579 }
580
581 var jitter_i=0;
582
583 function jitterStep() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100584 if(jitter_i++ > 100) {
585 clearInterval(iter_id);
586 } else {
587 labeler.start2(10);
588 applyJitter();
589 }
Marc Kupietz83305222016-04-28 09:57:22 +0200590 }
591
592 var last_cost=1000;
593
594 function step() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100595 var i = T.iter;
Marc Kupietz34c08172017-11-29 17:08:47 +0100596
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100597 if(i > <%= $no_iterations %>) {
598 stopStep();
599 } else {
600 var cost = Math.round(T.step() * 100000) / 100000; // do a few steps
601 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5));
602 if(i % 250 == 0 && cost >= last_cost) {
603 stopStep();
Marc Kupietz4abcd682017-11-28 20:51:08 +0100604 } else {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100605 last_cost = cost;
606 updateEmbedding();
Marc Kupietz4abcd682017-11-28 20:51:08 +0100607 }
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100608 }
Marc Kupietz83305222016-04-28 09:57:22 +0200609 }
610
611 function showMap(j) {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100612 data=j;
613 T.iter=0;
614 T.initDataRaw(data.vecs); // init embedding
615 drawEmbedding(); // draw initial embedding
Marc Kupietz78114532017-11-29 17:00:16 +0100616
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100617 if(iter_id >= 0) {
618 clearInterval(iter_id);
619 }
620 //T.debugGrad();
621 iter_id = setInterval(step, 1);
622 if(true) { // (<%= $show_som %>) {
623 makeSOM(j, <%= $no_iterations %>);
624 }
Marc Kupietz83305222016-04-28 09:57:22 +0200625 }
Marc Kupietz39179ab2017-07-04 16:28:06 +0200626 var queryword;
627
628 function onload() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100629 queryword = document.getElementById('word');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200630 }
631
632 function queryKorAP() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100633 window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200634 }
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100635
636 function queryKorAPCII(query) {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100637 window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP');
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100638 }
Marc Kupietz83305222016-04-28 09:57:22 +0200639 </script>
640 </head>
Marc Kupietz39179ab2017-07-04 16:28:06 +0200641 <body onload="onload()">
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100642 <div id="header">
643 <div id="pagetitle">
644 <h1>DeReKo-Vectors</h1>
645 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100646 <div id="options" class="widget">
Marc Kupietzdab9f222017-11-29 14:22:59 +0100647 <form id="queryform">
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100648 <input id="word" type="text" name="word" placeholder="Word(s) to be searched" value="<%= $word %>"
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100649 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 +0100650 <input id="SEARCH" type="button" value="SEARCH">
651 <input type="button" id="showoptions" name="showoptions" value="Options" />
652 </form>
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100653 <div id="dropdownoptions" style="display: none">
Marc Kupietzdab9f222017-11-29 14:22:59 +0100654 <form id="optionsform">
Marc Kupietz4abcd682017-11-28 20:51:08 +0100655 <div class="controlgroup-vertical">
656 <label for="cutoff">cut-off</label>
657 <input id="cutoff" type="text" name="cutoff" size="10" value="<%= $cutoff %>" title="Only consider the most frequent x word forms.">
658 <label for="dedupe">dedupe</label>
659 <input id="dedupe" type="checkbox" name="dedupe" value="1" <%= ($dedupe ? "checked" : "") %> title="radically filter out any near-duplicates">
660 % if($mergedEnd > 0) {
Marc Kupietz78114532017-11-29 17:00:16 +0100661 <label for="sbf">backw.</label>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100662 <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.">
663 % }
664 <label for="neighbours">max. neighbours:</label>
665 <input id="neighbours" size="4" name="n" value="<%= $no_nbs %>">
Marc Kupietzc1e42c32017-11-29 16:47:56 +0100666 <label for="no_iterations">max. iterations</label>
667 <input id="no_iterations" name="N" size="4" value="<%= $no_iterations %>">
Marc Kupietz78114532017-11-29 17:00:16 +0100668 <!-- <label for="dosom">SOM</label>
669 <input id="dosom" type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> -->
Marc Kupietz4abcd682017-11-28 20:51:08 +0100670 % if($collocators) {
671 <label for="sortby">window/sort</label>
672 <select id="sortby" name="sort">
673 <option value="0" <%= ($sort!=1 && $sort!=2? "selected":"") %>>auto focus</option>
Marc Kupietza77acce2017-11-30 16:59:07 +0100674 <!-- <option value="1" <%= ($sort==1? "selected":"") %>>any single position</option>
675 <option value="2" <%= ($sort==2? "selected":"") %>>whole window</option> -->
Marc Kupietz4abcd682017-11-28 20:51:08 +0100676 </select>
677 % }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100678 <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100679 </div>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100680 </form>
681 </div>
Marc Kupietz0af83e32017-11-27 09:31:37 +0100682 </div>
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100683 </div>
684 <div id="topwrapper">
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100685 <div style="visibility: hidden;" id="tabs">
Marc Kupietz4abcd682017-11-28 20:51:08 +0100686 <ul>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100687 <li><a href="#tabs-1">Semantics (TSNE-map)</a></li>
688 <li><a href="#tabs-2">Semantics (SOM)</a></li>
689 <li><a href="#tabs-3">Syntagmatic (collocators)</a></li>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100690 </ul>
691 <div id="tabs-1">
Marc Kupietzdab9f222017-11-29 14:22:59 +0100692 % if($lists && (@$lists) > 0 && (@$lists)[0]) {
693 <div id="wrapper">
Marc Kupietzaaae0152017-12-01 23:31:56 +0100694 <div id="first" style="width: 320px">
Marc Kupietzdab9f222017-11-29 14:22:59 +0100695 <table class="display compact nowrap" id="firsttable">
696 <thead>
697 <tr>
Marc Kupietzaaae0152017-12-01 23:31:56 +0100698 <th align="right">#</th><th align="right">cos</th><th align="left">similars</th>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100699 </tr>
700 </thead>
701 <tbody>
702 % my $j=0; my @words; my @vecs; my @ranks; my @marked;
703 % for my $list (@$lists) {
704 % my $i=0; while($list) {
705 % my $item = (@$list)[$i];
706 % my $c = ($collocators? (@$collocators)[$i] : 0);
707 % last if(!$c && !$item);
708 <tr>
709 <td align="right">
710 <%= ++$i %>.
711 </td>
712 % if($item) {
713 % if(!grep{$_ eq $item->{word}} @words) {
714 % push @vecs, $item->{vector};
715 % push @words, $item->{word};
716 % push @ranks, $item->{rank};
717 % push @marked, ($marked->{$item->{word}}? 1 : 0);
Marc Kupietz4abcd682017-11-28 20:51:08 +0100718 % }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100719 <td align="right">
720 <%= sprintf("%.3f", $item->{dist}) %>
721 </td>
722 <td>
Marc Kupietz34c08172017-11-29 17:08:47 +0100723 % my $class = ($marked->{$item->{word}}? "marked " : "");
724 % my $r = $item->{rank};
Marc Kupietzdab9f222017-11-29 14:22:59 +0100725 % if($r < $mergedEnd) {
726 % $class .= "merged";
727 % $r .= " (merged vocab)";
728 % } elsif($mergedEnd!=0 && $r > $mergedEnd) {
729 % $r -= $mergedEnd;
730 % }
731 <a class="<%= $class =%>"
732 title="freq. rank: <%= $r =%>"
733 href="<%= url_with->query([word => $item->{word}]) =%>">
734 <%= $item->{word} =%>
735 </a>
736 </td>
737 % } else {
738 <td colspan="2"/>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100739 % }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100740 </tr>
Marc Kupietzaaae0152017-12-01 23:31:56 +0100741 % last if($i >= $no_nbs);
Marc Kupietzdab9f222017-11-29 14:22:59 +0100742 % }
743 % }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100744 </tbody>
745 </table>
746 </div>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100747 <script>
748 % use Mojo::ByteStream 'b';
749 % my $urlprefix = url_with->query([word=>'']);
750 $(window).load(function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100751 var vecs = <%= b(Mojo::JSON::to_json($lists->[0])) %>;
752 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 +0100753 });
754 </script>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100755 % } else {
756 <div id="wrapper">
Marc Kupietz2f6b74a2017-12-01 13:20:21 +0100757 <div id="not-found-dialog" title="Not found">
758 <p>ERROR: "<%= $word %>" not found in vocabluary.</p>
759 <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>
760 </div>
761 <script>
762 $( function() {
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100763 $( "#not-found-dialog" ).dialog({
764 autoOpen: true,
765 modal: true,
766 draggable: false,
767 height: "auto",
768 width: "auto",
769 resizable: false,
770 buttons: {
771 "OK": function() {
772 $( this ).dialog( "close" );
773 },
774 "Apply": function() {
775 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
776 }
777 }
778 });
Marc Kupietz2f6b74a2017-12-01 13:20:21 +0100779 });
780 </script>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100781 </div>
782 % }
783 <div id="second">
784 <div id="embed">
785 </div>
786 <div id="cost">
787 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100788 </div>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100789 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100790 </div>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100791 <div id="tabs-2">
792 <div id="som2" style="width: 800; height: 800px">
793 </div>
794 <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div>
795 <div id="sominfo">SOM iteration <span id="iterations">0</span></div>
796 </div>
797 <div id="tabs-3">
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100798 <div style="width: 800px" id="secondt">
Marc Kupietz4abcd682017-11-28 20:51:08 +0100799 <table class="display compact nowrap" id="secondtable">
800 <thead>
801 <tr>
802 % if($collocators) {
Marc Kupietzdab9f222017-11-29 14:22:59 +0100803 <th>#</th>
Marc Kupietz22796142017-12-01 13:19:15 +0100804 <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 +0100805 <th align="right" title="Raw (max.) activation of the collocator in the output layers.">max(a)</th>
Marc Kupietza77acce2017-11-30 16:59:07 +0100806 <th title="Co-normalized raw activation sum of the collocator in the selected columns." align="right">⊥Σa</th>
807 <th title="Sum of activations over the selected colunns normalized by the total activation sum of the selected columns." align="right">Σa/Σc</th>
808 <th title="Sum of the column normalized activations over the selected colunns." align="right">Σ(a/c)</th>
809 <th title="Sum of the activations over the whole window normalized by the total window sum (no auto-focus)." align="right">Σa/Σw</th>
810 <th align="left">collocator</th>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100811 % }
812 </tr>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100813 </thead>
814 <tbody>
Marc Kupietz22796142017-12-01 13:19:15 +0100815 <tr>
816 <td align="right">
817 </td>
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100818 <td align="right">
819 </td>
820 <td align="right">
821 </td>
822 <td align="right">
823 </td>
824 <td align="right">
825 </td>
826 <td align="right">
827 </td>
828 <td align="right">
829 </td>
830 <td align="left">
831 </td>
Marc Kupietz22796142017-12-01 13:19:15 +0100832 </tr>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100833 </tbody>
834 </table>
835 </div> <!-- - tab2 -->
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100836 </div> <!-- tabs -->
837 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100838 </div> <!-- topwrapper -->
839 <div style="clear: both;"></div>
Marc Kupietz0af83e32017-11-27 09:31:37 +0100840 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100841 % if($training_args) {
842 <p>
843 Word vector model trained with <a href="https://code.google.com/p/word2vec/">word2vec</a> using the following parameters: <pre><%= $training_args %></pre>
844 </p>
Marc Kupietz83305222016-04-28 09:57:22 +0200845 % }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100846 </body>
Marc Kupietz83305222016-04-28 09:57:22 +0200847</html>