blob: db4f856481c20bdf1f569ea247105b57b482fb16 [file] [log] [blame]
Akron7d4cdd82016-08-17 21:39:45 +02001#/usr/bin/env perl
2use strict;
3use warnings;
4use File::Basename 'dirname';
5use File::Spec::Functions qw/catdir catfile/;
Akrond5bb4342017-06-19 11:50:49 +02006use File::Temp qw/:POSIX/;
Akron3ec0a1c2017-01-18 14:41:55 +01007use Mojo::File;
Akron821db3d2017-04-06 21:19:31 +02008use Mojo::Util qw/quote/;
Akron7d4cdd82016-08-17 21:39:45 +02009use Mojo::JSON qw/decode_json/;
10use IO::Uncompress::Gunzip;
11use Test::More;
12use Test::Output qw/:stdout :stderr :functions/;
13use Data::Dumper;
Nils Diewaldb3e9ccd2016-10-24 15:16:52 +020014use KorAP::XML::Archive;
Akron7d4cdd82016-08-17 21:39:45 +020015use utf8;
16
17my $f = dirname(__FILE__);
18my $script = catfile($f, '..', '..', 'script', 'korapxml2krill');
19
20my $call = join(
21 ' ',
22 'perl', $script,
23 'archive'
24);
25
Nils Diewaldb3e9ccd2016-10-24 15:16:52 +020026unless (KorAP::XML::Archive::test_unzip) {
27 plan skip_all => 'unzip not found';
28};
29
Akron7d4cdd82016-08-17 21:39:45 +020030# Test without parameters
31stdout_like(
32 sub {
33 system($call);
34 },
Akrona76d8352016-10-27 16:27:32 +020035 qr!archive.+?\$ korapxml2krill!s,
Akron7d4cdd82016-08-17 21:39:45 +020036 $call
37);
38
39my $input = catfile($f, '..', 'corpus', 'archive.zip');
40ok(-f $input, 'Input archive found');
41
Akron3ec48972016-08-17 23:24:52 +020042my $output = File::Temp->newdir(CLEANUP => 0);
43$output->unlink_on_destroy(0);
44
Akrond5bb4342017-06-19 11:50:49 +020045my $cache = tmpnam();
46
47
Akron7d4cdd82016-08-17 21:39:45 +020048ok(-d $output, 'Output directory exists');
49
50$call = join(
51 ' ',
52 'perl', $script,
53 'archive',
Akron821db3d2017-04-06 21:19:31 +020054 '--input' => '' . $input,
Akron7d4cdd82016-08-17 21:39:45 +020055 '--output' => $output,
Akrond5bb4342017-06-19 11:50:49 +020056 '--cache' => $cache,
Akron7d4cdd82016-08-17 21:39:45 +020057 '-t' => 'Base#tokens_aggr',
58 '-m' => 'Sgbr'
59);
60
61# Test without compression
62my $json;
63{
64 local $SIG{__WARN__} = sub {};
65 my $out = stdout_from(sub { system($call); });
66
67 like($out, qr!TEST-BSP-1\.json!s, $call);
68
69 $out =~ m!Processed (.+?\.json)!;
70 $json = $1;
71};
72
73ok(-f $json, 'Json file exists');
Akron3ec0a1c2017-01-18 14:41:55 +010074ok((my $file = Mojo::File->new($json)->slurp), 'Slurp data');
Akron7d4cdd82016-08-17 21:39:45 +020075ok(($json = decode_json $file), 'decode json');
76
77is($json->{data}->{tokenSource}, 'base#tokens_aggr', 'Title');
78is($json->{data}->{foundries}, 'base base/paragraphs base/sentences dereko dereko/structure sgbr sgbr/lemma sgbr/morpho', 'Foundries');
79is($json->{sgbrKodex}, 'M', 'Kodex meta data');
80
Akron3ec48972016-08-17 23:24:52 +020081
82# Use directory
83$input = catdir($f, '..', 'annotation', 'corpus');
84
85$call = join(
86 ' ',
87 'perl', $script,
88 'archive',
89 '--input' => $input,
90 '--output' => $output,
Akrond5bb4342017-06-19 11:50:49 +020091 '--cache' => $cache,
Akron3ec48972016-08-17 23:24:52 +020092 '-t' => 'Tree_Tagger#Tokens',
93 '-j' => 4 # 4 jobs!
94);
95
96my ($json_1, $json_2);
97
98{
99 local $SIG{__WARN__} = sub {};
100
101 # That's not really stable on slow machines!
102 my $out = stdout_from(sub { system($call); });
103
104 ok($out =~ m!\[\$(\d+?):1\/2\]!s, $call . ' pid 1');
105 my $pid1 = $1;
106 ok($out =~ m!\[\$(\d+?):2\/2\]!s, $call . ' pid 2');
107 my $pid2 = $1;
108
109 isnt($pid1, $pid2, 'No PID match');
110
111 ok($out =~ m!Processed .+?\/corpus-doc-0001\.json!s, $call);
112 ok($out =~ m!Processed .+?\/corpus-doc-0002\.json!s, $call);
113
114 ok(-d $output, 'Temporary directory still exists');
115 my $json_1 = catfile($output, 'corpus-doc-0001.json');
116 ok(-f $json_1, 'Json file exists 1');
117 my $json_2 = catfile($output, 'corpus-doc-0002.json');
118 ok(-f $json_2, 'Json file exists 2');
119
Akron3ec0a1c2017-01-18 14:41:55 +0100120 ok(($file = Mojo::File->new($json_1)->slurp), 'Slurp data');
Akron3ec48972016-08-17 23:24:52 +0200121 ok(($json_1 = decode_json $file), 'decode json');
122
123 is($json_1->{data}->{tokenSource}, 'tree_tagger#tokens', 'TokenSource');
124 is($json_1->{data}->{foundries}, 'base base/paragraphs base/sentences connexor connexor/morpho connexor/phrase connexor/sentences connexor/syntax corenlp corenlp/constituency corenlp/morpho corenlp/sentences dereko dereko/structure glemm glemm/morpho mate mate/dependency mate/morpho opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences xip xip/constituency xip/morpho xip/sentences', 'Foundries');
125 is($json_1->{textSigle}, 'Corpus/Doc/0001', 'Sigle');
126
127 ok(-f $json_2, 'Json file exists');
Akron3ec0a1c2017-01-18 14:41:55 +0100128 ok(($file = Mojo::File->new($json_2)->slurp), 'Slurp data');
Akron3ec48972016-08-17 23:24:52 +0200129 ok(($json_2 = decode_json $file), 'decode json');
130
131 is($json_2->{data}->{tokenSource}, 'tree_tagger#tokens', 'TokenSource');
132 is($json_2->{data}->{foundries}, 'base base/paragraphs base/sentences dereko dereko/structure malt malt/dependency treetagger treetagger/morpho treetagger/sentences', 'Foundries');
133 is($json_2->{textSigle}, 'Corpus/Doc/0002', 'Sigle');
134};
135
136ok(-d $output, 'Ouput directory exists');
Akron89df4fa2016-11-04 14:35:37 +0100137
138
139$input = catfile($f, '..', 'corpus', 'WDD15', 'A79', '83946');
140$call = join(
141 ' ',
142 'perl', $script,
Akrond5bb4342017-06-19 11:50:49 +0200143 '--input' => $input,
144 '--cache' => $cache
Akron89df4fa2016-11-04 14:35:37 +0100145);
146
147# Test without compression
148{
149 local $SIG{__WARN__} = sub {};
150 my $out = stderr_from(sub { system($call); });
151
152 like($out, qr!no base tokenization!s, $call);
153};
154
Akronf6240842017-02-17 23:45:26 +0100155my $input_quotes = catfile($f, '..', 'corpus', 'archive_quotes.zip');
156$call = join(
157 ' ',
158 'perl', $script,
159 'archive',
160 '--input' => $input_quotes,
161 '--output' => $output,
Akrond5bb4342017-06-19 11:50:49 +0200162 '--cache' => $cache,
Akronf6240842017-02-17 23:45:26 +0100163 '-t' => 'Base#tokens_aggr'
164);
165
166# Test without parameters
167stdout_like(
168 sub {
169 system($call);
170 },
171 qr!Done\.!is,
172 $call
173);
174
Akron89df4fa2016-11-04 14:35:37 +0100175
Akron3ec48972016-08-17 23:24:52 +0200176unlink($output);
177
Akron821db3d2017-04-06 21:19:31 +0200178
179$input_quotes = "'".catfile($f, '..', 'corpus', 'archives', 'wpd15*.zip') . "'";
180
181$call = join(
182 ' ',
183 'perl', $script,
184 'archive',
185 '--input' => $input_quotes,
186 '--output' => $output,
Akrond5bb4342017-06-19 11:50:49 +0200187 '--cache' => $cache,
Akron821db3d2017-04-06 21:19:31 +0200188 '-t' => 'Base#tokens_aggr'
189);
190
191# Test without parameters
192stdout_like(
193 sub {
194 system($call);
195 },
Akron63f20d42017-04-10 23:40:29 +0200196 qr!Input is .+?wpd15-single\.zip,.+?wpd15-single\.malt\.zip,.+?wpd15-single\.corenlp\.zip,.+?wpd15-single\.opennlp\.zip,.+?wpd15-single\.mdparser\.zip,.+?wpd15-single\.tree_tagger\.zip!is,
Akron821db3d2017-04-06 21:19:31 +0200197 $call
198);
199
Akron7d4cdd82016-08-17 21:39:45 +0200200done_testing;
201__END__