w2v-server: handle out of dictionary words in a more robust way
diff --git a/templates/index.html.ep b/templates/index.html.ep
index d42a282..6269e02 100644
--- a/templates/index.html.ep
+++ b/templates/index.html.ep
@@ -329,7 +329,7 @@
<span> </span><input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/>
</form>
<br>
- % if($lists) {
+ % if($lists && (@$lists) > 0 && (@$lists)[0]) {
<div id="wrapper">
<table id="first">
<tr>
@@ -408,6 +408,12 @@
showMap(<%= b(Mojo::JSON::to_json({target => " $word ", mergedEnd=> $mergedEnd, words => \@words, vecs => \@vecs, ranks => \@ranks, marked => \@marked, urlprefix => $urlprefix})); %>);
});
</script>
+ % } else { # ($word && $word !~ /^\s*$/)
+ <div id="wrapper">
+ <p>
+ ERROR: "<%= $word %>" not found in vocabluary.
+ </p>
+ </div>
% }
<div id="second" style="width:800px; height:800px; font-family: arial;">
<div id="embed">
diff --git a/w2v-server.pl b/w2v-server.pl
index a956b22..c22aa4c 100755
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -527,7 +527,8 @@
if (b == -1) {
fprintf(stderr, "Out of dictionary word!\n");
cn--;
- break;
+ free(wl);
+ return NULL;
}
}
wl->length=cn;
@@ -625,7 +626,7 @@
cutoff=words;
wl = getTargetWords(st1, search_backw);
- if(wl->length < 1)
+ if(wl == NULL || wl->length < 1)
goto end;
old_words = cutoff;