w2v-server.pl: show target word, too
diff --git a/w2v-server.pl b/w2v-server.pl
index c2d96bb..2bc555f 100644
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -115,9 +115,9 @@
for (b = 0; b < words; b++) if (!strcmp(&vocab[b * max_w], st[a])) break;
if (b == words) b = -1;
bi[a] = b;
- sprintf(stringBuffer, "\n<pre>Word: \"%s\" Position in vocabulary: %lld</pre>\n", st[a], bi[a]);
+ fprintf(stderr, "Word: \"%s\" Position in vocabulary: %lld\n", st[a], bi[a]);
if (b == -1) {
- sprintf(stringBuffer+strlen(stringBuffer), "Out of dictionary word!\n");
+ fprintf(stderr, "Out of dictionary word!\n");
break;
}
}
@@ -135,8 +135,9 @@
for (a = 0; a < N; a++) bestw[a][0] = 0;
for (c = 0; c < words; c++) {
a = 0;
- for (b = 0; b < cn; b++) if (bi[b] == c) a = 1;
- if (a == 1) continue;
+// don not skip taget word
+// for (b = 0; b < cn; b++) if (bi[b] == c) a = 1;
+// if (a == 1) continue;
dist = 0;
for (a = 0; a < size; a++) dist += vec[a] * M[a + c * size];
for (a = 0; a < N; a++) {
@@ -239,7 +240,13 @@
g.append("text")
.attr("text-anchor", "top")
.attr("font-size", 12)
- .attr("fill", "#333")
+ .attr("fill", function(d) {
+ if(d == data.target) {
+ return "red";
+ } else {
+ return "#333"
+ }
+ })
.text(function(d) { return d; });
var zoomListener = d3.behavior.zoom()
@@ -346,7 +353,7 @@
<script>
% use Mojo::ByteStream 'b';
$(window).load(function() {
- showMap(<%= b(Mojo::JSON::to_json({words => \@words, vecs => \@vecs})); %>);
+ showMap(<%= b(Mojo::JSON::to_json({target => $word, words => \@words, vecs => \@vecs})); %>);
});
</script>
% }