add -D <file> option to export ascii vecs without labels
diff --git a/w2v-server.pl b/w2v-server.pl
index c8b29f9..195bbb9 100755
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -24,6 +24,7 @@
our $opt_M;
our $opt_n = '';
our $opt_d;
+our $opt_D;
our $opt_G;
my %marked;
@@ -33,7 +34,7 @@
my %cccache; # classic collocator cache
my %spcache; # similar profile cache
-getopts('d:Gil:p:m:n:M:');
+getopts('d:D:Gil:p:m:n:M:');
if($opt_M) {
open my $handle, '<:encoding(UTF-8)', $opt_M
@@ -69,6 +70,11 @@
exit;
}
+if($opt_D) { # -D: dump vecs for numpy and exit
+ dump_for_numpy($opt_D);
+ exit;
+}
+
my $daemon = Mojo::Server::Daemon->new(
app => app,
listen => ['http://'.($opt_l ? $opt_l : '*').":$opt_p"]
@@ -1169,3 +1175,21 @@
return(0);
}
+int dump_for_numpy(char *fname) {
+ long i, j;
+ FILE *f;
+ /* if(words>200000) */
+ /* words=200000; */
+
+ if((f=fopen(fname, "w")) == NULL) {
+ fprintf(stderr, "cannot open %s for writing\n", fname);
+ return(-1);
+ }
+ for (i=0; i < words; i++) {
+ for(j=0; j < size - 1; j++)
+ fprintf(f, "%f\t", M[i*size + j]);
+ fprintf(f, "%f\n", M[i*size + j]);
+ }
+ fclose(f);
+ return(0);
+}