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();