w2vserver: simplify getTargetWords
diff --git a/w2v-server.pl b/w2v-server.pl
index 01b49a7..88b7d11 100755
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -724,12 +724,11 @@
return res;
}
-wordlist *getTargetWords(char *st1, int sbw) {
+wordlist *getTargetWords(char *st1, int search_backw) {
wordlist *wl = malloc(sizeof(wordlist));
char st[100][max_size], sep[100];
long a, b=0, c=0, cn=0;
int unmerged;
- int search_backw = 0;
while (1) {
st[cn][b] = st1[c];
@@ -754,17 +753,14 @@
if (search_backw) {
for (b = words - 1; b >= 0; b--) if (!strcmp(&vocab[b * max_w], st[a])) break;
} else {
- if (merge_words > 0 && a % 2 == 1) {
- for (b = merge_words; b < words; b++)
- if (!strcmp(&vocab[b * max_w], st[a])) break;
- } else {
- for (b = 0; b < words; b++)
- if (!strcmp(&vocab[b * max_w], st[a])) break;
- }
+ if (merge_words > 0 && a % 2 == 1)
+ for (b = merge_words; b < words && strcmp(&vocab[b * max_w], st[a]) != 0; b++);
+ else
+ for (b = 0; b < words && strcmp(&vocab[b * max_w], st[a]) != 0; b++);
}
if (b == words) b = -1;
wl->wordi[a] = b;
- fprintf(stderr, "Word: \"%s\" Position in vocabulary: %lld\n", st[a], wl->wordi[a]);
+ fprintf(stderr, "Word: \"%s\" Position in vocabulary: %lld\n", &vocab[wl->wordi[a]*max_w], wl->wordi[a]);
if (b == -1) {
fprintf(stderr, "Out of dictionary word!\n");
cn--;