w2v-server: load and serve collocation db i <net>.rocksdb existsa
diff --git a/w2v-server.pl b/w2v-server.pl
index 22dbb3a..3e59a57 100755
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -1,6 +1,6 @@
#!/usr/local/bin/perl
use Inline C;
-use Inline C => Config => CLEAN_AFTER_BUILD => 0, ccflags => $Config{ccflags}." -Wall -O4";
+use Inline C => Config => CLEAN_AFTER_BUILD => 0, BUILD_NOISY => 1, ccflags => $Config{ccflags}." -I/vol/work/kupietz/Work2/kl/trunk/CollocatorDB -L/vol/work/kupietz/Work2/kl/trunk/CollocatorDB -Wall -O4", libs => "-shared -lpthread -lcollocatordb -lrt -lsnappy -lz -lbz2 -llz4 -lzstd -lrocksdb";
#use Inline C => Config => BUILD_NOISY => 1, CFLAGS => $Config{cflags}." -O4 -mtune k9";
#use Inline C => Config => CLEAN_AFTER_BUILD => 0, ccflags => $Config{ccflags}." -Ofast -march k8 -mtune k8 ";
use Mojolicious::Lite;
@@ -89,6 +89,16 @@
$self->render(json => $vec);
};
+post '/derekovecs/getClassicCollocators' => sub {
+ my $self = shift;
+ $self->render(data => getClassicCollocators($self->req->json), format=>'json');
+};
+
+post '/getClassicCollocators' => sub {
+ my $self = shift;
+ $self->render(data => getClassicCollocators($self->req->json), format=>'json');
+};
+
get '*/img/*' => sub {
my $c = shift;
my $url = $c->req->url;
@@ -178,6 +188,7 @@
#include <stdlib.h> //strlen
#include <sys/mman.h>
#include <pthread.h>
+#include <collocatordb.h>
#define max_size 2000
#define max_w 50
@@ -232,6 +243,7 @@
float *window_sums;
char *vocab;
char *garbage = NULL;
+COLLOCATORDB *cdb = NULL;
long long words, size, merged_end;
long long merge_words = 0;
@@ -342,7 +354,19 @@
exit(-1);
}
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);
+ }
+ }
+ }
expTable = (float *) malloc((EXP_TABLE_SIZE + 1) * sizeof(float));
for (i = 0; i < EXP_TABLE_SIZE; i++) {
@@ -548,6 +572,11 @@
return result;
}
+char *getClassicCollocators(long node) {
+ char *res = (cdb? strdup(get_collocators_as_json(cdb, node)) : "[]");
+ return res;
+}
+
wordlist *getTargetWords(char *st1, int search_backw) {
wordlist *wl = malloc(sizeof(wordlist));
char st[100][max_size], sep[100];