w2v-server: add getOutputWeight function to C library
diff --git a/w2v-server.c b/w2v-server.c
index 3a8092c..df66371 100644
--- a/w2v-server.c
+++ b/w2v-server.c
@@ -114,7 +114,7 @@
   return 1;
 }
 
-int init_net(char *file_name, char *net_name, int latin) {
+int init_net(char *file_name, char *net_name, int latin, int do_open_cdb) {
   FILE *f, *binvecs, *binwords;
   int binwords_fd, binvecs_fd, net_fd, i;
   long long a, b, c, d, cn;
@@ -218,15 +218,17 @@
     }
     fprintf(stderr, "Successfully memmaped %s. Determined window size: %d\n", net_name, window);
 
-    char collocatordb_name[2048];
-    strcpy(collocatordb_name, net_name);
-    char *ext = rindex(collocatordb_name, '.');
-    if (ext) {
-      strcpy(ext, ".rocksdb");
-      if (access(collocatordb_name, R_OK) == 0) {
-        *ext = 0;
-        fprintf(stderr, "Opening collocator DB	%s\n", collocatordb_name);
-        cdb = open_collocatordb(collocatordb_name);
+    if (do_open_cdb) {
+      char collocatordb_name[2048];
+      strcpy(collocatordb_name, net_name);
+      char *ext = rindex(collocatordb_name, '.');
+      if (ext) {
+        strcpy(ext, ".rocksdb");
+        if (access(collocatordb_name, R_OK) == 0) {
+          *ext = 0;
+          fprintf(stderr, "Opening collocator DB	%s\n", collocatordb_name);
+          cdb = open_collocatordb(collocatordb_name);
+        }
       }
     }
   }
@@ -449,6 +451,33 @@
   pthread_exit(nbs);
 }
 
+float getOutputWeight(int hidden, long target, int window_position) {
+  const long window_layer_size = size * window * 2;
+  int a;
+
+  if (window_position == 0 || window_position > window || window_position < -window) {
+    fprintf(stderr, "window_position: %d - assert: -%d <= window_position <= %d && window_position != 0 failed.\n", window_position, window, window);
+    exit(-1);
+  }
+
+  if (hidden >= size) {
+    fprintf(stderr, "hidden: %d - assert: hidden < %d failed.\n", hidden, size);
+    exit(-1);
+  }
+
+  if (target >= words) {
+    fprintf(stderr, "target: %ld - assert: target < %ld failed.\n", target, words);
+    exit(-1);
+  }
+
+  a = window_position + window;
+  if (a > window) {
+    --a;
+  }
+  long window_offset = a * size;
+  return syn1neg_window[target * window_layer_size + window_offset + hidden];
+}
+
 AV *getVecs(AV *array) {
   int i, b;
   AV *result = newAV();
diff --git a/w2v-server.pl b/w2v-server.pl
index dbe179a..105f69a 100755
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -65,9 +65,9 @@
 
 # -cbow 1 -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -threads 40 -binary 1 -iter 15
 if(!$ARGV[0]) {
-  init_net("vectors15.bin", $opt_n, ($opt_i? 1 : 0));
+  init_net("vectors15.bin", $opt_n, ($opt_i? 1 : 0), 0);
 } else {
-  init_net($ARGV[0], $opt_n, ($opt_i? 1 : 0));
+  init_net($ARGV[0], $opt_n, ($opt_i? 1 : 0), 1);
   if(open(FILE, "$ARGV[0].args")) {
     $training_args = <FILE>;
   }