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