derekovecs: start outsourcing js from html-template to .js scripts
diff --git a/js/derekovcs.js b/js/derekovcs.js
index d2ed5b5..31f238b 100644
--- a/js/derekovcs.js
+++ b/js/derekovcs.js
@@ -14,3 +14,157 @@
return false;
}
}
+
+
+function makeVocabDistanceTable(id, baseURL) {
+ var urlprefix = new URLSearchParams(window.location.search);
+ return $(id).DataTable({
+ ajax: {
+ method: "GET",
+ url: baseURL + '/getBiggestVocabDistances',
+ dataType: 'json',
+ dataSrc: function (result) {
+ return result;
+ },
+ timeout: 30000,
+ },
+ "initComplete":function(settings, json){
+ vocabDistanceTable.columns.adjust().draw();
+ },
+ "createdRow": function (row, data, rowIndex) {
+ $.each($('td.collocator', row), function (colIndex) {
+ $(this).attr('title', "f("+data.word+")="+data.f2.toLocaleString("en-GB") + " f1: "+ccResult.f1+ " total: "+ccResult.N);
+ });
+ },
+ "sScrollY": "780px",
+ "bScrollCollapse": true,
+ "bPaginate": false,
+ "bJQueryUI": true,
+ "dom": '<"top">rt<"bottom"flp><"clear">',
+ "columns": [
+ { "data": "rank", type: "allnumeric" },
+ { "data": "dist", render: function ( data, type, row ) {return data.toFixed(3) }},
+ { "data": "word", class: "paradigmator", render: function ( data, type, row ) {
+ urlprefix.set("word", data); return '<a class="' + getMergedClass(row.rank) + '" href="?' + urlprefix + '">' + data + '</a>'
+ }}
+ ],
+ "columnDefs": [
+ { className: "dt-right", "targets": [0,1] },
+ { "searchable": false,
+ "orderable": false,
+ "targets": 0
+ },
+ { "orderSequence": [ "desc" ], "targets": [ 1 ] },
+ { "orderSequence": [ "asc", "desc" ], "targets": [ 2 ] },
+ ],
+ "oLanguage": {
+ "sSearch": "Filter: "
+ },
+ "order": [[ 1, 'desc' ]]
+ });
+}
+
+function toFixed(n, d) {
+ if(typeof n != "number") {
+ return n;
+ } else {
+ return n.toFixed(d);
+ }
+}
+
+function toExponential(n, d) {
+ if(typeof n != "number") {
+ return n;
+ } else {
+ return n.toExponential(d);
+ }
+}
+
+function bitmask2window(autofocus, win) {
+ var af_str = autofocus.toString(2).padStart(10, "0")
+ .replace(/^([0-9]{5})/, '$1 ')
+ .replace(/0/g, '·')
+ .replace(/1/g, '◼');
+ var w_str = win.toString(2).padStart(10, "0")
+ .replace(/^([0-9]{5})/, '$1 ')
+ .replace(/0/g, '·')
+ .replace(/1/g, 'o');
+ for (var i=0, l=af_str.length; i<l; i++) {
+ if(af_str.charAt(i) == '·' && w_str.charAt(i) == 'o' ) {
+ af_str = af_str.substring(0, i) + "◽" + af_str.substring(i+1);
+ }
+ }
+ return af_str;
+}
+
+function makeClassicCollocatorTable(id, baseURL, wordIndex) {
+ var classicCollocatorTable = $('#classicoloctable').DataTable({
+ ajax: {
+ method: "GET",
+ url: baseURL + '/getClassicCollocators',
+ dataType: 'json',
+ dataSrc: function (result) {
+ ccResult = result;
+ $("#rawfreq_tt").attr("title", "Raw frequencies of the co-occurence.\n"
+ + "f(" + ccResult.w1+")=" + ccResult.f1.toLocaleString("en-GB") + ";\n"
+ + "N=" + ccResult.N.toLocaleString("en-GB"));
+ return result.collocates;
+ },
+ timeout: 30000,
+ data: { w: wordIndex }
+ },
+ "initComplete":function(settings, json){
+ $("td.collocator").click(function(){
+ queryKorAPCII(this.textContent + " /w5 " + CIIsearchWords);
+ });
+ classicCollocatorTable.columns(".detail").visible(false);
+ $("#ccd").css('width', '680px');
+ classicCollocatorTable.columns.adjust().draw();
+ },
+ "createdRow": function (row, data, rowIndex) {
+ $.each($('td.collocator', row), function (colIndex) {
+ $(this).attr('title', "f("+data.word+")="+data.f2.toLocaleString("en-GB") + " f1: "+ccResult.f1+ " total: "+ccResult.N);
+ });
+ },
+ "sScrollY": "780px",
+ "bScrollCollapse": true,
+ "bPaginate": false,
+ "bJQueryUI": true,
+ "dom": '<"top">rt<"bottom"flp><"clear">',
+ "columns": [
+ // { "data": "pos", width: "7%", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitvec2window(data, row.heat, row.word) }},
+ { "data": "llr", render: function ( data, type, row ) {return toFixed(data, 0) }},
+ { "data": "pmi", render: function ( data, type, row ) {return toFixed(data, 2) }},
+ { "data": "md", render: function ( data, type, row ) {return toFixed(data, 2) }},
+ { "data": "lfmd", render: function ( data, type, row ) {return toFixed(data, 2) }},
+ // { "data": "fpmi", type: "scientific", render: function ( data, type, row ) {return data.toExponential(2) } },
+ { "data": "npmi", render: function ( data, type, row ) {return toFixed(data, 3) }},
+ { "data": "dice", render: function ( data, type, row ) {return toExponential(data, 2) }},
+ { "data": "ld", render: function ( data, type, row ) {return toFixed(data, 2) }},
+ { "data": "af", render: function ( data, type, row ) {return toFixed(data, 2) }},
+ { "data": "delta", render: function ( data, type, row ) {return toFixed(data, 2) }},
+ { "data": "afwin", width: "auto", sClass: "dt-center mono compact", render: function ( data, type, row ) {return bitmask2window(data, row.win) }},
+ { "data": "llfmd", render: function ( data, type, row ) {return toFixed(data, 1) }},
+ { "data": "rlfmd", render: function ( data, type, row ) {return toFixed(data, 1) }},
+ { "data": "lnpmi", render: function ( data, type, row ) {return toFixed(data, 2) }},
+ { "data": "rnpmi", render: function ( data, type, row ) {return toFixed(data, 2) }},
+ { "data": "f" },
+ { "data": "word", sClass: "collocator" }
+ ],
+ "columnDefs": [
+ { className: "dt-right", "targets": [0,1,2,3,4,5,6,7,8,10,11,12,13,14] },
+ { className: "dt-right detail", "targets": [5,10,11,12,13] },
+ { "searchable": false,
+ "orderable": false,
+ "targets": []
+ },
+ { "orderSequence": [ "desc" ], "targets": [0,1,2,3,4,5,6,7,10,11,12,13,14] },
+ { "orderSequence": [ "asc", "desc" ], "targets": [8,9,15] },
+ ],
+ "oLanguage": {
+ "sSearch": "Filter: "
+ },
+ "order": [[ 7, 'desc' ]],
+ });
+ return classicCollocatorTable;
+}