Marc Kupietz | cdd5130 | 2018-03-19 16:36:54 +0100 | [diff] [blame] | 1 | function queryKorAPpoliqarp(query) { |
| 2 | window.open('http://korap.ids-mannheim.de/kalamar/?ql=poliqarp&q='+encodeURIComponent(query), 'KorAP'); |
| 3 | } |
| 4 | |
| 5 | |
| 6 | function queryKorAPalternatives(alt1, alt2) { |
| 7 | queryKorAPpoliqarp("{1:[orth="+ alt1 +"]} | {2:[orth=" + alt2 +"]}"); |
| 8 | } |
| 9 | |
| 10 | function paradigmatorClick(e, target, paradigmator) { |
| 11 | if (e.which === 2) { |
| 12 | e.preventDefault(); |
| 13 | queryKorAPalternatives(target, paradigmator); |
| 14 | return false; |
| 15 | } |
| 16 | } |
Marc Kupietz | 9597700 | 2019-02-26 09:09:59 +0100 | [diff] [blame] | 17 | |
| 18 | |
| 19 | function makeVocabDistanceTable(id, baseURL) { |
| 20 | var urlprefix = new URLSearchParams(window.location.search); |
| 21 | return $(id).DataTable({ |
| 22 | ajax: { |
| 23 | method: "GET", |
| 24 | url: baseURL + '/getBiggestVocabDistances', |
| 25 | dataType: 'json', |
| 26 | dataSrc: function (result) { |
| 27 | return result; |
| 28 | }, |
| 29 | timeout: 30000, |
| 30 | }, |
| 31 | "initComplete":function(settings, json){ |
| 32 | vocabDistanceTable.columns.adjust().draw(); |
| 33 | }, |
| 34 | "createdRow": function (row, data, rowIndex) { |
| 35 | $.each($('td.collocator', row), function (colIndex) { |
| 36 | $(this).attr('title', "f("+data.word+")="+data.f2.toLocaleString("en-GB") + " f1: "+ccResult.f1+ " total: "+ccResult.N); |
| 37 | }); |
| 38 | }, |
| 39 | "sScrollY": "780px", |
| 40 | "bScrollCollapse": true, |
| 41 | "bPaginate": false, |
| 42 | "bJQueryUI": true, |
Marc Kupietz | 898e548 | 2024-02-20 15:03:07 +0100 | [diff] [blame] | 43 | "dom": '<"top">rt<"bottom"flpB><"clear">', |
| 44 | buttons: [ |
| 45 | { extend: 'copyHtml5', text: '<i class="fa fa-files-o"></i>', titleAttr: 'Copy' }, |
| 46 | { extend: 'csvHtml5', text: '<i class="fa fa-file-text-o"></i>', titleAttr: 'CSV', filename: currentWords+'_syn_neighbours' }, |
| 47 | { extend: 'excelHtml5', text: '<i class="fa fa-file-excel-o"></i>', titleAttr: 'Excel', filename: currentWords+'_sny_neighbours', |
| 48 | } |
| 49 | ], |
Marc Kupietz | 9597700 | 2019-02-26 09:09:59 +0100 | [diff] [blame] | 50 | "columns": [ |
| 51 | { "data": "rank", type: "allnumeric" }, |
| 52 | { "data": "dist", render: function ( data, type, row ) {return data.toFixed(3) }}, |
| 53 | { "data": "word", class: "paradigmator", render: function ( data, type, row ) { |
| 54 | urlprefix.set("word", data); return '<a class="' + getMergedClass(row.rank) + '" href="?' + urlprefix + '">' + data + '</a>' |
| 55 | }} |
| 56 | ], |
| 57 | "columnDefs": [ |
| 58 | { className: "dt-right", "targets": [0,1] }, |
| 59 | { "searchable": false, |
| 60 | "orderable": false, |
| 61 | "targets": 0 |
| 62 | }, |
| 63 | { "orderSequence": [ "desc" ], "targets": [ 1 ] }, |
| 64 | { "orderSequence": [ "asc", "desc" ], "targets": [ 2 ] }, |
| 65 | ], |
| 66 | "oLanguage": { |
| 67 | "sSearch": "Filter: " |
| 68 | }, |
| 69 | "order": [[ 1, 'desc' ]] |
| 70 | }); |
| 71 | } |
| 72 | |
| 73 | function toFixed(n, d) { |
| 74 | if(typeof n != "number") { |
| 75 | return n; |
| 76 | } else { |
| 77 | return n.toFixed(d); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | function toExponential(n, d) { |
| 82 | if(typeof n != "number") { |
| 83 | return n; |
| 84 | } else { |
| 85 | return n.toExponential(d); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | function bitmask2window(autofocus, win) { |
| 90 | var af_str = autofocus.toString(2).padStart(10, "0") |
| 91 | .replace(/^([0-9]{5})/, '$1 ') |
| 92 | .replace(/0/g, '·') |
| 93 | .replace(/1/g, '◼'); |
| 94 | var w_str = win.toString(2).padStart(10, "0") |
| 95 | .replace(/^([0-9]{5})/, '$1 ') |
| 96 | .replace(/0/g, '·') |
| 97 | .replace(/1/g, 'o'); |
| 98 | for (var i=0, l=af_str.length; i<l; i++) { |
| 99 | if(af_str.charAt(i) == '·' && w_str.charAt(i) == 'o' ) { |
| 100 | af_str = af_str.substring(0, i) + "◽" + af_str.substring(i+1); |
| 101 | } |
| 102 | } |
| 103 | return af_str; |
| 104 | } |
| 105 | |
| 106 | function makeClassicCollocatorTable(id, baseURL, wordIndex) { |
Marc Kupietz | 007b014 | 2021-02-10 16:53:56 +0100 | [diff] [blame] | 107 | $.fn.dataTable.ext.errMode = 'throw'; |
Marc Kupietz | 9597700 | 2019-02-26 09:09:59 +0100 | [diff] [blame] | 108 | var classicCollocatorTable = $('#classicoloctable').DataTable({ |
| 109 | ajax: { |
| 110 | method: "GET", |
| 111 | url: baseURL + '/getClassicCollocators', |
| 112 | dataType: 'json', |
| 113 | dataSrc: function (result) { |
| 114 | ccResult = result; |
| 115 | $("#rawfreq_tt").attr("title", "Raw frequencies of the co-occurence.\n" |
| 116 | + "f(" + ccResult.w1+")=" + ccResult.f1.toLocaleString("en-GB") + ";\n" |
| 117 | + "N=" + ccResult.N.toLocaleString("en-GB")); |
| 118 | return result.collocates; |
| 119 | }, |
Marc Kupietz | 007b014 | 2021-02-10 16:53:56 +0100 | [diff] [blame] | 120 | warning: function (request, error) { |
| 121 | }, |
Marc Kupietz | 9597700 | 2019-02-26 09:09:59 +0100 | [diff] [blame] | 122 | timeout: 30000, |
| 123 | data: { w: wordIndex } |
| 124 | }, |
| 125 | "initComplete":function(settings, json){ |
| 126 | $("td.collocator").click(function(){ |
| 127 | queryKorAPCII(this.textContent + " /w5 " + CIIsearchWords); |
| 128 | }); |
| 129 | classicCollocatorTable.columns(".detail").visible(false); |
| 130 | $("#ccd").css('width', '680px'); |
| 131 | classicCollocatorTable.columns.adjust().draw(); |
| 132 | }, |
| 133 | "createdRow": function (row, data, rowIndex) { |
| 134 | $.each($('td.collocator', row), function (colIndex) { |
| 135 | $(this).attr('title', "f("+data.word+")="+data.f2.toLocaleString("en-GB") + " f1: "+ccResult.f1+ " total: "+ccResult.N); |
| 136 | }); |
| 137 | }, |
| 138 | "sScrollY": "780px", |
| 139 | "bScrollCollapse": true, |
| 140 | "bPaginate": false, |
| 141 | "bJQueryUI": true, |
Marc Kupietz | 898e548 | 2024-02-20 15:03:07 +0100 | [diff] [blame] | 142 | "dom": '<"top">rt<"bottom"flpB><"clear">', |
| 143 | buttons: [ |
| 144 | { extend: 'copyHtml5', text: '<i class="fa fa-files-o"></i>', titleAttr: 'Copy' }, |
| 145 | { extend: 'csvHtml5', text: '<i class="fa fa-file-text-o"></i>', titleAttr: 'CSV', filename: currentWords+'_collocates' }, |
| 146 | { extend: 'excelHtml5', text: '<i class="fa fa-file-excel-o"></i>', titleAttr: 'Excel', filename: currentWords+'_collocates', exportOptions: { columns: ':visible' } , |
| 147 | } |
| 148 | ], |
Marc Kupietz | 9597700 | 2019-02-26 09:09:59 +0100 | [diff] [blame] | 149 | "columns": [ |
| 150 | // { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat, row.word) }}, |
| 151 | { "data": "llr", render: function ( data, type, row ) {return toFixed(data, 0) }}, |
| 152 | { "data": "pmi", render: function ( data, type, row ) {return toFixed(data, 2) }}, |
| 153 | { "data": "md", render: function ( data, type, row ) {return toFixed(data, 2) }}, |
| 154 | { "data": "lfmd", render: function ( data, type, row ) {return toFixed(data, 2) }}, |
| 155 | // { "data": "fpmi", type: "scientific", render: function ( data, type, row ) {return data.toExponential(2) } }, |
| 156 | { "data": "npmi", render: function ( data, type, row ) {return toFixed(data, 3) }}, |
| 157 | { "data": "dice", render: function ( data, type, row ) {return toExponential(data, 2) }}, |
| 158 | { "data": "ld", render: function ( data, type, row ) {return toFixed(data, 2) }}, |
Marc Kupietz | 09a493b | 2021-03-15 15:10:48 +0100 | [diff] [blame] | 159 | { "data": "ldaf", render: function ( data, type, row ) {return toFixed(data, 2) }}, |
Marc Kupietz | 9597700 | 2019-02-26 09:09:59 +0100 | [diff] [blame] | 160 | { "data": "delta", render: function ( data, type, row ) {return toFixed(data, 2) }}, |
| 161 | { "data": "afwin", width: "auto", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitmask2window(data, row.win) }}, |
Marc Kupietz | 09a493b | 2021-03-15 15:10:48 +0100 | [diff] [blame] | 162 | { "data": "ln_count", render: function ( data, type, row ) {return toFixed(data, 1) }}, |
| 163 | { "data": "rn_count", render: function ( data, type, row ) {return toFixed(data, 1) }}, |
| 164 | { "data": "ln_pmi", render: function ( data, type, row ) {return toFixed(data, 2) }}, |
| 165 | { "data": "rn_pmi", render: function ( data, type, row ) {return toFixed(data, 2) }}, |
Marc Kupietz | 9597700 | 2019-02-26 09:09:59 +0100 | [diff] [blame] | 166 | { "data": "f" }, |
| 167 | { "data": "word", sClass: "collocator" } |
| 168 | ], |
| 169 | "columnDefs": [ |
| 170 | { className: "dt-right", "targets": [0,1,2,3,4,5,6,7,8,10,11,12,13,14] }, |
| 171 | { className: "dt-right detail", "targets": [5,10,11,12,13] }, |
| 172 | { "searchable": false, |
| 173 | "orderable": false, |
| 174 | "targets": [] |
| 175 | }, |
| 176 | { "orderSequence": [ "desc" ], "targets": [0,1,2,3,4,5,6,7,10,11,12,13,14] }, |
| 177 | { "orderSequence": [ "asc", "desc" ], "targets": [8,9,15] }, |
| 178 | ], |
| 179 | "oLanguage": { |
| 180 | "sSearch": "Filter: " |
| 181 | }, |
| 182 | "order": [[ 7, 'desc' ]], |
| 183 | }); |
| 184 | return classicCollocatorTable; |
| 185 | } |