blob: 08f76305eeee1dadc2fd1e713eb27c4a4ae7ae1b [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 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 Kupietz58270662017-12-04 12:10:06 +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 Kupietz58270662017-12-04 12:10:06 +010036 $( "#tabs" ).on( "tabsactivate", function( event, ui ) {
37 if (localStorage) localStorage['tab'] = ui.newTab.index();
38 });
Marc Kupietz0af83e32017-11-27 09:31:37 +010039
Marc Kupietz58270662017-12-04 12:10:06 +010040 $(function(){
41 $("#SEARCH").click(function() {
42 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
43 });
44 });
Marc Kupietz2f6b74a2017-12-01 13:20:21 +010045
Marc Kupietz3eeb1022017-12-06 09:44:11 +010046 function changeCharColor(txt, heat, word) {
Marc Kupietz58270662017-12-04 12:10:06 +010047 var newText = "";
48 for (var i=0, l=txt.length; i<l; i++) {
Marc Kupietz3eeb1022017-12-06 09:44:11 +010049 newText += (i == 5 ? txt.charAt(i) : '<a href="http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q=' +
Marc Kupietzb3a2e4f2017-12-08 17:25:53 +010050 CIIsearchWords + ' /' + (i > 5? '%2B' : '-') + 'w' +
Marc Kupietz3eeb1022017-12-06 09:44:11 +010051 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 Kupietz58270662017-12-04 12:10:06 +010054 }
55 return newText;
Marc Kupietzb6c615d2017-12-02 10:38:20 +010056 }
Marc Kupietzb6c615d2017-12-02 10:38:20 +010057
Marc Kupietz58270662017-12-04 12:10:06 +010058 function getHeatColor(value) {
59 var hue=((1-value)*120).toString(10);
60 return ["hsl(",hue,",90%,70%)"].join("");
Marc Kupietz0d4c0ca2017-12-04 09:18:56 +010061 }
Marc Kupietz0d4c0ca2017-12-04 09:18:56 +010062
Marc Kupietz3eeb1022017-12-06 09:44:11 +010063 function bitvec2window(n, heat, word) {
Marc Kupietz58270662017-12-04 12:10:06 +010064 var str = n.toString(2).padStart(10, "0")
65 .replace(/^([0-9]{5})/, '$1x')
66 .replace(/0/g, '·')
67 .replace(/1/g, '+');
Marc Kupietz3eeb1022017-12-06 09:44:11 +010068 return changeCharColor(str, heat, word);
Marc Kupietzddaba632017-12-02 17:30:56 +010069 }
Marc Kupietz6e2fc102017-12-01 22:07:23 +010070
Marc Kupietz58270662017-12-04 12:10:06 +010071 % use Mojo::ByteStream 'b';
Marc Kupietz58270662017-12-04 12:10:06 +010072 var paraResults = <%= b(Mojo::JSON::to_json($lists)) %>;
73 var urlprefix = new URLSearchParams(window.location.search);
Marc Kupietz451f8d82017-12-04 13:19:47 +010074 if (paraResults.length > 0 && paraResults[0] != null) {
Marc Kupietz58270662017-12-04 12:10:06 +010075 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;}));
84 }
Marc Kupietz8f9c86a2017-12-04 17:17:13 +010085 showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: nvecs, ranks: nranks, marked: nmarked} );
Marc Kupietz58270662017-12-04 12:10:06 +010086 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 ],
Marc Kupietzd6b15442017-12-04 13:20:27 +0100107 "oLanguage": {
108 "sSearch": "Filter: "
109 },
Marc Kupietz58270662017-12-04 12:10:06 +0100110 "order": [[ 1, 'desc' ]],
111 } );
Marc Kupietz6e2fc102017-12-01 22:07:23 +0100112
Marc Kupietz58270662017-12-04 12:10:06 +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();
Marc Kupietzdab9f222017-11-29 14:22:59 +0100118
Marc Kupietz58270662017-12-04 12:10:06 +0100119 $( "#first" ).clone().prependTo( "#tabs-2" );
Marc Kupietzb6c615d2017-12-02 10:38:20 +0100120
Marc Kupietz58270662017-12-04 12:10:06 +0100121 }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100122
Marc Kupietz58270662017-12-04 12:10:06 +0100123 var collocatorData = <%= b(Mojo::JSON::to_json($collocators)) %>;
124 var maxHeat; // = Math.max.apply(Math,collocatorData.map(function(o){return o.cprob;}))
Marc Kupietz3305b0a2017-11-27 10:46:20 +0100125
Marc Kupietz58270662017-12-04 12:10:06 +0100126 if (collocatorData != null) {
127 maxHeat = Math.max.apply(Math,collocatorData.map(function(o){return Math.max.apply(Math,o.heat);}))
Marc Kupietz66bfd952017-12-11 09:59:45 +0100128 collocatorTable = $('#secondtable').DataTable({
Marc Kupietz58270662017-12-04 12:10:06 +0100129 data: collocatorData,
130 "sScrollY": "780px",
131 "bScrollCollapse": true,
132 "bPaginate": false,
133 "bJQueryUI": true,
134 "dom": '<"top">rt<"bottom"flp><"clear">',
135 "columns": [
136 { "data": "rank", type: "allnumeric" },
Marc Kupietz3eeb1022017-12-06 09:44:11 +0100137 { "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 +0100138 { "data": "max", render: function ( data, type, row ) {return data.toFixed(3) }},
Marc Kupietz4116b432017-12-06 14:15:32 +0100139 { "data": "average", render: function ( data, type, row ) {return data.toFixed(3) }},
Marc Kupietz58270662017-12-04 12:10:06 +0100140 { "data": "prob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
141 { "data": "cprob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
142 { "data": "overall", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
Marc Kupietz66bfd952017-12-11 09:59:45 +0100143 { "data": "word", sClass: "collocator" },
144 { "data": "rank", type: "allnumeric" }
Marc Kupietz58270662017-12-04 12:10:06 +0100145 ],
146 "columnDefs": [
147 { className: "dt-right", "targets": [0,2,3,4,5,6] },
148 { className: "dt-center", "targets": [ 1] },
149 { "searchable": false,
150 "orderable": false,
Marc Kupietz66bfd952017-12-11 09:59:45 +0100151 "targets": [0, 8]
Marc Kupietz58270662017-12-04 12:10:06 +0100152 },
153 { "type": "scientific", targets: [2,3,4,5,6] },
154 { "orderSequence": [ "desc" ], "targets": [ 2, 3, 4, 5, 6 ] },
155 { "orderSequence": [ "asc", "desc" ], "targets": [ 1, 7 ] },
Marc Kupietz66bfd952017-12-11 09:59:45 +0100156 { "targets": [8], "visible": false }
Marc Kupietz58270662017-12-04 12:10:06 +0100157 ],
Marc Kupietzd6b15442017-12-04 13:20:27 +0100158 "oLanguage": {
159 "sSearch": "Filter: "
160 },
Marc Kupietz58270662017-12-04 12:10:06 +0100161 "order": [[ 4, 'desc' ]],
162 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100163
Marc Kupietz66bfd952017-12-11 09:59:45 +0100164 collocatorTable.on( 'order.dt search.dt', function () {
165 collocatorTable.column(0, {order:'applied'}).nodes().each( function (cell, i) {
Marc Kupietz58270662017-12-04 12:10:06 +0100166 cell.innerHTML = i+1;
167 } );
168 } ).draw();
169
Marc Kupietz0ba5c812017-12-06 09:41:25 +0100170 if (localStorage && !window.location.hash) { // let's not crash if some user has IE7
Marc Kupietz58270662017-12-04 12:10:06 +0100171 var index = parseInt(localStorage['tab']||'0');
172 $("#tabs").tabs({ active: index });
173 }
174 }
175 $("#tabs").css("visibility", "visible"); // now we can show the tabs
176
177 });
178
179 $(function(){
180 $("#dropdownoptions").dialog({
181 title: "Options",
182 autoOpen: false,
183 modal: false,
184 draggable: false,
185 height: "auto",
186 width: "auto",
187 resizable: false,
188 buttons: {
189 "Cancel": function() {
190 $( this ).dialog( "close" );
191 },
192 "Apply": function() {
193 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
194 }
195 }
196 });
197 });
198
199 $(function(){
200 $("td.collocator").click(function(){
Marc Kupietzb3a2e4f2017-12-08 17:25:53 +0100201 queryKorAPCII(this.textContent + " /w5 " + CIIsearchWords);
Marc Kupietz58270662017-12-04 12:10:06 +0100202 });
203 });
204
205 $(function(){
206 $("#showoptions").click(function(){
207 $("#dropdownoptions").dialog("open");
208 var target = $(this);
209 $("#dropdownoptions").dialog("widget").position({
210 my: 'left bottom',
211 at: 'left bottom',
212 of: target
213 });
214 });
215 });
Marc Kupietz4abcd682017-11-28 20:51:08 +0100216
217 $( function() {
Marc Kupietz58270662017-12-04 12:10:06 +0100218 $( "#no_iterations" ).spinner({
219 spin: function( event, ui ) {
220 if ( ui.value < 1000 ) {
221 $( this ).spinner( "value", 1000 );
222 return false;
223 } else if ( ui.value > 10000 ) {
224 $( this ).spinner( "value", 10000 );
225 return false;
226 }
227 }
228 });
229 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100230
Marc Kupietz58270662017-12-04 12:10:06 +0100231 $( function() {
232 $( "#neighbours" ).spinner({
233 spin: function( event, ui ) {
234 if ( ui.value < 0 ) {
235 $( this ).spinner( "value", 0 );
236 return false;
237 } else if ( ui.value > 200 ) {
238 $( this ).spinner( "value", 200 );
239 return false;
240 }
241 }
242 });
243 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100244
Marc Kupietz58270662017-12-04 12:10:06 +0100245 $( function() {
246 $( "#cutoff" ).spinner({
247 spin: function( event, ui ) {
248 if ( ui.value < 100000 ) {
249 $( this ).spinner( "value", 100000 );
250 return false;
251 } else if ( ui.value > 2000000 ) {
252 $( this ).spinner( "value", 2000000 );
253 return false;
254 }
255 }
256 });
257 } );
258
259 $( function() {
260 $( "#tabs" ).tabs().addClass('tabs-min');
261 } );
262
263 $( function() {
264 $( ".controlgroup-vertical" ).controlgroup({
265 "direction": "vertical"
266 });
267 } );
268
269 $(function() {
270 $( document ).tooltip({
271 content: function() {
272 return $(this).attr('title');
273 }}
274 )
275 })
Marc Kupietz694610d2017-11-25 18:30:03 +0100276
Marc Kupietz83305222016-04-28 09:57:22 +0200277 </script>
Marc Kupietz58270662017-12-04 12:10:06 +0100278 <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
279 <script src="/derekovecs/js/tsne.js"></script>
280 <script src="/derekovecs/js/som.js"></script>
281 <script src="/derekovecs/js/labeler.js"></script>
Marc Kupietz83305222016-04-28 09:57:22 +0200282 <style>
283 body, input {
Marc Kupietz58270662017-12-04 12:10:06 +0100284 font-family: Lato, sans-serif;
285 font-size: 11pt;
Marc Kupietz83305222016-04-28 09:57:22 +0200286 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100287
Marc Kupietz58270662017-12-04 12:10:06 +0100288 h1, h2, h3 {
289 margin: 5px 10px 0 0;
290 color: rgb(246,168,0);
291 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;
292 font-weight: bold;
293 line-height: 1.35;
294 letter-spacing: normal;
295 text-transform: uppercase;
296 text-shadow: none;
297 word-wrap: break-word;
298 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100299
300
Marc Kupietz58270662017-12-04 12:10:06 +0100301 showoptions, #SEARCH {
302 margin-left: 10px;
303 margin-right: 10px;
304 }
Marc Kupietz6dbadd12017-11-29 16:43:33 +0100305
Marc Kupietz58270662017-12-04 12:10:06 +0100306 .tabs-left-vertical .ui-tabs-nav {
307 position: absolute;
308 width: 21em;
309 transform: translate(-100%,0%) rotate(-90deg);
310 transform-origin: 100% 0%;
311 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100312
Marc Kupietz58270662017-12-04 12:10:06 +0100313 .tabs-left-vertical .ui-tabs-nav li {
314 float: right;
315 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100316
Marc Kupietz58270662017-12-04 12:10:06 +0100317 .tabs-left-vertical .ui-tabs-panel {
318 padding-left: 3.5em;
319 }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100320
Marc Kupietz58270662017-12-04 12:10:06 +0100321 .tabs-left-vertical .ui-tabs-panel {
322 height: 20em;
323 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100324
Marc Kupietz58270662017-12-04 12:10:06 +0100325 .mono {
Marc Kupietzc8221182017-12-08 17:26:19 +0100326 font-family: "DejaVu Sans Mono", Inconsolata, SourceCodePro, "Courier New", Courier, monospace;
Marc Kupietz58270662017-12-04 12:10:06 +0100327 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100328
Marc Kupietz58270662017-12-04 12:10:06 +0100329 .ui-tooltip-content {
Marc Kupietz4116b432017-12-06 14:15:32 +0100330 font-size: 10pt;
Marc Kupietz58270662017-12-04 12:10:06 +0100331 color: #222222;
332 }
Marc Kupietzf4b49392016-04-28 10:49:56 +0200333
Marc Kupietz58270662017-12-04 12:10:06 +0100334 svg > .ui-tooltip-content {
335 font-size: 8pt;
336 color: #222222;
337 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100338
Marc Kupietz58270662017-12-04 12:10:06 +0100339 a.merged {
340 color: green;
341 fill: green;
342 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100343
Marc Kupietz58270662017-12-04 12:10:06 +0100344 #first a {
345 text-decoration: none;
346 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100347
Marc Kupietz58270662017-12-04 12:10:06 +0100348 a.marked, #first a.marked {
349 text-decoration: underline;
350 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100351
Marc Kupietz58270662017-12-04 12:10:06 +0100352 a.target {
353 color: red;
354 fill: red;
355 }
Marc Kupietz694610d2017-11-25 18:30:03 +0100356
Marc Kupietz58270662017-12-04 12:10:06 +0100357 table.display {
358 width: 40% important!;
359 margin: 1; /* <- works for me this way ****/
360 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100361
Marc Kupietz58270662017-12-04 12:10:06 +0100362 table.dataTable thead th, table.dataTable thead td, table.dataTable tbody td {
363 padding: 2px 2px;
364 // border-bottom: 1px solid #111;
365 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100366
Marc Kupietz8f75b1f2017-12-06 09:42:13 +0100367 td.collocator {
368 cursor: pointer;
369 }
370
Marc Kupietz58270662017-12-04 12:10:06 +0100371 #collocators {
372 margin-bottom: 15px;
373 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100374
Marc Kupietz58270662017-12-04 12:10:06 +0100375 #header {
376 width: 100%;
377 // border: 1px solid red;
378 overflow: hidden; /* will contain if #first is longer than #second */
379 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100380
Marc Kupietz58270662017-12-04 12:10:06 +0100381 #topwrapper {
382 width: 100%;
383 // border: 1px solid red;
384 overflow: hidden; /* will contain if #first is longer than #second */
385 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100386
Marc Kupietz58270662017-12-04 12:10:06 +0100387 #wrapper {
388 // border: 1px solid red;
389 overflow: hidden; /* will contain if #first is longer than #second */
390 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100391
Marc Kupietz58270662017-12-04 12:10:06 +0100392 #pagetitle {
393 max-width: 460px;
394 margin-right: 20px;
395 float: left;
396 overflow: hidden; /* if you don't want #second to wrap below #first */
397 // border: 1px solid green;
398 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100399
Marc Kupietz58270662017-12-04 12:10:06 +0100400 #options {
401 float: left;
402 width: 800px;
403 margin: 10px;
404 overflow: hidden; /* if you don't want #second to wrap below #first */
405 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100406
Marc Kupietz58270662017-12-04 12:10:06 +0100407 #word {
408 width: 50%;
409 }
Marc Kupietz81bf39c2017-11-29 17:04:35 +0100410
Marc Kupietz58270662017-12-04 12:10:06 +0100411 #first {
412 margin-right: 20px;
413 float: left;
414 overflow: hidden; /* if you don't want #second to wrap below #first */
415 // border: 1px solid green;
416 }
417 #tabs {
418 margin-right: 20px;
419 overflow: hidden; /* if you don't want #second to wrap below #first */
420 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100421
Marc Kupietz58270662017-12-04 12:10:06 +0100422 .tabs-min {
423 background: transparent;
424 border: none;
425 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100426
Marc Kupietz58270662017-12-04 12:10:06 +0100427 .tabs-min .ui-widget-header {
428 background: transparent;
429 border: none;
430 border-bottom: 1px solid #c0c0c0;
431 -moz-border-radius: 0px;
432 -webkit-border-radius: 0px;
433 border-radius: 0px;
434 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100435
Marc Kupietz58270662017-12-04 12:10:06 +0100436 .tabs-min .ui-tabs-nav .ui-state-default {
437 background: transparent;
438 border: none;
439 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100440
Marc Kupietz58270662017-12-04 12:10:06 +0100441 .tabs-min .ui-tabs-nav .ui-state-active {
442 background: transparent url(derekovecs/img/uiTabsArrow.png) no-repeat bottom center;
443 border: none;
444 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100445
Marc Kupietz58270662017-12-04 12:10:06 +0100446 .tabs-min .ui-tabs-nav .ui-state-default a {
447 color: #c0c0c0;
448 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100449
Marc Kupietz58270662017-12-04 12:10:06 +0100450 .tabs-min .ui-tabs-nav .ui-state-active a {
451 color: rgb(246,168,0);
452 }
Marc Kupietzdf3d4b52017-11-29 16:57:27 +0100453
Marc Kupietz58270662017-12-04 12:10:06 +0100454 #embed {
455 max-width: 802px;
456 border: 1px solid #333;
457 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100458
Marc Kupietz58270662017-12-04 12:10:06 +0100459 #second {
460 min-width: 800px;
461 // border: 1px solid #333;
462 overflow: hidden; /* if you don't want #second to wrap below #first */
463 }
464 #som2 svg {
465 border: 1px solid #333;
466 }
Marc Kupietz83305222016-04-28 09:57:22 +0200467
Marc Kupietz58270662017-12-04 12:10:06 +0100468 #cost {
469 font-size: 8pt;
470 color: #222222;
471 margin-top: 4px;
472 margin-bottom: 12px;
473 }
Marc Kupietz83305222016-04-28 09:57:22 +0200474
Marc Kupietz58270662017-12-04 12:10:06 +0100475 #sominfo1, #sominfo {
476 font-size: 8pt;
477 color: #222222;
478 margin-top: 0px;
479 }
Marc Kupietz83305222016-04-28 09:57:22 +0200480
Marc Kupietz58270662017-12-04 12:10:06 +0100481 #somcolor1, #somcolor2, #somcolor3 {
482 display: inline-block;
483 height: 10px;
484 width: 10px;
485 }
Marc Kupietz83305222016-04-28 09:57:22 +0200486
Marc Kupietz58270662017-12-04 12:10:06 +0100487 #third {
488 border: 1px solid #333;
489 }
Marc Kupietz83305222016-04-28 09:57:22 +0200490
491 </style>
492 <script>
493
494 var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>},
Marc Kupietz58270662017-12-04 12:10:06 +0100495 mapWidth = 800, // width map
496 mapHeight = 800,
497 jitterRadius = 7;
Marc Kupietz83305222016-04-28 09:57:22 +0200498
499 var T = new tsnejs.tSNE(opt); // create a tSNE instance
500
501 var Y;
502
503 var data;
504 var labeler;
505
506 function applyJitter() {
Marc Kupietz58270662017-12-04 12:10:06 +0100507 svg.selectAll('.tsnet')
508 .data(labels)
509 .transition()
510 .duration(50)
511 .attr("transform", function(d, i) {
512 T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20;
513 T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20;
514 return "translate(" +
Marc Kupietz66bfd952017-12-11 09:59:45 +0100515 (d.x) + "," +
516 (d.y) + ")";
Marc Kupietz58270662017-12-04 12:10:06 +0100517 });
Marc Kupietz83305222016-04-28 09:57:22 +0200518 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100519
Marc Kupietz83305222016-04-28 09:57:22 +0200520 function updateEmbedding() {
Marc Kupietz58270662017-12-04 12:10:06 +0100521 var Y = T.getSolution();
522 svg.selectAll('.tsnet')
523 .data(data.words)
524 .attr("transform", function(d, i) {
525 return "translate(" +
Marc Kupietz66bfd952017-12-11 09:59:45 +0100526 ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," +
527 ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; });
Marc Kupietz83305222016-04-28 09:57:22 +0200528 }
529
530 var svg;
531 var labels = [];
532 var anchor_array = [];
533 var text;
534
535 function drawEmbedding() {
Marc Kupietz58270662017-12-04 12:10:06 +0100536 var urlprefix = new URLSearchParams(window.location.search);
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100537 urlprefix.delete("word");
538 urlprefix.append("word","");
539
Marc Kupietz58270662017-12-04 12:10:06 +0100540 $("#embed").empty();
541 var div = d3.select("#embed");
Marc Kupietz34c08172017-11-29 17:08:47 +0100542
Marc Kupietz58270662017-12-04 12:10:06 +0100543 // get min and max in each column of Y
544 var Y = T.Y;
Marc Kupietz34c08172017-11-29 17:08:47 +0100545
Marc Kupietz58270662017-12-04 12:10:06 +0100546 svg = div.append("svg") // svg is global
547 .attr("width", mapWidth)
548 .attr("height", mapHeight);
Marc Kupietz34c08172017-11-29 17:08:47 +0100549
Marc Kupietz58270662017-12-04 12:10:06 +0100550 var g = svg.selectAll(".b")
551 .data(data.words)
552 .enter().append("g")
553 .attr("class", "tsnet");
Marc Kupietz34c08172017-11-29 17:08:47 +0100554
Marc Kupietz58270662017-12-04 12:10:06 +0100555 g.append("a")
556 .attr("xlink:href", function(word) {
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100557 return "?"+urlprefix+word; })
Marc Kupietz58270662017-12-04 12:10:06 +0100558 .attr("class", function(d, i) {
559 var res="";
560 if(data.marked[i]) {
561 res="marked ";
562 }
563 if(data.target.indexOf(" "+d+" ") >= 0) {
564 return res+"target";
565 } else if(data.ranks[i] < data.mergedEnd) {
566 return res+"merged";
567 } else {
568 return res;
569 }
570 })
571 .attr("title", function(d, i) {
572 if(data.mergedEnd > 0) {
573 if(data.ranks[i] >= data.mergedEnd) {
574 return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
575 } else {
576 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
577 }
578 } else {
579 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
580 }
581 })
582 .append("text")
583 .attr("text-anchor", "top")
584 .attr("font-size", 12)
585 .text(function(d) { return d; });
Marc Kupietz34c08172017-11-29 17:08:47 +0100586
Marc Kupietz58270662017-12-04 12:10:06 +0100587 var zoomListener = d3.behavior.zoom()
588 .scaleExtent([0.1, 10])
589 .center([0,0])
590 .on("zoom", zoomHandler);
591 zoomListener(svg);
Marc Kupietz83305222016-04-28 09:57:22 +0200592 }
593
594 var tx=0, ty=0;
595 var ss=1;
596 var iter_id=-1;
597
598 function zoomHandler() {
Marc Kupietz58270662017-12-04 12:10:06 +0100599 tx = d3.event.translate[0];
600 ty = d3.event.translate[1];
601 ss = d3.event.scale;
602 updateEmbedding();
Marc Kupietz83305222016-04-28 09:57:22 +0200603 }
604
605 var stepnum = 0;
606
607 function stopStep() {
Marc Kupietz58270662017-12-04 12:10:06 +0100608 clearInterval(iter_id);
609 text = svg.selectAll("text");
Marc Kupietz34c08172017-11-29 17:08:47 +0100610
Marc Kupietz58270662017-12-04 12:10:06 +0100611 // jitter function needs different data and co-ordinate representation
612 labels = d3.range(data.words.length).map(function(i) {
613 var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2;
614 var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2;
615 anchor_array.push({x: x, y: y, r: jitterRadius});
616 return {
617 x: x,
618 y: y,
619 name: data.words[i]
620 };
621 });
Marc Kupietz34c08172017-11-29 17:08:47 +0100622
Marc Kupietz58270662017-12-04 12:10:06 +0100623 // get the actual label bounding boxes for the jitter function
624 var index = 0;
625 text.each(function() {
626 labels[index].width = this.getBBox().width;
627 labels[index].height = this.getBBox().height;
628 index += 1;
629 });
Marc Kupietz83305222016-04-28 09:57:22 +0200630
Marc Kupietz34c08172017-11-29 17:08:47 +0100631
Marc Kupietz58270662017-12-04 12:10:06 +0100632 // setTimeout(updateEmbedding, 1);
633 // setTimeout(
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100634 labeler = d3.labeler()
635 .label(labels)
636 .anchor(anchor_array)
637 .width(mapWidth)
638 .height(mapHeight)
639 .update(applyJitter);
Marc Kupietz58270662017-12-04 12:10:06 +0100640 // .start(1000);
Marc Kupietz83305222016-04-28 09:57:22 +0200641
Marc Kupietz58270662017-12-04 12:10:06 +0100642 iter_id = setInterval(jitterStep, 1);
Marc Kupietz83305222016-04-28 09:57:22 +0200643 }
644
645 var jitter_i=0;
646
647 function jitterStep() {
Marc Kupietz58270662017-12-04 12:10:06 +0100648 if(jitter_i++ > 100) {
649 clearInterval(iter_id);
650 } else {
651 labeler.start2(10);
652 applyJitter();
653 }
Marc Kupietz83305222016-04-28 09:57:22 +0200654 }
655
656 var last_cost=1000;
657
658 function step() {
Marc Kupietz58270662017-12-04 12:10:06 +0100659 var i = T.iter;
Marc Kupietz34c08172017-11-29 17:08:47 +0100660
Marc Kupietz58270662017-12-04 12:10:06 +0100661 if(i > <%= $no_iterations %>) {
662 stopStep();
663 } else {
664 var cost = Math.round(T.step() * 100000) / 100000; // do a few steps
665 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5));
666 if(i % 250 == 0 && cost >= last_cost) {
667 stopStep();
668 } else {
669 last_cost = cost;
670 updateEmbedding();
671 }
672 }
Marc Kupietz83305222016-04-28 09:57:22 +0200673 }
674
675 function showMap(j) {
Marc Kupietz58270662017-12-04 12:10:06 +0100676 data=j;
677 T.iter=0;
Marc Kupietz66bfd952017-12-11 09:59:45 +0100678 iter_id = -1;
679 last_cost=1000;
Marc Kupietz58270662017-12-04 12:10:06 +0100680 T.initDataRaw(data.vecs); // init embedding
681 drawEmbedding(); // draw initial embedding
Marc Kupietz78114532017-11-29 17:00:16 +0100682
Marc Kupietz58270662017-12-04 12:10:06 +0100683 if(iter_id >= 0) {
684 clearInterval(iter_id);
685 }
686 //T.debugGrad();
687 iter_id = setInterval(step, 1);
688 if(true) { // (<%= $show_som %>) {
689 makeSOM(j, <%= $no_iterations %>);
690 }
Marc Kupietz83305222016-04-28 09:57:22 +0200691 }
Marc Kupietz39179ab2017-07-04 16:28:06 +0200692 var queryword;
693
Marc Kupietz66bfd952017-12-11 09:59:45 +0100694 function showCollocatorSOM() {
695 if (collocatorTable) {
696 var ctableData = collocatorTable.rows().data();
697 var nwords = [],
698 nranks = [];
699 for (var i=0; i < ctableData.length && i < 100; i++) {
700 nranks.push(ctableData[i].rank);
701 nwords.push(ctableData[i].word);
702 }
703 $.post('/derekovecs/getVecsByRanks',
704 JSON.stringify(nranks),
705 function(data, status){
706 showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: data, ranks: nranks, marked: Array(100).fill(false)} );
707 }, 'json');
708 }
709 }
710
Marc Kupietz39179ab2017-07-04 16:28:06 +0200711 function onload() {
Marc Kupietz58270662017-12-04 12:10:06 +0100712 queryword = document.getElementById('word');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200713 }
714
715 function queryKorAP() {
Marc Kupietz58270662017-12-04 12:10:06 +0100716 window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200717 }
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100718
719 function queryKorAPCII(query) {
Marc Kupietz58270662017-12-04 12:10:06 +0100720 window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP');
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100721 }
Marc Kupietz83305222016-04-28 09:57:22 +0200722 </script>
723 </head>
Marc Kupietz39179ab2017-07-04 16:28:06 +0200724 <body onload="onload()">
Marc Kupietz58270662017-12-04 12:10:06 +0100725 <div id="header">
726 <div id="pagetitle">
727 <h1>DeReKo-Vectors</h1>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100728 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100729 <div id="options" class="widget">
730 <form id="queryform">
731 <input id="word" type="text" name="word" placeholder="Word(s) to be searched" value="<%= $word %>"
732 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."/>
733 <input id="SEARCH" type="button" value="SEARCH">
734 <input type="button" id="showoptions" name="showoptions" value="Options" />
735 </form>
736 <div id="dropdownoptions" style="display: none">
737 <form id="optionsform">
738 <div class="controlgroup-vertical">
739 <label for="cutoff">cut-off</label>
740 <input id="cutoff" type="text" name="cutoff" size="10" value="<%= $cutoff %>" title="Only consider the most frequent x word forms.">
741 <label for="dedupe">dedupe</label>
742 <input id="dedupe" type="checkbox" name="dedupe" value="1" <%= ($dedupe ? "checked" : "") %> title="radically filter out any near-duplicates">
743 % if($mergedEnd > 0) {
744 <label for="sbf">backw.</label>
745 <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.">
746 % }
747 <label for="neighbours">max. neighbours:</label>
748 <input id="neighbours" size="4" name="n" value="<%= $no_nbs %>">
749 <label for="no_iterations">max. iterations</label>
750 <input id="no_iterations" name="N" size="4" value="<%= $no_iterations %>">
751 <!-- <label for="dosom">SOM</label>
752 <input id="dosom" type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> -->
753 % if($collocators) {
754 <label for="sortby">window/sort</label>
755 <select id="sortby" name="sort">
756 <option value="0" <%= ($sort!=1 && $sort!=2? "selected":"") %>>auto focus</option>
757 <!-- <option value="1" <%= ($sort==1? "selected":"") %>>any single position</option>
758 <option value="2" <%= ($sort==2? "selected":"") %>>whole window</option> -->
759 </select>
760 % }
761 <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/>
762 </div>
763 </form>
764 </div>
765 </div>
766 </div>
767 <div id="topwrapper">
768 <div style="visibility: hidden;" id="tabs">
769 <ul>
770 <li><a href="#tabs-1">Semantics (TSNE-map)</a></li>
771 <li><a href="#tabs-2">Semantics (SOM)</a></li>
772 <li><a href="#tabs-3">Syntagmatic (collocators)</a></li>
773 </ul>
774 <div id="tabs-1">
775 % if($lists && (@$lists) > 0 && (@$lists)[0]) {
776 <div id="wrapper">
777 <div id="first" style="width: 320px">
778 <table class="display compact nowrap" id="firsttable">
779 <thead>
780 <tr>
781 <th align="right">#</th><th align="right">cos</th><th align="left">similars</th>
782 </tr>
783 </thead>
784 <tbody>
785 <tr>
786 <td align="right">
787 </td>
788 <td align="right">
789 </td>
790 <td></td>
791 </tr>
792 </tbody>
793 </table>
794 </div>
795 <script>
796 </script>
797 <div id="second">
798 <div id="embed">
799 </div>
800 <div id="cost">
801 </div>
802 </div>
803 </div>
804 % } elsif($word !~ /^\s*$/) {
805 <div id="wrapper">
806 <div id="not-found-dialog" title="Not found">
807 <p>ERROR: "<%= $word %>" not found in vocabluary.</p>
808 <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>
809 </div>
810 <script>
811 $( function() {
812 $( "#not-found-dialog" ).dialog({
813 autoOpen: true,
814 modal: true,
815 draggable: false,
816 height: "auto",
817 width: "auto",
818 resizable: false,
819 buttons: {
820 "OK": function() {
821 $( this ).dialog( "close" );
822 },
823 "Apply": function() {
824 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
825 }
826 }
827 });
828 });
829 </script>
830 </div>
831 % }
832 </div>
833 <div id="tabs-2">
Marc Kupietz66bfd952017-12-11 09:59:45 +0100834 <div id="som2" style="width: 800;">
Marc Kupietz58270662017-12-04 12:10:06 +0100835 </div>
836 <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div>
837 <div id="sominfo">SOM iteration <span id="iterations">0</span></div>
838 </div>
839 <div id="tabs-3">
840 <div style="width: 800px" id="secondt">
841 <table class="display compact nowrap" id="secondtable">
842 <thead>
843 <tr>
844 % if($collocators) {
845 <th>#</th>
Marc Kupietz4116b432017-12-06 14:15:32 +0100846 <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>
847 <th align="right" title="Maximum activation of the collocator anywhere in the output layer.">max(a)</th>
848 <th title="Average raw activation of the collocator in the columns selected by auto-focus." align="right">⟨a⟩</th>
849 <th title="Sum of activations over the selected colunns normalized by the total activation sum of the selected columns." align="right">Σa/Σw'</th>
850 <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 +0100851 <th title="Sum of the activations over the whole window normalized by the total window sum (no auto-focus)." align="right">Σa/Σw</th>
852 <th align="left">collocator</th>
853 % }
854 </tr>
855 </thead>
856 <tbody>
857 <tr>
858 <td align="right">
859 </td>
860 <td align="right">
861 </td>
862 <td align="right">
863 </td>
864 <td align="right">
865 </td>
866 <td align="right">
867 </td>
868 <td align="right">
869 </td>
Marc Kupietz58270662017-12-04 12:10:06 +0100870 </tr>
871 </tbody>
872 </table>
Marc Kupietz66bfd952017-12-11 09:59:45 +0100873 </div>
874 <div style="float: right; overflow: hidden" id="extra"><button onClick="showCollocatorSOM()"> </button></div>
875 <div style="float: right; overflow: hidden" id="clock"></div>
876 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100877 </div>
878 </div> <!-- topwrapper -->
879 <div style="clear: both;"></div>
880 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100881 % if($training_args) {
882 <p>
883 Word vector model trained with <a href="https://code.google.com/p/word2vec/">word2vec</a> using the following parameters: <pre><%= $training_args %></pre>
884 </p>
Marc Kupietz83305222016-04-28 09:57:22 +0200885 % }
Marc Kupietz58270662017-12-04 12:10:06 +0100886 </body>
Marc Kupietz83305222016-04-28 09:57:22 +0200887</html>