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