blob: 38a41a01cb7b09c3d1a8dacc1f6f5744cd6cfffa [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 Kupietze6a7a732018-01-12 09:21:08 +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 Kupietzb3a2e4f2017-12-08 17:25:53 +010018 var currentWords = urlParams.get("word");
19 var CIIsearchWords = (currentWords.includes(" ") ? '('+currentWords.replace(/ +/g, " oder ")+')' : currentWords);
Marc Kupietz66bfd952017-12-11 09:59:45 +010020 var collocatorTable = null;
Marc Kupietza6e08f02017-12-01 22:06:21 +010021
Marc Kupietz4abcd682017-11-28 20:51:08 +010022 $('#firstable').hide();
Marc Kupietz58270662017-12-04 12:10:06 +010023 $(document).ready(function() {
Marc Kupietz694610d2017-11-25 18:30:03 +010024
Marc Kupietze6a7a732018-01-12 09:21:08 +010025 $("input").bind("keydown", function(event) {
26 // track enter key
27 var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
28 if (keycode == 13) { // keycode for enter key
29 // force the 'Enter Key' to implicitly click the Update button
30 document.getElementById('SEARCH').click();
31 return false;
32 } else {
33 return true;
34 }});
Marc Kupietzdab9f222017-11-29 14:22:59 +010035
Marc Kupietze6a7a732018-01-12 09:21:08 +010036 $( "#tabs" ).on( "tabsactivate", function( event, ui ) {
37 if (localStorage) localStorage['tab'] = ui.newTab.index();
38 });
39
40 $(function(){
41 $("#SEARCH").click(function() {
42 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
Marc Kupietz58270662017-12-04 12:10:06 +010043 });
Marc Kupietze6a7a732018-01-12 09:21:08 +010044 });
Marc Kupietz0af83e32017-11-27 09:31:37 +010045
Marc Kupietze6a7a732018-01-12 09:21:08 +010046 function changeCharColor(txt, heat, word) {
47 var newText = "";
48 for (var i=0, l=txt.length; i<l; i++) {
49 newText += (i == 5 ? txt.charAt(i) : '<a href="http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q=' +
50 CIIsearchWords + ' /' + (i > 5? '%2B' : '-') + 'w' +
51 Math.abs(i-5) + ':' + Math.abs(i-5) + ' ' + word +
52 '" target="korap"><span style="background-color:' +
53 getHeatColor(heat[i]/maxHeat)+'">'+txt.charAt(i)+'</span></a>');
Marc Kupietzb6c615d2017-12-02 10:38:20 +010054 }
Marc Kupietze6a7a732018-01-12 09:21:08 +010055 return newText;
56 }
Marc Kupietzb6c615d2017-12-02 10:38:20 +010057
Marc Kupietze6a7a732018-01-12 09:21:08 +010058 function getHeatColor(value) {
59 var hue=((1-value)*120).toString(10);
60 return ["hsl(",hue,",90%,70%)"].join("");
61 }
62
63 function bitvec2window(n, heat, word) {
64 var str = n.toString(2).padStart(10, "0")
65 .replace(/^([0-9]{5})/, '$1x')
66 .replace(/0/g, '·')
67 .replace(/1/g, '+');
68 return changeCharColor(str, heat, word);
69 }
70
71 % use Mojo::ByteStream 'b';
72 var paraResults = <%= b(Mojo::JSON::to_json($lists)) %>;
73 var urlprefix = new URLSearchParams(window.location.search);
74 if (paraResults.length > 0 && paraResults[0] != null) {
75 var nvecs = [],
76 nwords = [],
77 nranks = [],
78 nmarked = [];
79 for(var i = 0; i < paraResults.length; i++) {
80 nwords = nwords.concat(paraResults[i].map(function(a){return a.word;}));
81 nvecs = nvecs.concat(paraResults[i].map(function(a){return a.vector;}));
82 nranks = nranks.concat(paraResults[i].map(function(a){return a.rank;}));
83 nmarked = nmarked.concat(paraResults[i].map(function(a){return a.marked;}));
Marc Kupietz0d4c0ca2017-12-04 09:18:56 +010084 }
Marc Kupietze6a7a732018-01-12 09:21:08 +010085 showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: nvecs, ranks: nranks, marked: nmarked} );
86 var t = $('#firsttable').DataTable({
87 data: paraResults[0],
88 "sScrollY": "780px",
89 "bScrollCollapse": true,
90 "bPaginate": false,
91 "bJQueryUI": true,
92 "dom": '<"top">rt<"bottom"flp><"clear">',
93 "columns": [
94 { "data": "rank", type: "allnumeric" },
95 { "data": "dist", render: function ( data, type, row ) {return data.toFixed(3) }},
96 { "data": "word", render: function ( data, type, row ) {urlprefix.set("word", data); return '<a href="?' + urlprefix + '">' + data + '</a>' }}
97 ],
98 "columnDefs": [
99 { className: "dt-right", "targets": [0,1] },
100 { "searchable": false,
101 "orderable": false,
102 "targets": 0
103 },
104 { "orderSequence": [ "desc" ], "targets": [ 1 ] },
105 { "orderSequence": [ "asc", "desc" ], "targets": [ 2 ] },
106 ],
107 "oLanguage": {
108 "sSearch": "Filter: "
109 },
110 "order": [[ 1, 'desc' ]],
111 } );
Marc Kupietz0d4c0ca2017-12-04 09:18:56 +0100112
Marc Kupietze6a7a732018-01-12 09:21:08 +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();
118
119 $( "#first" ).clone().prependTo( "#tabs-2" );
120
121 }
122
123
124 var collocatorData = <%= b(Mojo::JSON::to_json($collocators)) %>;
125 var maxHeat; // = Math.max.apply(Math,collocatorData.map(function(o){return o.cprob;}))
126
127 if (collocatorData != null) {
128 maxHeat = Math.max.apply(Math,collocatorData.map(function(o){return Math.max.apply(Math,o.heat);}))
129 collocatorTable = $('#secondtable').DataTable({
130 data: collocatorData,
131 "sScrollY": "780px",
132 "bScrollCollapse": true,
133 "bPaginate": false,
134 "bJQueryUI": true,
135 "dom": '<"top">rt<"bottom"flp><"clear">',
136 "columns": [
137 { "data": "rank", type: "allnumeric" },
138 { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat, row.word) }},
139 { "data": "max", render: function ( data, type, row ) {return data.toFixed(3) }},
140 { "data": "average", render: function ( data, type, row ) {return data.toFixed(3) }},
141 { "data": "prob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
142 { "data": "cprob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
143 { "data": "overall", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
144 { "data": "word", sClass: "collocator" },
145 { "data": "rank", type: "allnumeric" }
146 ],
147 "columnDefs": [
148 { className: "dt-right", "targets": [0,2,3,4,5,6] },
149 { className: "dt-center", "targets": [ 1] },
150 { "searchable": false,
151 "orderable": false,
152 "targets": [0, 8]
153 },
154 { "type": "scientific", targets: [2,3,4,5,6] },
155 { "orderSequence": [ "desc" ], "targets": [ 2, 3, 4, 5, 6 ] },
156 { "orderSequence": [ "asc", "desc" ], "targets": [ 1, 7 ] },
157 { "targets": [8], "visible": false }
158 ],
159 "oLanguage": {
160 "sSearch": "Filter: "
161 },
162 "order": [[ 4, 'desc' ]],
163 } );
164 $.ajaxSetup({
165 type: 'POST',
166 timeout: 30000,
167 error: function(xhr) {
168 $('#display_error')
169 .html('Error: ' + xhr.status + ' ' + xhr.statusText);
170 }
171 })
172
173 $.post('/derekovecs/getClassicCollocators',
174 JSON.stringify(paraResults[0][0].rank),
175 function(collocators, status) {
176 collocatorTable = $('#classicoloctable').DataTable({
177 data: collocators,
178 "sScrollY": "780px",
179 "bScrollCollapse": true,
180 "bPaginate": false,
181 "bJQueryUI": true,
182 "dom": '<"top">rt<"bottom"flp><"clear">',
183 "columns": [
184 // { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat, row.word) }},
185 { "data": "llr", render: function ( data, type, row ) {return data.toFixed(3) }},
186 { "data": "lfmd", render: function ( data, type, row ) {return data.toFixed(3) }},
187 { "data": "fpmi", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
188 { "data": "npmi", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
189 { "data": "word", sClass: "collocator" }
190 ],
191 "columnDefs": [
192 { className: "dt-right", "targets": [0,1,2,3] },
193 { "searchable": false,
194 "orderable": false,
195 "targets": []
196 },
197 { "type": "scientific", targets: [2,3] },
198 { "orderSequence": [ "desc" ], "targets": [ 0, 1, 2, 3 ] },
199 { "orderSequence": [ "asc", "desc" ], "targets": [ 4 ] },
200 ],
201 "oLanguage": {
202 "sSearch": "Filter: "
203 },
204 "order": [[ 1, 'desc' ]],
205 } );
206 }, 'json');
207
208 collocatorTable.on( 'order.dt search.dt', function () {
209 collocatorTable.column(0, {order:'applied'}).nodes().each( function (cell, i) {
210 cell.innerHTML = i+1;
211 } );
212 } ).draw();
213
214 if (localStorage && !window.location.hash) { // let's not crash if some user has IE7
215 var index = parseInt(localStorage['tab']||'0');
216 $("#tabs").tabs({ active: index });
Marc Kupietzddaba632017-12-02 17:30:56 +0100217 }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100218 }
219 $("#tabs").css("visibility", "visible"); // now we can show the tabs
Marc Kupietz58270662017-12-04 12:10:06 +0100220
221 });
222
223 $(function(){
Marc Kupietze6a7a732018-01-12 09:21:08 +0100224 $("#dropdownoptions").dialog({
225 title: "Options",
226 autoOpen: false,
227 modal: false,
228 draggable: false,
229 height: "auto",
230 width: "auto",
231 resizable: false,
232 buttons: {
233 "Cancel": function() {
234 $( this ).dialog( "close" );
235 },
236 "Apply": function() {
237 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
238 }
239 }
240 });
Marc Kupietz58270662017-12-04 12:10:06 +0100241 });
242
243 $(function(){
Marc Kupietze6a7a732018-01-12 09:21:08 +0100244 $("td.collocator").click(function(){
245 queryKorAPCII(this.textContent + " /w5 " + CIIsearchWords);
246 });
Marc Kupietz58270662017-12-04 12:10:06 +0100247 });
248
249 $(function(){
Marc Kupietze6a7a732018-01-12 09:21:08 +0100250 $("#showoptions").click(function(){
251 $("#dropdownoptions").dialog("open");
252 var target = $(this);
253 $("#dropdownoptions").dialog("widget").position({
254 my: 'left bottom',
255 at: 'left bottom',
256 of: target
Marc Kupietz58270662017-12-04 12:10:06 +0100257 });
Marc Kupietze6a7a732018-01-12 09:21:08 +0100258 });
Marc Kupietz58270662017-12-04 12:10:06 +0100259 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100260
261 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100262 $( "#no_iterations" ).spinner({
263 spin: function( event, ui ) {
264 if ( ui.value < 1000 ) {
265 $( this ).spinner( "value", 1000 );
266 return false;
267 } else if ( ui.value > 10000 ) {
268 $( this ).spinner( "value", 10000 );
269 return false;
270 }
271 }
272 });
Marc Kupietz58270662017-12-04 12:10:06 +0100273 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100274
Marc Kupietz58270662017-12-04 12:10:06 +0100275 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100276 $( "#neighbours" ).spinner({
277 spin: function( event, ui ) {
278 if ( ui.value < 0 ) {
279 $( this ).spinner( "value", 0 );
280 return false;
281 } else if ( ui.value > 200 ) {
282 $( this ).spinner( "value", 200 );
283 return false;
284 }
285 }
286 });
Marc Kupietz58270662017-12-04 12:10:06 +0100287 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100288
Marc Kupietz58270662017-12-04 12:10:06 +0100289 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100290 $( "#cutoff" ).spinner({
291 spin: function( event, ui ) {
292 if ( ui.value < 100000 ) {
293 $( this ).spinner( "value", 100000 );
294 return false;
295 } else if ( ui.value > 2000000 ) {
296 $( this ).spinner( "value", 2000000 );
297 return false;
298 }
299 }
300 });
Marc Kupietz58270662017-12-04 12:10:06 +0100301 } );
302
303 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100304 $( "#tabs" ).tabs().addClass('tabs-min');
Marc Kupietz58270662017-12-04 12:10:06 +0100305 } );
306
307 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100308 $( ".controlgroup-vertical" ).controlgroup({
309 "direction": "vertical"
310 });
Marc Kupietz58270662017-12-04 12:10:06 +0100311 } );
312
313 $(function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100314 $( document ).tooltip({
315 content: function() {
316 return $(this).attr('title');
317 }}
318 )
Marc Kupietz58270662017-12-04 12:10:06 +0100319 })
Marc Kupietz694610d2017-11-25 18:30:03 +0100320
Marc Kupietz83305222016-04-28 09:57:22 +0200321 </script>
Marc Kupietz58270662017-12-04 12:10:06 +0100322 <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
323 <script src="/derekovecs/js/tsne.js"></script>
324 <script src="/derekovecs/js/som.js"></script>
325 <script src="/derekovecs/js/labeler.js"></script>
Marc Kupietz83305222016-04-28 09:57:22 +0200326 <style>
327 body, input {
Marc Kupietz58270662017-12-04 12:10:06 +0100328 font-family: Lato, sans-serif;
329 font-size: 11pt;
Marc Kupietz83305222016-04-28 09:57:22 +0200330 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100331
Marc Kupietze6a7a732018-01-12 09:21:08 +0100332 .info {
333 font-size: 8pt;
334 margin-top: 4px;
335 /* position: absolute;
336 bottom: 0;
337 left: 0;
338 right: 0; */
339 }
340
Marc Kupietz58270662017-12-04 12:10:06 +0100341 h1, h2, h3 {
342 margin: 5px 10px 0 0;
343 color: rgb(246,168,0);
344 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;
345 font-weight: bold;
346 line-height: 1.35;
347 letter-spacing: normal;
348 text-transform: uppercase;
349 text-shadow: none;
350 word-wrap: break-word;
351 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100352
353
Marc Kupietz58270662017-12-04 12:10:06 +0100354 showoptions, #SEARCH {
355 margin-left: 10px;
356 margin-right: 10px;
357 }
Marc Kupietz6dbadd12017-11-29 16:43:33 +0100358
Marc Kupietz58270662017-12-04 12:10:06 +0100359 .tabs-left-vertical .ui-tabs-nav {
360 position: absolute;
361 width: 21em;
362 transform: translate(-100%,0%) rotate(-90deg);
363 transform-origin: 100% 0%;
364 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100365
Marc Kupietz58270662017-12-04 12:10:06 +0100366 .tabs-left-vertical .ui-tabs-nav li {
367 float: right;
368 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100369
Marc Kupietz58270662017-12-04 12:10:06 +0100370 .tabs-left-vertical .ui-tabs-panel {
371 padding-left: 3.5em;
372 }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100373
Marc Kupietz58270662017-12-04 12:10:06 +0100374 .tabs-left-vertical .ui-tabs-panel {
375 height: 20em;
376 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100377
Marc Kupietz58270662017-12-04 12:10:06 +0100378 .mono {
Marc Kupietzc8221182017-12-08 17:26:19 +0100379 font-family: "DejaVu Sans Mono", Inconsolata, SourceCodePro, "Courier New", Courier, monospace;
Marc Kupietz58270662017-12-04 12:10:06 +0100380 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100381
Marc Kupietz58270662017-12-04 12:10:06 +0100382 .ui-tooltip-content {
Marc Kupietz4116b432017-12-06 14:15:32 +0100383 font-size: 10pt;
Marc Kupietz58270662017-12-04 12:10:06 +0100384 color: #222222;
385 }
Marc Kupietzf4b49392016-04-28 10:49:56 +0200386
Marc Kupietz58270662017-12-04 12:10:06 +0100387 svg > .ui-tooltip-content {
388 font-size: 8pt;
389 color: #222222;
390 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100391
Marc Kupietz58270662017-12-04 12:10:06 +0100392 a.merged {
393 color: green;
394 fill: green;
395 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100396
Marc Kupietz58270662017-12-04 12:10:06 +0100397 #first a {
398 text-decoration: none;
399 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100400
Marc Kupietz58270662017-12-04 12:10:06 +0100401 a.marked, #first a.marked {
402 text-decoration: underline;
403 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100404
Marc Kupietz58270662017-12-04 12:10:06 +0100405 a.target {
406 color: red;
407 fill: red;
408 }
Marc Kupietz694610d2017-11-25 18:30:03 +0100409
Marc Kupietz58270662017-12-04 12:10:06 +0100410 table.display {
411 width: 40% important!;
412 margin: 1; /* <- works for me this way ****/
413 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100414
Marc Kupietz58270662017-12-04 12:10:06 +0100415 table.dataTable thead th, table.dataTable thead td, table.dataTable tbody td {
416 padding: 2px 2px;
417 // border-bottom: 1px solid #111;
418 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100419
Marc Kupietz8f75b1f2017-12-06 09:42:13 +0100420 td.collocator {
421 cursor: pointer;
422 }
423
Marc Kupietz58270662017-12-04 12:10:06 +0100424 #collocators {
425 margin-bottom: 15px;
426 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100427
Marc Kupietz58270662017-12-04 12:10:06 +0100428 #header {
429 width: 100%;
430 // border: 1px solid red;
431 overflow: hidden; /* will contain if #first is longer than #second */
432 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100433
Marc Kupietz58270662017-12-04 12:10:06 +0100434 #topwrapper {
435 width: 100%;
436 // border: 1px solid red;
437 overflow: hidden; /* will contain if #first is longer than #second */
438 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100439
Marc Kupietz58270662017-12-04 12:10:06 +0100440 #wrapper {
441 // border: 1px solid red;
442 overflow: hidden; /* will contain if #first is longer than #second */
443 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100444
Marc Kupietz58270662017-12-04 12:10:06 +0100445 #pagetitle {
446 max-width: 460px;
447 margin-right: 20px;
448 float: left;
449 overflow: hidden; /* if you don't want #second to wrap below #first */
450 // border: 1px solid green;
451 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100452
Marc Kupietz58270662017-12-04 12:10:06 +0100453 #options {
454 float: left;
455 width: 800px;
456 margin: 10px;
457 overflow: hidden; /* if you don't want #second to wrap below #first */
458 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100459
Marc Kupietz58270662017-12-04 12:10:06 +0100460 #word {
461 width: 50%;
462 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100463
Marc Kupietz58270662017-12-04 12:10:06 +0100464 #first {
465 margin-right: 20px;
466 float: left;
467 overflow: hidden; /* if you don't want #second to wrap below #first */
468 // border: 1px solid green;
469 }
470 #tabs {
471 margin-right: 20px;
472 overflow: hidden; /* if you don't want #second to wrap below #first */
473 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100474
Marc Kupietz58270662017-12-04 12:10:06 +0100475 .tabs-min {
476 background: transparent;
477 border: none;
478 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100479
Marc Kupietz58270662017-12-04 12:10:06 +0100480 .tabs-min .ui-widget-header {
481 background: transparent;
482 border: none;
483 border-bottom: 1px solid #c0c0c0;
484 -moz-border-radius: 0px;
485 -webkit-border-radius: 0px;
486 border-radius: 0px;
487 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100488
Marc Kupietz58270662017-12-04 12:10:06 +0100489 .tabs-min .ui-tabs-nav .ui-state-default {
490 background: transparent;
491 border: none;
492 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100493
Marc Kupietz58270662017-12-04 12:10:06 +0100494 .tabs-min .ui-tabs-nav .ui-state-active {
495 background: transparent url(derekovecs/img/uiTabsArrow.png) no-repeat bottom center;
496 border: none;
497 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100498
Marc Kupietz58270662017-12-04 12:10:06 +0100499 .tabs-min .ui-tabs-nav .ui-state-default a {
500 color: #c0c0c0;
501 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100502
Marc Kupietz58270662017-12-04 12:10:06 +0100503 .tabs-min .ui-tabs-nav .ui-state-active a {
504 color: rgb(246,168,0);
505 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100506
Marc Kupietz58270662017-12-04 12:10:06 +0100507 #embed {
508 max-width: 802px;
509 border: 1px solid #333;
510 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100511
Marc Kupietz58270662017-12-04 12:10:06 +0100512 #second {
513 min-width: 800px;
514 // border: 1px solid #333;
515 overflow: hidden; /* if you don't want #second to wrap below #first */
516 }
517 #som2 svg {
518 border: 1px solid #333;
519 }
Marc Kupietz83305222016-04-28 09:57:22 +0200520
Marc Kupietz58270662017-12-04 12:10:06 +0100521 #cost {
522 font-size: 8pt;
523 color: #222222;
524 margin-top: 4px;
525 margin-bottom: 12px;
526 }
Marc Kupietz83305222016-04-28 09:57:22 +0200527
Marc Kupietz58270662017-12-04 12:10:06 +0100528 #sominfo1, #sominfo {
529 font-size: 8pt;
530 color: #222222;
531 margin-top: 0px;
532 }
Marc Kupietz83305222016-04-28 09:57:22 +0200533
Marc Kupietz58270662017-12-04 12:10:06 +0100534 #somcolor1, #somcolor2, #somcolor3 {
535 display: inline-block;
536 height: 10px;
537 width: 10px;
538 }
Marc Kupietz83305222016-04-28 09:57:22 +0200539
Marc Kupietz58270662017-12-04 12:10:06 +0100540 #third {
541 border: 1px solid #333;
542 }
Marc Kupietz83305222016-04-28 09:57:22 +0200543
544 </style>
545 <script>
546
547 var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>},
Marc Kupietz58270662017-12-04 12:10:06 +0100548 mapWidth = 800, // width map
549 mapHeight = 800,
550 jitterRadius = 7;
Marc Kupietz83305222016-04-28 09:57:22 +0200551
552 var T = new tsnejs.tSNE(opt); // create a tSNE instance
553
554 var Y;
555
556 var data;
557 var labeler;
558
559 function applyJitter() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100560 svg.selectAll('.tsnet')
561 .data(labels)
562 .transition()
563 .duration(50)
564 .attr("transform", function(d, i) {
565 T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20;
566 T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20;
567 return "translate(" +
568 (d.x) + "," +
569 (d.y) + ")";
570 });
Marc Kupietz83305222016-04-28 09:57:22 +0200571 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100572
Marc Kupietz83305222016-04-28 09:57:22 +0200573 function updateEmbedding() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100574 var Y = T.getSolution();
575 svg.selectAll('.tsnet')
576 .data(data.words)
577 .attr("transform", function(d, i) {
578 return "translate(" +
579 ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," +
580 ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; });
Marc Kupietz83305222016-04-28 09:57:22 +0200581 }
582
583 var svg;
584 var labels = [];
585 var anchor_array = [];
586 var text;
587
588 function drawEmbedding() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100589 var urlprefix = new URLSearchParams(window.location.search);
590 urlprefix.delete("word");
591 urlprefix.append("word","");
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100592
Marc Kupietze6a7a732018-01-12 09:21:08 +0100593 $("#embed").empty();
594 var div = d3.select("#embed");
Marc Kupietz34c08172017-11-29 17:08:47 +0100595
Marc Kupietze6a7a732018-01-12 09:21:08 +0100596 // get min and max in each column of Y
597 var Y = T.Y;
Marc Kupietz34c08172017-11-29 17:08:47 +0100598
Marc Kupietze6a7a732018-01-12 09:21:08 +0100599 svg = div.append("svg") // svg is global
600 .attr("width", mapWidth)
601 .attr("height", mapHeight);
Marc Kupietz34c08172017-11-29 17:08:47 +0100602
Marc Kupietze6a7a732018-01-12 09:21:08 +0100603 var g = svg.selectAll(".b")
604 .data(data.words)
605 .enter().append("g")
606 .attr("class", "tsnet");
Marc Kupietz34c08172017-11-29 17:08:47 +0100607
Marc Kupietze6a7a732018-01-12 09:21:08 +0100608 g.append("a")
609 .attr("xlink:href", function(word) {
610 return "?"+urlprefix+word; })
611 .attr("class", function(d, i) {
612 var res="";
613 if(data.marked[i]) {
614 res="marked ";
615 }
616 if(data.target.indexOf(" "+d+" ") >= 0) {
617 return res+"target";
618 } else if(data.ranks[i] < data.mergedEnd) {
619 return res+"merged";
620 } else {
621 return res;
622 }
623 })
624 .attr("title", function(d, i) {
625 if(data.mergedEnd > 0) {
626 if(data.ranks[i] >= data.mergedEnd) {
627 return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
628 } else {
629 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
630 }
631 } else {
632 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
633 }
634 })
635 .append("text")
636 .attr("text-anchor", "top")
637 .attr("font-size", 12)
638 .text(function(d) { return d; });
Marc Kupietz34c08172017-11-29 17:08:47 +0100639
Marc Kupietze6a7a732018-01-12 09:21:08 +0100640 var zoomListener = d3.behavior.zoom()
641 .scaleExtent([0.1, 10])
642 .center([0,0])
643 .on("zoom", zoomHandler);
644 zoomListener(svg);
Marc Kupietz83305222016-04-28 09:57:22 +0200645 }
646
647 var tx=0, ty=0;
648 var ss=1;
649 var iter_id=-1;
650
651 function zoomHandler() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100652 tx = d3.event.translate[0];
653 ty = d3.event.translate[1];
654 ss = d3.event.scale;
655 updateEmbedding();
Marc Kupietz83305222016-04-28 09:57:22 +0200656 }
657
658 var stepnum = 0;
659
660 function stopStep() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100661 clearInterval(iter_id);
662 text = svg.selectAll("text");
Marc Kupietz34c08172017-11-29 17:08:47 +0100663
Marc Kupietze6a7a732018-01-12 09:21:08 +0100664 // jitter function needs different data and co-ordinate representation
665 labels = d3.range(data.words.length).map(function(i) {
666 var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2;
667 var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2;
668 anchor_array.push({x: x, y: y, r: jitterRadius});
669 return {
670 x: x,
671 y: y,
672 name: data.words[i]
673 };
674 });
Marc Kupietz34c08172017-11-29 17:08:47 +0100675
Marc Kupietze6a7a732018-01-12 09:21:08 +0100676 // get the actual label bounding boxes for the jitter function
677 var index = 0;
678 text.each(function() {
679 labels[index].width = this.getBBox().width;
680 labels[index].height = this.getBBox().height;
681 index += 1;
682 });
Marc Kupietz83305222016-04-28 09:57:22 +0200683
Marc Kupietz34c08172017-11-29 17:08:47 +0100684
Marc Kupietze6a7a732018-01-12 09:21:08 +0100685 // setTimeout(updateEmbedding, 1);
686 // setTimeout(
687 labeler = d3.labeler()
688 .label(labels)
689 .anchor(anchor_array)
690 .width(mapWidth)
691 .height(mapHeight)
692 .update(applyJitter);
693 // .start(1000);
Marc Kupietz83305222016-04-28 09:57:22 +0200694
Marc Kupietze6a7a732018-01-12 09:21:08 +0100695 iter_id = setInterval(jitterStep, 1);
Marc Kupietz83305222016-04-28 09:57:22 +0200696 }
697
698 var jitter_i=0;
699
700 function jitterStep() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100701 if(jitter_i++ > 100) {
702 clearInterval(iter_id);
703 } else {
704 labeler.start2(10);
705 applyJitter();
706 }
Marc Kupietz83305222016-04-28 09:57:22 +0200707 }
708
709 var last_cost=1000;
710
711 function step() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100712 var i = T.iter;
Marc Kupietz34c08172017-11-29 17:08:47 +0100713
Marc Kupietze6a7a732018-01-12 09:21:08 +0100714 if(i > <%= $no_iterations %>) {
715 stopStep();
716 } else {
717 var cost = Math.round(T.step() * 100000) / 100000; // do a few steps
718 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5));
719 if(i % 250 == 0 && cost >= last_cost) {
720 stopStep();
Marc Kupietz58270662017-12-04 12:10:06 +0100721 } else {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100722 last_cost = cost;
723 updateEmbedding();
Marc Kupietz58270662017-12-04 12:10:06 +0100724 }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100725 }
Marc Kupietz83305222016-04-28 09:57:22 +0200726 }
727
728 function showMap(j) {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100729 data=j;
730 T.iter=0;
731 iter_id = -1;
732 last_cost=1000;
733 T.initDataRaw(data.vecs); // init embedding
734 drawEmbedding(); // draw initial embedding
Marc Kupietz78114532017-11-29 17:00:16 +0100735
Marc Kupietze6a7a732018-01-12 09:21:08 +0100736 if(iter_id >= 0) {
737 clearInterval(iter_id);
738 }
739 //T.debugGrad();
740 iter_id = setInterval(step, 1);
741 if(true) { // (<%= $show_som %>) {
742 makeSOM(j, <%= $no_iterations %>);
743 }
Marc Kupietz83305222016-04-28 09:57:22 +0200744 }
Marc Kupietz39179ab2017-07-04 16:28:06 +0200745 var queryword;
746
Marc Kupietz66bfd952017-12-11 09:59:45 +0100747 function showCollocatorSOM() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100748 if (collocatorTable) {
749 var ctableData = collocatorTable.rows().data();
750 var nwords = [],
751 nranks = [];
752 for (var i=0; i < ctableData.length && i < 100; i++) {
753 nranks.push(ctableData[i].rank);
754 nwords.push(ctableData[i].word);
Marc Kupietz66bfd952017-12-11 09:59:45 +0100755 }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100756 $.post('/derekovecs/getVecsByRanks',
757 JSON.stringify(nranks),
758 function(data, status){
759 showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: data, ranks: nranks, marked: Array(100).fill(false)} );
760 }, 'json');
761 }
Marc Kupietz66bfd952017-12-11 09:59:45 +0100762 }
763
Marc Kupietz39179ab2017-07-04 16:28:06 +0200764 function onload() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100765 queryword = document.getElementById('word');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200766 }
767
768 function queryKorAP() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100769 window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200770 }
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100771
772 function queryKorAPCII(query) {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100773 window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP');
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100774 }
Marc Kupietz83305222016-04-28 09:57:22 +0200775 </script>
776 </head>
Marc Kupietz39179ab2017-07-04 16:28:06 +0200777 <body onload="onload()">
Marc Kupietz58270662017-12-04 12:10:06 +0100778 <div id="header">
779 <div id="pagetitle">
780 <h1>DeReKo-Vectors</h1>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100781 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100782 <div id="options" class="widget">
783 <form id="queryform">
784 <input id="word" type="text" name="word" placeholder="Word(s) to be searched" value="<%= $word %>"
785 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."/>
786 <input id="SEARCH" type="button" value="SEARCH">
787 <input type="button" id="showoptions" name="showoptions" value="Options" />
788 </form>
789 <div id="dropdownoptions" style="display: none">
790 <form id="optionsform">
791 <div class="controlgroup-vertical">
792 <label for="cutoff">cut-off</label>
793 <input id="cutoff" type="text" name="cutoff" size="10" value="<%= $cutoff %>" title="Only consider the most frequent x word forms.">
794 <label for="dedupe">dedupe</label>
795 <input id="dedupe" type="checkbox" name="dedupe" value="1" <%= ($dedupe ? "checked" : "") %> title="radically filter out any near-duplicates">
796 % if($mergedEnd > 0) {
797 <label for="sbf">backw.</label>
798 <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.">
799 % }
800 <label for="neighbours">max. neighbours:</label>
801 <input id="neighbours" size="4" name="n" value="<%= $no_nbs %>">
802 <label for="no_iterations">max. iterations</label>
803 <input id="no_iterations" name="N" size="4" value="<%= $no_iterations %>">
804 <!-- <label for="dosom">SOM</label>
805 <input id="dosom" type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> -->
806 % if($collocators) {
807 <label for="sortby">window/sort</label>
808 <select id="sortby" name="sort">
809 <option value="0" <%= ($sort!=1 && $sort!=2? "selected":"") %>>auto focus</option>
810 <!-- <option value="1" <%= ($sort==1? "selected":"") %>>any single position</option>
811 <option value="2" <%= ($sort==2? "selected":"") %>>whole window</option> -->
812 </select>
813 % }
814 <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/>
815 </div>
816 </form>
817 </div>
818 </div>
819 </div>
820 <div id="topwrapper">
821 <div style="visibility: hidden;" id="tabs">
822 <ul>
823 <li><a href="#tabs-1">Semantics (TSNE-map)</a></li>
824 <li><a href="#tabs-2">Semantics (SOM)</a></li>
825 <li><a href="#tabs-3">Syntagmatic (collocators)</a></li>
826 </ul>
827 <div id="tabs-1">
828 % if($lists && (@$lists) > 0 && (@$lists)[0]) {
829 <div id="wrapper">
830 <div id="first" style="width: 320px">
831 <table class="display compact nowrap" id="firsttable">
832 <thead>
833 <tr>
834 <th align="right">#</th><th align="right">cos</th><th align="left">similars</th>
835 </tr>
836 </thead>
837 <tbody>
838 <tr>
839 <td align="right">
840 </td>
841 <td align="right">
842 </td>
843 <td></td>
844 </tr>
845 </tbody>
846 </table>
847 </div>
848 <script>
849 </script>
850 <div id="second">
851 <div id="embed">
852 </div>
853 <div id="cost">
854 </div>
855 </div>
856 </div>
857 % } elsif($word !~ /^\s*$/) {
858 <div id="wrapper">
859 <div id="not-found-dialog" title="Not found">
860 <p>ERROR: "<%= $word %>" not found in vocabluary.</p>
861 <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>
862 </div>
863 <script>
864 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100865 $( "#not-found-dialog" ).dialog({
866 autoOpen: true,
867 modal: true,
868 draggable: false,
869 height: "auto",
870 width: "auto",
871 resizable: false,
872 buttons: {
873 "OK": function() {
874 $( this ).dialog( "close" );
875 },
876 "Apply": function() {
877 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
878 }
879 }
880 });
Marc Kupietz58270662017-12-04 12:10:06 +0100881 });
882 </script>
883 </div>
Marc Kupietze6a7a732018-01-12 09:21:08 +0100884 % }
Marc Kupietz58270662017-12-04 12:10:06 +0100885 </div>
886 <div id="tabs-2">
Marc Kupietz66bfd952017-12-11 09:59:45 +0100887 <div id="som2" style="width: 800;">
Marc Kupietz58270662017-12-04 12:10:06 +0100888 </div>
889 <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div>
890 <div id="sominfo">SOM iteration <span id="iterations">0</span></div>
891 </div>
Marc Kupietze6a7a732018-01-12 09:21:08 +0100892 <div id="tabs-3" style="width:1300px">
893 <div style="width: 60%; float: left;" id="secondt">
894 <table class="display compact nowrap" id="secondtable">
Marc Kupietz58270662017-12-04 12:10:06 +0100895 <thead>
896 <tr>
897 % if($collocators) {
898 <th>#</th>
Marc Kupietz4116b432017-12-06 14:15:32 +0100899 <th align="center" title="Activation of the respective collocator in the columns around the target normalized by its maximum (red). Columns selected by the auto-focus funtion (which window of all possible column-combinations maximizes ⊥(a/c)?) are marked with +. Click on the column postions to lauch a KorAP query with target word and collocator in the respective position.">w'</th>
900 <th align="right" title="Maximum activation of the collocator anywhere in the output layer.">max(a)</th>
901 <th title="Average raw activation of the collocator in the columns selected by auto-focus." align="right">⟨a⟩</th>
902 <th title="Sum of activations over the selected colunns normalized by the total activation sum of the selected columns." align="right">Σa/Σw'</th>
903 <th title="Co-norm of the column-normalized activations over the colunns selected by the auto-focus." align="right">⊥(a/c)</th>
Marc Kupietz58270662017-12-04 12:10:06 +0100904 <th title="Sum of the activations over the whole window normalized by the total window sum (no auto-focus)." align="right">Σa/Σw</th>
905 <th align="left">collocator</th>
906 % }
907 </tr>
908 </thead>
909 <tbody>
910 <tr>
911 <td align="right">
912 </td>
913 <td align="right">
914 </td>
915 <td align="right">
916 </td>
917 <td align="right">
918 </td>
919 <td align="right">
920 </td>
921 <td align="right">
922 </td>
Marc Kupietz58270662017-12-04 12:10:06 +0100923 </tr>
924 </tbody>
925 </table>
Marc Kupietz66bfd952017-12-11 09:59:45 +0100926 </div>
Marc Kupietze6a7a732018-01-12 09:21:08 +0100927 <div style="margin-left:20px; float:right; width: 500px">
928 <table class="display compact nowrap" id="classicoloctable">
929 <thead>
930 <tr>
931 <th>llr</th>
932 <th title="log-frequency biased mutual dependency">lfmd</th>
933 <th title="frequency biased pointwise mutual information">fpmi</th>
934 <th title="normalized mutual information">npmi</th>
935 <th>collocator</th>
936 </tr>
937 </thead>
938 <tbody>
939 <tr>
940 <td align="right">
941 </td>
942 <td align="right">
943 </td>
944 <td align="right">
945 </td>
946 <td align="right">
947 </td>
948 </tr>
949 </tbody>
950 </table>
951 </div>
952 <div style="clear:both" ></div>
Marc Kupietz66bfd952017-12-11 09:59:45 +0100953 <div style="float: right; overflow: hidden" id="extra"><button onClick="showCollocatorSOM()"> </button></div>
Marc Kupietz66bfd952017-12-11 09:59:45 +0100954 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100955 </div>
956 </div> <!-- topwrapper -->
957 <div style="clear: both;"></div>
958 </div>
Marc Kupietzebea4702018-01-12 09:16:09 +0100959 % if($training_args && (@$lists)[0]) {
960 <div class="info">
961 % if($training_args =~ /-type\s*3/) {
962 Calculations are based on a word embedding model trained with an extension of <a href="https://github.com/wlin12/wang2vec/">wang2vec</a> using the following parameters: <%= $training_args %>
963 % } else {
964 Calculations are based on a word embedding model trained with <a href="https://code.google.com/p/word2vec/">word2vec</a> using the following parameters: <%= $training_args %>
965 % }
966 </div>
Marc Kupietz83305222016-04-28 09:57:22 +0200967 % }
Marc Kupietz58270662017-12-04 12:10:06 +0100968 </body>
Marc Kupietz83305222016-04-28 09:57:22 +0200969</html>