blob: 32be0a87dbbba1068937de8dd833f653bc8acc49 [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 },
184 "sScrollY": "780px",
185 "bScrollCollapse": true,
186 "bPaginate": false,
187 "bJQueryUI": true,
188 "dom": '<"top">rt<"bottom"flp><"clear">',
189 "columns": [
190 // { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat, row.word) }},
191 { "data": "llr", render: function ( data, type, row ) {return data.toFixed(3) }},
192 { "data": "lfmd", render: function ( data, type, row ) {return data.toFixed(3) }},
193 { "data": "fpmi", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
194 { "data": "npmi", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
195 { "data": "word", sClass: "collocator" }
196 ],
197 "columnDefs": [
198 { className: "dt-right", "targets": [0,1,2,3] },
199 { "searchable": false,
200 "orderable": false,
201 "targets": []
202 },
203 { "type": "scientific", targets: [2,3] },
204 { "orderSequence": [ "desc" ], "targets": [ 0, 1, 2, 3 ] },
205 { "orderSequence": [ "asc", "desc" ], "targets": [ 4 ] },
206 ],
207 "oLanguage": {
208 "sSearch": "Filter: "
209 },
210 "order": [[ 1, 'desc' ]],
211 });
Marc Kupietze6a7a732018-01-12 09:21:08 +0100212
213 collocatorTable.on( 'order.dt search.dt', function () {
214 collocatorTable.column(0, {order:'applied'}).nodes().each( function (cell, i) {
215 cell.innerHTML = i+1;
216 } );
Marc Kupietz78b434a2018-01-12 22:33:32 +0100217 }).draw();
218 }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100219
Marc Kupietz78b434a2018-01-12 22:33:32 +0100220 if (localStorage && !window.location.hash) { // let's not crash if some user has IE7
221 var index = parseInt(localStorage['tab']||'0');
222 $("#tabs").tabs({ active: index });
Marc Kupietze6a7a732018-01-12 09:21:08 +0100223 }
224 $("#tabs").css("visibility", "visible"); // now we can show the tabs
Marc Kupietz58270662017-12-04 12:10:06 +0100225 });
226
227 $(function(){
Marc Kupietze6a7a732018-01-12 09:21:08 +0100228 $("#dropdownoptions").dialog({
229 title: "Options",
230 autoOpen: false,
231 modal: false,
232 draggable: false,
233 height: "auto",
234 width: "auto",
235 resizable: false,
236 buttons: {
237 "Cancel": function() {
238 $( this ).dialog( "close" );
239 },
240 "Apply": function() {
241 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
242 }
243 }
244 });
Marc Kupietz58270662017-12-04 12:10:06 +0100245 });
246
247 $(function(){
Marc Kupietze6a7a732018-01-12 09:21:08 +0100248 $("td.collocator").click(function(){
249 queryKorAPCII(this.textContent + " /w5 " + CIIsearchWords);
250 });
Marc Kupietz58270662017-12-04 12:10:06 +0100251 });
252
253 $(function(){
Marc Kupietze6a7a732018-01-12 09:21:08 +0100254 $("#showoptions").click(function(){
255 $("#dropdownoptions").dialog("open");
256 var target = $(this);
257 $("#dropdownoptions").dialog("widget").position({
258 my: 'left bottom',
259 at: 'left bottom',
260 of: target
Marc Kupietz58270662017-12-04 12:10:06 +0100261 });
Marc Kupietze6a7a732018-01-12 09:21:08 +0100262 });
Marc Kupietz58270662017-12-04 12:10:06 +0100263 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100264
265 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100266 $( "#no_iterations" ).spinner({
267 spin: function( event, ui ) {
268 if ( ui.value < 1000 ) {
269 $( this ).spinner( "value", 1000 );
270 return false;
271 } else if ( ui.value > 10000 ) {
272 $( this ).spinner( "value", 10000 );
273 return false;
274 }
275 }
276 });
Marc Kupietz58270662017-12-04 12:10:06 +0100277 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100278
Marc Kupietz58270662017-12-04 12:10:06 +0100279 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100280 $( "#neighbours" ).spinner({
281 spin: function( event, ui ) {
282 if ( ui.value < 0 ) {
283 $( this ).spinner( "value", 0 );
284 return false;
285 } else if ( ui.value > 200 ) {
286 $( this ).spinner( "value", 200 );
287 return false;
288 }
289 }
290 });
Marc Kupietz58270662017-12-04 12:10:06 +0100291 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100292
Marc Kupietz58270662017-12-04 12:10:06 +0100293 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100294 $( "#cutoff" ).spinner({
295 spin: function( event, ui ) {
296 if ( ui.value < 100000 ) {
297 $( this ).spinner( "value", 100000 );
298 return false;
299 } else if ( ui.value > 2000000 ) {
300 $( this ).spinner( "value", 2000000 );
301 return false;
302 }
303 }
304 });
Marc Kupietz58270662017-12-04 12:10:06 +0100305 } );
306
307 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100308 $( "#tabs" ).tabs().addClass('tabs-min');
Marc Kupietz58270662017-12-04 12:10:06 +0100309 } );
310
311 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100312 $( ".controlgroup-vertical" ).controlgroup({
313 "direction": "vertical"
314 });
Marc Kupietz58270662017-12-04 12:10:06 +0100315 } );
316
317 $(function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100318 $( document ).tooltip({
319 content: function() {
320 return $(this).attr('title');
321 }}
322 )
Marc Kupietz58270662017-12-04 12:10:06 +0100323 })
Marc Kupietz694610d2017-11-25 18:30:03 +0100324
Marc Kupietz83305222016-04-28 09:57:22 +0200325 </script>
Marc Kupietz58270662017-12-04 12:10:06 +0100326 <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
327 <script src="/derekovecs/js/tsne.js"></script>
328 <script src="/derekovecs/js/som.js"></script>
329 <script src="/derekovecs/js/labeler.js"></script>
Marc Kupietz83305222016-04-28 09:57:22 +0200330 <style>
331 body, input {
Marc Kupietz58270662017-12-04 12:10:06 +0100332 font-family: Lato, sans-serif;
333 font-size: 11pt;
Marc Kupietz83305222016-04-28 09:57:22 +0200334 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100335
Marc Kupietze6a7a732018-01-12 09:21:08 +0100336 .info {
337 font-size: 8pt;
338 margin-top: 4px;
339 /* position: absolute;
340 bottom: 0;
341 left: 0;
342 right: 0; */
343 }
344
Marc Kupietz58270662017-12-04 12:10:06 +0100345 h1, h2, h3 {
346 margin: 5px 10px 0 0;
347 color: rgb(246,168,0);
348 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;
349 font-weight: bold;
350 line-height: 1.35;
351 letter-spacing: normal;
352 text-transform: uppercase;
353 text-shadow: none;
354 word-wrap: break-word;
355 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100356
357
Marc Kupietz58270662017-12-04 12:10:06 +0100358 showoptions, #SEARCH {
359 margin-left: 10px;
360 margin-right: 10px;
361 }
Marc Kupietz6dbadd12017-11-29 16:43:33 +0100362
Marc Kupietz58270662017-12-04 12:10:06 +0100363 .tabs-left-vertical .ui-tabs-nav {
364 position: absolute;
365 width: 21em;
366 transform: translate(-100%,0%) rotate(-90deg);
367 transform-origin: 100% 0%;
368 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100369
Marc Kupietz58270662017-12-04 12:10:06 +0100370 .tabs-left-vertical .ui-tabs-nav li {
371 float: right;
372 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100373
Marc Kupietz58270662017-12-04 12:10:06 +0100374 .tabs-left-vertical .ui-tabs-panel {
375 padding-left: 3.5em;
376 }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100377
Marc Kupietz58270662017-12-04 12:10:06 +0100378 .tabs-left-vertical .ui-tabs-panel {
379 height: 20em;
380 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100381
Marc Kupietz58270662017-12-04 12:10:06 +0100382 .mono {
Marc Kupietzc8221182017-12-08 17:26:19 +0100383 font-family: "DejaVu Sans Mono", Inconsolata, SourceCodePro, "Courier New", Courier, monospace;
Marc Kupietz58270662017-12-04 12:10:06 +0100384 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100385
Marc Kupietz58270662017-12-04 12:10:06 +0100386 .ui-tooltip-content {
Marc Kupietz4116b432017-12-06 14:15:32 +0100387 font-size: 10pt;
Marc Kupietz58270662017-12-04 12:10:06 +0100388 color: #222222;
389 }
Marc Kupietzf4b49392016-04-28 10:49:56 +0200390
Marc Kupietz58270662017-12-04 12:10:06 +0100391 svg > .ui-tooltip-content {
392 font-size: 8pt;
393 color: #222222;
394 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100395
Marc Kupietz58270662017-12-04 12:10:06 +0100396 a.merged {
397 color: green;
398 fill: green;
399 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100400
Marc Kupietz58270662017-12-04 12:10:06 +0100401 #first a {
402 text-decoration: none;
403 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100404
Marc Kupietz58270662017-12-04 12:10:06 +0100405 a.marked, #first a.marked {
406 text-decoration: underline;
407 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100408
Marc Kupietz58270662017-12-04 12:10:06 +0100409 a.target {
410 color: red;
411 fill: red;
412 }
Marc Kupietz694610d2017-11-25 18:30:03 +0100413
Marc Kupietz58270662017-12-04 12:10:06 +0100414 table.display {
415 width: 40% important!;
416 margin: 1; /* <- works for me this way ****/
417 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100418
Marc Kupietz58270662017-12-04 12:10:06 +0100419 table.dataTable thead th, table.dataTable thead td, table.dataTable tbody td {
420 padding: 2px 2px;
421 // border-bottom: 1px solid #111;
422 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100423
Marc Kupietz8f75b1f2017-12-06 09:42:13 +0100424 td.collocator {
425 cursor: pointer;
426 }
427
Marc Kupietz58270662017-12-04 12:10:06 +0100428 #collocators {
429 margin-bottom: 15px;
430 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100431
Marc Kupietz58270662017-12-04 12:10:06 +0100432 #header {
433 width: 100%;
434 // border: 1px solid red;
435 overflow: hidden; /* will contain if #first is longer than #second */
436 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100437
Marc Kupietz58270662017-12-04 12:10:06 +0100438 #topwrapper {
439 width: 100%;
440 // border: 1px solid red;
441 overflow: hidden; /* will contain if #first is longer than #second */
442 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100443
Marc Kupietz58270662017-12-04 12:10:06 +0100444 #wrapper {
445 // border: 1px solid red;
446 overflow: hidden; /* will contain if #first is longer than #second */
447 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100448
Marc Kupietz58270662017-12-04 12:10:06 +0100449 #pagetitle {
450 max-width: 460px;
451 margin-right: 20px;
452 float: left;
453 overflow: hidden; /* if you don't want #second to wrap below #first */
454 // border: 1px solid green;
455 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100456
Marc Kupietz58270662017-12-04 12:10:06 +0100457 #options {
458 float: left;
459 width: 800px;
460 margin: 10px;
461 overflow: hidden; /* if you don't want #second to wrap below #first */
462 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100463
Marc Kupietz58270662017-12-04 12:10:06 +0100464 #word {
465 width: 50%;
466 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100467
Marc Kupietz58270662017-12-04 12:10:06 +0100468 #first {
469 margin-right: 20px;
470 float: left;
471 overflow: hidden; /* if you don't want #second to wrap below #first */
472 // border: 1px solid green;
473 }
474 #tabs {
475 margin-right: 20px;
476 overflow: hidden; /* if you don't want #second to wrap below #first */
477 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100478
Marc Kupietz58270662017-12-04 12:10:06 +0100479 .tabs-min {
480 background: transparent;
481 border: none;
482 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100483
Marc Kupietz58270662017-12-04 12:10:06 +0100484 .tabs-min .ui-widget-header {
485 background: transparent;
486 border: none;
487 border-bottom: 1px solid #c0c0c0;
488 -moz-border-radius: 0px;
489 -webkit-border-radius: 0px;
490 border-radius: 0px;
491 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100492
Marc Kupietz58270662017-12-04 12:10:06 +0100493 .tabs-min .ui-tabs-nav .ui-state-default {
494 background: transparent;
495 border: none;
496 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100497
Marc Kupietz58270662017-12-04 12:10:06 +0100498 .tabs-min .ui-tabs-nav .ui-state-active {
499 background: transparent url(derekovecs/img/uiTabsArrow.png) no-repeat bottom center;
500 border: none;
501 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100502
Marc Kupietz58270662017-12-04 12:10:06 +0100503 .tabs-min .ui-tabs-nav .ui-state-default a {
504 color: #c0c0c0;
505 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100506
Marc Kupietz58270662017-12-04 12:10:06 +0100507 .tabs-min .ui-tabs-nav .ui-state-active a {
508 color: rgb(246,168,0);
509 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100510
Marc Kupietz58270662017-12-04 12:10:06 +0100511 #embed {
512 max-width: 802px;
513 border: 1px solid #333;
514 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100515
Marc Kupietz58270662017-12-04 12:10:06 +0100516 #second {
517 min-width: 800px;
518 // border: 1px solid #333;
519 overflow: hidden; /* if you don't want #second to wrap below #first */
520 }
521 #som2 svg {
522 border: 1px solid #333;
523 }
Marc Kupietz83305222016-04-28 09:57:22 +0200524
Marc Kupietz58270662017-12-04 12:10:06 +0100525 #cost {
526 font-size: 8pt;
527 color: #222222;
528 margin-top: 4px;
529 margin-bottom: 12px;
530 }
Marc Kupietz83305222016-04-28 09:57:22 +0200531
Marc Kupietz58270662017-12-04 12:10:06 +0100532 #sominfo1, #sominfo {
533 font-size: 8pt;
534 color: #222222;
535 margin-top: 0px;
536 }
Marc Kupietz83305222016-04-28 09:57:22 +0200537
Marc Kupietz58270662017-12-04 12:10:06 +0100538 #somcolor1, #somcolor2, #somcolor3 {
539 display: inline-block;
540 height: 10px;
541 width: 10px;
542 }
Marc Kupietz83305222016-04-28 09:57:22 +0200543
Marc Kupietz58270662017-12-04 12:10:06 +0100544 #third {
545 border: 1px solid #333;
546 }
Marc Kupietz83305222016-04-28 09:57:22 +0200547
548 </style>
549 <script>
550
551 var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>},
Marc Kupietz58270662017-12-04 12:10:06 +0100552 mapWidth = 800, // width map
553 mapHeight = 800,
554 jitterRadius = 7;
Marc Kupietz83305222016-04-28 09:57:22 +0200555
556 var T = new tsnejs.tSNE(opt); // create a tSNE instance
557
558 var Y;
559
560 var data;
561 var labeler;
562
563 function applyJitter() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100564 svg.selectAll('.tsnet')
565 .data(labels)
566 .transition()
567 .duration(50)
568 .attr("transform", function(d, i) {
569 T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20;
570 T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20;
571 return "translate(" +
572 (d.x) + "," +
573 (d.y) + ")";
574 });
Marc Kupietz83305222016-04-28 09:57:22 +0200575 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100576
Marc Kupietz83305222016-04-28 09:57:22 +0200577 function updateEmbedding() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100578 var Y = T.getSolution();
579 svg.selectAll('.tsnet')
580 .data(data.words)
581 .attr("transform", function(d, i) {
582 return "translate(" +
583 ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," +
584 ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; });
Marc Kupietz83305222016-04-28 09:57:22 +0200585 }
586
587 var svg;
588 var labels = [];
589 var anchor_array = [];
590 var text;
591
592 function drawEmbedding() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100593 var urlprefix = new URLSearchParams(window.location.search);
594 urlprefix.delete("word");
595 urlprefix.append("word","");
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100596
Marc Kupietze6a7a732018-01-12 09:21:08 +0100597 $("#embed").empty();
598 var div = d3.select("#embed");
Marc Kupietz34c08172017-11-29 17:08:47 +0100599
Marc Kupietze6a7a732018-01-12 09:21:08 +0100600 // get min and max in each column of Y
601 var Y = T.Y;
Marc Kupietz34c08172017-11-29 17:08:47 +0100602
Marc Kupietze6a7a732018-01-12 09:21:08 +0100603 svg = div.append("svg") // svg is global
604 .attr("width", mapWidth)
605 .attr("height", mapHeight);
Marc Kupietz34c08172017-11-29 17:08:47 +0100606
Marc Kupietze6a7a732018-01-12 09:21:08 +0100607 var g = svg.selectAll(".b")
608 .data(data.words)
609 .enter().append("g")
610 .attr("class", "tsnet");
Marc Kupietz34c08172017-11-29 17:08:47 +0100611
Marc Kupietze6a7a732018-01-12 09:21:08 +0100612 g.append("a")
613 .attr("xlink:href", function(word) {
614 return "?"+urlprefix+word; })
615 .attr("class", function(d, i) {
616 var res="";
617 if(data.marked[i]) {
618 res="marked ";
619 }
620 if(data.target.indexOf(" "+d+" ") >= 0) {
621 return res+"target";
622 } else if(data.ranks[i] < data.mergedEnd) {
623 return res+"merged";
624 } else {
625 return res;
626 }
627 })
628 .attr("title", function(d, i) {
629 if(data.mergedEnd > 0) {
630 if(data.ranks[i] >= data.mergedEnd) {
631 return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
632 } else {
633 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
634 }
635 } else {
636 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
637 }
638 })
639 .append("text")
640 .attr("text-anchor", "top")
641 .attr("font-size", 12)
642 .text(function(d) { return d; });
Marc Kupietz34c08172017-11-29 17:08:47 +0100643
Marc Kupietze6a7a732018-01-12 09:21:08 +0100644 var zoomListener = d3.behavior.zoom()
645 .scaleExtent([0.1, 10])
646 .center([0,0])
647 .on("zoom", zoomHandler);
648 zoomListener(svg);
Marc Kupietz83305222016-04-28 09:57:22 +0200649 }
650
651 var tx=0, ty=0;
652 var ss=1;
653 var iter_id=-1;
654
655 function zoomHandler() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100656 tx = d3.event.translate[0];
657 ty = d3.event.translate[1];
658 ss = d3.event.scale;
659 updateEmbedding();
Marc Kupietz83305222016-04-28 09:57:22 +0200660 }
661
662 var stepnum = 0;
663
664 function stopStep() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100665 clearInterval(iter_id);
666 text = svg.selectAll("text");
Marc Kupietz34c08172017-11-29 17:08:47 +0100667
Marc Kupietze6a7a732018-01-12 09:21:08 +0100668 // jitter function needs different data and co-ordinate representation
669 labels = d3.range(data.words.length).map(function(i) {
670 var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2;
671 var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2;
672 anchor_array.push({x: x, y: y, r: jitterRadius});
673 return {
674 x: x,
675 y: y,
676 name: data.words[i]
677 };
678 });
Marc Kupietz34c08172017-11-29 17:08:47 +0100679
Marc Kupietze6a7a732018-01-12 09:21:08 +0100680 // get the actual label bounding boxes for the jitter function
681 var index = 0;
682 text.each(function() {
683 labels[index].width = this.getBBox().width;
684 labels[index].height = this.getBBox().height;
685 index += 1;
686 });
Marc Kupietz83305222016-04-28 09:57:22 +0200687
Marc Kupietz34c08172017-11-29 17:08:47 +0100688
Marc Kupietze6a7a732018-01-12 09:21:08 +0100689 // setTimeout(updateEmbedding, 1);
690 // setTimeout(
691 labeler = d3.labeler()
692 .label(labels)
693 .anchor(anchor_array)
694 .width(mapWidth)
695 .height(mapHeight)
696 .update(applyJitter);
697 // .start(1000);
Marc Kupietz83305222016-04-28 09:57:22 +0200698
Marc Kupietze6a7a732018-01-12 09:21:08 +0100699 iter_id = setInterval(jitterStep, 1);
Marc Kupietz83305222016-04-28 09:57:22 +0200700 }
701
702 var jitter_i=0;
703
704 function jitterStep() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100705 if(jitter_i++ > 100) {
706 clearInterval(iter_id);
707 } else {
708 labeler.start2(10);
709 applyJitter();
710 }
Marc Kupietz83305222016-04-28 09:57:22 +0200711 }
712
713 var last_cost=1000;
714
715 function step() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100716 var i = T.iter;
Marc Kupietz34c08172017-11-29 17:08:47 +0100717
Marc Kupietze6a7a732018-01-12 09:21:08 +0100718 if(i > <%= $no_iterations %>) {
719 stopStep();
720 } else {
721 var cost = Math.round(T.step() * 100000) / 100000; // do a few steps
722 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5));
723 if(i % 250 == 0 && cost >= last_cost) {
724 stopStep();
Marc Kupietz58270662017-12-04 12:10:06 +0100725 } else {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100726 last_cost = cost;
727 updateEmbedding();
Marc Kupietz58270662017-12-04 12:10:06 +0100728 }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100729 }
Marc Kupietz83305222016-04-28 09:57:22 +0200730 }
731
732 function showMap(j) {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100733 data=j;
734 T.iter=0;
735 iter_id = -1;
736 last_cost=1000;
737 T.initDataRaw(data.vecs); // init embedding
738 drawEmbedding(); // draw initial embedding
Marc Kupietz78114532017-11-29 17:00:16 +0100739
Marc Kupietze6a7a732018-01-12 09:21:08 +0100740 if(iter_id >= 0) {
741 clearInterval(iter_id);
742 }
743 //T.debugGrad();
744 iter_id = setInterval(step, 1);
745 if(true) { // (<%= $show_som %>) {
746 makeSOM(j, <%= $no_iterations %>);
747 }
Marc Kupietz83305222016-04-28 09:57:22 +0200748 }
Marc Kupietz39179ab2017-07-04 16:28:06 +0200749 var queryword;
750
Marc Kupietz66bfd952017-12-11 09:59:45 +0100751 function showCollocatorSOM() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100752 if (collocatorTable) {
753 var ctableData = collocatorTable.rows().data();
754 var nwords = [],
755 nranks = [];
756 for (var i=0; i < ctableData.length && i < 100; i++) {
757 nranks.push(ctableData[i].rank);
758 nwords.push(ctableData[i].word);
Marc Kupietz66bfd952017-12-11 09:59:45 +0100759 }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100760 $.post('/derekovecs/getVecsByRanks',
761 JSON.stringify(nranks),
762 function(data, status){
763 showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: data, ranks: nranks, marked: Array(100).fill(false)} );
764 }, 'json');
765 }
Marc Kupietz66bfd952017-12-11 09:59:45 +0100766 }
767
Marc Kupietz39179ab2017-07-04 16:28:06 +0200768 function onload() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100769 queryword = document.getElementById('word');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200770 }
771
772 function queryKorAP() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100773 window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200774 }
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100775
776 function queryKorAPCII(query) {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100777 window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP');
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100778 }
Marc Kupietz83305222016-04-28 09:57:22 +0200779 </script>
780 </head>
Marc Kupietz39179ab2017-07-04 16:28:06 +0200781 <body onload="onload()">
Marc Kupietz58270662017-12-04 12:10:06 +0100782 <div id="header">
783 <div id="pagetitle">
784 <h1>DeReKo-Vectors</h1>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100785 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100786 <div id="options" class="widget">
787 <form id="queryform">
788 <input id="word" type="text" name="word" placeholder="Word(s) to be searched" value="<%= $word %>"
789 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."/>
790 <input id="SEARCH" type="button" value="SEARCH">
791 <input type="button" id="showoptions" name="showoptions" value="Options" />
792 </form>
793 <div id="dropdownoptions" style="display: none">
794 <form id="optionsform">
795 <div class="controlgroup-vertical">
796 <label for="cutoff">cut-off</label>
797 <input id="cutoff" type="text" name="cutoff" size="10" value="<%= $cutoff %>" title="Only consider the most frequent x word forms.">
798 <label for="dedupe">dedupe</label>
799 <input id="dedupe" type="checkbox" name="dedupe" value="1" <%= ($dedupe ? "checked" : "") %> title="radically filter out any near-duplicates">
800 % if($mergedEnd > 0) {
801 <label for="sbf">backw.</label>
802 <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.">
803 % }
804 <label for="neighbours">max. neighbours:</label>
805 <input id="neighbours" size="4" name="n" value="<%= $no_nbs %>">
806 <label for="no_iterations">max. iterations</label>
807 <input id="no_iterations" name="N" size="4" value="<%= $no_iterations %>">
808 <!-- <label for="dosom">SOM</label>
809 <input id="dosom" type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> -->
810 % if($collocators) {
811 <label for="sortby">window/sort</label>
812 <select id="sortby" name="sort">
813 <option value="0" <%= ($sort!=1 && $sort!=2? "selected":"") %>>auto focus</option>
814 <!-- <option value="1" <%= ($sort==1? "selected":"") %>>any single position</option>
815 <option value="2" <%= ($sort==2? "selected":"") %>>whole window</option> -->
816 </select>
817 % }
818 <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/>
819 </div>
820 </form>
821 </div>
822 </div>
823 </div>
824 <div id="topwrapper">
825 <div style="visibility: hidden;" id="tabs">
826 <ul>
827 <li><a href="#tabs-1">Semantics (TSNE-map)</a></li>
828 <li><a href="#tabs-2">Semantics (SOM)</a></li>
829 <li><a href="#tabs-3">Syntagmatic (collocators)</a></li>
830 </ul>
831 <div id="tabs-1">
832 % if($lists && (@$lists) > 0 && (@$lists)[0]) {
833 <div id="wrapper">
834 <div id="first" style="width: 320px">
835 <table class="display compact nowrap" id="firsttable">
836 <thead>
837 <tr>
838 <th align="right">#</th><th align="right">cos</th><th align="left">similars</th>
839 </tr>
840 </thead>
841 <tbody>
842 <tr>
843 <td align="right">
844 </td>
845 <td align="right">
846 </td>
847 <td></td>
848 </tr>
849 </tbody>
850 </table>
851 </div>
852 <script>
853 </script>
854 <div id="second">
855 <div id="embed">
856 </div>
857 <div id="cost">
858 </div>
859 </div>
860 </div>
861 % } elsif($word !~ /^\s*$/) {
862 <div id="wrapper">
863 <div id="not-found-dialog" title="Not found">
864 <p>ERROR: "<%= $word %>" not found in vocabluary.</p>
865 <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>
866 </div>
867 <script>
868 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100869 $( "#not-found-dialog" ).dialog({
870 autoOpen: true,
871 modal: true,
872 draggable: false,
873 height: "auto",
874 width: "auto",
875 resizable: false,
876 buttons: {
877 "OK": function() {
878 $( this ).dialog( "close" );
879 },
880 "Apply": function() {
881 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
882 }
883 }
884 });
Marc Kupietz58270662017-12-04 12:10:06 +0100885 });
886 </script>
887 </div>
Marc Kupietze6a7a732018-01-12 09:21:08 +0100888 % }
Marc Kupietz58270662017-12-04 12:10:06 +0100889 </div>
890 <div id="tabs-2">
Marc Kupietz66bfd952017-12-11 09:59:45 +0100891 <div id="som2" style="width: 800;">
Marc Kupietz58270662017-12-04 12:10:06 +0100892 </div>
893 <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div>
894 <div id="sominfo">SOM iteration <span id="iterations">0</span></div>
895 </div>
Marc Kupietze6a7a732018-01-12 09:21:08 +0100896 <div id="tabs-3" style="width:1300px">
897 <div style="width: 60%; float: left;" id="secondt">
898 <table class="display compact nowrap" id="secondtable">
Marc Kupietz58270662017-12-04 12:10:06 +0100899 <thead>
900 <tr>
901 % if($collocators) {
902 <th>#</th>
Marc Kupietz4116b432017-12-06 14:15:32 +0100903 <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>
904 <th align="right" title="Maximum activation of the collocator anywhere in the output layer.">max(a)</th>
905 <th title="Average raw activation of the collocator in the columns selected by auto-focus." align="right">⟨a⟩</th>
906 <th title="Sum of activations over the selected colunns normalized by the total activation sum of the selected columns." align="right">Σa/Σw'</th>
907 <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 +0100908 <th title="Sum of the activations over the whole window normalized by the total window sum (no auto-focus)." align="right">Σa/Σw</th>
909 <th align="left">collocator</th>
910 % }
911 </tr>
912 </thead>
913 <tbody>
914 <tr>
915 <td align="right">
916 </td>
917 <td align="right">
918 </td>
919 <td align="right">
920 </td>
921 <td align="right">
922 </td>
923 <td align="right">
924 </td>
925 <td align="right">
926 </td>
Marc Kupietz58270662017-12-04 12:10:06 +0100927 </tr>
928 </tbody>
929 </table>
Marc Kupietz66bfd952017-12-11 09:59:45 +0100930 </div>
Marc Kupietze6a7a732018-01-12 09:21:08 +0100931 <div style="margin-left:20px; float:right; width: 500px">
932 <table class="display compact nowrap" id="classicoloctable">
933 <thead>
934 <tr>
935 <th>llr</th>
936 <th title="log-frequency biased mutual dependency">lfmd</th>
937 <th title="frequency biased pointwise mutual information">fpmi</th>
Marc Kupietz78b434a2018-01-12 22:33:32 +0100938 <th title="normalized pointwise mutual information">npmi</th>
Marc Kupietze6a7a732018-01-12 09:21:08 +0100939 <th>collocator</th>
940 </tr>
941 </thead>
942 <tbody>
943 <tr>
944 <td align="right">
945 </td>
946 <td align="right">
947 </td>
948 <td align="right">
949 </td>
950 <td align="right">
951 </td>
952 </tr>
953 </tbody>
954 </table>
955 </div>
956 <div style="clear:both" ></div>
Marc Kupietz66bfd952017-12-11 09:59:45 +0100957 <div style="float: right; overflow: hidden" id="extra"><button onClick="showCollocatorSOM()"> </button></div>
Marc Kupietz66bfd952017-12-11 09:59:45 +0100958 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100959 </div>
960 </div> <!-- topwrapper -->
961 <div style="clear: both;"></div>
962 </div>
Marc Kupietzebea4702018-01-12 09:16:09 +0100963 % if($training_args && (@$lists)[0]) {
964 <div class="info">
965 % if($training_args =~ /-type\s*3/) {
966 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 %>
967 % } else {
968 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 %>
969 % }
970 </div>
Marc Kupietz83305222016-04-28 09:57:22 +0200971 % }
Marc Kupietz58270662017-12-04 12:10:06 +0100972 </body>
Marc Kupietz83305222016-04-28 09:57:22 +0200973</html>