blob: 14792ffef7821bd25de7d7842c92ca263fa78d44 [file] [log] [blame]
Marc Kupietzcdd51302018-03-19 16:36:54 +01001function queryKorAPpoliqarp(query) {
2 window.open('http://korap.ids-mannheim.de/kalamar/?ql=poliqarp&q='+encodeURIComponent(query), 'KorAP');
3}
4
5
6function queryKorAPalternatives(alt1, alt2) {
7 queryKorAPpoliqarp("{1:[orth="+ alt1 +"]} | {2:[orth=" + alt2 +"]}");
8}
9
10function paradigmatorClick(e, target, paradigmator) {
11 if (e.which === 2) {
12 e.preventDefault();
13 queryKorAPalternatives(target, paradigmator);
14 return false;
15 }
16}
Marc Kupietz95977002019-02-26 09:09:59 +010017
18
19function 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,
43 "dom": '<"top">rt<"bottom"flp><"clear">',
44 "columns": [
45 { "data": "rank", type: "allnumeric" },
46 { "data": "dist", render: function ( data, type, row ) {return data.toFixed(3) }},
47 { "data": "word", class: "paradigmator", render: function ( data, type, row ) {
48 urlprefix.set("word", data); return '<a class="' + getMergedClass(row.rank) + '" href="?' + urlprefix + '">' + data + '</a>'
49 }}
50 ],
51 "columnDefs": [
52 { className: "dt-right", "targets": [0,1] },
53 { "searchable": false,
54 "orderable": false,
55 "targets": 0
56 },
57 { "orderSequence": [ "desc" ], "targets": [ 1 ] },
58 { "orderSequence": [ "asc", "desc" ], "targets": [ 2 ] },
59 ],
60 "oLanguage": {
61 "sSearch": "Filter: "
62 },
63 "order": [[ 1, 'desc' ]]
64 });
65}
66
67function toFixed(n, d) {
68 if(typeof n != "number") {
69 return n;
70 } else {
71 return n.toFixed(d);
72 }
73}
74
75function toExponential(n, d) {
76 if(typeof n != "number") {
77 return n;
78 } else {
79 return n.toExponential(d);
80 }
81}
82
83function bitmask2window(autofocus, win) {
84 var af_str = autofocus.toString(2).padStart(10, "0")
85 .replace(/^([0-9]{5})/, '$1 ')
86 .replace(/0/g, '·')
87 .replace(/1/g, '◼');
88 var w_str = win.toString(2).padStart(10, "0")
89 .replace(/^([0-9]{5})/, '$1 ')
90 .replace(/0/g, '·')
91 .replace(/1/g, 'o');
92 for (var i=0, l=af_str.length; i<l; i++) {
93 if(af_str.charAt(i) == '·' && w_str.charAt(i) == 'o' ) {
94 af_str = af_str.substring(0, i) + "◽" + af_str.substring(i+1);
95 }
96 }
97 return af_str;
98}
99
100function makeClassicCollocatorTable(id, baseURL, wordIndex) {
Marc Kupietz007b0142021-02-10 16:53:56 +0100101 $.fn.dataTable.ext.errMode = 'throw';
Marc Kupietz95977002019-02-26 09:09:59 +0100102 var classicCollocatorTable = $('#classicoloctable').DataTable({
103 ajax: {
104 method: "GET",
105 url: baseURL + '/getClassicCollocators',
106 dataType: 'json',
107 dataSrc: function (result) {
108 ccResult = result;
109 $("#rawfreq_tt").attr("title", "Raw frequencies of the co-occurence.\n"
110 + "f(" + ccResult.w1+")=" + ccResult.f1.toLocaleString("en-GB") + ";\n"
111 + "N=" + ccResult.N.toLocaleString("en-GB"));
112 return result.collocates;
113 },
Marc Kupietz007b0142021-02-10 16:53:56 +0100114 warning: function (request, error) {
115 },
Marc Kupietz95977002019-02-26 09:09:59 +0100116 timeout: 30000,
117 data: { w: wordIndex }
118 },
119 "initComplete":function(settings, json){
120 $("td.collocator").click(function(){
121 queryKorAPCII(this.textContent + " /w5 " + CIIsearchWords);
122 });
123 classicCollocatorTable.columns(".detail").visible(false);
124 $("#ccd").css('width', '680px');
125 classicCollocatorTable.columns.adjust().draw();
126 },
127 "createdRow": function (row, data, rowIndex) {
128 $.each($('td.collocator', row), function (colIndex) {
129 $(this).attr('title', "f("+data.word+")="+data.f2.toLocaleString("en-GB") + " f1: "+ccResult.f1+ " total: "+ccResult.N);
130 });
131 },
132 "sScrollY": "780px",
133 "bScrollCollapse": true,
134 "bPaginate": false,
135 "bJQueryUI": true,
136 "dom": '<"top">rt<"bottom"flp><"clear">',
137 "columns": [
138 // { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat, row.word) }},
139 { "data": "llr", render: function ( data, type, row ) {return toFixed(data, 0) }},
140 { "data": "pmi", render: function ( data, type, row ) {return toFixed(data, 2) }},
141 { "data": "md", render: function ( data, type, row ) {return toFixed(data, 2) }},
142 { "data": "lfmd", render: function ( data, type, row ) {return toFixed(data, 2) }},
143 // { "data": "fpmi", type: "scientific", render: function ( data, type, row ) {return data.toExponential(2) } },
144 { "data": "npmi", render: function ( data, type, row ) {return toFixed(data, 3) }},
145 { "data": "dice", render: function ( data, type, row ) {return toExponential(data, 2) }},
146 { "data": "ld", render: function ( data, type, row ) {return toFixed(data, 2) }},
Marc Kupietz09a493b2021-03-15 15:10:48 +0100147 { "data": "ldaf", render: function ( data, type, row ) {return toFixed(data, 2) }},
Marc Kupietz95977002019-02-26 09:09:59 +0100148 { "data": "delta", render: function ( data, type, row ) {return toFixed(data, 2) }},
149 { "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 +0100150 { "data": "ln_count", render: function ( data, type, row ) {return toFixed(data, 1) }},
151 { "data": "rn_count", render: function ( data, type, row ) {return toFixed(data, 1) }},
152 { "data": "ln_pmi", render: function ( data, type, row ) {return toFixed(data, 2) }},
153 { "data": "rn_pmi", render: function ( data, type, row ) {return toFixed(data, 2) }},
Marc Kupietz95977002019-02-26 09:09:59 +0100154 { "data": "f" },
155 { "data": "word", sClass: "collocator" }
156 ],
157 "columnDefs": [
158 { className: "dt-right", "targets": [0,1,2,3,4,5,6,7,8,10,11,12,13,14] },
159 { className: "dt-right detail", "targets": [5,10,11,12,13] },
160 { "searchable": false,
161 "orderable": false,
162 "targets": []
163 },
164 { "orderSequence": [ "desc" ], "targets": [0,1,2,3,4,5,6,7,10,11,12,13,14] },
165 { "orderSequence": [ "asc", "desc" ], "targets": [8,9,15] },
166 ],
167 "oLanguage": {
168 "sSearch": "Filter: "
169 },
170 "order": [[ 7, 'desc' ]],
171 });
172 return classicCollocatorTable;
173}