Revive -d option to dump vecs as ascii file

Change-Id: Ib78b6ad00af74aaf410544f8c872ac6cf67e90e8
diff --git a/Makefile.PL b/Makefile.PL
index 96bcd3f..8d5319d 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -12,6 +12,7 @@
     LICENSE        => 'apache',
     BUILD_REQUIRES => {
      'Test::More' => 0,
+     'Test::TempFile' => 0,
      "REST::Client" => 0,
      "Data::Dump" => 0,
     },
diff --git a/lib/IDS/DeReKoVecs/Read.pm b/lib/IDS/DeReKoVecs/Read.pm
index 06011c3..f4e7a98 100644
--- a/lib/IDS/DeReKoVecs/Read.pm
+++ b/lib/IDS/DeReKoVecs/Read.pm
@@ -25,7 +25,7 @@
 use Mojo::JSON qw(decode_json encode_json to_json);
 use Exporter qw(import);
 
-our @EXPORT = qw(init_net load_sprofiles getCollocationAssociation getClassicCollocatorsCached getSimilarProfiles getSimilarProfilesCached getBiggestMergedDifferences filter_garbage get_neighbours getWordNumber);
+our @EXPORT = qw(init_net load_sprofiles getCollocationAssociation getClassicCollocatorsCached getSimilarProfiles getSimilarProfilesCached getBiggestMergedDifferences filter_garbage get_neighbours getWordNumber dump_vecs dump_for_numpy);
 
 
 sub getCollocationAssociation {
diff --git a/script/derekovecs-server b/script/derekovecs-server
index 3531910..b09ffcf 100755
--- a/script/derekovecs-server
+++ b/script/derekovecs-server
@@ -1,7 +1,7 @@
 #!/usr/local/bin/perl
 our $VERSION = '0.90';
 
-use IDS::DeReKoVecs::Read qw(init_net load_sprofiles getCollocationAssociation getClassicCollocatorsCached getSimilarProfiles getSimilarProfilesCached getBiggestMergedDifferences filter_garbage get_neighbours getWordNumber);
+use IDS::DeReKoVecs::Read;
 use Mojolicious::Lite;
 use Mojo::JSON qw(decode_json encode_json to_json);
 use base 'Mojolicious::Plugin';
@@ -62,7 +62,20 @@
 my $title="";
 my $training_args="";
 
-getopts('d:D:Gil:p:m:n:M:C');
+getopts('d:D:Gil:p:m:n:M:C') or usage();
+
+sub usage() {
+  print STDERR <<EOF;
+non-server mode usage: MOJO_CONFIG=`pwd`/example.conf $0 [-h] [-d <file>]
+-h        : this (help) message
+-d file   : dump binary vecs as ascii text to <file>
+
+server-mode invocation:
+
+MOJO_CONFIG=`pwd`/example.conf morbo $0
+EOF
+  exit;
+}
 
 if($opt_M) {
   open my $handle, '<:encoding(UTF-8)', $opt_M
diff --git a/t/test.t b/t/test.t
index f45afb3..c080f2f 100644
--- a/t/test.t
+++ b/t/test.t
@@ -1,6 +1,7 @@
 use strict;
 use warnings;
-use Test::More tests => 3;
+use Test::TempFile;
+use Test::More tests => 4;
 use Mojo::JSON qw(decode_json encode_json to_json);
 
 use_ok('IDS::DeReKoVecs::Read');
@@ -28,4 +29,12 @@
     is( $res->{collocates}->[0]->{word}, "diesem", "primary collocate of Grund" );
 };
 
+subtest 'dump ascii vecs' => sub {
+    my $t = Test::TempFile->new();
+    $res = IDS::DeReKoVecs::Read::dump_vecs($t->path);
+    $t->exists_ok
+        ->content_like(qr/^10544 200.*/, 'ascii vecs dump')
+        ->content_like(qr/Wortzeichen -?[01]\.[0-9]/, 'ascii vecs dump contains some words');
+};
+
 done_testing;