blob: a29ced362439e8958ba74f98043bc1309b6b0a9d [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 Kupietz3eeb1022017-12-06 09:44:11 +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 Kupietza6e08f02017-12-01 22:06:21 +010020
Marc Kupietz4abcd682017-11-28 20:51:08 +010021 $('#firstable').hide();
Marc Kupietz58270662017-12-04 12:10:06 +010022 $(document).ready(function() {
Marc Kupietz694610d2017-11-25 18:30:03 +010023
Marc Kupietz58270662017-12-04 12:10:06 +010024 $("input").bind("keydown", function(event) {
25 // track enter key
26 var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
27 if (keycode == 13) { // keycode for enter key
28 // force the 'Enter Key' to implicitly click the Update button
29 document.getElementById('SEARCH').click();
30 return false;
31 } else {
32 return true;
33 }});
Marc Kupietzdab9f222017-11-29 14:22:59 +010034
Marc Kupietz58270662017-12-04 12:10:06 +010035 $( "#tabs" ).on( "tabsactivate", function( event, ui ) {
36 if (localStorage) localStorage['tab'] = ui.newTab.index();
37 });
Marc Kupietz0af83e32017-11-27 09:31:37 +010038
Marc Kupietz58270662017-12-04 12:10:06 +010039 $(function(){
40 $("#SEARCH").click(function() {
41 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
42 });
43 });
Marc Kupietz2f6b74a2017-12-01 13:20:21 +010044
Marc Kupietz3eeb1022017-12-06 09:44:11 +010045 function changeCharColor(txt, heat, word) {
Marc Kupietz58270662017-12-04 12:10:06 +010046 var newText = "";
47 for (var i=0, l=txt.length; i<l; i++) {
Marc Kupietz3eeb1022017-12-06 09:44:11 +010048 newText += (i == 5 ? txt.charAt(i) : '<a href="http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q=' +
Marc Kupietzb3a2e4f2017-12-08 17:25:53 +010049 CIIsearchWords + ' /' + (i > 5? '%2B' : '-') + 'w' +
Marc Kupietz3eeb1022017-12-06 09:44:11 +010050 Math.abs(i-5) + ':' + Math.abs(i-5) + ' ' + word +
51 '" target="korap"><span style="background-color:' +
52 getHeatColor(heat[i]/maxHeat)+'">'+txt.charAt(i)+'</span></a>');
Marc Kupietz58270662017-12-04 12:10:06 +010053 }
54 return newText;
Marc Kupietzb6c615d2017-12-02 10:38:20 +010055 }
Marc Kupietzb6c615d2017-12-02 10:38:20 +010056
Marc Kupietz58270662017-12-04 12:10:06 +010057 function getHeatColor(value) {
58 var hue=((1-value)*120).toString(10);
59 return ["hsl(",hue,",90%,70%)"].join("");
Marc Kupietz0d4c0ca2017-12-04 09:18:56 +010060 }
Marc Kupietz0d4c0ca2017-12-04 09:18:56 +010061
Marc Kupietz3eeb1022017-12-06 09:44:11 +010062 function bitvec2window(n, heat, word) {
Marc Kupietz58270662017-12-04 12:10:06 +010063 var str = n.toString(2).padStart(10, "0")
64 .replace(/^([0-9]{5})/, '$1x')
65 .replace(/0/g, '·')
66 .replace(/1/g, '+');
Marc Kupietz3eeb1022017-12-06 09:44:11 +010067 return changeCharColor(str, heat, word);
Marc Kupietzddaba632017-12-02 17:30:56 +010068 }
Marc Kupietz6e2fc102017-12-01 22:07:23 +010069
Marc Kupietz58270662017-12-04 12:10:06 +010070 % use Mojo::ByteStream 'b';
Marc Kupietz58270662017-12-04 12:10:06 +010071 var paraResults = <%= b(Mojo::JSON::to_json($lists)) %>;
72 var urlprefix = new URLSearchParams(window.location.search);
Marc Kupietz451f8d82017-12-04 13:19:47 +010073 if (paraResults.length > 0 && paraResults[0] != null) {
Marc Kupietz58270662017-12-04 12:10:06 +010074 var nvecs = [],
75 nwords = [],
76 nranks = [],
77 nmarked = [];
78 for(var i = 0; i < paraResults.length; i++) {
79 nwords = nwords.concat(paraResults[i].map(function(a){return a.word;}));
80 nvecs = nvecs.concat(paraResults[i].map(function(a){return a.vector;}));
81 nranks = nranks.concat(paraResults[i].map(function(a){return a.rank;}));
82 nmarked = nmarked.concat(paraResults[i].map(function(a){return a.marked;}));
83 }
Marc Kupietz8f9c86a2017-12-04 17:17:13 +010084 showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: nvecs, ranks: nranks, marked: nmarked} );
Marc Kupietz58270662017-12-04 12:10:06 +010085 var t = $('#firsttable').DataTable({
86 data: paraResults[0],
87 "sScrollY": "780px",
88 "bScrollCollapse": true,
89 "bPaginate": false,
90 "bJQueryUI": true,
91 "dom": '<"top">rt<"bottom"flp><"clear">',
92 "columns": [
93 { "data": "rank", type: "allnumeric" },
94 { "data": "dist", render: function ( data, type, row ) {return data.toFixed(3) }},
95 { "data": "word", render: function ( data, type, row ) {urlprefix.set("word", data); return '<a href="?' + urlprefix + '">' + data + '</a>' }}
96 ],
97 "columnDefs": [
98 { className: "dt-right", "targets": [0,1] },
99 { "searchable": false,
100 "orderable": false,
101 "targets": 0
102 },
103 { "orderSequence": [ "desc" ], "targets": [ 1 ] },
104 { "orderSequence": [ "asc", "desc" ], "targets": [ 2 ] },
105 ],
Marc Kupietzd6b15442017-12-04 13:20:27 +0100106 "oLanguage": {
107 "sSearch": "Filter: "
108 },
Marc Kupietz58270662017-12-04 12:10:06 +0100109 "order": [[ 1, 'desc' ]],
110 } );
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100111
Marc Kupietz58270662017-12-04 12:10:06 +0100112 t.on( 'order.dt search.dt', function () {
113 t.column(0, {order:'applied'}).nodes().each( function (cell, i) {
114 cell.innerHTML = i+1;
115 } );
116 } ).draw();
Marc Kupietzdab9f222017-11-29 14:22:59 +0100117
Marc Kupietz58270662017-12-04 12:10:06 +0100118 $( "#first" ).clone().prependTo( "#tabs-2" );
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100119
Marc Kupietz58270662017-12-04 12:10:06 +0100120 }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100121
Marc Kupietz58270662017-12-04 12:10:06 +0100122 var collocatorData = <%= b(Mojo::JSON::to_json($collocators)) %>;
123 var maxHeat; // = Math.max.apply(Math,collocatorData.map(function(o){return o.cprob;}))
Marc Kupietz3305b0a2017-11-27 10:46:20 +0100124
Marc Kupietz58270662017-12-04 12:10:06 +0100125 if (collocatorData != null) {
126 maxHeat = Math.max.apply(Math,collocatorData.map(function(o){return Math.max.apply(Math,o.heat);}))
127 var t = $('#secondtable').DataTable({
128 data: collocatorData,
129 "sScrollY": "780px",
130 "bScrollCollapse": true,
131 "bPaginate": false,
132 "bJQueryUI": true,
133 "dom": '<"top">rt<"bottom"flp><"clear">',
134 "columns": [
135 { "data": "rank", type: "allnumeric" },
Marc Kupietz3eeb1022017-12-06 09:44:11 +0100136 { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat, row.word) }},
Marc Kupietz58270662017-12-04 12:10:06 +0100137 { "data": "max", render: function ( data, type, row ) {return data.toFixed(3) }},
Marc Kupietz4116b432017-12-06 14:15:32 +0100138 { "data": "average", render: function ( data, type, row ) {return data.toFixed(3) }},
Marc Kupietz58270662017-12-04 12:10:06 +0100139 { "data": "prob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
140 { "data": "cprob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
141 { "data": "overall", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
142 { "data": "word", sClass: "collocator" }
143 ],
144 "columnDefs": [
145 { className: "dt-right", "targets": [0,2,3,4,5,6] },
146 { className: "dt-center", "targets": [ 1] },
147 { "searchable": false,
148 "orderable": false,
149 "targets": 0
150 },
151 { "type": "scientific", targets: [2,3,4,5,6] },
152 { "orderSequence": [ "desc" ], "targets": [ 2, 3, 4, 5, 6 ] },
153 { "orderSequence": [ "asc", "desc" ], "targets": [ 1, 7 ] },
154 ],
Marc Kupietzd6b15442017-12-04 13:20:27 +0100155 "oLanguage": {
156 "sSearch": "Filter: "
157 },
Marc Kupietz58270662017-12-04 12:10:06 +0100158 "order": [[ 4, 'desc' ]],
159 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100160
Marc Kupietz58270662017-12-04 12:10:06 +0100161 t.on( 'order.dt search.dt', function () {
162 t.column(0, {order:'applied'}).nodes().each( function (cell, i) {
163 cell.innerHTML = i+1;
164 } );
165 } ).draw();
166
Marc Kupietz0ba5c812017-12-06 09:41:25 +0100167 if (localStorage && !window.location.hash) { // let's not crash if some user has IE7
Marc Kupietz58270662017-12-04 12:10:06 +0100168 var index = parseInt(localStorage['tab']||'0');
169 $("#tabs").tabs({ active: index });
170 }
171 }
172 $("#tabs").css("visibility", "visible"); // now we can show the tabs
173
174 });
175
176 $(function(){
177 $("#dropdownoptions").dialog({
178 title: "Options",
179 autoOpen: false,
180 modal: false,
181 draggable: false,
182 height: "auto",
183 width: "auto",
184 resizable: false,
185 buttons: {
186 "Cancel": function() {
187 $( this ).dialog( "close" );
188 },
189 "Apply": function() {
190 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
191 }
192 }
193 });
194 });
195
196 $(function(){
197 $("td.collocator").click(function(){
Marc Kupietzb3a2e4f2017-12-08 17:25:53 +0100198 queryKorAPCII(this.textContent + " /w5 " + CIIsearchWords);
Marc Kupietz58270662017-12-04 12:10:06 +0100199 });
200 });
201
202 $(function(){
203 $("#showoptions").click(function(){
204 $("#dropdownoptions").dialog("open");
205 var target = $(this);
206 $("#dropdownoptions").dialog("widget").position({
207 my: 'left bottom',
208 at: 'left bottom',
209 of: target
210 });
211 });
212 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100213
214 $( function() {
Marc Kupietz58270662017-12-04 12:10:06 +0100215 $( "#no_iterations" ).spinner({
216 spin: function( event, ui ) {
217 if ( ui.value < 1000 ) {
218 $( this ).spinner( "value", 1000 );
219 return false;
220 } else if ( ui.value > 10000 ) {
221 $( this ).spinner( "value", 10000 );
222 return false;
223 }
224 }
225 });
226 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100227
Marc Kupietz58270662017-12-04 12:10:06 +0100228 $( function() {
229 $( "#neighbours" ).spinner({
230 spin: function( event, ui ) {
231 if ( ui.value < 0 ) {
232 $( this ).spinner( "value", 0 );
233 return false;
234 } else if ( ui.value > 200 ) {
235 $( this ).spinner( "value", 200 );
236 return false;
237 }
238 }
239 });
240 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100241
Marc Kupietz58270662017-12-04 12:10:06 +0100242 $( function() {
243 $( "#cutoff" ).spinner({
244 spin: function( event, ui ) {
245 if ( ui.value < 100000 ) {
246 $( this ).spinner( "value", 100000 );
247 return false;
248 } else if ( ui.value > 2000000 ) {
249 $( this ).spinner( "value", 2000000 );
250 return false;
251 }
252 }
253 });
254 } );
255
256 $( function() {
257 $( "#tabs" ).tabs().addClass('tabs-min');
258 } );
259
260 $( function() {
261 $( ".controlgroup-vertical" ).controlgroup({
262 "direction": "vertical"
263 });
264 } );
265
266 $(function() {
267 $( document ).tooltip({
268 content: function() {
269 return $(this).attr('title');
270 }}
271 )
272 })
Marc Kupietz694610d2017-11-25 18:30:03 +0100273
Marc Kupietz83305222016-04-28 09:57:22 +0200274 </script>
Marc Kupietz58270662017-12-04 12:10:06 +0100275 <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
276 <script src="/derekovecs/js/tsne.js"></script>
277 <script src="/derekovecs/js/som.js"></script>
278 <script src="/derekovecs/js/labeler.js"></script>
Marc Kupietz83305222016-04-28 09:57:22 +0200279 <style>
280 body, input {
Marc Kupietz58270662017-12-04 12:10:06 +0100281 font-family: Lato, sans-serif;
282 font-size: 11pt;
Marc Kupietz83305222016-04-28 09:57:22 +0200283 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100284
Marc Kupietz58270662017-12-04 12:10:06 +0100285 h1, h2, h3 {
286 margin: 5px 10px 0 0;
287 color: rgb(246,168,0);
288 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;
289 font-weight: bold;
290 line-height: 1.35;
291 letter-spacing: normal;
292 text-transform: uppercase;
293 text-shadow: none;
294 word-wrap: break-word;
295 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100296
297
Marc Kupietz58270662017-12-04 12:10:06 +0100298 showoptions, #SEARCH {
299 margin-left: 10px;
300 margin-right: 10px;
301 }
Marc Kupietz6dbadd12017-11-29 16:43:33 +0100302
Marc Kupietz58270662017-12-04 12:10:06 +0100303 .tabs-left-vertical .ui-tabs-nav {
304 position: absolute;
305 width: 21em;
306 transform: translate(-100%,0%) rotate(-90deg);
307 transform-origin: 100% 0%;
308 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100309
Marc Kupietz58270662017-12-04 12:10:06 +0100310 .tabs-left-vertical .ui-tabs-nav li {
311 float: right;
312 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100313
Marc Kupietz58270662017-12-04 12:10:06 +0100314 .tabs-left-vertical .ui-tabs-panel {
315 padding-left: 3.5em;
316 }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100317
Marc Kupietz58270662017-12-04 12:10:06 +0100318 .tabs-left-vertical .ui-tabs-panel {
319 height: 20em;
320 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100321
Marc Kupietz58270662017-12-04 12:10:06 +0100322 .mono {
323 font-family: "DejaVu Sans Mono", Inconsolata, SourceCodePro, Courier;
324 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100325
Marc Kupietz58270662017-12-04 12:10:06 +0100326 .ui-tooltip-content {
Marc Kupietz4116b432017-12-06 14:15:32 +0100327 font-size: 10pt;
Marc Kupietz58270662017-12-04 12:10:06 +0100328 color: #222222;
329 }
Marc Kupietzf4b49392016-04-28 10:49:56 +0200330
Marc Kupietz58270662017-12-04 12:10:06 +0100331 svg > .ui-tooltip-content {
332 font-size: 8pt;
333 color: #222222;
334 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100335
Marc Kupietz58270662017-12-04 12:10:06 +0100336 a.merged {
337 color: green;
338 fill: green;
339 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100340
Marc Kupietz58270662017-12-04 12:10:06 +0100341 #first a {
342 text-decoration: none;
343 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100344
Marc Kupietz58270662017-12-04 12:10:06 +0100345 a.marked, #first a.marked {
346 text-decoration: underline;
347 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100348
Marc Kupietz58270662017-12-04 12:10:06 +0100349 a.target {
350 color: red;
351 fill: red;
352 }
Marc Kupietz694610d2017-11-25 18:30:03 +0100353
Marc Kupietz58270662017-12-04 12:10:06 +0100354 table.display {
355 width: 40% important!;
356 margin: 1; /* <- works for me this way ****/
357 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100358
Marc Kupietz58270662017-12-04 12:10:06 +0100359 table.dataTable thead th, table.dataTable thead td, table.dataTable tbody td {
360 padding: 2px 2px;
361 // border-bottom: 1px solid #111;
362 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100363
Marc Kupietz8f75b1f2017-12-06 09:42:13 +0100364 td.collocator {
365 cursor: pointer;
366 }
367
Marc Kupietz58270662017-12-04 12:10:06 +0100368 #collocators {
369 margin-bottom: 15px;
370 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100371
Marc Kupietz58270662017-12-04 12:10:06 +0100372 #header {
373 width: 100%;
374 // border: 1px solid red;
375 overflow: hidden; /* will contain if #first is longer than #second */
376 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100377
Marc Kupietz58270662017-12-04 12:10:06 +0100378 #topwrapper {
379 width: 100%;
380 // border: 1px solid red;
381 overflow: hidden; /* will contain if #first is longer than #second */
382 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100383
Marc Kupietz58270662017-12-04 12:10:06 +0100384 #wrapper {
385 // border: 1px solid red;
386 overflow: hidden; /* will contain if #first is longer than #second */
387 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100388
Marc Kupietz58270662017-12-04 12:10:06 +0100389 #pagetitle {
390 max-width: 460px;
391 margin-right: 20px;
392 float: left;
393 overflow: hidden; /* if you don't want #second to wrap below #first */
394 // border: 1px solid green;
395 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100396
Marc Kupietz58270662017-12-04 12:10:06 +0100397 #options {
398 float: left;
399 width: 800px;
400 margin: 10px;
401 overflow: hidden; /* if you don't want #second to wrap below #first */
402 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100403
Marc Kupietz58270662017-12-04 12:10:06 +0100404 #word {
405 width: 50%;
406 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100407
Marc Kupietz58270662017-12-04 12:10:06 +0100408 #first {
409 margin-right: 20px;
410 float: left;
411 overflow: hidden; /* if you don't want #second to wrap below #first */
412 // border: 1px solid green;
413 }
414 #tabs {
415 margin-right: 20px;
416 overflow: hidden; /* if you don't want #second to wrap below #first */
417 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100418
Marc Kupietz58270662017-12-04 12:10:06 +0100419 .tabs-min {
420 background: transparent;
421 border: none;
422 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100423
Marc Kupietz58270662017-12-04 12:10:06 +0100424 .tabs-min .ui-widget-header {
425 background: transparent;
426 border: none;
427 border-bottom: 1px solid #c0c0c0;
428 -moz-border-radius: 0px;
429 -webkit-border-radius: 0px;
430 border-radius: 0px;
431 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100432
Marc Kupietz58270662017-12-04 12:10:06 +0100433 .tabs-min .ui-tabs-nav .ui-state-default {
434 background: transparent;
435 border: none;
436 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100437
Marc Kupietz58270662017-12-04 12:10:06 +0100438 .tabs-min .ui-tabs-nav .ui-state-active {
439 background: transparent url(derekovecs/img/uiTabsArrow.png) no-repeat bottom center;
440 border: none;
441 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100442
Marc Kupietz58270662017-12-04 12:10:06 +0100443 .tabs-min .ui-tabs-nav .ui-state-default a {
444 color: #c0c0c0;
445 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100446
Marc Kupietz58270662017-12-04 12:10:06 +0100447 .tabs-min .ui-tabs-nav .ui-state-active a {
448 color: rgb(246,168,0);
449 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100450
Marc Kupietz58270662017-12-04 12:10:06 +0100451 #embed {
452 max-width: 802px;
453 border: 1px solid #333;
454 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100455
Marc Kupietz58270662017-12-04 12:10:06 +0100456 #second {
457 min-width: 800px;
458 // border: 1px solid #333;
459 overflow: hidden; /* if you don't want #second to wrap below #first */
460 }
461 #som2 svg {
462 border: 1px solid #333;
463 }
Marc Kupietz83305222016-04-28 09:57:22 +0200464
Marc Kupietz58270662017-12-04 12:10:06 +0100465 #cost {
466 font-size: 8pt;
467 color: #222222;
468 margin-top: 4px;
469 margin-bottom: 12px;
470 }
Marc Kupietz83305222016-04-28 09:57:22 +0200471
Marc Kupietz58270662017-12-04 12:10:06 +0100472 #sominfo1, #sominfo {
473 font-size: 8pt;
474 color: #222222;
475 margin-top: 0px;
476 }
Marc Kupietz83305222016-04-28 09:57:22 +0200477
Marc Kupietz58270662017-12-04 12:10:06 +0100478 #somcolor1, #somcolor2, #somcolor3 {
479 display: inline-block;
480 height: 10px;
481 width: 10px;
482 }
Marc Kupietz83305222016-04-28 09:57:22 +0200483
Marc Kupietz58270662017-12-04 12:10:06 +0100484 #third {
485 border: 1px solid #333;
486 }
Marc Kupietz83305222016-04-28 09:57:22 +0200487
488 </style>
489 <script>
490
491 var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>},
Marc Kupietz58270662017-12-04 12:10:06 +0100492 mapWidth = 800, // width map
493 mapHeight = 800,
494 jitterRadius = 7;
Marc Kupietz83305222016-04-28 09:57:22 +0200495
496 var T = new tsnejs.tSNE(opt); // create a tSNE instance
497
498 var Y;
499
500 var data;
501 var labeler;
502
503 function applyJitter() {
Marc Kupietz58270662017-12-04 12:10:06 +0100504 svg.selectAll('.tsnet')
505 .data(labels)
506 .transition()
507 .duration(50)
508 .attr("transform", function(d, i) {
509 T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20;
510 T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20;
511 return "translate(" +
Marc Kupietz3eeb1022017-12-06 09:44:11 +0100512 (d.x) + "," +
513 (d.y) + ")";
Marc Kupietz58270662017-12-04 12:10:06 +0100514 });
Marc Kupietz83305222016-04-28 09:57:22 +0200515 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100516
Marc Kupietz83305222016-04-28 09:57:22 +0200517 function updateEmbedding() {
Marc Kupietz58270662017-12-04 12:10:06 +0100518 var Y = T.getSolution();
519 svg.selectAll('.tsnet')
520 .data(data.words)
521 .attr("transform", function(d, i) {
522 return "translate(" +
Marc Kupietz3eeb1022017-12-06 09:44:11 +0100523 ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," +
524 ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; });
Marc Kupietz83305222016-04-28 09:57:22 +0200525 }
526
527 var svg;
528 var labels = [];
529 var anchor_array = [];
530 var text;
531
532 function drawEmbedding() {
Marc Kupietz58270662017-12-04 12:10:06 +0100533 var urlprefix = new URLSearchParams(window.location.search);
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100534 urlprefix.delete("word");
535 urlprefix.append("word","");
536
Marc Kupietz58270662017-12-04 12:10:06 +0100537 $("#embed").empty();
538 var div = d3.select("#embed");
Marc Kupietz34c08172017-11-29 17:08:47 +0100539
Marc Kupietz58270662017-12-04 12:10:06 +0100540 // get min and max in each column of Y
541 var Y = T.Y;
Marc Kupietz34c08172017-11-29 17:08:47 +0100542
Marc Kupietz58270662017-12-04 12:10:06 +0100543 svg = div.append("svg") // svg is global
544 .attr("width", mapWidth)
545 .attr("height", mapHeight);
Marc Kupietz34c08172017-11-29 17:08:47 +0100546
Marc Kupietz58270662017-12-04 12:10:06 +0100547 var g = svg.selectAll(".b")
548 .data(data.words)
549 .enter().append("g")
550 .attr("class", "tsnet");
Marc Kupietz34c08172017-11-29 17:08:47 +0100551
Marc Kupietz58270662017-12-04 12:10:06 +0100552 g.append("a")
553 .attr("xlink:href", function(word) {
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100554 return "?"+urlprefix+word; })
Marc Kupietz58270662017-12-04 12:10:06 +0100555 .attr("class", function(d, i) {
556 var res="";
557 if(data.marked[i]) {
558 res="marked ";
559 }
560 if(data.target.indexOf(" "+d+" ") >= 0) {
561 return res+"target";
562 } else if(data.ranks[i] < data.mergedEnd) {
563 return res+"merged";
564 } else {
565 return res;
566 }
567 })
568 .attr("title", function(d, i) {
569 if(data.mergedEnd > 0) {
570 if(data.ranks[i] >= data.mergedEnd) {
571 return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
572 } else {
573 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
574 }
575 } else {
576 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
577 }
578 })
579 .append("text")
580 .attr("text-anchor", "top")
581 .attr("font-size", 12)
582 .text(function(d) { return d; });
Marc Kupietz34c08172017-11-29 17:08:47 +0100583
Marc Kupietz58270662017-12-04 12:10:06 +0100584 var zoomListener = d3.behavior.zoom()
585 .scaleExtent([0.1, 10])
586 .center([0,0])
587 .on("zoom", zoomHandler);
588 zoomListener(svg);
Marc Kupietz83305222016-04-28 09:57:22 +0200589 }
590
591 var tx=0, ty=0;
592 var ss=1;
593 var iter_id=-1;
594
595 function zoomHandler() {
Marc Kupietz58270662017-12-04 12:10:06 +0100596 tx = d3.event.translate[0];
597 ty = d3.event.translate[1];
598 ss = d3.event.scale;
599 updateEmbedding();
Marc Kupietz83305222016-04-28 09:57:22 +0200600 }
601
602 var stepnum = 0;
603
604 function stopStep() {
Marc Kupietz58270662017-12-04 12:10:06 +0100605 clearInterval(iter_id);
606 text = svg.selectAll("text");
Marc Kupietz34c08172017-11-29 17:08:47 +0100607
Marc Kupietz58270662017-12-04 12:10:06 +0100608 // jitter function needs different data and co-ordinate representation
609 labels = d3.range(data.words.length).map(function(i) {
610 var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2;
611 var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2;
612 anchor_array.push({x: x, y: y, r: jitterRadius});
613 return {
614 x: x,
615 y: y,
616 name: data.words[i]
617 };
618 });
Marc Kupietz34c08172017-11-29 17:08:47 +0100619
Marc Kupietz58270662017-12-04 12:10:06 +0100620 // get the actual label bounding boxes for the jitter function
621 var index = 0;
622 text.each(function() {
623 labels[index].width = this.getBBox().width;
624 labels[index].height = this.getBBox().height;
625 index += 1;
626 });
Marc Kupietz83305222016-04-28 09:57:22 +0200627
Marc Kupietz34c08172017-11-29 17:08:47 +0100628
Marc Kupietz58270662017-12-04 12:10:06 +0100629 // setTimeout(updateEmbedding, 1);
630 // setTimeout(
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100631 labeler = d3.labeler()
632 .label(labels)
633 .anchor(anchor_array)
634 .width(mapWidth)
635 .height(mapHeight)
636 .update(applyJitter);
Marc Kupietz58270662017-12-04 12:10:06 +0100637 // .start(1000);
Marc Kupietz83305222016-04-28 09:57:22 +0200638
Marc Kupietz58270662017-12-04 12:10:06 +0100639 iter_id = setInterval(jitterStep, 1);
Marc Kupietz83305222016-04-28 09:57:22 +0200640 }
641
642 var jitter_i=0;
643
644 function jitterStep() {
Marc Kupietz58270662017-12-04 12:10:06 +0100645 if(jitter_i++ > 100) {
646 clearInterval(iter_id);
647 } else {
648 labeler.start2(10);
649 applyJitter();
650 }
Marc Kupietz83305222016-04-28 09:57:22 +0200651 }
652
653 var last_cost=1000;
654
655 function step() {
Marc Kupietz58270662017-12-04 12:10:06 +0100656 var i = T.iter;
Marc Kupietz34c08172017-11-29 17:08:47 +0100657
Marc Kupietz58270662017-12-04 12:10:06 +0100658 if(i > <%= $no_iterations %>) {
659 stopStep();
660 } else {
661 var cost = Math.round(T.step() * 100000) / 100000; // do a few steps
662 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5));
663 if(i % 250 == 0 && cost >= last_cost) {
664 stopStep();
665 } else {
666 last_cost = cost;
667 updateEmbedding();
668 }
669 }
Marc Kupietz83305222016-04-28 09:57:22 +0200670 }
671
672 function showMap(j) {
Marc Kupietz58270662017-12-04 12:10:06 +0100673 data=j;
674 T.iter=0;
675 T.initDataRaw(data.vecs); // init embedding
676 drawEmbedding(); // draw initial embedding
Marc Kupietz78114532017-11-29 17:00:16 +0100677
Marc Kupietz58270662017-12-04 12:10:06 +0100678 if(iter_id >= 0) {
679 clearInterval(iter_id);
680 }
681 //T.debugGrad();
682 iter_id = setInterval(step, 1);
683 if(true) { // (<%= $show_som %>) {
684 makeSOM(j, <%= $no_iterations %>);
685 }
Marc Kupietz83305222016-04-28 09:57:22 +0200686 }
Marc Kupietz39179ab2017-07-04 16:28:06 +0200687 var queryword;
688
689 function onload() {
Marc Kupietz58270662017-12-04 12:10:06 +0100690 queryword = document.getElementById('word');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200691 }
692
693 function queryKorAP() {
Marc Kupietz58270662017-12-04 12:10:06 +0100694 window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200695 }
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100696
697 function queryKorAPCII(query) {
Marc Kupietz58270662017-12-04 12:10:06 +0100698 window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP');
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100699 }
Marc Kupietz83305222016-04-28 09:57:22 +0200700 </script>
701 </head>
Marc Kupietz39179ab2017-07-04 16:28:06 +0200702 <body onload="onload()">
Marc Kupietz58270662017-12-04 12:10:06 +0100703 <div id="header">
704 <div id="pagetitle">
705 <h1>DeReKo-Vectors</h1>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100706 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100707 <div id="options" class="widget">
708 <form id="queryform">
709 <input id="word" type="text" name="word" placeholder="Word(s) to be searched" value="<%= $word %>"
710 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."/>
711 <input id="SEARCH" type="button" value="SEARCH">
712 <input type="button" id="showoptions" name="showoptions" value="Options" />
713 </form>
714 <div id="dropdownoptions" style="display: none">
715 <form id="optionsform">
716 <div class="controlgroup-vertical">
717 <label for="cutoff">cut-off</label>
718 <input id="cutoff" type="text" name="cutoff" size="10" value="<%= $cutoff %>" title="Only consider the most frequent x word forms.">
719 <label for="dedupe">dedupe</label>
720 <input id="dedupe" type="checkbox" name="dedupe" value="1" <%= ($dedupe ? "checked" : "") %> title="radically filter out any near-duplicates">
721 % if($mergedEnd > 0) {
722 <label for="sbf">backw.</label>
723 <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.">
724 % }
725 <label for="neighbours">max. neighbours:</label>
726 <input id="neighbours" size="4" name="n" value="<%= $no_nbs %>">
727 <label for="no_iterations">max. iterations</label>
728 <input id="no_iterations" name="N" size="4" value="<%= $no_iterations %>">
729 <!-- <label for="dosom">SOM</label>
730 <input id="dosom" type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> -->
731 % if($collocators) {
732 <label for="sortby">window/sort</label>
733 <select id="sortby" name="sort">
734 <option value="0" <%= ($sort!=1 && $sort!=2? "selected":"") %>>auto focus</option>
735 <!-- <option value="1" <%= ($sort==1? "selected":"") %>>any single position</option>
736 <option value="2" <%= ($sort==2? "selected":"") %>>whole window</option> -->
737 </select>
738 % }
739 <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/>
740 </div>
741 </form>
742 </div>
743 </div>
744 </div>
745 <div id="topwrapper">
746 <div style="visibility: hidden;" id="tabs">
747 <ul>
748 <li><a href="#tabs-1">Semantics (TSNE-map)</a></li>
749 <li><a href="#tabs-2">Semantics (SOM)</a></li>
750 <li><a href="#tabs-3">Syntagmatic (collocators)</a></li>
751 </ul>
752 <div id="tabs-1">
753 % if($lists && (@$lists) > 0 && (@$lists)[0]) {
754 <div id="wrapper">
755 <div id="first" style="width: 320px">
756 <table class="display compact nowrap" id="firsttable">
757 <thead>
758 <tr>
759 <th align="right">#</th><th align="right">cos</th><th align="left">similars</th>
760 </tr>
761 </thead>
762 <tbody>
763 <tr>
764 <td align="right">
765 </td>
766 <td align="right">
767 </td>
768 <td></td>
769 </tr>
770 </tbody>
771 </table>
772 </div>
773 <script>
774 </script>
775 <div id="second">
776 <div id="embed">
777 </div>
778 <div id="cost">
779 </div>
780 </div>
781 </div>
782 % } elsif($word !~ /^\s*$/) {
783 <div id="wrapper">
784 <div id="not-found-dialog" title="Not found">
785 <p>ERROR: "<%= $word %>" not found in vocabluary.</p>
786 <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>
787 </div>
788 <script>
789 $( function() {
790 $( "#not-found-dialog" ).dialog({
791 autoOpen: true,
792 modal: true,
793 draggable: false,
794 height: "auto",
795 width: "auto",
796 resizable: false,
797 buttons: {
798 "OK": function() {
799 $( this ).dialog( "close" );
800 },
801 "Apply": function() {
802 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
803 }
804 }
805 });
806 });
807 </script>
808 </div>
809 % }
810 </div>
811 <div id="tabs-2">
812 <div id="som2" style="width: 800; height: 800px">
813 </div>
814 <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div>
815 <div id="sominfo">SOM iteration <span id="iterations">0</span></div>
816 </div>
817 <div id="tabs-3">
818 <div style="width: 800px" id="secondt">
819 <table class="display compact nowrap" id="secondtable">
820 <thead>
821 <tr>
822 % if($collocators) {
823 <th>#</th>
Marc Kupietz4116b432017-12-06 14:15:32 +0100824 <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>
825 <th align="right" title="Maximum activation of the collocator anywhere in the output layer.">max(a)</th>
826 <th title="Average raw activation of the collocator in the columns selected by auto-focus." align="right">⟨a⟩</th>
827 <th title="Sum of activations over the selected colunns normalized by the total activation sum of the selected columns." align="right">Σa/Σw'</th>
828 <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 +0100829 <th title="Sum of the activations over the whole window normalized by the total window sum (no auto-focus)." align="right">Σa/Σw</th>
830 <th align="left">collocator</th>
831 % }
832 </tr>
833 </thead>
834 <tbody>
835 <tr>
836 <td align="right">
837 </td>
838 <td align="right">
839 </td>
840 <td align="right">
841 </td>
842 <td align="right">
843 </td>
844 <td align="right">
845 </td>
846 <td align="right">
847 </td>
848 <script
Marc Kupietz3eeb1022017-12-06 09:44:11 +0100849 src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
Marc Kupietz58270662017-12-04 12:10:06 +0100850 </td>
851 </tr>
852 </tbody>
853 </table>
854 </div> <!-- - tab2 -->
855 </div> <!-- tabs -->
856 </div>
857 </div> <!-- topwrapper -->
858 <div style="clear: both;"></div>
859 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100860 % if($training_args) {
861 <p>
862 Word vector model trained with <a href="https://code.google.com/p/word2vec/">word2vec</a> using the following parameters: <pre><%= $training_args %></pre>
863 </p>
Marc Kupietz83305222016-04-28 09:57:22 +0200864 % }
Marc Kupietz58270662017-12-04 12:10:06 +0100865 </body>
Marc Kupietz83305222016-04-28 09:57:22 +0200866</html>