derekovecs: handle nan, inf and NA
diff --git a/templates/index.html.ep b/templates/index.html.ep
index 409b158..dda695d 100644
--- a/templates/index.html.ep
+++ b/templates/index.html.ep
@@ -136,6 +136,22 @@
return changeCharColor(str, heat, word);
}
+ 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);
+ }
+ }
+
% use Mojo::ByteStream 'b';
var paraResults = <%= b(Mojo::JSON::to_json($lists)) %>;
var urlprefix = new URLSearchParams(window.location.search);
@@ -322,21 +338,21 @@
"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 data.toFixed(0) }},
- { "data": "pmi", render: function ( data, type, row ) {return data.toFixed(2) }},
- { "data": "md", render: function ( data, type, row ) {return data.toFixed(2) }},
- { "data": "lfmd", render: function ( data, type, row ) {return data.toFixed(2) }},
+ { "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 data.toFixed(3) }},
- { "data": "dice", render: function ( data, type, row ) {return data.toExponential(2) }},
- { "data": "ld", render: function ( data, type, row ) {return data.toFixed(2) }},
- { "data": "af", render: function ( data, type, row ) {return data.toFixed(2) }},
- { "data": "delta", render: function ( data, type, row ) {return data.toFixed(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 data.toFixed(1) }},
- { "data": "rlfmd", render: function ( data, type, row ) {return data.toFixed(1) }},
- { "data": "lnpmi", render: function ( data, type, row ) {return data.toFixed(2) }},
- { "data": "rnpmi", render: function ( data, type, row ) {return data.toFixed(2) }},
+ { "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" }
],
diff --git a/w2v-server.pl b/w2v-server.pl
index 527c7ce..8bf0f14 100755
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -125,6 +125,7 @@
if(!$cccache{$word}) {
$c->app->log->info("Getting classic collocates of $word.");
$cccache{$word} = getClassicCollocators($word);
+ $cccache{$word} =~ s/:(-?)(nan|inf)/:"${1}${2}"/g;
} else {
$c->app->log->info("Getting classic collocates for $word from cache.");
}
@@ -144,7 +145,7 @@
}
foreach my $i (@{$d1->{collocates}}) {
my $w = $i->{word};
- $i->{delta} = $i->{ld} - (defined $d2ld{$w} ? $d2ld{$w} : -5);
+ $i->{delta} = $i->{ld} - (defined $d2ld{$w} ? $d2ld{$w} : 0);
}
return(encode_json($d1));
} else {