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