blob: 9b6f69cd92e4e3278c32eef35826480fb1be8b00 [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 }
Marc Kupietz78b434a2018-01-12 22:33:32 +0100171 });
Marc Kupietze6a7a732018-01-12 09:21:08 +0100172
Marc Kupietz78b434a2018-01-12 22:33:32 +0100173 classicCollocatorTable = $('#classicoloctable').DataTable({
174 ajax: {
175 method: "POST",
176 url: '/derekovecs/getClassicCollocators',
177 dataType: 'json',
178 dataSrc: "",
179 timeout: 30000,
180 data: function ( d ) {
181 return JSON.stringify(paraResults[0][0].rank);
182 }
183 },
Marc Kupietzad783722018-01-13 17:45:21 +0100184 "initComplete":function(settings, json){
185 $("td.collocator").click(function(){
186 queryKorAPCII(this.textContent + " /w5 " + CIIsearchWords);
187 });
188 },
Marc Kupietz78b434a2018-01-12 22:33:32 +0100189 "sScrollY": "780px",
190 "bScrollCollapse": true,
191 "bPaginate": false,
192 "bJQueryUI": true,
193 "dom": '<"top">rt<"bottom"flp><"clear">',
194 "columns": [
195 // { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat, row.word) }},
196 { "data": "llr", render: function ( data, type, row ) {return data.toFixed(3) }},
197 { "data": "lfmd", render: function ( data, type, row ) {return data.toFixed(3) }},
198 { "data": "fpmi", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
199 { "data": "npmi", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
200 { "data": "word", sClass: "collocator" }
201 ],
202 "columnDefs": [
203 { className: "dt-right", "targets": [0,1,2,3] },
204 { "searchable": false,
205 "orderable": false,
206 "targets": []
207 },
208 { "type": "scientific", targets: [2,3] },
209 { "orderSequence": [ "desc" ], "targets": [ 0, 1, 2, 3 ] },
210 { "orderSequence": [ "asc", "desc" ], "targets": [ 4 ] },
211 ],
212 "oLanguage": {
213 "sSearch": "Filter: "
214 },
215 "order": [[ 1, 'desc' ]],
216 });
Marc Kupietze6a7a732018-01-12 09:21:08 +0100217
Marc Kupietzad783722018-01-13 17:45:21 +0100218 $("td.collocator").click(function(){
219 queryKorAPCII(this.textContent + " /w5 " + CIIsearchWords);
220 });
221
Marc Kupietze6a7a732018-01-12 09:21:08 +0100222 collocatorTable.on( 'order.dt search.dt', function () {
223 collocatorTable.column(0, {order:'applied'}).nodes().each( function (cell, i) {
224 cell.innerHTML = i+1;
225 } );
Marc Kupietz78b434a2018-01-12 22:33:32 +0100226 }).draw();
227 }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100228
Marc Kupietz78b434a2018-01-12 22:33:32 +0100229 if (localStorage && !window.location.hash) { // let's not crash if some user has IE7
230 var index = parseInt(localStorage['tab']||'0');
231 $("#tabs").tabs({ active: index });
Marc Kupietze6a7a732018-01-12 09:21:08 +0100232 }
233 $("#tabs").css("visibility", "visible"); // now we can show the tabs
Marc Kupietz58270662017-12-04 12:10:06 +0100234 });
235
236 $(function(){
Marc Kupietze6a7a732018-01-12 09:21:08 +0100237 $("#dropdownoptions").dialog({
238 title: "Options",
239 autoOpen: false,
240 modal: false,
241 draggable: false,
242 height: "auto",
243 width: "auto",
244 resizable: false,
245 buttons: {
246 "Cancel": function() {
247 $( this ).dialog( "close" );
248 },
249 "Apply": function() {
250 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
251 }
252 }
253 });
Marc Kupietz58270662017-12-04 12:10:06 +0100254 });
255
256 $(function(){
Marc Kupietze6a7a732018-01-12 09:21:08 +0100257 $("#showoptions").click(function(){
258 $("#dropdownoptions").dialog("open");
259 var target = $(this);
260 $("#dropdownoptions").dialog("widget").position({
261 my: 'left bottom',
262 at: 'left bottom',
263 of: target
Marc Kupietz58270662017-12-04 12:10:06 +0100264 });
Marc Kupietze6a7a732018-01-12 09:21:08 +0100265 });
Marc Kupietz58270662017-12-04 12:10:06 +0100266 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100267
268 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100269 $( "#no_iterations" ).spinner({
270 spin: function( event, ui ) {
271 if ( ui.value < 1000 ) {
272 $( this ).spinner( "value", 1000 );
273 return false;
274 } else if ( ui.value > 10000 ) {
275 $( this ).spinner( "value", 10000 );
276 return false;
277 }
278 }
279 });
Marc Kupietz58270662017-12-04 12:10:06 +0100280 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100281
Marc Kupietz58270662017-12-04 12:10:06 +0100282 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100283 $( "#neighbours" ).spinner({
284 spin: function( event, ui ) {
285 if ( ui.value < 0 ) {
286 $( this ).spinner( "value", 0 );
287 return false;
288 } else if ( ui.value > 200 ) {
289 $( this ).spinner( "value", 200 );
290 return false;
291 }
292 }
293 });
Marc Kupietz58270662017-12-04 12:10:06 +0100294 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100295
Marc Kupietz58270662017-12-04 12:10:06 +0100296 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100297 $( "#cutoff" ).spinner({
298 spin: function( event, ui ) {
299 if ( ui.value < 100000 ) {
300 $( this ).spinner( "value", 100000 );
301 return false;
302 } else if ( ui.value > 2000000 ) {
303 $( this ).spinner( "value", 2000000 );
304 return false;
305 }
306 }
307 });
Marc Kupietz58270662017-12-04 12:10:06 +0100308 } );
309
310 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100311 $( "#tabs" ).tabs().addClass('tabs-min');
Marc Kupietz58270662017-12-04 12:10:06 +0100312 } );
313
314 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100315 $( ".controlgroup-vertical" ).controlgroup({
316 "direction": "vertical"
317 });
Marc Kupietz58270662017-12-04 12:10:06 +0100318 } );
319
320 $(function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100321 $( document ).tooltip({
322 content: function() {
323 return $(this).attr('title');
324 }}
325 )
Marc Kupietz58270662017-12-04 12:10:06 +0100326 })
Marc Kupietz694610d2017-11-25 18:30:03 +0100327
Marc Kupietz83305222016-04-28 09:57:22 +0200328 </script>
Marc Kupietz58270662017-12-04 12:10:06 +0100329 <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
330 <script src="/derekovecs/js/tsne.js"></script>
331 <script src="/derekovecs/js/som.js"></script>
332 <script src="/derekovecs/js/labeler.js"></script>
Marc Kupietz83305222016-04-28 09:57:22 +0200333 <style>
334 body, input {
Marc Kupietz58270662017-12-04 12:10:06 +0100335 font-family: Lato, sans-serif;
336 font-size: 11pt;
Marc Kupietz83305222016-04-28 09:57:22 +0200337 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100338
Marc Kupietze6a7a732018-01-12 09:21:08 +0100339 .info {
340 font-size: 8pt;
341 margin-top: 4px;
342 /* position: absolute;
343 bottom: 0;
344 left: 0;
345 right: 0; */
346 }
347
Marc Kupietz58270662017-12-04 12:10:06 +0100348 h1, h2, h3 {
349 margin: 5px 10px 0 0;
350 color: rgb(246,168,0);
351 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;
352 font-weight: bold;
353 line-height: 1.35;
354 letter-spacing: normal;
355 text-transform: uppercase;
356 text-shadow: none;
357 word-wrap: break-word;
358 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100359
360
Marc Kupietz58270662017-12-04 12:10:06 +0100361 showoptions, #SEARCH {
362 margin-left: 10px;
363 margin-right: 10px;
364 }
Marc Kupietz6dbadd12017-11-29 16:43:33 +0100365
Marc Kupietz58270662017-12-04 12:10:06 +0100366 .tabs-left-vertical .ui-tabs-nav {
367 position: absolute;
368 width: 21em;
369 transform: translate(-100%,0%) rotate(-90deg);
370 transform-origin: 100% 0%;
371 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100372
Marc Kupietz58270662017-12-04 12:10:06 +0100373 .tabs-left-vertical .ui-tabs-nav li {
374 float: right;
375 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100376
Marc Kupietz58270662017-12-04 12:10:06 +0100377 .tabs-left-vertical .ui-tabs-panel {
378 padding-left: 3.5em;
379 }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100380
Marc Kupietz58270662017-12-04 12:10:06 +0100381 .tabs-left-vertical .ui-tabs-panel {
382 height: 20em;
383 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100384
Marc Kupietz58270662017-12-04 12:10:06 +0100385 .mono {
Marc Kupietzc8221182017-12-08 17:26:19 +0100386 font-family: "DejaVu Sans Mono", Inconsolata, SourceCodePro, "Courier New", Courier, monospace;
Marc Kupietz58270662017-12-04 12:10:06 +0100387 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100388
Marc Kupietz58270662017-12-04 12:10:06 +0100389 .ui-tooltip-content {
Marc Kupietz4116b432017-12-06 14:15:32 +0100390 font-size: 10pt;
Marc Kupietz58270662017-12-04 12:10:06 +0100391 color: #222222;
392 }
Marc Kupietzf4b49392016-04-28 10:49:56 +0200393
Marc Kupietz58270662017-12-04 12:10:06 +0100394 svg > .ui-tooltip-content {
395 font-size: 8pt;
396 color: #222222;
397 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100398
Marc Kupietz58270662017-12-04 12:10:06 +0100399 a.merged {
400 color: green;
401 fill: green;
402 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100403
Marc Kupietz58270662017-12-04 12:10:06 +0100404 #first a {
405 text-decoration: none;
406 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100407
Marc Kupietz58270662017-12-04 12:10:06 +0100408 a.marked, #first a.marked {
409 text-decoration: underline;
410 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100411
Marc Kupietz58270662017-12-04 12:10:06 +0100412 a.target {
413 color: red;
414 fill: red;
415 }
Marc Kupietz694610d2017-11-25 18:30:03 +0100416
Marc Kupietz58270662017-12-04 12:10:06 +0100417 table.display {
418 width: 40% important!;
419 margin: 1; /* <- works for me this way ****/
420 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100421
Marc Kupietz58270662017-12-04 12:10:06 +0100422 table.dataTable thead th, table.dataTable thead td, table.dataTable tbody td {
423 padding: 2px 2px;
424 // border-bottom: 1px solid #111;
425 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100426
Marc Kupietz8f75b1f2017-12-06 09:42:13 +0100427 td.collocator {
428 cursor: pointer;
429 }
430
Marc Kupietz58270662017-12-04 12:10:06 +0100431 #collocators {
432 margin-bottom: 15px;
433 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100434
Marc Kupietz58270662017-12-04 12:10:06 +0100435 #header {
436 width: 100%;
437 // border: 1px solid red;
438 overflow: hidden; /* will contain if #first is longer than #second */
439 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100440
Marc Kupietz58270662017-12-04 12:10:06 +0100441 #topwrapper {
442 width: 100%;
443 // border: 1px solid red;
444 overflow: hidden; /* will contain if #first is longer than #second */
445 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100446
Marc Kupietz58270662017-12-04 12:10:06 +0100447 #wrapper {
448 // border: 1px solid red;
449 overflow: hidden; /* will contain if #first is longer than #second */
450 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100451
Marc Kupietz58270662017-12-04 12:10:06 +0100452 #pagetitle {
453 max-width: 460px;
454 margin-right: 20px;
455 float: left;
456 overflow: hidden; /* if you don't want #second to wrap below #first */
457 // border: 1px solid green;
458 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100459
Marc Kupietz58270662017-12-04 12:10:06 +0100460 #options {
461 float: left;
462 width: 800px;
463 margin: 10px;
464 overflow: hidden; /* if you don't want #second to wrap below #first */
465 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100466
Marc Kupietz58270662017-12-04 12:10:06 +0100467 #word {
468 width: 50%;
469 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100470
Marc Kupietz58270662017-12-04 12:10:06 +0100471 #first {
472 margin-right: 20px;
473 float: left;
474 overflow: hidden; /* if you don't want #second to wrap below #first */
475 // border: 1px solid green;
476 }
477 #tabs {
478 margin-right: 20px;
479 overflow: hidden; /* if you don't want #second to wrap below #first */
480 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100481
Marc Kupietz58270662017-12-04 12:10:06 +0100482 .tabs-min {
483 background: transparent;
484 border: none;
485 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100486
Marc Kupietz58270662017-12-04 12:10:06 +0100487 .tabs-min .ui-widget-header {
488 background: transparent;
489 border: none;
490 border-bottom: 1px solid #c0c0c0;
491 -moz-border-radius: 0px;
492 -webkit-border-radius: 0px;
493 border-radius: 0px;
494 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100495
Marc Kupietz58270662017-12-04 12:10:06 +0100496 .tabs-min .ui-tabs-nav .ui-state-default {
497 background: transparent;
498 border: none;
499 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100500
Marc Kupietz58270662017-12-04 12:10:06 +0100501 .tabs-min .ui-tabs-nav .ui-state-active {
502 background: transparent url(derekovecs/img/uiTabsArrow.png) no-repeat bottom center;
503 border: none;
504 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100505
Marc Kupietz58270662017-12-04 12:10:06 +0100506 .tabs-min .ui-tabs-nav .ui-state-default a {
507 color: #c0c0c0;
508 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100509
Marc Kupietz58270662017-12-04 12:10:06 +0100510 .tabs-min .ui-tabs-nav .ui-state-active a {
511 color: rgb(246,168,0);
512 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100513
Marc Kupietz58270662017-12-04 12:10:06 +0100514 #embed {
515 max-width: 802px;
516 border: 1px solid #333;
517 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100518
Marc Kupietz58270662017-12-04 12:10:06 +0100519 #second {
520 min-width: 800px;
521 // border: 1px solid #333;
522 overflow: hidden; /* if you don't want #second to wrap below #first */
523 }
524 #som2 svg {
525 border: 1px solid #333;
526 }
Marc Kupietz83305222016-04-28 09:57:22 +0200527
Marc Kupietz58270662017-12-04 12:10:06 +0100528 #cost {
529 font-size: 8pt;
530 color: #222222;
531 margin-top: 4px;
532 margin-bottom: 12px;
533 }
Marc Kupietz83305222016-04-28 09:57:22 +0200534
Marc Kupietz58270662017-12-04 12:10:06 +0100535 #sominfo1, #sominfo {
536 font-size: 8pt;
537 color: #222222;
538 margin-top: 0px;
539 }
Marc Kupietz83305222016-04-28 09:57:22 +0200540
Marc Kupietz58270662017-12-04 12:10:06 +0100541 #somcolor1, #somcolor2, #somcolor3 {
542 display: inline-block;
543 height: 10px;
544 width: 10px;
545 }
Marc Kupietz83305222016-04-28 09:57:22 +0200546
Marc Kupietz58270662017-12-04 12:10:06 +0100547 #third {
548 border: 1px solid #333;
549 }
Marc Kupietz83305222016-04-28 09:57:22 +0200550
551 </style>
552 <script>
553
554 var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>},
Marc Kupietz58270662017-12-04 12:10:06 +0100555 mapWidth = 800, // width map
556 mapHeight = 800,
557 jitterRadius = 7;
Marc Kupietz83305222016-04-28 09:57:22 +0200558
559 var T = new tsnejs.tSNE(opt); // create a tSNE instance
560
561 var Y;
562
563 var data;
564 var labeler;
565
566 function applyJitter() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100567 svg.selectAll('.tsnet')
568 .data(labels)
569 .transition()
570 .duration(50)
571 .attr("transform", function(d, i) {
572 T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20;
573 T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20;
574 return "translate(" +
575 (d.x) + "," +
576 (d.y) + ")";
577 });
Marc Kupietz83305222016-04-28 09:57:22 +0200578 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100579
Marc Kupietz83305222016-04-28 09:57:22 +0200580 function updateEmbedding() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100581 var Y = T.getSolution();
582 svg.selectAll('.tsnet')
583 .data(data.words)
584 .attr("transform", function(d, i) {
585 return "translate(" +
586 ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," +
587 ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; });
Marc Kupietz83305222016-04-28 09:57:22 +0200588 }
589
590 var svg;
591 var labels = [];
592 var anchor_array = [];
593 var text;
594
595 function drawEmbedding() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100596 var urlprefix = new URLSearchParams(window.location.search);
597 urlprefix.delete("word");
598 urlprefix.append("word","");
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100599
Marc Kupietze6a7a732018-01-12 09:21:08 +0100600 $("#embed").empty();
601 var div = d3.select("#embed");
Marc Kupietz34c08172017-11-29 17:08:47 +0100602
Marc Kupietze6a7a732018-01-12 09:21:08 +0100603 // get min and max in each column of Y
604 var Y = T.Y;
Marc Kupietz34c08172017-11-29 17:08:47 +0100605
Marc Kupietze6a7a732018-01-12 09:21:08 +0100606 svg = div.append("svg") // svg is global
607 .attr("width", mapWidth)
608 .attr("height", mapHeight);
Marc Kupietz34c08172017-11-29 17:08:47 +0100609
Marc Kupietze6a7a732018-01-12 09:21:08 +0100610 var g = svg.selectAll(".b")
611 .data(data.words)
612 .enter().append("g")
613 .attr("class", "tsnet");
Marc Kupietz34c08172017-11-29 17:08:47 +0100614
Marc Kupietze6a7a732018-01-12 09:21:08 +0100615 g.append("a")
616 .attr("xlink:href", function(word) {
617 return "?"+urlprefix+word; })
618 .attr("class", function(d, i) {
619 var res="";
620 if(data.marked[i]) {
621 res="marked ";
622 }
623 if(data.target.indexOf(" "+d+" ") >= 0) {
624 return res+"target";
625 } else if(data.ranks[i] < data.mergedEnd) {
626 return res+"merged";
627 } else {
628 return res;
629 }
630 })
631 .attr("title", function(d, i) {
632 if(data.mergedEnd > 0) {
633 if(data.ranks[i] >= data.mergedEnd) {
634 return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
635 } else {
636 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
637 }
638 } else {
639 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
640 }
641 })
642 .append("text")
643 .attr("text-anchor", "top")
644 .attr("font-size", 12)
645 .text(function(d) { return d; });
Marc Kupietz34c08172017-11-29 17:08:47 +0100646
Marc Kupietze6a7a732018-01-12 09:21:08 +0100647 var zoomListener = d3.behavior.zoom()
648 .scaleExtent([0.1, 10])
649 .center([0,0])
650 .on("zoom", zoomHandler);
651 zoomListener(svg);
Marc Kupietz83305222016-04-28 09:57:22 +0200652 }
653
654 var tx=0, ty=0;
655 var ss=1;
656 var iter_id=-1;
657
658 function zoomHandler() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100659 tx = d3.event.translate[0];
660 ty = d3.event.translate[1];
661 ss = d3.event.scale;
662 updateEmbedding();
Marc Kupietz83305222016-04-28 09:57:22 +0200663 }
664
665 var stepnum = 0;
666
667 function stopStep() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100668 clearInterval(iter_id);
669 text = svg.selectAll("text");
Marc Kupietz34c08172017-11-29 17:08:47 +0100670
Marc Kupietze6a7a732018-01-12 09:21:08 +0100671 // jitter function needs different data and co-ordinate representation
672 labels = d3.range(data.words.length).map(function(i) {
673 var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2;
674 var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2;
675 anchor_array.push({x: x, y: y, r: jitterRadius});
676 return {
677 x: x,
678 y: y,
679 name: data.words[i]
680 };
681 });
Marc Kupietz34c08172017-11-29 17:08:47 +0100682
Marc Kupietze6a7a732018-01-12 09:21:08 +0100683 // get the actual label bounding boxes for the jitter function
684 var index = 0;
685 text.each(function() {
686 labels[index].width = this.getBBox().width;
687 labels[index].height = this.getBBox().height;
688 index += 1;
689 });
Marc Kupietz83305222016-04-28 09:57:22 +0200690
Marc Kupietz34c08172017-11-29 17:08:47 +0100691
Marc Kupietze6a7a732018-01-12 09:21:08 +0100692 // setTimeout(updateEmbedding, 1);
693 // setTimeout(
694 labeler = d3.labeler()
695 .label(labels)
696 .anchor(anchor_array)
697 .width(mapWidth)
698 .height(mapHeight)
699 .update(applyJitter);
700 // .start(1000);
Marc Kupietz83305222016-04-28 09:57:22 +0200701
Marc Kupietze6a7a732018-01-12 09:21:08 +0100702 iter_id = setInterval(jitterStep, 1);
Marc Kupietz83305222016-04-28 09:57:22 +0200703 }
704
705 var jitter_i=0;
706
707 function jitterStep() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100708 if(jitter_i++ > 100) {
709 clearInterval(iter_id);
710 } else {
711 labeler.start2(10);
712 applyJitter();
713 }
Marc Kupietz83305222016-04-28 09:57:22 +0200714 }
715
716 var last_cost=1000;
717
718 function step() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100719 var i = T.iter;
Marc Kupietz34c08172017-11-29 17:08:47 +0100720
Marc Kupietze6a7a732018-01-12 09:21:08 +0100721 if(i > <%= $no_iterations %>) {
722 stopStep();
723 } else {
724 var cost = Math.round(T.step() * 100000) / 100000; // do a few steps
725 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5));
726 if(i % 250 == 0 && cost >= last_cost) {
727 stopStep();
Marc Kupietz58270662017-12-04 12:10:06 +0100728 } else {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100729 last_cost = cost;
730 updateEmbedding();
Marc Kupietz58270662017-12-04 12:10:06 +0100731 }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100732 }
Marc Kupietz83305222016-04-28 09:57:22 +0200733 }
734
735 function showMap(j) {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100736 data=j;
737 T.iter=0;
738 iter_id = -1;
739 last_cost=1000;
740 T.initDataRaw(data.vecs); // init embedding
741 drawEmbedding(); // draw initial embedding
Marc Kupietz78114532017-11-29 17:00:16 +0100742
Marc Kupietze6a7a732018-01-12 09:21:08 +0100743 if(iter_id >= 0) {
744 clearInterval(iter_id);
745 }
746 //T.debugGrad();
747 iter_id = setInterval(step, 1);
748 if(true) { // (<%= $show_som %>) {
749 makeSOM(j, <%= $no_iterations %>);
750 }
Marc Kupietz83305222016-04-28 09:57:22 +0200751 }
Marc Kupietz39179ab2017-07-04 16:28:06 +0200752 var queryword;
753
Marc Kupietz66bfd952017-12-11 09:59:45 +0100754 function showCollocatorSOM() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100755 if (collocatorTable) {
756 var ctableData = collocatorTable.rows().data();
757 var nwords = [],
758 nranks = [];
759 for (var i=0; i < ctableData.length && i < 100; i++) {
760 nranks.push(ctableData[i].rank);
761 nwords.push(ctableData[i].word);
Marc Kupietz66bfd952017-12-11 09:59:45 +0100762 }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100763 $.post('/derekovecs/getVecsByRanks',
764 JSON.stringify(nranks),
765 function(data, status){
766 showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: data, ranks: nranks, marked: Array(100).fill(false)} );
767 }, 'json');
768 }
Marc Kupietz66bfd952017-12-11 09:59:45 +0100769 }
770
Marc Kupietz39179ab2017-07-04 16:28:06 +0200771 function onload() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100772 queryword = document.getElementById('word');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200773 }
774
775 function queryKorAP() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100776 window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200777 }
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100778
779 function queryKorAPCII(query) {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100780 window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP');
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100781 }
Marc Kupietz83305222016-04-28 09:57:22 +0200782 </script>
783 </head>
Marc Kupietz39179ab2017-07-04 16:28:06 +0200784 <body onload="onload()">
Marc Kupietz58270662017-12-04 12:10:06 +0100785 <div id="header">
786 <div id="pagetitle">
787 <h1>DeReKo-Vectors</h1>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100788 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100789 <div id="options" class="widget">
790 <form id="queryform">
791 <input id="word" type="text" name="word" placeholder="Word(s) to be searched" value="<%= $word %>"
792 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."/>
793 <input id="SEARCH" type="button" value="SEARCH">
794 <input type="button" id="showoptions" name="showoptions" value="Options" />
795 </form>
796 <div id="dropdownoptions" style="display: none">
797 <form id="optionsform">
798 <div class="controlgroup-vertical">
799 <label for="cutoff">cut-off</label>
800 <input id="cutoff" type="text" name="cutoff" size="10" value="<%= $cutoff %>" title="Only consider the most frequent x word forms.">
801 <label for="dedupe">dedupe</label>
802 <input id="dedupe" type="checkbox" name="dedupe" value="1" <%= ($dedupe ? "checked" : "") %> title="radically filter out any near-duplicates">
803 % if($mergedEnd > 0) {
804 <label for="sbf">backw.</label>
805 <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.">
806 % }
807 <label for="neighbours">max. neighbours:</label>
808 <input id="neighbours" size="4" name="n" value="<%= $no_nbs %>">
809 <label for="no_iterations">max. iterations</label>
810 <input id="no_iterations" name="N" size="4" value="<%= $no_iterations %>">
811 <!-- <label for="dosom">SOM</label>
812 <input id="dosom" type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> -->
813 % if($collocators) {
814 <label for="sortby">window/sort</label>
815 <select id="sortby" name="sort">
816 <option value="0" <%= ($sort!=1 && $sort!=2? "selected":"") %>>auto focus</option>
817 <!-- <option value="1" <%= ($sort==1? "selected":"") %>>any single position</option>
818 <option value="2" <%= ($sort==2? "selected":"") %>>whole window</option> -->
819 </select>
820 % }
821 <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/>
822 </div>
823 </form>
824 </div>
825 </div>
826 </div>
827 <div id="topwrapper">
828 <div style="visibility: hidden;" id="tabs">
829 <ul>
830 <li><a href="#tabs-1">Semantics (TSNE-map)</a></li>
831 <li><a href="#tabs-2">Semantics (SOM)</a></li>
832 <li><a href="#tabs-3">Syntagmatic (collocators)</a></li>
833 </ul>
834 <div id="tabs-1">
835 % if($lists && (@$lists) > 0 && (@$lists)[0]) {
836 <div id="wrapper">
837 <div id="first" style="width: 320px">
838 <table class="display compact nowrap" id="firsttable">
839 <thead>
840 <tr>
841 <th align="right">#</th><th align="right">cos</th><th align="left">similars</th>
842 </tr>
843 </thead>
844 <tbody>
845 <tr>
846 <td align="right">
847 </td>
848 <td align="right">
849 </td>
850 <td></td>
851 </tr>
852 </tbody>
853 </table>
854 </div>
855 <script>
856 </script>
857 <div id="second">
858 <div id="embed">
859 </div>
860 <div id="cost">
861 </div>
862 </div>
863 </div>
864 % } elsif($word !~ /^\s*$/) {
865 <div id="wrapper">
866 <div id="not-found-dialog" title="Not found">
867 <p>ERROR: "<%= $word %>" not found in vocabluary.</p>
868 <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>
869 </div>
870 <script>
871 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100872 $( "#not-found-dialog" ).dialog({
873 autoOpen: true,
874 modal: true,
875 draggable: false,
876 height: "auto",
877 width: "auto",
878 resizable: false,
879 buttons: {
880 "OK": function() {
881 $( this ).dialog( "close" );
882 },
883 "Apply": function() {
884 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
885 }
886 }
887 });
Marc Kupietz58270662017-12-04 12:10:06 +0100888 });
889 </script>
890 </div>
Marc Kupietze6a7a732018-01-12 09:21:08 +0100891 % }
Marc Kupietz58270662017-12-04 12:10:06 +0100892 </div>
893 <div id="tabs-2">
Marc Kupietz66bfd952017-12-11 09:59:45 +0100894 <div id="som2" style="width: 800;">
Marc Kupietz58270662017-12-04 12:10:06 +0100895 </div>
896 <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div>
897 <div id="sominfo">SOM iteration <span id="iterations">0</span></div>
898 </div>
Marc Kupietze6a7a732018-01-12 09:21:08 +0100899 <div id="tabs-3" style="width:1300px">
900 <div style="width: 60%; float: left;" id="secondt">
901 <table class="display compact nowrap" id="secondtable">
Marc Kupietz58270662017-12-04 12:10:06 +0100902 <thead>
903 <tr>
904 % if($collocators) {
905 <th>#</th>
Marc Kupietz4116b432017-12-06 14:15:32 +0100906 <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>
907 <th align="right" title="Maximum activation of the collocator anywhere in the output layer.">max(a)</th>
908 <th title="Average raw activation of the collocator in the columns selected by auto-focus." align="right">⟨a⟩</th>
909 <th title="Sum of activations over the selected colunns normalized by the total activation sum of the selected columns." align="right">Σa/Σw'</th>
910 <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 +0100911 <th title="Sum of the activations over the whole window normalized by the total window sum (no auto-focus)." align="right">Σa/Σw</th>
912 <th align="left">collocator</th>
913 % }
914 </tr>
915 </thead>
916 <tbody>
917 <tr>
918 <td align="right">
919 </td>
920 <td align="right">
921 </td>
922 <td align="right">
923 </td>
924 <td align="right">
925 </td>
926 <td align="right">
927 </td>
928 <td align="right">
929 </td>
Marc Kupietz58270662017-12-04 12:10:06 +0100930 </tr>
931 </tbody>
932 </table>
Marc Kupietz66bfd952017-12-11 09:59:45 +0100933 </div>
Marc Kupietze6a7a732018-01-12 09:21:08 +0100934 <div style="margin-left:20px; float:right; width: 500px">
935 <table class="display compact nowrap" id="classicoloctable">
936 <thead>
937 <tr>
938 <th>llr</th>
939 <th title="log-frequency biased mutual dependency">lfmd</th>
940 <th title="frequency biased pointwise mutual information">fpmi</th>
Marc Kupietz78b434a2018-01-12 22:33:32 +0100941 <th title="normalized pointwise mutual information">npmi</th>
Marc Kupietze6a7a732018-01-12 09:21:08 +0100942 <th>collocator</th>
943 </tr>
944 </thead>
945 <tbody>
946 <tr>
947 <td align="right">
948 </td>
949 <td align="right">
950 </td>
951 <td align="right">
952 </td>
953 <td align="right">
954 </td>
955 </tr>
956 </tbody>
957 </table>
958 </div>
959 <div style="clear:both" ></div>
Marc Kupietz66bfd952017-12-11 09:59:45 +0100960 <div style="float: right; overflow: hidden" id="extra"><button onClick="showCollocatorSOM()"> </button></div>
Marc Kupietz66bfd952017-12-11 09:59:45 +0100961 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100962 </div>
963 </div> <!-- topwrapper -->
964 <div style="clear: both;"></div>
965 </div>
Marc Kupietzebea4702018-01-12 09:16:09 +0100966 % if($training_args && (@$lists)[0]) {
967 <div class="info">
968 % if($training_args =~ /-type\s*3/) {
969 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 %>
970 % } else {
971 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 %>
972 % }
973 </div>
Marc Kupietz83305222016-04-28 09:57:22 +0200974 % }
Marc Kupietz58270662017-12-04 12:10:06 +0100975 </body>
Marc Kupietz83305222016-04-28 09:57:22 +0200976</html>