blob: 44d3f01d2782bd8049800be242bbc318b0789a04 [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>
Marc Kupietza0ffb392018-01-25 08:53:43 +010011 <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML'></script>
Marc Kupietz58270662017-12-04 12:10:06 +010012 <link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css">
Marc Kupietz4949d232018-03-19 16:43:18 +010013 <link rel="stylesheet" href="/derekovecs/css/derekovecs.css">
Marc Kupietz80bd7b92017-07-04 16:25:54 +020014 <script
Marc Kupietze6a7a732018-01-12 09:21:08 +010015 src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
16 integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
17 crossorigin="anonymous"></script>
Marc Kupietz80bd7b92017-07-04 16:25:54 +020018 <script>
Marc Kupietza0ffb392018-01-25 08:53:43 +010019 MathJax.Hub.Config({
20 config: ["MMLorHTML.js"],
21 jax: ["input/TeX","input/MathML","output/HTML-CSS","output/NativeMML", "output/PreviewHTML"],
22 extensions: ["tex2jax.js","mml2jax.js","MathMenu.js","MathZoom.js", "fast-preview.js", "AssistiveMML.js", "a11y/accessibility-menu.js"],
23 TeX: {
24 extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]
25 }
26 });
Marc Kupietz58270662017-12-04 12:10:06 +010027 var urlParams = new URLSearchParams(window.location.search);
Marc Kupietzb3a2e4f2017-12-08 17:25:53 +010028 var currentWords = urlParams.get("word");
Marc Kupietza0ffb392018-01-25 08:53:43 +010029 var CIIsearchWords = (currentWords && currentWords.includes(" ") ? '('+currentWords.replace(/ +/g, " oder ")+')' : currentWords);
Marc Kupietz66bfd952017-12-11 09:59:45 +010030 var collocatorTable = null;
Marc Kupietza6e08f02017-12-01 22:06:21 +010031
Marc Kupietz58270662017-12-04 12:10:06 +010032 $(document).ready(function() {
Marc Kupietz694610d2017-11-25 18:30:03 +010033
Marc Kupietza0ffb392018-01-25 08:53:43 +010034 $('#firstable').hide();
35 //Set up a callback to hear back when MathJax is done rendering the equations
36 // it finds
37 $('#ccd').load(
38 '@Url.Action("ActionResultMethod","ControllerName",{controller parameters})',
39 function () {
40 MathJax.Hub.Queue(
41 ["Typeset",MathJax.Hub,"ccd"],
42 function () {
43 $("#lfmd_tt").attr("title",$("#lfmd_ttt").html());
44 $("#npmi_tt").attr("title",$("#npmi_ttt").html());
45 }
46 );
47 });
48
49 //set things up so that we can shove raw html into what is shown in the tooltip;
50 // in this case, we will have already put into the title attribute the html that
51 // contains the MathJax rendered equations (via what we do in the callback).
52 $(function () {
53 $(document).tooltip({
54 content: function () {
55 return $(this).prop('title');
56 }
57 });
58 });
59
Marc Kupietze6a7a732018-01-12 09:21:08 +010060 $("input").bind("keydown", function(event) {
61 // track enter key
62 var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
63 if (keycode == 13) { // keycode for enter key
64 // force the 'Enter Key' to implicitly click the Update button
65 document.getElementById('SEARCH').click();
66 return false;
67 } else {
68 return true;
69 }});
Marc Kupietzdab9f222017-11-29 14:22:59 +010070
Marc Kupietze871abd2018-01-25 16:18:27 +010071 var collocatorTable_activated = false;
Marc Kupietze6a7a732018-01-12 09:21:08 +010072 $( "#tabs" ).on( "tabsactivate", function( event, ui ) {
73 if (localStorage) localStorage['tab'] = ui.newTab.index();
Marc Kupietze871abd2018-01-25 16:18:27 +010074 if(ui.newTab.index() == 2 && !collocatorTable_activated) {
75 classicCollocatorTable.columns.adjust();
76 collocatorTable.columns.adjust();
77 collocatorTable_activated = true;
78 }
Marc Kupietze6a7a732018-01-12 09:21:08 +010079 });
80
81 $(function(){
82 $("#SEARCH").click(function() {
83 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
Marc Kupietz58270662017-12-04 12:10:06 +010084 });
Marc Kupietze6a7a732018-01-12 09:21:08 +010085 });
Marc Kupietz0af83e32017-11-27 09:31:37 +010086
Marc Kupietze6a7a732018-01-12 09:21:08 +010087 function changeCharColor(txt, heat, word) {
88 var newText = "";
89 for (var i=0, l=txt.length; i<l; i++) {
90 newText += (i == 5 ? txt.charAt(i) : '<a href="http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q=' +
91 CIIsearchWords + ' /' + (i > 5? '%2B' : '-') + 'w' +
92 Math.abs(i-5) + ':' + Math.abs(i-5) + ' ' + word +
93 '" target="korap"><span style="background-color:' +
94 getHeatColor(heat[i]/maxHeat)+'">'+txt.charAt(i)+'</span></a>');
Marc Kupietzb6c615d2017-12-02 10:38:20 +010095 }
Marc Kupietze6a7a732018-01-12 09:21:08 +010096 return newText;
97 }
Marc Kupietzb6c615d2017-12-02 10:38:20 +010098
Marc Kupietze6a7a732018-01-12 09:21:08 +010099 function getHeatColor(value) {
100 var hue=((1-value)*120).toString(10);
101 return ["hsl(",hue,",90%,70%)"].join("");
102 }
103
104 function bitvec2window(n, heat, word) {
105 var str = n.toString(2).padStart(10, "0")
106 .replace(/^([0-9]{5})/, '$1x')
107 .replace(/0/g, '·')
108 .replace(/1/g, '+');
109 return changeCharColor(str, heat, word);
110 }
111
112 % use Mojo::ByteStream 'b';
113 var paraResults = <%= b(Mojo::JSON::to_json($lists)) %>;
114 var urlprefix = new URLSearchParams(window.location.search);
115 if (paraResults.length > 0 && paraResults[0] != null) {
116 var nvecs = [],
117 nwords = [],
118 nranks = [],
119 nmarked = [];
120 for(var i = 0; i < paraResults.length; i++) {
121 nwords = nwords.concat(paraResults[i].map(function(a){return a.word;}));
122 nvecs = nvecs.concat(paraResults[i].map(function(a){return a.vector;}));
123 nranks = nranks.concat(paraResults[i].map(function(a){return a.rank;}));
124 nmarked = nmarked.concat(paraResults[i].map(function(a){return a.marked;}));
Marc Kupietz0d4c0ca2017-12-04 09:18:56 +0100125 }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100126 showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: nvecs, ranks: nranks, marked: nmarked} );
127 var t = $('#firsttable').DataTable({
128 data: paraResults[0],
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" },
136 { "data": "dist", render: function ( data, type, row ) {return data.toFixed(3) }},
137 { "data": "word", render: function ( data, type, row ) {urlprefix.set("word", data); return '<a href="?' + urlprefix + '">' + data + '</a>' }}
138 ],
139 "columnDefs": [
140 { className: "dt-right", "targets": [0,1] },
141 { "searchable": false,
142 "orderable": false,
143 "targets": 0
144 },
145 { "orderSequence": [ "desc" ], "targets": [ 1 ] },
146 { "orderSequence": [ "asc", "desc" ], "targets": [ 2 ] },
147 ],
148 "oLanguage": {
149 "sSearch": "Filter: "
150 },
151 "order": [[ 1, 'desc' ]],
152 } );
Marc Kupietz0d4c0ca2017-12-04 09:18:56 +0100153
Marc Kupietze6a7a732018-01-12 09:21:08 +0100154 t.on( 'order.dt search.dt', function () {
155 t.column(0, {order:'applied'}).nodes().each( function (cell, i) {
156 cell.innerHTML = i+1;
157 } );
158 } ).draw();
159
160 $( "#first" ).clone().prependTo( "#tabs-2" );
161
162 }
163
164
165 var collocatorData = <%= b(Mojo::JSON::to_json($collocators)) %>;
166 var maxHeat; // = Math.max.apply(Math,collocatorData.map(function(o){return o.cprob;}))
167
168 if (collocatorData != null) {
169 maxHeat = Math.max.apply(Math,collocatorData.map(function(o){return Math.max.apply(Math,o.heat);}))
170 collocatorTable = $('#secondtable').DataTable({
171 data: collocatorData,
172 "sScrollY": "780px",
173 "bScrollCollapse": true,
174 "bPaginate": false,
175 "bJQueryUI": true,
176 "dom": '<"top">rt<"bottom"flp><"clear">',
177 "columns": [
178 { "data": "rank", type: "allnumeric" },
179 { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat, row.word) }},
180 { "data": "max", render: function ( data, type, row ) {return data.toFixed(3) }},
181 { "data": "average", render: function ( data, type, row ) {return data.toFixed(3) }},
182 { "data": "prob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
183 { "data": "cprob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
184 { "data": "overall", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } },
185 { "data": "word", sClass: "collocator" },
186 { "data": "rank", type: "allnumeric" }
187 ],
188 "columnDefs": [
189 { className: "dt-right", "targets": [0,2,3,4,5,6] },
190 { className: "dt-center", "targets": [ 1] },
191 { "searchable": false,
192 "orderable": false,
193 "targets": [0, 8]
194 },
195 { "type": "scientific", targets: [2,3,4,5,6] },
196 { "orderSequence": [ "desc" ], "targets": [ 2, 3, 4, 5, 6 ] },
197 { "orderSequence": [ "asc", "desc" ], "targets": [ 1, 7 ] },
198 { "targets": [8], "visible": false }
199 ],
200 "oLanguage": {
201 "sSearch": "Filter: "
202 },
203 "order": [[ 4, 'desc' ]],
204 } );
205 $.ajaxSetup({
206 type: 'POST',
207 timeout: 30000,
208 error: function(xhr) {
209 $('#display_error')
210 .html('Error: ' + xhr.status + ' ' + xhr.statusText);
211 }
Marc Kupietz78b434a2018-01-12 22:33:32 +0100212 });
Marc Kupietze6a7a732018-01-12 09:21:08 +0100213
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100214 // var filterQuot = /(^quot?=[A-Z])|(quot$)/g;
215 var filterQuot = /^quot/;
Marc Kupietz78b434a2018-01-12 22:33:32 +0100216 classicCollocatorTable = $('#classicoloctable').DataTable({
217 ajax: {
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100218 method: "GET",
219 url: '/derekovecs/getClassicCollocators',
220 dataType: 'json',
221 dataSrc: "",
222 timeout: 30000,
223 data: { w: paraResults[0][0].rank }
Marc Kupietz78b434a2018-01-12 22:33:32 +0100224 },
Marc Kupietzad783722018-01-13 17:45:21 +0100225 "initComplete":function(settings, json){
226 $("td.collocator").click(function(){
227 queryKorAPCII(this.textContent + " /w5 " + CIIsearchWords);
228 });
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100229 classicCollocatorTable.columns(".detail").visible(false);
230 $("#ccd").css('width', '450px');
231 classicCollocatorTable.columns.adjust().draw();
Marc Kupietzad783722018-01-13 17:45:21 +0100232 },
Marc Kupietz78b434a2018-01-12 22:33:32 +0100233 "sScrollY": "780px",
234 "bScrollCollapse": true,
235 "bPaginate": false,
236 "bJQueryUI": true,
237 "dom": '<"top">rt<"bottom"flp><"clear">',
238 "columns": [
239 // { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat, row.word) }},
Marc Kupietzb4b53ca2018-01-25 08:57:11 +0100240 { "data": "llr", render: function ( data, type, row ) {return data.toFixed(0) }},
241 { "data": "lfmd", render: function ( data, type, row ) {return data.toFixed(1) }},
Marc Kupietz1acb3172018-02-17 09:41:26 +0100242 // { "data": "fpmi", type: "scientific", render: function ( data, type, row ) {return data.toExponential(2) } },
Marc Kupietzb4b53ca2018-01-25 08:57:11 +0100243 { "data": "npmi", render: function ( data, type, row ) {return data.toFixed(2) }},
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100244 { "data": "llfmd", render: function ( data, type, row ) {return data.toFixed(1) }},
245 { "data": "rlfmd", render: function ( data, type, row ) {return data.toFixed(1) }},
246 { "data": "lnpmi", render: function ( data, type, row ) {return data.toFixed(2) }},
247 { "data": "rnpmi", render: function ( data, type, row ) {return data.toFixed(2) }},
Marc Kupietzb4b53ca2018-01-25 08:57:11 +0100248 { "data": "f" },
Marc Kupietz78b434a2018-01-12 22:33:32 +0100249 { "data": "word", sClass: "collocator" }
250 ],
251 "columnDefs": [
Marc Kupietzb4b53ca2018-01-25 08:57:11 +0100252 { className: "dt-right", "targets": [0,1,2,3,4,5,6,7] },
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100253 { className: "dt-right detail", "targets": [3,4,5,6] },
Marc Kupietz78b434a2018-01-12 22:33:32 +0100254 { "searchable": false,
255 "orderable": false,
256 "targets": []
257 },
Marc Kupietzb4b53ca2018-01-25 08:57:11 +0100258 { "orderSequence": [ "desc" ], "targets": [ 0, 1, 2,3,4,5,6,7 ] },
259 { "orderSequence": [ "asc", "desc" ], "targets": [ 8 ] },
Marc Kupietz78b434a2018-01-12 22:33:32 +0100260 ],
261 "oLanguage": {
262 "sSearch": "Filter: "
263 },
264 "order": [[ 1, 'desc' ]],
265 });
Marc Kupietze6a7a732018-01-12 09:21:08 +0100266
Marc Kupietz1acb3172018-02-17 09:41:26 +0100267
268 $('#show-details').change(function (e) {
269 var columns = classicCollocatorTable.columns(".detail");
270 if(this.checked) {
271 columns.visible(true);
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100272 $("#ccd").css('width', 'auto');
Marc Kupietz1acb3172018-02-17 09:41:26 +0100273 } else {
274 columns.visible(false);
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100275 $("#ccd").css('width', '450px');
Marc Kupietz1acb3172018-02-17 09:41:26 +0100276 }
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100277 classicCollocatorTable.columns.adjust().draw();
Marc Kupietz1acb3172018-02-17 09:41:26 +0100278 } );
279
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100280 $("td.collocator").click(function(){
281 queryKorAPCII(this.textContent + " /w5 " + CIIsearchWords);
Marc Kupietzad783722018-01-13 17:45:21 +0100282 });
283
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100284 collocatorTable.on( 'order.dt search.dt', function () {
285 collocatorTable.column(0, {order:'applied'}).nodes().each( function (cell, i) {
286 cell.innerHTML = i+1;
287 } );
288 }).draw();
289 }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100290
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100291 if (localStorage && !window.location.hash) { // let's not crash if some user has IE7
292 var index = parseInt(localStorage['tab']||'0');
293 $("#tabs").tabs({ active: index });
294 }
295 $("#tabs").css("visibility", "visible"); // now we can show the tabs
296 });
Marc Kupietz58270662017-12-04 12:10:06 +0100297
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100298 $(function(){
299 $("#dropdownoptions").dialog({
300 title: "Options",
301 autoOpen: false,
302 modal: false,
303 draggable: false,
304 height: "auto",
305 width: "auto",
306 resizable: false,
307 buttons: {
308 "Cancel": function() {
309 $( this ).dialog( "close" );
Marc Kupietze6a7a732018-01-12 09:21:08 +0100310 },
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100311 "Apply": function() {
312 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
Marc Kupietze6a7a732018-01-12 09:21:08 +0100313 }
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100314 }
315 });
316 });
317
318 $(function(){
319 $("#showoptions").click(function(){
320 $("#dropdownoptions").dialog("open");
321 var target = $(this);
322 $("#dropdownoptions").dialog("widget").position({
323 my: 'left bottom',
324 at: 'left bottom',
325 of: target
Marc Kupietz58270662017-12-04 12:10:06 +0100326 });
Marc Kupietze6a7a732018-01-12 09:21:08 +0100327 });
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100328 });
329
330 $( function() {
331 $( "#no_iterations" ).spinner({
332 spin: function( event, ui ) {
333 if ( ui.value < 1000 ) {
334 $( this ).spinner( "value", 1000 );
335 return false;
336 } else if ( ui.value > 10000 ) {
337 $( this ).spinner( "value", 10000 );
338 return false;
339 }
340 }
341 });
342 } );
343
344 $( function() {
345 $( "#neighbours" ).spinner({
346 spin: function( event, ui ) {
347 if ( ui.value < 0 ) {
348 $( this ).spinner( "value", 0 );
349 return false;
350 } else if ( ui.value > 200 ) {
351 $( this ).spinner( "value", 200 );
352 return false;
353 }
354 }
355 });
356 } );
357
358 $( function() {
359 $( "#cutoff" ).spinner({
360 spin: function( event, ui ) {
361 if ( ui.value < 100000 ) {
362 $( this ).spinner( "value", 100000 );
363 return false;
364 } else if ( ui.value > 2000000 ) {
365 $( this ).spinner( "value", 2000000 );
366 return false;
367 }
368 }
369 });
370 } );
371
372 $( function() {
373 $( "#tabs" ).tabs().addClass('tabs-min');
374 } );
375
376 $( function() {
377 $( ".controlgroup-vertical" ).controlgroup({
378 "direction": "vertical"
379 });
380 } );
381
382 $(function() {
383 $( document ).tooltip({
384 content: function() {
385 return $(this).attr('title');
386 }}
387 )
388 });
389
390 $(function () {
391 $(document).tooltip({
392 content: function () {
393 return $(this).prop('title');
394 },
395 show: null,
396 close: function (event, ui) {
397 ui.tooltip.hover(
398 function () {
399 $(this).stop(true).fadeTo(400, 1);
400 },
401 function () {
402 $(this).fadeOut("400", function () {
403 $(this).remove();
404 })
405 });
406 }
407 });
408 });
Marc Kupietz83305222016-04-28 09:57:22 +0200409 </script>
Marc Kupietz58270662017-12-04 12:10:06 +0100410 <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
411 <script src="/derekovecs/js/tsne.js"></script>
412 <script src="/derekovecs/js/som.js"></script>
413 <script src="/derekovecs/js/labeler.js"></script>
Marc Kupietzcdd51302018-03-19 16:36:54 +0100414 <script src="/derekovecs/js/derekovcs.js"></script>
Marc Kupietz83305222016-04-28 09:57:22 +0200415 <script>
416
417 var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>},
Marc Kupietz58270662017-12-04 12:10:06 +0100418 mapWidth = 800, // width map
419 mapHeight = 800,
420 jitterRadius = 7;
Marc Kupietz83305222016-04-28 09:57:22 +0200421
422 var T = new tsnejs.tSNE(opt); // create a tSNE instance
423
424 var Y;
425
426 var data;
427 var labeler;
428
429 function applyJitter() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100430 svg.selectAll('.tsnet')
431 .data(labels)
432 .transition()
433 .duration(50)
434 .attr("transform", function(d, i) {
435 T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20;
436 T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20;
437 return "translate(" +
Marc Kupietz1acb3172018-02-17 09:41:26 +0100438 (d.x) + "," +
439 (d.y) + ")";
Marc Kupietze6a7a732018-01-12 09:21:08 +0100440 });
Marc Kupietz83305222016-04-28 09:57:22 +0200441 }
Marc Kupietz34c08172017-11-29 17:08:47 +0100442
Marc Kupietz83305222016-04-28 09:57:22 +0200443 function updateEmbedding() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100444 var Y = T.getSolution();
445 svg.selectAll('.tsnet')
446 .data(data.words)
447 .attr("transform", function(d, i) {
448 return "translate(" +
Marc Kupietz1acb3172018-02-17 09:41:26 +0100449 ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," +
450 ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; });
Marc Kupietz83305222016-04-28 09:57:22 +0200451 }
452
453 var svg;
454 var labels = [];
455 var anchor_array = [];
456 var text;
457
458 function drawEmbedding() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100459 var urlprefix = new URLSearchParams(window.location.search);
460 urlprefix.delete("word");
461 urlprefix.append("word","");
Marc Kupietz8f9c86a2017-12-04 17:17:13 +0100462
Marc Kupietze6a7a732018-01-12 09:21:08 +0100463 $("#embed").empty();
464 var div = d3.select("#embed");
Marc Kupietz34c08172017-11-29 17:08:47 +0100465
Marc Kupietze6a7a732018-01-12 09:21:08 +0100466 // get min and max in each column of Y
467 var Y = T.Y;
Marc Kupietz34c08172017-11-29 17:08:47 +0100468
Marc Kupietze6a7a732018-01-12 09:21:08 +0100469 svg = div.append("svg") // svg is global
470 .attr("width", mapWidth)
471 .attr("height", mapHeight);
Marc Kupietz34c08172017-11-29 17:08:47 +0100472
Marc Kupietze6a7a732018-01-12 09:21:08 +0100473 var g = svg.selectAll(".b")
474 .data(data.words)
475 .enter().append("g")
476 .attr("class", "tsnet");
Marc Kupietz34c08172017-11-29 17:08:47 +0100477
Marc Kupietze6a7a732018-01-12 09:21:08 +0100478 g.append("a")
479 .attr("xlink:href", function(word) {
480 return "?"+urlprefix+word; })
481 .attr("class", function(d, i) {
482 var res="";
483 if(data.marked[i]) {
484 res="marked ";
485 }
486 if(data.target.indexOf(" "+d+" ") >= 0) {
487 return res+"target";
488 } else if(data.ranks[i] < data.mergedEnd) {
489 return res+"merged";
490 } else {
491 return res;
492 }
493 })
494 .attr("title", function(d, i) {
495 if(data.mergedEnd > 0) {
496 if(data.ranks[i] >= data.mergedEnd) {
497 return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
498 } else {
499 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
500 }
501 } else {
502 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
503 }
504 })
505 .append("text")
506 .attr("text-anchor", "top")
507 .attr("font-size", 12)
508 .text(function(d) { return d; });
Marc Kupietz34c08172017-11-29 17:08:47 +0100509
Marc Kupietze6a7a732018-01-12 09:21:08 +0100510 var zoomListener = d3.behavior.zoom()
511 .scaleExtent([0.1, 10])
512 .center([0,0])
513 .on("zoom", zoomHandler);
514 zoomListener(svg);
Marc Kupietz83305222016-04-28 09:57:22 +0200515 }
516
517 var tx=0, ty=0;
518 var ss=1;
519 var iter_id=-1;
520
521 function zoomHandler() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100522 tx = d3.event.translate[0];
523 ty = d3.event.translate[1];
524 ss = d3.event.scale;
525 updateEmbedding();
Marc Kupietz83305222016-04-28 09:57:22 +0200526 }
527
528 var stepnum = 0;
529
530 function stopStep() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100531 clearInterval(iter_id);
532 text = svg.selectAll("text");
Marc Kupietz34c08172017-11-29 17:08:47 +0100533
Marc Kupietze6a7a732018-01-12 09:21:08 +0100534 // jitter function needs different data and co-ordinate representation
535 labels = d3.range(data.words.length).map(function(i) {
536 var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2;
537 var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2;
538 anchor_array.push({x: x, y: y, r: jitterRadius});
539 return {
540 x: x,
541 y: y,
542 name: data.words[i]
543 };
544 });
Marc Kupietz34c08172017-11-29 17:08:47 +0100545
Marc Kupietze6a7a732018-01-12 09:21:08 +0100546 // get the actual label bounding boxes for the jitter function
547 var index = 0;
548 text.each(function() {
549 labels[index].width = this.getBBox().width;
550 labels[index].height = this.getBBox().height;
551 index += 1;
552 });
Marc Kupietz83305222016-04-28 09:57:22 +0200553
Marc Kupietz34c08172017-11-29 17:08:47 +0100554
Marc Kupietze6a7a732018-01-12 09:21:08 +0100555 // setTimeout(updateEmbedding, 1);
556 // setTimeout(
557 labeler = d3.labeler()
558 .label(labels)
559 .anchor(anchor_array)
560 .width(mapWidth)
561 .height(mapHeight)
562 .update(applyJitter);
563 // .start(1000);
Marc Kupietz83305222016-04-28 09:57:22 +0200564
Marc Kupietze6a7a732018-01-12 09:21:08 +0100565 iter_id = setInterval(jitterStep, 1);
Marc Kupietz83305222016-04-28 09:57:22 +0200566 }
567
568 var jitter_i=0;
569
570 function jitterStep() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100571 if(jitter_i++ > 100) {
572 clearInterval(iter_id);
573 } else {
574 labeler.start2(10);
575 applyJitter();
576 }
Marc Kupietz83305222016-04-28 09:57:22 +0200577 }
578
579 var last_cost=1000;
580
581 function step() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100582 var i = T.iter;
Marc Kupietz34c08172017-11-29 17:08:47 +0100583
Marc Kupietze6a7a732018-01-12 09:21:08 +0100584 if(i > <%= $no_iterations %>) {
585 stopStep();
586 } else {
587 var cost = Math.round(T.step() * 100000) / 100000; // do a few steps
588 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5));
589 if(i % 250 == 0 && cost >= last_cost) {
590 stopStep();
Marc Kupietz58270662017-12-04 12:10:06 +0100591 } else {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100592 last_cost = cost;
593 updateEmbedding();
Marc Kupietz58270662017-12-04 12:10:06 +0100594 }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100595 }
Marc Kupietz83305222016-04-28 09:57:22 +0200596 }
597
598 function showMap(j) {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100599 data=j;
600 T.iter=0;
601 iter_id = -1;
602 last_cost=1000;
603 T.initDataRaw(data.vecs); // init embedding
604 drawEmbedding(); // draw initial embedding
Marc Kupietz78114532017-11-29 17:00:16 +0100605
Marc Kupietze6a7a732018-01-12 09:21:08 +0100606 if(iter_id >= 0) {
607 clearInterval(iter_id);
608 }
609 //T.debugGrad();
610 iter_id = setInterval(step, 1);
611 if(true) { // (<%= $show_som %>) {
612 makeSOM(j, <%= $no_iterations %>);
613 }
Marc Kupietz83305222016-04-28 09:57:22 +0200614 }
Marc Kupietz39179ab2017-07-04 16:28:06 +0200615 var queryword;
616
Marc Kupietz66bfd952017-12-11 09:59:45 +0100617 function showCollocatorSOM() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100618 if (collocatorTable) {
619 var ctableData = collocatorTable.rows().data();
620 var nwords = [],
621 nranks = [];
622 for (var i=0; i < ctableData.length && i < 100; i++) {
623 nranks.push(ctableData[i].rank);
624 nwords.push(ctableData[i].word);
Marc Kupietz66bfd952017-12-11 09:59:45 +0100625 }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100626 $.post('/derekovecs/getVecsByRanks',
627 JSON.stringify(nranks),
628 function(data, status){
629 showMap({target: " "+urlParams.get('word')+" ", mergedEnd: 0, words: nwords, vecs: data, ranks: nranks, marked: Array(100).fill(false)} );
630 }, 'json');
631 }
Marc Kupietz66bfd952017-12-11 09:59:45 +0100632 }
633
Marc Kupietz39179ab2017-07-04 16:28:06 +0200634 function onload() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100635 queryword = document.getElementById('word');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200636 }
637
638 function queryKorAP() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100639 window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200640 }
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100641
642 function queryKorAPCII(query) {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100643 window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP');
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100644 }
Marc Kupietz83305222016-04-28 09:57:22 +0200645 </script>
646 </head>
Marc Kupietz39179ab2017-07-04 16:28:06 +0200647 <body onload="onload()">
Marc Kupietz5a7f9ac2018-01-30 11:22:44 +0100648 <div style="display:none;" id="lfmd_ttt">PMI cubed [1], also called log-frequency biased mutual dependency [2]: $$\text{PMI}^3=\text{LFMD}=log_2\frac{p^3(w_1,w_2)}{p(w_1) p(w_2)}$$<p class="citation">[1] Daille, B. (1994): <a href="http://www.bdaille.com/index.php?option=com_docman&task=doc_download&gid=8&Itemid=">Approche mixte pour l’extraction automatique de terminologie: statistiques lexicales et filtres linguistiques</a>. PhD thesis, Université Paris 7.</p><p class="citation">[2] Thanopoulos, A., Fakotakis, N., Kokkinakis, G. (2002): <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.11.8101&rep=rep1&type=pdf">Comparative evaluation of collocation extraction metrics</a>. In: Proc. of LREC 2002: 620–625.</p></div>
Marc Kupietza0ffb392018-01-25 08:53:43 +0100649 <div style="display:none;" id="npmi_ttt">Normalized pointwise mutual information: $$\frac{log_2\frac{p(w_1,w_2)}{p(w_1)p(w_2)}}{-log_2(p(w_1,w_2))}$$<p class="citation">Bouma, Gerlof (2009): <a href="https://svn.spraakdata.gu.se/repos/gerlof/pub/www/Docs/npmi-pfd.pdf">Normalized (pointwise) mutual information in collocation extraction</a>. In Proceedings of GSCL.</p></div>
Marc Kupietz58270662017-12-04 12:10:06 +0100650 <div id="header">
651 <div id="pagetitle">
652 <h1>DeReKo-Vectors</h1>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100653 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100654 <div id="options" class="widget">
655 <form id="queryform">
656 <input id="word" type="text" name="word" placeholder="Word(s) to be searched" value="<%= $word %>"
657 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."/>
658 <input id="SEARCH" type="button" value="SEARCH">
659 <input type="button" id="showoptions" name="showoptions" value="Options" />
660 </form>
661 <div id="dropdownoptions" style="display: none">
662 <form id="optionsform">
663 <div class="controlgroup-vertical">
664 <label for="cutoff">cut-off</label>
665 <input id="cutoff" type="text" name="cutoff" size="10" value="<%= $cutoff %>" title="Only consider the most frequent x word forms.">
666 <label for="dedupe">dedupe</label>
667 <input id="dedupe" type="checkbox" name="dedupe" value="1" <%= ($dedupe ? "checked" : "") %> title="radically filter out any near-duplicates">
668 % if($mergedEnd > 0) {
669 <label for="sbf">backw.</label>
670 <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.">
671 % }
672 <label for="neighbours">max. neighbours:</label>
673 <input id="neighbours" size="4" name="n" value="<%= $no_nbs %>">
674 <label for="no_iterations">max. iterations</label>
675 <input id="no_iterations" name="N" size="4" value="<%= $no_iterations %>">
676 <!-- <label for="dosom">SOM</label>
677 <input id="dosom" type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> -->
678 % if($collocators) {
679 <label for="sortby">window/sort</label>
680 <select id="sortby" name="sort">
681 <option value="0" <%= ($sort!=1 && $sort!=2? "selected":"") %>>auto focus</option>
682 <!-- <option value="1" <%= ($sort==1? "selected":"") %>>any single position</option>
683 <option value="2" <%= ($sort==2? "selected":"") %>>whole window</option> -->
684 </select>
685 % }
686 <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/>
Marc Kupietz1acb3172018-02-17 09:41:26 +0100687 <input id="show-details" type="checkbox" name="show-details" value="1" >
688 <label for="show-details">
689 Show details
690 </label>
Marc Kupietz58270662017-12-04 12:10:06 +0100691 </div>
692 </form>
693 </div>
694 </div>
695 </div>
696 <div id="topwrapper">
697 <div style="visibility: hidden;" id="tabs">
698 <ul>
699 <li><a href="#tabs-1">Semantics (TSNE-map)</a></li>
700 <li><a href="#tabs-2">Semantics (SOM)</a></li>
701 <li><a href="#tabs-3">Syntagmatic (collocators)</a></li>
702 </ul>
703 <div id="tabs-1">
704 % if($lists && (@$lists) > 0 && (@$lists)[0]) {
705 <div id="wrapper">
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100706 <div id="first" style="min-width: 320px; margin-bottom: 15px;">
Marc Kupietz58270662017-12-04 12:10:06 +0100707 <table class="display compact nowrap" id="firsttable">
708 <thead>
709 <tr>
710 <th align="right">#</th><th align="right">cos</th><th align="left">similars</th>
711 </tr>
712 </thead>
713 <tbody>
714 <tr>
715 <td align="right">
716 </td>
717 <td align="right">
718 </td>
719 <td></td>
720 </tr>
721 </tbody>
722 </table>
723 </div>
724 <script>
725 </script>
726 <div id="second">
727 <div id="embed">
728 </div>
729 <div id="cost">
730 </div>
731 </div>
732 </div>
733 % } elsif($word !~ /^\s*$/) {
734 <div id="wrapper">
735 <div id="not-found-dialog" title="Not found">
736 <p>ERROR: "<%= $word %>" not found in vocabluary.</p>
737 <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>
738 </div>
739 <script>
740 $( function() {
Marc Kupietze6a7a732018-01-12 09:21:08 +0100741 $( "#not-found-dialog" ).dialog({
742 autoOpen: true,
743 modal: true,
744 draggable: false,
745 height: "auto",
746 width: "auto",
747 resizable: false,
748 buttons: {
749 "OK": function() {
750 $( this ).dialog( "close" );
751 },
752 "Apply": function() {
753 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
754 }
755 }
756 });
Marc Kupietz58270662017-12-04 12:10:06 +0100757 });
758 </script>
759 </div>
Marc Kupietze6a7a732018-01-12 09:21:08 +0100760 % }
Marc Kupietz58270662017-12-04 12:10:06 +0100761 </div>
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100762 <div id="tabs-2" style="display: flex; padding: 5px; flex-flow: row wrap;">
Marc Kupietz66bfd952017-12-11 09:59:45 +0100763 <div id="som2" style="width: 800;">
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100764 <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div>
765 <div id="sominfo" style="text-align: right">SOM iteration <span id="iterations">0</span></div>
Marc Kupietz58270662017-12-04 12:10:06 +0100766 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100767 </div>
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100768 <div id="tabs-3" style="display: flex; padding:5px; flex-flow: row wrap;">
769 <div style="margin-right: 20px; margin-bottom: 10px;" id="secondt">
Marc Kupietze6a7a732018-01-12 09:21:08 +0100770 <table class="display compact nowrap" id="secondtable">
Marc Kupietz58270662017-12-04 12:10:06 +0100771 <thead>
772 <tr>
773 % if($collocators) {
774 <th>#</th>
Marc Kupietz4116b432017-12-06 14:15:32 +0100775 <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>
776 <th align="right" title="Maximum activation of the collocator anywhere in the output layer.">max(a)</th>
777 <th title="Average raw activation of the collocator in the columns selected by auto-focus." align="right">⟨a⟩</th>
778 <th title="Sum of activations over the selected colunns normalized by the total activation sum of the selected columns." align="right">Σa/Σw'</th>
779 <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 +0100780 <th title="Sum of the activations over the whole window normalized by the total window sum (no auto-focus)." align="right">Σa/Σw</th>
781 <th align="left">collocator</th>
782 % }
783 </tr>
784 </thead>
785 <tbody>
786 <tr>
787 <td align="right">
788 </td>
789 <td align="right">
790 </td>
791 <td align="right">
792 </td>
793 <td align="right">
794 </td>
795 <td align="right">
796 </td>
797 <td align="right">
798 </td>
Marc Kupietz58270662017-12-04 12:10:06 +0100799 </tr>
800 </tbody>
801 </table>
Marc Kupietz66bfd952017-12-11 09:59:45 +0100802 </div>
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100803 <div id="ccd" style="">
Marc Kupietze6a7a732018-01-12 09:21:08 +0100804 <table class="display compact nowrap" id="classicoloctable">
805 <thead>
Marc Kupietzcd136e22018-01-29 09:18:12 +0100806 % if($collocators) {
807 <tr>
808 <th>LLR</th>
Marc Kupietz5a7f9ac2018-01-30 11:22:44 +0100809 <th id="lfmd_tt">PMI³</th>
Marc Kupietzcd136e22018-01-29 09:18:12 +0100810 <th id="npmi_tt">nPMI</th>
Marc Kupietz5a7f9ac2018-01-30 11:22:44 +0100811 <th title="PMI³ restricted to left neighbour">l-PMI³</th>
812 <th title="PMI³ restricted to right neighbour">r-PMI³</th>
813 <th title="nPMI restricted to left neighbour">l-nPMI</th>
814 <th title="nPMI restricted to right neighbour">r-nPMI</th>
Marc Kupietzcd136e22018-01-29 09:18:12 +0100815 <th title="raw max frequency of collocation within window">raw</th>
816 <th>collocator</th>
817 </tr>
Marc Kupietz1acb3172018-02-17 09:41:26 +0100818 % }
Marc Kupietze6a7a732018-01-12 09:21:08 +0100819 </thead>
820 <tbody>
821 <tr>
822 <td align="right">
823 </td>
824 <td align="right">
825 </td>
826 <td align="right">
827 </td>
828 <td align="right">
829 </td>
Marc Kupietzcfcdcfc2018-01-24 09:51:26 +0100830 <td align="right">
831 </td>
832 <td align="right">
833 </td>
Marc Kupietzb4b53ca2018-01-25 08:57:11 +0100834 <td align="right"></td>
835 <td align="right"></td>
836 <td align="left"></td>
Marc Kupietze6a7a732018-01-12 09:21:08 +0100837 </tr>
838 </tbody>
839 </table>
840 </div>
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100841<!--
Marc Kupietze6a7a732018-01-12 09:21:08 +0100842 <div style="clear:both" ></div>
Marc Kupietz66bfd952017-12-11 09:59:45 +0100843 <div style="float: right; overflow: hidden" id="extra"><button onClick="showCollocatorSOM()"> </button></div>
Marc Kupietzdeb8f622018-03-12 09:41:00 +0100844-->
Marc Kupietz66bfd952017-12-11 09:59:45 +0100845 </div>
Marc Kupietz58270662017-12-04 12:10:06 +0100846 </div>
847 </div> <!-- topwrapper -->
848 <div style="clear: both;"></div>
849 </div>
Marc Kupietzebea4702018-01-12 09:16:09 +0100850 % if($training_args && (@$lists)[0]) {
851 <div class="info">
852 % if($training_args =~ /-type\s*3/) {
853 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 %>
854 % } else {
855 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 %>
856 % }
857 </div>
Marc Kupietz83305222016-04-28 09:57:22 +0200858 % }
Marc Kupietz58270662017-12-04 12:10:06 +0100859 </body>
Marc Kupietz83305222016-04-28 09:57:22 +0200860</html>