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