w2v-server: support subtraction of word vecs
E.g.: use "Merkel-Deutschland" as search term
diff --git a/w2v-server.pl b/w2v-server.pl
index 0d6bff3..2d1b874 100644
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -151,7 +151,7 @@
int N = pars->N;
unsigned long from = pars -> from;
unsigned long upto = pars -> upto;
- char file_name[max_size], st[100][max_size];
+ char file_name[max_size], st[100][max_size], sep[100];
float dist, len, *bestd, vec[max_size];
long long a, b, c, d, cn, bi[100], *besti;
char ch;
@@ -173,8 +173,8 @@
c++;
st[cn][b] = 0;
if (st1[c] == 0) break;
- if (st1[c] == ' ') {
- cn++;
+ if (st1[c] == ' ' || st1[c] == '-') {
+ sep[cn++] = st1[c];
b = 0;
c++;
}
@@ -198,7 +198,10 @@
for (a = 0; a < size; a++) vec[a] = 0;
for (b = 0; b < cn; b++) {
if (bi[b] == -1) continue;
- for (a = 0; a < size; a++) vec[a] += M[a + bi[b] * size];
+ if(b>0 && sep[b-1] == '-')
+ for (a = 0; a < size; a++) vec[a] -= M[a + bi[b] * size];
+ else
+ for (a = 0; a < size; a++) vec[a] += M[a + bi[b] * size];
}
len = 0;
for (a = 0; a < size; a++) len += vec[a] * vec[a];