w2v-server.pl: pass vector file as command line argument
diff --git a/w2v-server.pl b/w2v-server.pl
index 56e0180..0d6bff3 100644
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -6,9 +6,13 @@
use Mojo::Server::Daemon;
plugin 'Log::Access';
-print STDERR $ARGV[0];
+print STDERR $ARGV[1];
# -cbow 1 -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -threads 40 -binary 1 -iter 15
-init_net("vectors15.bin");
+if(!$ARGV[1]) {
+ init_net("vectors15.bin");
+} else {
+ init_net($ARGV[1]);
+}
get '/' => sub {
my $c = shift;
@@ -95,16 +99,8 @@
fscanf(f, "%lld", &words);
if(MAX_WORDS > 0 && words > MAX_WORDS) words = MAX_WORDS;
fscanf(f, "%lld", &size);
- if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) >= 0 && (binwords_fd = open(binwords_fname, O_RDONLY)) >= 0) {
- M = mmap(0, sizeof(float) * (long long)words * (long long)size, PROT_READ, MAP_SHARED, binvecs_fd, 0);
- vocab = mmap(0, sizeof(char) * (long long)words * max_w, PROT_READ, MAP_SHARED, binwords_fd, 0);
- if (M == MAP_FAILED || vocab == MAP_FAILED) {
- close(binvecs_fd);
- close(binwords_fd);
- fprintf(stderr, "Cannot mmap %s or %s\n", binwords_fname, binvecs_fname);
- exit(-1);
- }
- } else {
+ if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) < 0 || (binwords_fd = open(binwords_fname, O_RDONLY)) < 0) {
+ printf("Converting %s to memory mappable structures\n", file_name);
vocab = (char *)malloc((long long)words * max_w * sizeof(char));
M = (float *)malloc((long long)words * (long long)size * sizeof(float));
if (M == NULL) {
@@ -131,6 +127,19 @@
fwrite(vocab, sizeof(char), (long long)words * max_w, binwords);
fclose(binwords);
}
+ }
+ if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) >= 0 && (binwords_fd = open(binwords_fname, O_RDONLY)) >= 0) {
+ M = mmap(0, sizeof(float) * (long long)words * (long long)size, PROT_READ, MAP_SHARED, binvecs_fd, 0);
+ vocab = mmap(0, sizeof(char) * (long long)words * max_w, PROT_READ, MAP_SHARED, binwords_fd, 0);
+ if (M == MAP_FAILED || vocab == MAP_FAILED) {
+ close(binvecs_fd);
+ close(binwords_fd);
+ fprintf(stderr, "Cannot mmap %s or %s\n", binwords_fname, binvecs_fname);
+ exit(-1);
+ }
+ } else {
+ fprintf(stderr, "Cannot open %s or %s\n", binwords_fname, binvecs_fname);
+ exit(-1);
}
fclose(f);
return 0;