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