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