Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
Marc Kupietz | c053d97 | 2019-01-10 10:41:51 +0100 | [diff] [blame] | 4 | <% my $plain_title = $title; $plain_title=~s/<[^>]+>//g; %> |
| 5 | <title><%= $plain_title %>:<%= $word %> DeReKo-Word-Vector-Distances</title> |
Marc Kupietz | 80bd7b9 | 2017-07-04 16:25:54 +0200 | [diff] [blame] | 6 | <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 7 | <link href="https://fonts.googleapis.com/css?family=Lato|Roboto+Condensed" rel="stylesheet"> |
Marc Kupietz | 80bd7b9 | 2017-07-04 16:25:54 +0200 | [diff] [blame] | 8 | <script src="http://code.jquery.com/jquery-latest.min.js"></script> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 9 | <script src = "https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script> |
| 10 | <script src = "https://cdn.datatables.net/fixedcolumns/3.2.3/js/dataTables.fixedColumns.min.js"></script> |
| 11 | <script src = "https://cdn.datatables.net/plug-ins/1.10.16/sorting/scientific.js"></script> |
Marc Kupietz | a0ffb39 | 2018-01-25 08:53:43 +0100 | [diff] [blame] | 12 | <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML'></script> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 13 | <link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css"> |
Marc Kupietz | 4949d23 | 2018-03-19 16:43:18 +0100 | [diff] [blame] | 14 | <link rel="stylesheet" href="/derekovecs/css/derekovecs.css"> |
Marc Kupietz | 80bd7b9 | 2017-07-04 16:25:54 +0200 | [diff] [blame] | 15 | <script |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 16 | src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js" |
| 17 | integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" |
| 18 | crossorigin="anonymous"></script> |
Marc Kupietz | 80bd7b9 | 2017-07-04 16:25:54 +0200 | [diff] [blame] | 19 | <script> |
Marc Kupietz | a0ffb39 | 2018-01-25 08:53:43 +0100 | [diff] [blame] | 20 | MathJax.Hub.Config({ |
| 21 | config: ["MMLorHTML.js"], |
| 22 | jax: ["input/TeX","input/MathML","output/HTML-CSS","output/NativeMML", "output/PreviewHTML"], |
| 23 | extensions: ["tex2jax.js","mml2jax.js","MathMenu.js","MathZoom.js", "fast-preview.js", "AssistiveMML.js", "a11y/accessibility-menu.js"], |
| 24 | TeX: { |
| 25 | extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"] |
| 26 | } |
| 27 | }); |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 28 | var urlParams = new URLSearchParams(window.location.search); |
Marc Kupietz | b3a2e4f | 2017-12-08 17:25:53 +0100 | [diff] [blame] | 29 | var currentWords = urlParams.get("word"); |
Marc Kupietz | a0ffb39 | 2018-01-25 08:53:43 +0100 | [diff] [blame] | 30 | var CIIsearchWords = (currentWords && currentWords.includes(" ") ? '('+currentWords.replace(/ +/g, " oder ")+')' : currentWords); |
Marc Kupietz | 66bfd95 | 2017-12-11 09:59:45 +0100 | [diff] [blame] | 31 | var collocatorTable = null; |
Marc Kupietz | a6e08f0 | 2017-12-01 22:06:21 +0100 | [diff] [blame] | 32 | |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 33 | $(document).ready(function() { |
Marc Kupietz | 694610d | 2017-11-25 18:30:03 +0100 | [diff] [blame] | 34 | |
Marc Kupietz | a0ffb39 | 2018-01-25 08:53:43 +0100 | [diff] [blame] | 35 | $('#firstable').hide(); |
| 36 | //Set up a callback to hear back when MathJax is done rendering the equations |
| 37 | // it finds |
| 38 | $('#ccd').load( |
| 39 | '@Url.Action("ActionResultMethod","ControllerName",{controller parameters})', |
| 40 | function () { |
| 41 | MathJax.Hub.Queue( |
| 42 | ["Typeset",MathJax.Hub,"ccd"], |
| 43 | function () { |
Marc Kupietz | 7bd5523 | 2019-01-22 15:29:06 +0100 | [diff] [blame^] | 44 | $("#mi_tt").attr("title",$("#pmi_ttt").html()); |
Marc Kupietz | a0ffb39 | 2018-01-25 08:53:43 +0100 | [diff] [blame] | 45 | $("#lfmd_tt").attr("title",$("#lfmd_ttt").html()); |
Marc Kupietz | 7bd5523 | 2019-01-22 15:29:06 +0100 | [diff] [blame^] | 46 | $("#md_tt").attr("title",$("#md_ttt").html()); |
Marc Kupietz | a0ffb39 | 2018-01-25 08:53:43 +0100 | [diff] [blame] | 47 | $("#npmi_tt").attr("title",$("#npmi_ttt").html()); |
Marc Kupietz | f19814b | 2019-01-21 16:50:19 +0100 | [diff] [blame] | 48 | $("#ll_tt").attr("title",$("#ll_ttt").html()); |
Marc Kupietz | 7bd5523 | 2019-01-22 15:29:06 +0100 | [diff] [blame^] | 49 | $("#logdice_tt").attr("title",$("#logdice_ttt").html()); |
Marc Kupietz | a0ffb39 | 2018-01-25 08:53:43 +0100 | [diff] [blame] | 50 | } |
| 51 | ); |
| 52 | }); |
| 53 | |
| 54 | //set things up so that we can shove raw html into what is shown in the tooltip; |
| 55 | // in this case, we will have already put into the title attribute the html that |
| 56 | // contains the MathJax rendered equations (via what we do in the callback). |
| 57 | $(function () { |
| 58 | $(document).tooltip({ |
| 59 | content: function () { |
| 60 | return $(this).prop('title'); |
| 61 | } |
| 62 | }); |
| 63 | }); |
| 64 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 65 | $("input").bind("keydown", function(event) { |
| 66 | // track enter key |
| 67 | var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode)); |
| 68 | if (keycode == 13) { // keycode for enter key |
| 69 | // force the 'Enter Key' to implicitly click the Update button |
| 70 | document.getElementById('SEARCH').click(); |
| 71 | return false; |
| 72 | } else { |
| 73 | return true; |
| 74 | }}); |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame] | 75 | |
Marc Kupietz | e871abd | 2018-01-25 16:18:27 +0100 | [diff] [blame] | 76 | var collocatorTable_activated = false; |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 77 | $( "#tabs" ).on( "tabsactivate", function( event, ui ) { |
| 78 | if (localStorage) localStorage['tab'] = ui.newTab.index(); |
Marc Kupietz | e871abd | 2018-01-25 16:18:27 +0100 | [diff] [blame] | 79 | if(ui.newTab.index() == 2 && !collocatorTable_activated) { |
| 80 | classicCollocatorTable.columns.adjust(); |
| 81 | collocatorTable.columns.adjust(); |
| 82 | collocatorTable_activated = true; |
| 83 | } |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 84 | }); |
| 85 | |
| 86 | $(function(){ |
| 87 | $("#SEARCH").click(function() { |
| 88 | window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self"); |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 89 | }); |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 90 | }); |
Marc Kupietz | 0af83e3 | 2017-11-27 09:31:37 +0100 | [diff] [blame] | 91 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 92 | function changeCharColor(txt, heat, word) { |
| 93 | var newText = ""; |
| 94 | for (var i=0, l=txt.length; i<l; i++) { |
| 95 | newText += (i == 5 ? txt.charAt(i) : '<a href="http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q=' + |
| 96 | CIIsearchWords + ' /' + (i > 5? '%2B' : '-') + 'w' + |
| 97 | Math.abs(i-5) + ':' + Math.abs(i-5) + ' ' + word + |
| 98 | '" target="korap"><span style="background-color:' + |
| 99 | getHeatColor(heat[i]/maxHeat)+'">'+txt.charAt(i)+'</span></a>'); |
Marc Kupietz | b6c615d | 2017-12-02 10:38:20 +0100 | [diff] [blame] | 100 | } |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 101 | return newText; |
| 102 | } |
Marc Kupietz | b6c615d | 2017-12-02 10:38:20 +0100 | [diff] [blame] | 103 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 104 | function getHeatColor(value) { |
| 105 | var hue=((1-value)*120).toString(10); |
| 106 | return ["hsl(",hue,",90%,70%)"].join(""); |
| 107 | } |
| 108 | |
| 109 | function bitvec2window(n, heat, word) { |
| 110 | var str = n.toString(2).padStart(10, "0") |
| 111 | .replace(/^([0-9]{5})/, '$1x') |
| 112 | .replace(/0/g, '·') |
| 113 | .replace(/1/g, '+'); |
| 114 | return changeCharColor(str, heat, word); |
| 115 | } |
| 116 | |
| 117 | % use Mojo::ByteStream 'b'; |
| 118 | var paraResults = <%= b(Mojo::JSON::to_json($lists)) %>; |
| 119 | var urlprefix = new URLSearchParams(window.location.search); |
| 120 | if (paraResults.length > 0 && paraResults[0] != null) { |
| 121 | var nvecs = [], |
| 122 | nwords = [], |
| 123 | nranks = [], |
| 124 | nmarked = []; |
| 125 | for(var i = 0; i < paraResults.length; i++) { |
| 126 | nwords = nwords.concat(paraResults[i].map(function(a){return a.word;})); |
| 127 | nvecs = nvecs.concat(paraResults[i].map(function(a){return a.vector;})); |
| 128 | nranks = nranks.concat(paraResults[i].map(function(a){return a.rank;})); |
| 129 | nmarked = nmarked.concat(paraResults[i].map(function(a){return a.marked;})); |
Marc Kupietz | 0d4c0ca | 2017-12-04 09:18:56 +0100 | [diff] [blame] | 130 | } |
Marc Kupietz | 2e2e4db | 2018-12-21 15:07:37 +0100 | [diff] [blame] | 131 | showMap({target: " "+urlParams.get('word')+" ", mergedEnd: <%= $mergedEnd %>, words: nwords, vecs: nvecs, ranks: nranks, marked: nmarked} ); |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 132 | var t = $('#firsttable').DataTable({ |
Marc Kupietz | ee894d5 | 2019-01-09 14:55:14 +0100 | [diff] [blame] | 133 | data: [].concat.apply([], paraResults), |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 134 | "sScrollY": "780px", |
| 135 | "bScrollCollapse": true, |
| 136 | "bPaginate": false, |
| 137 | "bJQueryUI": true, |
| 138 | "dom": '<"top">rt<"bottom"flp><"clear">', |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 139 | "initComplete":function(settings, json) { |
| 140 | $('td.paradigmator a').on('mousedown', function(e) { |
| 141 | return paradigmatorClick(e, paraResults[0][0].word, this.childNodes["0"].textContent); |
| 142 | }); |
| 143 | }, |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 144 | "columns": [ |
| 145 | { "data": "rank", type: "allnumeric" }, |
| 146 | { "data": "dist", render: function ( data, type, row ) {return data.toFixed(3) }}, |
Marc Kupietz | 2e2e4db | 2018-12-21 15:07:37 +0100 | [diff] [blame] | 147 | { "data": "word", class: "paradigmator", render: function ( data, type, row ) { |
| 148 | urlprefix.set("word", data); return '<a class="' + getMergedClass(row.rank) + '" href="?' + urlprefix + '">' + data + '</a>' |
| 149 | }} |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 150 | ], |
| 151 | "columnDefs": [ |
| 152 | { className: "dt-right", "targets": [0,1] }, |
| 153 | { "searchable": false, |
| 154 | "orderable": false, |
| 155 | "targets": 0 |
| 156 | }, |
| 157 | { "orderSequence": [ "desc" ], "targets": [ 1 ] }, |
| 158 | { "orderSequence": [ "asc", "desc" ], "targets": [ 2 ] }, |
| 159 | ], |
| 160 | "oLanguage": { |
| 161 | "sSearch": "Filter: " |
| 162 | }, |
| 163 | "order": [[ 1, 'desc' ]], |
| 164 | } ); |
Marc Kupietz | 0d4c0ca | 2017-12-04 09:18:56 +0100 | [diff] [blame] | 165 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 166 | t.on( 'order.dt search.dt', function () { |
| 167 | t.column(0, {order:'applied'}).nodes().each( function (cell, i) { |
| 168 | cell.innerHTML = i+1; |
| 169 | } ); |
| 170 | } ).draw(); |
| 171 | |
| 172 | $( "#first" ).clone().prependTo( "#tabs-2" ); |
| 173 | |
| 174 | } |
| 175 | |
| 176 | |
| 177 | var collocatorData = <%= b(Mojo::JSON::to_json($collocators)) %>; |
| 178 | var maxHeat; // = Math.max.apply(Math,collocatorData.map(function(o){return o.cprob;})) |
| 179 | |
| 180 | if (collocatorData != null) { |
| 181 | maxHeat = Math.max.apply(Math,collocatorData.map(function(o){return Math.max.apply(Math,o.heat);})) |
| 182 | collocatorTable = $('#secondtable').DataTable({ |
| 183 | data: collocatorData, |
| 184 | "sScrollY": "780px", |
| 185 | "bScrollCollapse": true, |
| 186 | "bPaginate": false, |
| 187 | "bJQueryUI": true, |
| 188 | "dom": '<"top">rt<"bottom"flp><"clear">', |
| 189 | "columns": [ |
| 190 | { "data": "rank", type: "allnumeric" }, |
| 191 | { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat, row.word) }}, |
| 192 | { "data": "max", render: function ( data, type, row ) {return data.toFixed(3) }}, |
| 193 | { "data": "average", render: function ( data, type, row ) {return data.toFixed(3) }}, |
| 194 | { "data": "prob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } }, |
| 195 | { "data": "cprob", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } }, |
| 196 | { "data": "overall", type: "scientific", render: function ( data, type, row ) {return data.toExponential(3) } }, |
| 197 | { "data": "word", sClass: "collocator" }, |
| 198 | { "data": "rank", type: "allnumeric" } |
| 199 | ], |
| 200 | "columnDefs": [ |
| 201 | { className: "dt-right", "targets": [0,2,3,4,5,6] }, |
| 202 | { className: "dt-center", "targets": [ 1] }, |
| 203 | { "searchable": false, |
| 204 | "orderable": false, |
| 205 | "targets": [0, 8] |
| 206 | }, |
| 207 | { "type": "scientific", targets: [2,3,4,5,6] }, |
| 208 | { "orderSequence": [ "desc" ], "targets": [ 2, 3, 4, 5, 6 ] }, |
| 209 | { "orderSequence": [ "asc", "desc" ], "targets": [ 1, 7 ] }, |
| 210 | { "targets": [8], "visible": false } |
| 211 | ], |
| 212 | "oLanguage": { |
| 213 | "sSearch": "Filter: " |
| 214 | }, |
| 215 | "order": [[ 4, 'desc' ]], |
| 216 | } ); |
| 217 | $.ajaxSetup({ |
| 218 | type: 'POST', |
| 219 | timeout: 30000, |
| 220 | error: function(xhr) { |
| 221 | $('#display_error') |
| 222 | .html('Error: ' + xhr.status + ' ' + xhr.statusText); |
| 223 | } |
Marc Kupietz | 78b434a | 2018-01-12 22:33:32 +0100 | [diff] [blame] | 224 | }); |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 225 | |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 226 | |
| 227 | if($('#sprofiles').length) { |
| 228 | similarProfileTable = $('#sprofiles').DataTable({ |
| 229 | ajax: { |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 230 | method: "GET", |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 231 | url: '/derekovecs/getSimilarProfiles', |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 232 | dataType: 'json', |
| 233 | dataSrc: "", |
| 234 | timeout: 30000, |
| 235 | data: { w: paraResults[0][0].rank } |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 236 | }, |
| 237 | "initComplete":function(settings, json){ |
| 238 | $('td.paradigmator a').on('mousedown', function(e) { |
| 239 | if (e.which === 2) { |
| 240 | e.preventDefault(); |
| 241 | queryKorAPalternatives(paraResults[0][0].word, this.childNodes["0"].textContent); |
| 242 | return false; |
| 243 | } |
| 244 | }); |
| 245 | }, |
| 246 | "sScrollY": "780px", |
| 247 | "bScrollCollapse": true, |
| 248 | "bPaginate": false, |
| 249 | "bJQueryUI": true, |
| 250 | "dom": '<"top">rt<"bottom"flp><"clear">', |
| 251 | "columns": [ |
| 252 | { "data": "v", render: function ( data, type, row ) {return data.toFixed(3) }}, |
| 253 | { "data": "w", sClass: "paradigmator", render: function ( data, type, row ) {urlprefix.set("word", data); return '<a href="?' + urlprefix + '">' + data + '</a>' } } |
| 254 | ], |
| 255 | "columnDefs": [ |
| 256 | { className: "dt-right", "targets": [0] }, |
| 257 | ], |
| 258 | "oLanguage": { |
| 259 | "sSearch": "Filter: " |
| 260 | }, |
| 261 | "order": [[ 0, 'desc' ]], |
| 262 | }); |
| 263 | } |
| 264 | // var filterQuot = /(^quot?=[A-Z])|(quot$)/g; |
| 265 | var filterQuot = /^quot/; |
| 266 | classicCollocatorTable = $('#classicoloctable').DataTable({ |
| 267 | ajax: { |
| 268 | method: "GET", |
| 269 | url: '/derekovecs/getClassicCollocators', |
| 270 | dataType: 'json', |
| 271 | dataSrc: "", |
| 272 | timeout: 30000, |
| 273 | data: { w: paraResults[0][0].rank } |
Marc Kupietz | 78b434a | 2018-01-12 22:33:32 +0100 | [diff] [blame] | 274 | }, |
Marc Kupietz | ad78372 | 2018-01-13 17:45:21 +0100 | [diff] [blame] | 275 | "initComplete":function(settings, json){ |
| 276 | $("td.collocator").click(function(){ |
| 277 | queryKorAPCII(this.textContent + " /w5 " + CIIsearchWords); |
| 278 | }); |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 279 | classicCollocatorTable.columns(".detail").visible(false); |
| 280 | $("#ccd").css('width', '450px'); |
| 281 | classicCollocatorTable.columns.adjust().draw(); |
Marc Kupietz | ad78372 | 2018-01-13 17:45:21 +0100 | [diff] [blame] | 282 | }, |
Marc Kupietz | 78b434a | 2018-01-12 22:33:32 +0100 | [diff] [blame] | 283 | "sScrollY": "780px", |
| 284 | "bScrollCollapse": true, |
| 285 | "bPaginate": false, |
| 286 | "bJQueryUI": true, |
| 287 | "dom": '<"top">rt<"bottom"flp><"clear">', |
| 288 | "columns": [ |
| 289 | // { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat, row.word) }}, |
Marc Kupietz | b4b53ca | 2018-01-25 08:57:11 +0100 | [diff] [blame] | 290 | { "data": "llr", render: function ( data, type, row ) {return data.toFixed(0) }}, |
Marc Kupietz | 7bd5523 | 2019-01-22 15:29:06 +0100 | [diff] [blame^] | 291 | { "data": "pmi", render: function ( data, type, row ) {return data.toFixed(2) }}, |
| 292 | { "data": "md", render: function ( data, type, row ) {return data.toFixed(2) }}, |
| 293 | { "data": "lfmd", render: function ( data, type, row ) {return data.toFixed(2) }}, |
Marc Kupietz | 1acb317 | 2018-02-17 09:41:26 +0100 | [diff] [blame] | 294 | // { "data": "fpmi", type: "scientific", render: function ( data, type, row ) {return data.toExponential(2) } }, |
Marc Kupietz | 7bd5523 | 2019-01-22 15:29:06 +0100 | [diff] [blame^] | 295 | { "data": "npmi", render: function ( data, type, row ) {return data.toFixed(3) }}, |
| 296 | { "data": "dice", render: function ( data, type, row ) {return data.toExponential(2) }}, |
| 297 | { "data": "ld", render: function ( data, type, row ) {return data.toFixed(2) }}, |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 298 | { "data": "llfmd", render: function ( data, type, row ) {return data.toFixed(1) }}, |
| 299 | { "data": "rlfmd", render: function ( data, type, row ) {return data.toFixed(1) }}, |
| 300 | { "data": "lnpmi", render: function ( data, type, row ) {return data.toFixed(2) }}, |
| 301 | { "data": "rnpmi", render: function ( data, type, row ) {return data.toFixed(2) }}, |
Marc Kupietz | b4b53ca | 2018-01-25 08:57:11 +0100 | [diff] [blame] | 302 | { "data": "f" }, |
Marc Kupietz | 78b434a | 2018-01-12 22:33:32 +0100 | [diff] [blame] | 303 | { "data": "word", sClass: "collocator" } |
| 304 | ], |
| 305 | "columnDefs": [ |
Marc Kupietz | 7bd5523 | 2019-01-22 15:29:06 +0100 | [diff] [blame^] | 306 | { className: "dt-right", "targets": [0,1,2,3,4,5,6,7,8,9,10,11] }, |
| 307 | { className: "dt-right detail", "targets": [5,7,8,9,10] }, |
Marc Kupietz | 78b434a | 2018-01-12 22:33:32 +0100 | [diff] [blame] | 308 | { "searchable": false, |
| 309 | "orderable": false, |
| 310 | "targets": [] |
| 311 | }, |
Marc Kupietz | 7bd5523 | 2019-01-22 15:29:06 +0100 | [diff] [blame^] | 312 | { "orderSequence": [ "desc" ], "targets": [0,1,2,3,4,5,6,7,8,9,10,11] }, |
| 313 | { "orderSequence": [ "asc", "desc" ], "targets": [12] }, |
Marc Kupietz | 78b434a | 2018-01-12 22:33:32 +0100 | [diff] [blame] | 314 | ], |
| 315 | "oLanguage": { |
| 316 | "sSearch": "Filter: " |
| 317 | }, |
| 318 | "order": [[ 1, 'desc' ]], |
| 319 | }); |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 320 | |
Marc Kupietz | 1acb317 | 2018-02-17 09:41:26 +0100 | [diff] [blame] | 321 | |
| 322 | $('#show-details').change(function (e) { |
| 323 | var columns = classicCollocatorTable.columns(".detail"); |
| 324 | if(this.checked) { |
| 325 | columns.visible(true); |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 326 | $("#ccd").css('width', 'auto'); |
Marc Kupietz | 1acb317 | 2018-02-17 09:41:26 +0100 | [diff] [blame] | 327 | } else { |
| 328 | columns.visible(false); |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 329 | $("#ccd").css('width', '450px'); |
Marc Kupietz | 1acb317 | 2018-02-17 09:41:26 +0100 | [diff] [blame] | 330 | } |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 331 | classicCollocatorTable.columns.adjust().draw(); |
Marc Kupietz | 1acb317 | 2018-02-17 09:41:26 +0100 | [diff] [blame] | 332 | } ); |
| 333 | |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 334 | $("td.collocator").click(function(){ |
| 335 | queryKorAPCII(this.textContent + " /w5 " + CIIsearchWords); |
Marc Kupietz | ad78372 | 2018-01-13 17:45:21 +0100 | [diff] [blame] | 336 | }); |
| 337 | |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 338 | collocatorTable.on( 'order.dt search.dt', function () { |
| 339 | collocatorTable.column(0, {order:'applied'}).nodes().each( function (cell, i) { |
| 340 | cell.innerHTML = i+1; |
| 341 | } ); |
| 342 | }).draw(); |
| 343 | } |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 344 | |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 345 | if (localStorage && !window.location.hash) { // let's not crash if some user has IE7 |
| 346 | var index = parseInt(localStorage['tab']||'0'); |
| 347 | $("#tabs").tabs({ active: index }); |
| 348 | } |
| 349 | $("#tabs").css("visibility", "visible"); // now we can show the tabs |
| 350 | }); |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 351 | |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 352 | $(function(){ |
| 353 | $("#dropdownoptions").dialog({ |
| 354 | title: "Options", |
| 355 | autoOpen: false, |
| 356 | modal: false, |
| 357 | draggable: false, |
| 358 | height: "auto", |
| 359 | width: "auto", |
| 360 | resizable: false, |
| 361 | buttons: { |
| 362 | "Cancel": function() { |
| 363 | $( this ).dialog( "close" ); |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 364 | }, |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 365 | "Apply": function() { |
| 366 | window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self"); |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 367 | } |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 368 | } |
| 369 | }); |
| 370 | }); |
| 371 | |
| 372 | $(function(){ |
| 373 | $("#showoptions").click(function(){ |
| 374 | $("#dropdownoptions").dialog("open"); |
| 375 | var target = $(this); |
| 376 | $("#dropdownoptions").dialog("widget").position({ |
| 377 | my: 'left bottom', |
| 378 | at: 'left bottom', |
| 379 | of: target |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 380 | }); |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 381 | }); |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 382 | }); |
| 383 | |
| 384 | $( function() { |
| 385 | $( "#no_iterations" ).spinner({ |
| 386 | spin: function( event, ui ) { |
| 387 | if ( ui.value < 1000 ) { |
| 388 | $( this ).spinner( "value", 1000 ); |
| 389 | return false; |
| 390 | } else if ( ui.value > 10000 ) { |
| 391 | $( this ).spinner( "value", 10000 ); |
| 392 | return false; |
| 393 | } |
| 394 | } |
| 395 | }); |
| 396 | } ); |
| 397 | |
| 398 | $( function() { |
| 399 | $( "#neighbours" ).spinner({ |
| 400 | spin: function( event, ui ) { |
| 401 | if ( ui.value < 0 ) { |
| 402 | $( this ).spinner( "value", 0 ); |
| 403 | return false; |
| 404 | } else if ( ui.value > 200 ) { |
| 405 | $( this ).spinner( "value", 200 ); |
| 406 | return false; |
| 407 | } |
| 408 | } |
| 409 | }); |
| 410 | } ); |
| 411 | |
| 412 | $( function() { |
| 413 | $( "#cutoff" ).spinner({ |
| 414 | spin: function( event, ui ) { |
| 415 | if ( ui.value < 100000 ) { |
| 416 | $( this ).spinner( "value", 100000 ); |
| 417 | return false; |
| 418 | } else if ( ui.value > 2000000 ) { |
| 419 | $( this ).spinner( "value", 2000000 ); |
| 420 | return false; |
| 421 | } |
| 422 | } |
| 423 | }); |
| 424 | } ); |
| 425 | |
| 426 | $( function() { |
| 427 | $( "#tabs" ).tabs().addClass('tabs-min'); |
| 428 | } ); |
| 429 | |
| 430 | $( function() { |
| 431 | $( ".controlgroup-vertical" ).controlgroup({ |
| 432 | "direction": "vertical" |
| 433 | }); |
| 434 | } ); |
| 435 | |
| 436 | $(function() { |
| 437 | $( document ).tooltip({ |
| 438 | content: function() { |
| 439 | return $(this).attr('title'); |
| 440 | }} |
| 441 | ) |
| 442 | }); |
| 443 | |
| 444 | $(function () { |
| 445 | $(document).tooltip({ |
| 446 | content: function () { |
| 447 | return $(this).prop('title'); |
| 448 | }, |
| 449 | show: null, |
| 450 | close: function (event, ui) { |
| 451 | ui.tooltip.hover( |
| 452 | function () { |
| 453 | $(this).stop(true).fadeTo(400, 1); |
| 454 | }, |
| 455 | function () { |
| 456 | $(this).fadeOut("400", function () { |
| 457 | $(this).remove(); |
| 458 | }) |
| 459 | }); |
| 460 | } |
| 461 | }); |
| 462 | }); |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 463 | </script> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 464 | <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> |
| 465 | <script src="/derekovecs/js/tsne.js"></script> |
| 466 | <script src="/derekovecs/js/som.js"></script> |
| 467 | <script src="/derekovecs/js/labeler.js"></script> |
Marc Kupietz | cdd5130 | 2018-03-19 16:36:54 +0100 | [diff] [blame] | 468 | <script src="/derekovecs/js/derekovcs.js"></script> |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 469 | <script> |
| 470 | |
| 471 | var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>}, |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 472 | mapWidth = 800, // width map |
| 473 | mapHeight = 800, |
| 474 | jitterRadius = 7; |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 475 | |
| 476 | var T = new tsnejs.tSNE(opt); // create a tSNE instance |
| 477 | |
| 478 | var Y; |
| 479 | |
| 480 | var data; |
| 481 | var labeler; |
| 482 | |
| 483 | function applyJitter() { |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 484 | svg.selectAll('.tsnet') |
| 485 | .data(labels) |
| 486 | .transition() |
| 487 | .duration(50) |
| 488 | .attr("transform", function(d, i) { |
| 489 | T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20; |
| 490 | T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20; |
| 491 | return "translate(" + |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 492 | (d.x) + "," + |
| 493 | (d.y) + ")"; |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 494 | }); |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 495 | } |
Marc Kupietz | 34c0817 | 2017-11-29 17:08:47 +0100 | [diff] [blame] | 496 | |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 497 | function updateEmbedding() { |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 498 | var Y = T.getSolution(); |
| 499 | svg.selectAll('.tsnet') |
| 500 | .data(data.words) |
| 501 | .attr("transform", function(d, i) { |
| 502 | return "translate(" + |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 503 | ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," + |
| 504 | ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; }); |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | var svg; |
| 508 | var labels = []; |
| 509 | var anchor_array = []; |
| 510 | var text; |
| 511 | |
Marc Kupietz | 2e2e4db | 2018-12-21 15:07:37 +0100 | [diff] [blame] | 512 | function getMergedClass(i) { |
| 513 | if(data.mergedEnd && i > data.mergedEnd) { |
| 514 | return " merged" |
| 515 | } else { |
| 516 | return ""; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | function getRankTooltip(i) { |
| 521 | if(data.mergedEnd) { |
| 522 | if(data.ranks[i] < data.mergedEnd) { |
| 523 | return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); |
| 524 | } else { |
| 525 | return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]-data.mergedEnd).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)"; |
| 526 | } |
| 527 | } else { |
| 528 | return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); |
| 529 | } |
| 530 | } |
| 531 | |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 532 | function drawEmbedding() { |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 533 | var urlprefix = new URLSearchParams(window.location.search); |
| 534 | urlprefix.delete("word"); |
| 535 | urlprefix.append("word",""); |
Marc Kupietz | 8f9c86a | 2017-12-04 17:17:13 +0100 | [diff] [blame] | 536 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 537 | $("#embed").empty(); |
| 538 | var div = d3.select("#embed"); |
Marc Kupietz | 34c0817 | 2017-11-29 17:08:47 +0100 | [diff] [blame] | 539 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 540 | // get min and max in each column of Y |
| 541 | var Y = T.Y; |
Marc Kupietz | 34c0817 | 2017-11-29 17:08:47 +0100 | [diff] [blame] | 542 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 543 | svg = div.append("svg") // svg is global |
| 544 | .attr("width", mapWidth) |
| 545 | .attr("height", mapHeight); |
Marc Kupietz | 34c0817 | 2017-11-29 17:08:47 +0100 | [diff] [blame] | 546 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 547 | var g = svg.selectAll(".b") |
| 548 | .data(data.words) |
| 549 | .enter().append("g") |
| 550 | .attr("class", "tsnet"); |
Marc Kupietz | 34c0817 | 2017-11-29 17:08:47 +0100 | [diff] [blame] | 551 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 552 | g.append("a") |
| 553 | .attr("xlink:href", function(word) { |
| 554 | return "?"+urlprefix+word; }) |
| 555 | .attr("class", function(d, i) { |
| 556 | var res=""; |
| 557 | if(data.marked[i]) { |
| 558 | res="marked "; |
| 559 | } |
| 560 | if(data.target.indexOf(" "+d+" ") >= 0) { |
Marc Kupietz | 2e2e4db | 2018-12-21 15:07:37 +0100 | [diff] [blame] | 561 | res += "target"; |
| 562 | } |
| 563 | if(data.mergedEnd && data.ranks[i] >= data.mergedEnd) { |
| 564 | return res+" merged"; |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 565 | } else { |
| 566 | return res; |
| 567 | } |
| 568 | }) |
| 569 | .attr("title", function(d, i) { |
Marc Kupietz | 2e2e4db | 2018-12-21 15:07:37 +0100 | [diff] [blame] | 570 | return getRankTooltip(i); |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 571 | }) |
| 572 | .append("text") |
| 573 | .attr("text-anchor", "top") |
| 574 | .attr("font-size", 12) |
| 575 | .text(function(d) { return d; }); |
Marc Kupietz | 34c0817 | 2017-11-29 17:08:47 +0100 | [diff] [blame] | 576 | |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 577 | g.append("svg:title") |
| 578 | .text(function(d, i) { |
Marc Kupietz | 2e2e4db | 2018-12-21 15:07:37 +0100 | [diff] [blame] | 579 | return getRankTooltip(i); |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 580 | }); |
| 581 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 582 | var zoomListener = d3.behavior.zoom() |
| 583 | .scaleExtent([0.1, 10]) |
| 584 | .center([0,0]) |
| 585 | .on("zoom", zoomHandler); |
| 586 | zoomListener(svg); |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | var tx=0, ty=0; |
| 590 | var ss=1; |
| 591 | var iter_id=-1; |
| 592 | |
| 593 | function zoomHandler() { |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 594 | tx = d3.event.translate[0]; |
| 595 | ty = d3.event.translate[1]; |
| 596 | ss = d3.event.scale; |
| 597 | updateEmbedding(); |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | var stepnum = 0; |
| 601 | |
| 602 | function stopStep() { |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 603 | clearInterval(iter_id); |
| 604 | text = svg.selectAll("text"); |
Marc Kupietz | 34c0817 | 2017-11-29 17:08:47 +0100 | [diff] [blame] | 605 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 606 | // jitter function needs different data and co-ordinate representation |
| 607 | labels = d3.range(data.words.length).map(function(i) { |
| 608 | var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2; |
| 609 | var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2; |
| 610 | anchor_array.push({x: x, y: y, r: jitterRadius}); |
| 611 | return { |
| 612 | x: x, |
| 613 | y: y, |
| 614 | name: data.words[i] |
| 615 | }; |
| 616 | }); |
Marc Kupietz | 34c0817 | 2017-11-29 17:08:47 +0100 | [diff] [blame] | 617 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 618 | // get the actual label bounding boxes for the jitter function |
| 619 | var index = 0; |
| 620 | text.each(function() { |
| 621 | labels[index].width = this.getBBox().width; |
| 622 | labels[index].height = this.getBBox().height; |
| 623 | index += 1; |
| 624 | }); |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 625 | |
Marc Kupietz | 34c0817 | 2017-11-29 17:08:47 +0100 | [diff] [blame] | 626 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 627 | // setTimeout(updateEmbedding, 1); |
| 628 | // setTimeout( |
| 629 | labeler = d3.labeler() |
| 630 | .label(labels) |
| 631 | .anchor(anchor_array) |
| 632 | .width(mapWidth) |
| 633 | .height(mapHeight) |
| 634 | .update(applyJitter); |
| 635 | // .start(1000); |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 636 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 637 | iter_id = setInterval(jitterStep, 1); |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | var jitter_i=0; |
| 641 | |
| 642 | function jitterStep() { |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 643 | if(jitter_i++ > 100) { |
| 644 | clearInterval(iter_id); |
| 645 | } else { |
| 646 | labeler.start2(10); |
| 647 | applyJitter(); |
| 648 | } |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | var last_cost=1000; |
| 652 | |
| 653 | function step() { |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 654 | var i = T.iter; |
Marc Kupietz | 34c0817 | 2017-11-29 17:08:47 +0100 | [diff] [blame] | 655 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 656 | if(i > <%= $no_iterations %>) { |
| 657 | stopStep(); |
| 658 | } else { |
| 659 | var cost = Math.round(T.step() * 100000) / 100000; // do a few steps |
| 660 | $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5)); |
| 661 | if(i % 250 == 0 && cost >= last_cost) { |
| 662 | stopStep(); |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 663 | } else { |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 664 | last_cost = cost; |
| 665 | updateEmbedding(); |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 666 | } |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 667 | } |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | function showMap(j) { |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 671 | data=j; |
| 672 | T.iter=0; |
| 673 | iter_id = -1; |
| 674 | last_cost=1000; |
| 675 | T.initDataRaw(data.vecs); // init embedding |
| 676 | drawEmbedding(); // draw initial embedding |
Marc Kupietz | 7811453 | 2017-11-29 17:00:16 +0100 | [diff] [blame] | 677 | |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 678 | 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 Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 686 | } |
Marc Kupietz | 39179ab | 2017-07-04 16:28:06 +0200 | [diff] [blame] | 687 | var queryword; |
| 688 | |
Marc Kupietz | 66bfd95 | 2017-12-11 09:59:45 +0100 | [diff] [blame] | 689 | function showCollocatorSOM() { |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 690 | if (collocatorTable) { |
| 691 | var ctableData = collocatorTable.rows().data(); |
| 692 | var nwords = [], |
| 693 | nranks = []; |
| 694 | for (var i=0; i < ctableData.length && i < 100; i++) { |
| 695 | nranks.push(ctableData[i].rank); |
| 696 | nwords.push(ctableData[i].word); |
Marc Kupietz | 66bfd95 | 2017-12-11 09:59:45 +0100 | [diff] [blame] | 697 | } |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 698 | $.post('/derekovecs/getVecsByRanks', |
| 699 | JSON.stringify(nranks), |
| 700 | function(data, status){ |
Marc Kupietz | 2e2e4db | 2018-12-21 15:07:37 +0100 | [diff] [blame] | 701 | showMap({target: " "+urlParams.get('word')+" ", mergedEnd: <%= $mergedEnd %>, words: nwords, vecs: data, ranks: nranks, marked: Array(100).fill(false)} ); |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 702 | }, 'json'); |
| 703 | } |
Marc Kupietz | 66bfd95 | 2017-12-11 09:59:45 +0100 | [diff] [blame] | 704 | } |
| 705 | |
Marc Kupietz | 39179ab | 2017-07-04 16:28:06 +0200 | [diff] [blame] | 706 | function onload() { |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 707 | queryword = document.getElementById('word'); |
Marc Kupietz | 39179ab | 2017-07-04 16:28:06 +0200 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | function queryKorAP() { |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 711 | window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP'); |
Marc Kupietz | 39179ab | 2017-07-04 16:28:06 +0200 | [diff] [blame] | 712 | } |
Marc Kupietz | 4dc270c | 2017-11-24 10:17:12 +0100 | [diff] [blame] | 713 | |
| 714 | function queryKorAPCII(query) { |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 715 | window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP'); |
Marc Kupietz | 4dc270c | 2017-11-24 10:17:12 +0100 | [diff] [blame] | 716 | } |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 717 | </script> |
| 718 | </head> |
Marc Kupietz | 39179ab | 2017-07-04 16:28:06 +0200 | [diff] [blame] | 719 | <body onload="onload()"> |
Marc Kupietz | 7bd5523 | 2019-01-22 15:29:06 +0100 | [diff] [blame^] | 720 | <div style="display:none;" id="pmi_ttt">Pointwise mutual information: $$\text{MI}=\text{MI}=log_2\frac{p(w_1,w_2)}{p(w_1) p(w_2)}$$<p class="citation">Church, K. W. and Hanks, P. (1990): Word association norms, mutual information, and lexicography. Comput. Linguist. 16, 1 (March 1990), 22-29.</p></div> |
| 721 | <div style="display:none;" id="md_ttt">Pointwise mutual information squared [1], also called mutual dependency [2]: $$\text{MI}^2=\text{MD}=log_2\frac{p^2(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> |
| 722 | <div style="display:none;" id="lfmd_ttt">Pointwise mutual information cubed [1], also called log-frequency biased mutual dependency [2]: $$\text{MI}^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 Kupietz | a0ffb39 | 2018-01-25 08:53:43 +0100 | [diff] [blame] | 723 | <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 Kupietz | f19814b | 2019-01-21 16:50:19 +0100 | [diff] [blame] | 724 | <div style="display:none;" id="ll_ttt">Log-likelihood: $$2*\sum_{ij}O_{ij}*log\frac{O_{ij}}{E_{ij}}$$<p class="citation">Evert, Stefan (2004): <a href="http://purl.org/stefan.evert/PUB/Evert2004phd.pdf">The Statistics of Word Cooccurrences: Word Pairs and Collocations.</a> PhD dissertation, IMS, University of Stuttgart. Published in 2005, URN urn:nbn:de:bsz:93-opus-23714.</p></div> |
Marc Kupietz | 7bd5523 | 2019-01-22 15:29:06 +0100 | [diff] [blame^] | 725 | <div style="display:none;" id="logdice_ttt">Log-Dice: $$14 + log_2 \frac{2*(f_{12}+ε)}{(f_1+ε) + (f_2+ε)}$$<p class="citation">Rychlý, Pavel (2008): <a href="http://www.fi.muni.cz/usr/sojka/download/raslan2008/13.pdf">A lexicographer-friendly association score.</a> In Proceedings of Recent Advances in Slavonic Natural Language Processing, RASLAN, 6–9, 2008</p></div> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 726 | <div id="header"> |
| 727 | <div id="pagetitle"> |
Marc Kupietz | c053d97 | 2019-01-10 10:41:51 +0100 | [diff] [blame] | 728 | <h1>DeReKoVecs</h1> |
| 729 | <h2><%== $title %></h2> |
Marc Kupietz | 4fcda0c | 2017-11-29 09:00:31 +0100 | [diff] [blame] | 730 | </div> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 731 | <div id="options" class="widget"> |
| 732 | <form id="queryform"> |
| 733 | <input id="word" type="text" name="word" placeholder="Word(s) to be searched" value="<%= $word %>" |
| 734 | 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."/> |
| 735 | <input id="SEARCH" type="button" value="SEARCH"> |
| 736 | <input type="button" id="showoptions" name="showoptions" value="Options" /> |
| 737 | </form> |
| 738 | <div id="dropdownoptions" style="display: none"> |
| 739 | <form id="optionsform"> |
| 740 | <div class="controlgroup-vertical"> |
| 741 | <label for="cutoff">cut-off</label> |
| 742 | <input id="cutoff" type="text" name="cutoff" size="10" value="<%= $cutoff %>" title="Only consider the most frequent x word forms."> |
| 743 | <label for="dedupe">dedupe</label> |
| 744 | <input id="dedupe" type="checkbox" name="dedupe" value="1" <%= ($dedupe ? "checked" : "") %> title="radically filter out any near-duplicates"> |
| 745 | % if($mergedEnd > 0) { |
| 746 | <label for="sbf">backw.</label> |
| 747 | <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."> |
| 748 | % } |
| 749 | <label for="neighbours">max. neighbours:</label> |
| 750 | <input id="neighbours" size="4" name="n" value="<%= $no_nbs %>"> |
| 751 | <label for="no_iterations">max. iterations</label> |
| 752 | <input id="no_iterations" name="N" size="4" value="<%= $no_iterations %>"> |
| 753 | <!-- <label for="dosom">SOM</label> |
| 754 | <input id="dosom" type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> --> |
| 755 | % if($collocators) { |
| 756 | <label for="sortby">window/sort</label> |
| 757 | <select id="sortby" name="sort"> |
| 758 | <option value="0" <%= ($sort!=1 && $sort!=2? "selected":"") %>>auto focus</option> |
| 759 | <!-- <option value="1" <%= ($sort==1? "selected":"") %>>any single position</option> |
| 760 | <option value="2" <%= ($sort==2? "selected":"") %>>whole window</option> --> |
| 761 | </select> |
| 762 | % } |
| 763 | <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/> |
Marc Kupietz | 1acb317 | 2018-02-17 09:41:26 +0100 | [diff] [blame] | 764 | <input id="show-details" type="checkbox" name="show-details" value="1" > |
| 765 | <label for="show-details"> |
| 766 | Show details |
| 767 | </label> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 768 | </div> |
| 769 | </form> |
| 770 | </div> |
| 771 | </div> |
| 772 | </div> |
| 773 | <div id="topwrapper"> |
| 774 | <div style="visibility: hidden;" id="tabs"> |
| 775 | <ul> |
| 776 | <li><a href="#tabs-1">Semantics (TSNE-map)</a></li> |
| 777 | <li><a href="#tabs-2">Semantics (SOM)</a></li> |
Marc Kupietz | bb3da6a | 2019-01-22 15:21:38 +0100 | [diff] [blame] | 778 | <li><a href="#tabs-3">Syntagmatic (collocates)</a></li> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 779 | </ul> |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 780 | <div id="tabs-1" style="display: flex; padding: 5px; flex-flow: row wrap;"> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 781 | % if($lists && (@$lists) > 0 && (@$lists)[0]) { |
| 782 | <div id="wrapper"> |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 783 | <div id="first" style="width: 230px; margin-bottom: 15px;"> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 784 | <table class="display compact nowrap" id="firsttable"> |
| 785 | <thead> |
| 786 | <tr> |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 787 | <th align="right">#</th><th align="right">cos</th><th align="left">similars by w2v</th> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 788 | </tr> |
| 789 | </thead> |
| 790 | <tbody> |
| 791 | <tr> |
| 792 | <td align="right"> |
| 793 | </td> |
| 794 | <td align="right"> |
| 795 | </td> |
| 796 | <td></td> |
| 797 | </tr> |
| 798 | </tbody> |
| 799 | </table> |
| 800 | </div> |
Marc Kupietz | a55a09a | 2018-07-06 13:30:30 +0200 | [diff] [blame] | 801 | % if(0 && $haveSProfiles) { |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 802 | <div id="sprofilesdiv" style="width: 200px; padding-right: 10px;"> |
| 803 | <table class="display compact nowrap" id="sprofiles"> |
| 804 | <thead> |
| 805 | <tr> |
| 806 | <th align="right">cos</th><th align="left">similars by coll. profile</th> |
| 807 | </tr> |
| 808 | </thead> |
| 809 | <tbody> |
| 810 | <tr> |
| 811 | <td align="right"> |
| 812 | </td> |
| 813 | <td></td> |
| 814 | </tr> |
| 815 | </tbody> |
| 816 | </table> |
| 817 | </div> |
| 818 | %} |
| 819 | <div id="second"> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 820 | <div id="embed"> |
| 821 | </div> |
| 822 | <div id="cost"> |
| 823 | </div> |
| 824 | </div> |
| 825 | </div> |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 826 | % } elsif($word !~ /^\s*$/) { |
| 827 | <div id="wrapper"> |
| 828 | <div id="not-found-dialog" title="Not found"> |
| 829 | <p>ERROR: "<%= $word %>" not found in vocabluary.</p> |
| 830 | <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> |
| 831 | </div> |
| 832 | <script> |
| 833 | $( function() { |
| 834 | $( "#not-found-dialog" ).dialog({ |
| 835 | autoOpen: true, |
| 836 | modal: true, |
| 837 | draggable: false, |
| 838 | height: "auto", |
| 839 | width: "auto", |
| 840 | resizable: false, |
| 841 | buttons: { |
| 842 | "OK": function() { |
| 843 | $( this ).dialog( "close" ); |
| 844 | }, |
| 845 | "Apply": function() { |
| 846 | window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self"); |
| 847 | } |
| 848 | } |
| 849 | }); |
| 850 | }); |
| 851 | </script> |
| 852 | </div> |
| 853 | % } |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 854 | </div> |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 855 | <div id="tabs-2" style="display: flex; padding: 5px; flex-flow: row wrap;"> |
Marc Kupietz | 66bfd95 | 2017-12-11 09:59:45 +0100 | [diff] [blame] | 856 | <div id="som2" style="width: 800;"> |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 857 | <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div> |
| 858 | <div id="sominfo" style="text-align: right">SOM iteration <span id="iterations">0</span></div> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 859 | </div> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 860 | </div> |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 861 | <div id="tabs-3" style="display: flex; padding:5px; flex-flow: row wrap;"> |
| 862 | <div style="margin-right: 20px; margin-bottom: 10px;" id="secondt"> |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 863 | <table class="display compact nowrap" id="secondtable"> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 864 | <thead> |
| 865 | <tr> |
| 866 | % if($collocators) { |
| 867 | <th>#</th> |
Marc Kupietz | 4116b43 | 2017-12-06 14:15:32 +0100 | [diff] [blame] | 868 | <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> |
| 869 | <th align="right" title="Maximum activation of the collocator anywhere in the output layer.">max(a)</th> |
| 870 | <th title="Average raw activation of the collocator in the columns selected by auto-focus." align="right">⟨a⟩</th> |
| 871 | <th title="Sum of activations over the selected colunns normalized by the total activation sum of the selected columns." align="right">Σa/Σw'</th> |
| 872 | <th title="Co-norm of the column-normalized activations over the colunns selected by the auto-focus." align="right">⊥(a/c)</th> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 873 | <th title="Sum of the activations over the whole window normalized by the total window sum (no auto-focus)." align="right">Σa/Σw</th> |
Marc Kupietz | bb3da6a | 2019-01-22 15:21:38 +0100 | [diff] [blame] | 874 | <th align="left">collocate (by w2v)</th> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 875 | % } |
| 876 | </tr> |
| 877 | </thead> |
| 878 | <tbody> |
| 879 | <tr> |
| 880 | <td align="right"> |
| 881 | </td> |
| 882 | <td align="right"> |
| 883 | </td> |
| 884 | <td align="right"> |
| 885 | </td> |
| 886 | <td align="right"> |
| 887 | </td> |
| 888 | <td align="right"> |
| 889 | </td> |
| 890 | <td align="right"> |
| 891 | </td> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 892 | </tr> |
| 893 | </tbody> |
| 894 | </table> |
Marc Kupietz | 66bfd95 | 2017-12-11 09:59:45 +0100 | [diff] [blame] | 895 | </div> |
Marc Kupietz | deb8f62 | 2018-03-12 09:41:00 +0100 | [diff] [blame] | 896 | <div id="ccd" style=""> |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 897 | <table class="display compact nowrap" id="classicoloctable"> |
| 898 | <thead> |
Marc Kupietz | cd136e2 | 2018-01-29 09:18:12 +0100 | [diff] [blame] | 899 | % if($collocators) { |
| 900 | <tr> |
Marc Kupietz | cd136e2 | 2018-01-29 09:18:12 +0100 | [diff] [blame] | 901 | <th id="npmi_tt">nPMI</th> |
Marc Kupietz | f19814b | 2019-01-21 16:50:19 +0100 | [diff] [blame] | 902 | <th id="ll_tt">LL</th> |
| 903 | <th id="lfmd_tt">MI³</th> |
Marc Kupietz | 5a7f9ac | 2018-01-30 11:22:44 +0100 | [diff] [blame] | 904 | <th title="PMI³ restricted to left neighbour">l-PMI³</th> |
| 905 | <th title="PMI³ restricted to right neighbour">r-PMI³</th> |
| 906 | <th title="nPMI restricted to left neighbour">l-nPMI</th> |
| 907 | <th title="nPMI restricted to right neighbour">r-nPMI</th> |
Marc Kupietz | bb3da6a | 2019-01-22 15:21:38 +0100 | [diff] [blame] | 908 | <th title="raw frequency sum of collocation within window">raw</th> |
| 909 | <th>collocate (by CA)</th> |
Marc Kupietz | cd136e2 | 2018-01-29 09:18:12 +0100 | [diff] [blame] | 910 | </tr> |
Marc Kupietz | 1acb317 | 2018-02-17 09:41:26 +0100 | [diff] [blame] | 911 | % } |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 912 | </thead> |
| 913 | <tbody> |
| 914 | <tr> |
| 915 | <td align="right"> |
| 916 | </td> |
| 917 | <td align="right"> |
| 918 | </td> |
| 919 | <td align="right"> |
| 920 | </td> |
| 921 | <td align="right"> |
| 922 | </td> |
Marc Kupietz | cfcdcfc | 2018-01-24 09:51:26 +0100 | [diff] [blame] | 923 | <td align="right"> |
| 924 | </td> |
| 925 | <td align="right"> |
| 926 | </td> |
Marc Kupietz | b4b53ca | 2018-01-25 08:57:11 +0100 | [diff] [blame] | 927 | <td align="right"></td> |
| 928 | <td align="right"></td> |
| 929 | <td align="left"></td> |
Marc Kupietz | e6a7a73 | 2018-01-12 09:21:08 +0100 | [diff] [blame] | 930 | </tr> |
| 931 | </tbody> |
| 932 | </table> |
| 933 | </div> |
Marc Kupietz | 384c913 | 2018-03-19 16:45:24 +0100 | [diff] [blame] | 934 | <!-- |
| 935 | <div style="clear:both" ></div> |
| 936 | <div style="float: right; overflow: hidden" id="extra"><button onClick="showCollocatorSOM()"> </button></div> |
| 937 | --> |
Marc Kupietz | 66bfd95 | 2017-12-11 09:59:45 +0100 | [diff] [blame] | 938 | </div> |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 939 | </div> |
| 940 | </div> <!-- topwrapper --> |
| 941 | <div style="clear: both;"></div> |
| 942 | </div> |
Marc Kupietz | ebea470 | 2018-01-12 09:16:09 +0100 | [diff] [blame] | 943 | % if($training_args && (@$lists)[0]) { |
| 944 | <div class="info"> |
| 945 | % if($training_args =~ /-type\s*3/) { |
| 946 | 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 %> |
| 947 | % } else { |
| 948 | 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 %> |
| 949 | % } |
| 950 | </div> |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 951 | % } |
Marc Kupietz | 5827066 | 2017-12-04 12:10:06 +0100 | [diff] [blame] | 952 | </body> |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 953 | </html> |