blob: 9851b45a03ff786d93a198987246ebf895937779 [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 Kupietz8f75b1f2017-12-06 09:42:13 +0100358 td.collocator {
359 cursor: pointer;
360 }
361
Marc Kupietz58270662017-12-04 12:10:06 +0100362 #collocators {
363 margin-bottom: 15px;
364 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100365
Marc Kupietz58270662017-12-04 12:10:06 +0100366 #header {
367 width: 100%;
368 // border: 1px solid red;
369 overflow: hidden; /* will contain if #first is longer than #second */
370 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100371
Marc Kupietz58270662017-12-04 12:10:06 +0100372 #topwrapper {
373 width: 100%;
374 // border: 1px solid red;
375 overflow: hidden; /* will contain if #first is longer than #second */
376 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100377
Marc Kupietz58270662017-12-04 12:10:06 +0100378 #wrapper {
379 // border: 1px solid red;
380 overflow: hidden; /* will contain if #first is longer than #second */
381 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100382
Marc Kupietz58270662017-12-04 12:10:06 +0100383 #pagetitle {
384 max-width: 460px;
385 margin-right: 20px;
386 float: left;
387 overflow: hidden; /* if you don't want #second to wrap below #first */
388 // border: 1px solid green;
389 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100390
Marc Kupietz58270662017-12-04 12:10:06 +0100391 #options {
392 float: left;
393 width: 800px;
394 margin: 10px;
395 overflow: hidden; /* if you don't want #second to wrap below #first */
396 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100397
Marc Kupietz58270662017-12-04 12:10:06 +0100398 #word {
399 width: 50%;
400 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100401
Marc Kupietz58270662017-12-04 12:10:06 +0100402 #first {
403 margin-right: 20px;
404 float: left;
405 overflow: hidden; /* if you don't want #second to wrap below #first */
406 // border: 1px solid green;
407 }
408 #tabs {
409 margin-right: 20px;
410 overflow: hidden; /* if you don't want #second to wrap below #first */
411 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100412
Marc Kupietz58270662017-12-04 12:10:06 +0100413 .tabs-min {
414 background: transparent;
415 border: none;
416 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100417
Marc Kupietz58270662017-12-04 12:10:06 +0100418 .tabs-min .ui-widget-header {
419 background: transparent;
420 border: none;
421 border-bottom: 1px solid #c0c0c0;
422 -moz-border-radius: 0px;
423 -webkit-border-radius: 0px;
424 border-radius: 0px;
425 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100426
Marc Kupietz58270662017-12-04 12:10:06 +0100427 .tabs-min .ui-tabs-nav .ui-state-default {
428 background: transparent;
429 border: none;
430 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100431
Marc Kupietz58270662017-12-04 12:10:06 +0100432 .tabs-min .ui-tabs-nav .ui-state-active {
433 background: transparent url(derekovecs/img/uiTabsArrow.png) no-repeat bottom center;
434 border: none;
435 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100436
Marc Kupietz58270662017-12-04 12:10:06 +0100437 .tabs-min .ui-tabs-nav .ui-state-default a {
438 color: #c0c0c0;
439 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100440
Marc Kupietz58270662017-12-04 12:10:06 +0100441 .tabs-min .ui-tabs-nav .ui-state-active a {
442 color: rgb(246,168,0);
443 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100444
Marc Kupietz58270662017-12-04 12:10:06 +0100445 #embed {
446 max-width: 802px;
447 border: 1px solid #333;
448 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100449
Marc Kupietz58270662017-12-04 12:10:06 +0100450 #second {
451 min-width: 800px;
452 // border: 1px solid #333;
453 overflow: hidden; /* if you don't want #second to wrap below #first */
454 }
455 #som2 svg {
456 border: 1px solid #333;
457 }
Marc Kupietz83305222016-04-28 09:57:22 +0200458
Marc Kupietz58270662017-12-04 12:10:06 +0100459 #cost {
460 font-size: 8pt;
461 color: #222222;
462 margin-top: 4px;
463 margin-bottom: 12px;
464 }
Marc Kupietz83305222016-04-28 09:57:22 +0200465
Marc Kupietz58270662017-12-04 12:10:06 +0100466 #sominfo1, #sominfo {
467 font-size: 8pt;
468 color: #222222;
469 margin-top: 0px;
470 }
Marc Kupietz83305222016-04-28 09:57:22 +0200471
Marc Kupietz58270662017-12-04 12:10:06 +0100472 #somcolor1, #somcolor2, #somcolor3 {
473 display: inline-block;
474 height: 10px;
475 width: 10px;
476 }
Marc Kupietz83305222016-04-28 09:57:22 +0200477
Marc Kupietz58270662017-12-04 12:10:06 +0100478 #third {
479 border: 1px solid #333;
480 }
Marc Kupietz83305222016-04-28 09:57:22 +0200481
482 </style>
483 <script>
484
485 var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>},
Marc Kupietz58270662017-12-04 12:10:06 +0100486 mapWidth = 800, // width map
487 mapHeight = 800,
488 jitterRadius = 7;
Marc Kupietz83305222016-04-28 09:57:22 +0200489
490 var T = new tsnejs.tSNE(opt); // create a tSNE instance
491
492 var Y;
493
494 var data;
495 var labeler;
496
497 function applyJitter() {
Marc Kupietz58270662017-12-04 12:10:06 +0100498 svg.selectAll('.tsnet')
499 .data(labels)
500 .transition()
501 .duration(50)
502 .attr("transform", function(d, i) {
503 T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20;
504 T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20;
505 return "translate(" +
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100506 (d.x) + "," +
507 (d.y) + ")";
Marc Kupietz58270662017-12-04 12:10:06 +0100508 });
Marc Kupietz83305222016-04-28 09:57:22 +0200509 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100510
Marc Kupietz83305222016-04-28 09:57:22 +0200511 function updateEmbedding() {
Marc Kupietz58270662017-12-04 12:10:06 +0100512 var Y = T.getSolution();
513 svg.selectAll('.tsnet')
514 .data(data.words)
515 .attr("transform", function(d, i) {
516 return "translate(" +
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100517 ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," +
518 ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; });
Marc Kupietz83305222016-04-28 09:57:22 +0200519 }
520
521 var svg;
522 var labels = [];
523 var anchor_array = [];
524 var text;
525
526 function drawEmbedding() {
Marc Kupietz58270662017-12-04 12:10:06 +0100527 var urlprefix = new URLSearchParams(window.location.search);
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100528 urlprefix.delete("word");
529 urlprefix.append("word","");
530
Marc Kupietz58270662017-12-04 12:10:06 +0100531 $("#embed").empty();
532 var div = d3.select("#embed");
Marc Kupietz34c08172017-11-29 17:08:47 +0100533
Marc Kupietz58270662017-12-04 12:10:06 +0100534 // get min and max in each column of Y
535 var Y = T.Y;
Marc Kupietz34c08172017-11-29 17:08:47 +0100536
Marc Kupietz58270662017-12-04 12:10:06 +0100537 svg = div.append("svg") // svg is global
538 .attr("width", mapWidth)
539 .attr("height", mapHeight);
Marc Kupietz34c08172017-11-29 17:08:47 +0100540
Marc Kupietz58270662017-12-04 12:10:06 +0100541 var g = svg.selectAll(".b")
542 .data(data.words)
543 .enter().append("g")
544 .attr("class", "tsnet");
Marc Kupietz34c08172017-11-29 17:08:47 +0100545
Marc Kupietz58270662017-12-04 12:10:06 +0100546 g.append("a")
547 .attr("xlink:href", function(word) {
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100548 return "?"+urlprefix+word; })
Marc Kupietz58270662017-12-04 12:10:06 +0100549 .attr("class", function(d, i) {
550 var res="";
551 if(data.marked[i]) {
552 res="marked ";
553 }
554 if(data.target.indexOf(" "+d+" ") >= 0) {
555 return res+"target";
556 } else if(data.ranks[i] < data.mergedEnd) {
557 return res+"merged";
558 } else {
559 return res;
560 }
561 })
562 .attr("title", function(d, i) {
563 if(data.mergedEnd > 0) {
564 if(data.ranks[i] >= data.mergedEnd) {
565 return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
566 } else {
567 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
568 }
569 } else {
570 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
571 }
572 })
573 .append("text")
574 .attr("text-anchor", "top")
575 .attr("font-size", 12)
576 .text(function(d) { return d; });
Marc Kupietz34c08172017-11-29 17:08:47 +0100577
Marc Kupietz58270662017-12-04 12:10:06 +0100578 var zoomListener = d3.behavior.zoom()
579 .scaleExtent([0.1, 10])
580 .center([0,0])
581 .on("zoom", zoomHandler);
582 zoomListener(svg);
Marc Kupietz83305222016-04-28 09:57:22 +0200583 }
584
585 var tx=0, ty=0;
586 var ss=1;
587 var iter_id=-1;
588
589 function zoomHandler() {
Marc Kupietz58270662017-12-04 12:10:06 +0100590 tx = d3.event.translate[0];
591 ty = d3.event.translate[1];
592 ss = d3.event.scale;
593 updateEmbedding();
Marc Kupietz83305222016-04-28 09:57:22 +0200594 }
595
596 var stepnum = 0;
597
598 function stopStep() {
Marc Kupietz58270662017-12-04 12:10:06 +0100599 clearInterval(iter_id);
600 text = svg.selectAll("text");
Marc Kupietz34c08172017-11-29 17:08:47 +0100601
Marc Kupietz58270662017-12-04 12:10:06 +0100602 // jitter function needs different data and co-ordinate representation
603 labels = d3.range(data.words.length).map(function(i) {
604 var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2;
605 var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2;
606 anchor_array.push({x: x, y: y, r: jitterRadius});
607 return {
608 x: x,
609 y: y,
610 name: data.words[i]
611 };
612 });
Marc Kupietz34c08172017-11-29 17:08:47 +0100613
Marc Kupietz58270662017-12-04 12:10:06 +0100614 // get the actual label bounding boxes for the jitter function
615 var index = 0;
616 text.each(function() {
617 labels[index].width = this.getBBox().width;
618 labels[index].height = this.getBBox().height;
619 index += 1;
620 });
Marc Kupietz83305222016-04-28 09:57:22 +0200621
Marc Kupietz34c08172017-11-29 17:08:47 +0100622
Marc Kupietz58270662017-12-04 12:10:06 +0100623 // setTimeout(updateEmbedding, 1);
624 // setTimeout(
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100625 labeler = d3.labeler()
626 .label(labels)
627 .anchor(anchor_array)
628 .width(mapWidth)
629 .height(mapHeight)
630 .update(applyJitter);
Marc Kupietz58270662017-12-04 12:10:06 +0100631 // .start(1000);
Marc Kupietz83305222016-04-28 09:57:22 +0200632
Marc Kupietz58270662017-12-04 12:10:06 +0100633 iter_id = setInterval(jitterStep, 1);
Marc Kupietz83305222016-04-28 09:57:22 +0200634 }
635
636 var jitter_i=0;
637
638 function jitterStep() {
Marc Kupietz58270662017-12-04 12:10:06 +0100639 if(jitter_i++ > 100) {
640 clearInterval(iter_id);
641 } else {
642 labeler.start2(10);
643 applyJitter();
644 }
Marc Kupietz83305222016-04-28 09:57:22 +0200645 }
646
647 var last_cost=1000;
648
649 function step() {
Marc Kupietz58270662017-12-04 12:10:06 +0100650 var i = T.iter;
Marc Kupietz34c08172017-11-29 17:08:47 +0100651
Marc Kupietz58270662017-12-04 12:10:06 +0100652 if(i > <%= $no_iterations %>) {
653 stopStep();
654 } else {
655 var cost = Math.round(T.step() * 100000) / 100000; // do a few steps
656 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5));
657 if(i % 250 == 0 && cost >= last_cost) {
658 stopStep();
659 } else {
660 last_cost = cost;
661 updateEmbedding();
662 }
663 }
Marc Kupietz83305222016-04-28 09:57:22 +0200664 }
665
666 function showMap(j) {
Marc Kupietz58270662017-12-04 12:10:06 +0100667 data=j;
668 T.iter=0;
669 T.initDataRaw(data.vecs); // init embedding
670 drawEmbedding(); // draw initial embedding
Marc Kupietz78114532017-11-29 17:00:16 +0100671
Marc Kupietz58270662017-12-04 12:10:06 +0100672 if(iter_id >= 0) {
673 clearInterval(iter_id);
674 }
675 //T.debugGrad();
676 iter_id = setInterval(step, 1);
677 if(true) { // (<%= $show_som %>) {
678 makeSOM(j, <%= $no_iterations %>);
679 }
Marc Kupietz83305222016-04-28 09:57:22 +0200680 }
Marc Kupietz39179ab2017-07-04 16:28:06 +0200681 var queryword;
682
683 function onload() {
Marc Kupietz58270662017-12-04 12:10:06 +0100684 queryword = document.getElementById('word');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200685 }
686
687 function queryKorAP() {
Marc Kupietz58270662017-12-04 12:10:06 +0100688 window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200689 }
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100690
691 function queryKorAPCII(query) {
Marc Kupietz58270662017-12-04 12:10:06 +0100692 window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP');
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100693 }
Marc Kupietz83305222016-04-28 09:57:22 +0200694 </script>
695 </head>
Marc Kupietz39179ab2017-07-04 16:28:06 +0200696 <body onload="onload()">
Marc Kupietz58270662017-12-04 12:10:06 +0100697 <div id="header">
698 <div id="pagetitle">
699 <h1>DeReKo-Vectors</h1>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100700 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100701 <div id="options" class="widget">
702 <form id="queryform">
703 <input id="word" type="text" name="word" placeholder="Word(s) to be searched" value="<%= $word %>"
704 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."/>
705 <input id="SEARCH" type="button" value="SEARCH">
706 <input type="button" id="showoptions" name="showoptions" value="Options" />
707 </form>
708 <div id="dropdownoptions" style="display: none">
709 <form id="optionsform">
710 <div class="controlgroup-vertical">
711 <label for="cutoff">cut-off</label>
712 <input id="cutoff" type="text" name="cutoff" size="10" value="<%= $cutoff %>" title="Only consider the most frequent x word forms.">
713 <label for="dedupe">dedupe</label>
714 <input id="dedupe" type="checkbox" name="dedupe" value="1" <%= ($dedupe ? "checked" : "") %> title="radically filter out any near-duplicates">
715 % if($mergedEnd > 0) {
716 <label for="sbf">backw.</label>
717 <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.">
718 % }
719 <label for="neighbours">max. neighbours:</label>
720 <input id="neighbours" size="4" name="n" value="<%= $no_nbs %>">
721 <label for="no_iterations">max. iterations</label>
722 <input id="no_iterations" name="N" size="4" value="<%= $no_iterations %>">
723 <!-- <label for="dosom">SOM</label>
724 <input id="dosom" type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> -->
725 % if($collocators) {
726 <label for="sortby">window/sort</label>
727 <select id="sortby" name="sort">
728 <option value="0" <%= ($sort!=1 && $sort!=2? "selected":"") %>>auto focus</option>
729 <!-- <option value="1" <%= ($sort==1? "selected":"") %>>any single position</option>
730 <option value="2" <%= ($sort==2? "selected":"") %>>whole window</option> -->
731 </select>
732 % }
733 <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/>
734 </div>
735 </form>
736 </div>
737 </div>
738 </div>
739 <div id="topwrapper">
740 <div style="visibility: hidden;" id="tabs">
741 <ul>
742 <li><a href="#tabs-1">Semantics (TSNE-map)</a></li>
743 <li><a href="#tabs-2">Semantics (SOM)</a></li>
744 <li><a href="#tabs-3">Syntagmatic (collocators)</a></li>
745 </ul>
746 <div id="tabs-1">
747 % if($lists && (@$lists) > 0 && (@$lists)[0]) {
748 <div id="wrapper">
749 <div id="first" style="width: 320px">
750 <table class="display compact nowrap" id="firsttable">
751 <thead>
752 <tr>
753 <th align="right">#</th><th align="right">cos</th><th align="left">similars</th>
754 </tr>
755 </thead>
756 <tbody>
757 <tr>
758 <td align="right">
759 </td>
760 <td align="right">
761 </td>
762 <td></td>
763 </tr>
764 </tbody>
765 </table>
766 </div>
767 <script>
768 </script>
769 <div id="second">
770 <div id="embed">
771 </div>
772 <div id="cost">
773 </div>
774 </div>
775 </div>
776 % } elsif($word !~ /^\s*$/) {
777 <div id="wrapper">
778 <div id="not-found-dialog" title="Not found">
779 <p>ERROR: "<%= $word %>" not found in vocabluary.</p>
780 <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>
781 </div>
782 <script>
783 $( function() {
784 $( "#not-found-dialog" ).dialog({
785 autoOpen: true,
786 modal: true,
787 draggable: false,
788 height: "auto",
789 width: "auto",
790 resizable: false,
791 buttons: {
792 "OK": function() {
793 $( this ).dialog( "close" );
794 },
795 "Apply": function() {
796 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
797 }
798 }
799 });
800 });
801 </script>
802 </div>
803 % }
804 </div>
805 <div id="tabs-2">
806 <div id="som2" style="width: 800; height: 800px">
807 </div>
808 <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div>
809 <div id="sominfo">SOM iteration <span id="iterations">0</span></div>
810 </div>
811 <div id="tabs-3">
812 <div style="width: 800px" id="secondt">
813 <table class="display compact nowrap" id="secondtable">
814 <thead>
815 <tr>
816 % if($collocators) {
817 <th>#</th>
818 <th align="center" title="The columns (c) around the target are considered for summation are marked with *.">w'</th>
819 <th align="right" title="Raw (max.) activation of the collocator in the output layers.">max(a)</th>
820 <th title="Co-normalized raw activation sum of the collocator in the selected columns." align="right">⊥Σa</th>
821 <th title="Sum of activations over the selected colunns normalized by the total activation sum of the selected columns." align="right">Σa/Σc</th>
822 <th title="Sum of the column normalized activations over the selected colunns." align="right">Σ(a/c)</th>
823 <th title="Sum of the activations over the whole window normalized by the total window sum (no auto-focus)." align="right">Σa/Σw</th>
824 <th align="left">collocator</th>
825 % }
826 </tr>
827 </thead>
828 <tbody>
829 <tr>
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 <td align="right">
839 </td>
840 <td align="right">
841 </td>
842 <script
843 src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
844 </td>
845 </tr>
846 </tbody>
847 </table>
848 </div> <!-- - tab2 -->
849 </div> <!-- tabs -->
850 </div>
851 </div> <!-- topwrapper -->
852 <div style="clear: both;"></div>
853 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100854 % if($training_args) {
855 <p>
856 Word vector model trained with <a href="https://code.google.com/p/word2vec/">word2vec</a> using the following parameters: <pre><%= $training_args %></pre>
857 </p>
Marc Kupietz83305222016-04-28 09:57:22 +0200858 % }
Marc Kupietz58270662017-12-04 12:10:06 +0100859 </body>
Marc Kupietz83305222016-04-28 09:57:22 +0200860</html>