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