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