Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 1 | #/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | use File::Basename 'dirname'; |
| 5 | use File::Spec::Functions qw/catdir catfile/; |
| 6 | use File::Temp qw/tempdir/; |
Akron | 3ec0a1c | 2017-01-18 14:41:55 +0100 | [diff] [blame] | 7 | use Mojo::File; |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 8 | use Mojo::Util qw/quote/; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 9 | use Mojo::JSON qw/decode_json/; |
| 10 | use IO::Uncompress::Gunzip; |
| 11 | use Test::More; |
| 12 | use Test::Output qw/:stdout :stderr :functions/; |
| 13 | use Data::Dumper; |
Nils Diewald | b3e9ccd | 2016-10-24 15:16:52 +0200 | [diff] [blame] | 14 | use KorAP::XML::Archive; |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 15 | use utf8; |
| 16 | |
| 17 | my $f = dirname(__FILE__); |
| 18 | my $script = catfile($f, '..', '..', 'script', 'korapxml2krill'); |
| 19 | |
| 20 | my $call = join( |
| 21 | ' ', |
| 22 | 'perl', $script, |
| 23 | 'archive' |
| 24 | ); |
| 25 | |
Nils Diewald | b3e9ccd | 2016-10-24 15:16:52 +0200 | [diff] [blame] | 26 | unless (KorAP::XML::Archive::test_unzip) { |
| 27 | plan skip_all => 'unzip not found'; |
| 28 | }; |
| 29 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 30 | # Test without parameters |
| 31 | stdout_like( |
| 32 | sub { |
| 33 | system($call); |
| 34 | }, |
Akron | a76d835 | 2016-10-27 16:27:32 +0200 | [diff] [blame] | 35 | qr!archive.+?\$ korapxml2krill!s, |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 36 | $call |
| 37 | ); |
| 38 | |
| 39 | my $input = catfile($f, '..', 'corpus', 'archive.zip'); |
| 40 | ok(-f $input, 'Input archive found'); |
| 41 | |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 42 | my $output = File::Temp->newdir(CLEANUP => 0); |
| 43 | $output->unlink_on_destroy(0); |
| 44 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 45 | ok(-d $output, 'Output directory exists'); |
| 46 | |
| 47 | $call = join( |
| 48 | ' ', |
| 49 | 'perl', $script, |
| 50 | 'archive', |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 51 | '--input' => '' . $input, |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 52 | '--output' => $output, |
| 53 | '-t' => 'Base#tokens_aggr', |
| 54 | '-m' => 'Sgbr' |
| 55 | ); |
| 56 | |
| 57 | # Test without compression |
| 58 | my $json; |
| 59 | { |
| 60 | local $SIG{__WARN__} = sub {}; |
| 61 | my $out = stdout_from(sub { system($call); }); |
| 62 | |
| 63 | like($out, qr!TEST-BSP-1\.json!s, $call); |
| 64 | |
| 65 | $out =~ m!Processed (.+?\.json)!; |
| 66 | $json = $1; |
| 67 | }; |
| 68 | |
| 69 | ok(-f $json, 'Json file exists'); |
Akron | 3ec0a1c | 2017-01-18 14:41:55 +0100 | [diff] [blame] | 70 | ok((my $file = Mojo::File->new($json)->slurp), 'Slurp data'); |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 71 | ok(($json = decode_json $file), 'decode json'); |
| 72 | |
| 73 | is($json->{data}->{tokenSource}, 'base#tokens_aggr', 'Title'); |
| 74 | is($json->{data}->{foundries}, 'base base/paragraphs base/sentences dereko dereko/structure sgbr sgbr/lemma sgbr/morpho', 'Foundries'); |
| 75 | is($json->{sgbrKodex}, 'M', 'Kodex meta data'); |
| 76 | |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 77 | |
| 78 | # Use directory |
| 79 | $input = catdir($f, '..', 'annotation', 'corpus'); |
| 80 | |
| 81 | $call = join( |
| 82 | ' ', |
| 83 | 'perl', $script, |
| 84 | 'archive', |
| 85 | '--input' => $input, |
| 86 | '--output' => $output, |
| 87 | '-t' => 'Tree_Tagger#Tokens', |
| 88 | '-j' => 4 # 4 jobs! |
| 89 | ); |
| 90 | |
| 91 | my ($json_1, $json_2); |
| 92 | |
| 93 | { |
| 94 | local $SIG{__WARN__} = sub {}; |
| 95 | |
| 96 | # That's not really stable on slow machines! |
| 97 | my $out = stdout_from(sub { system($call); }); |
| 98 | |
| 99 | ok($out =~ m!\[\$(\d+?):1\/2\]!s, $call . ' pid 1'); |
| 100 | my $pid1 = $1; |
| 101 | ok($out =~ m!\[\$(\d+?):2\/2\]!s, $call . ' pid 2'); |
| 102 | my $pid2 = $1; |
| 103 | |
| 104 | isnt($pid1, $pid2, 'No PID match'); |
| 105 | |
| 106 | ok($out =~ m!Processed .+?\/corpus-doc-0001\.json!s, $call); |
| 107 | ok($out =~ m!Processed .+?\/corpus-doc-0002\.json!s, $call); |
| 108 | |
| 109 | ok(-d $output, 'Temporary directory still exists'); |
| 110 | my $json_1 = catfile($output, 'corpus-doc-0001.json'); |
| 111 | ok(-f $json_1, 'Json file exists 1'); |
| 112 | my $json_2 = catfile($output, 'corpus-doc-0002.json'); |
| 113 | ok(-f $json_2, 'Json file exists 2'); |
| 114 | |
Akron | 3ec0a1c | 2017-01-18 14:41:55 +0100 | [diff] [blame] | 115 | ok(($file = Mojo::File->new($json_1)->slurp), 'Slurp data'); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 116 | ok(($json_1 = decode_json $file), 'decode json'); |
| 117 | |
| 118 | is($json_1->{data}->{tokenSource}, 'tree_tagger#tokens', 'TokenSource'); |
| 119 | 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'); |
| 120 | is($json_1->{textSigle}, 'Corpus/Doc/0001', 'Sigle'); |
| 121 | |
| 122 | ok(-f $json_2, 'Json file exists'); |
Akron | 3ec0a1c | 2017-01-18 14:41:55 +0100 | [diff] [blame] | 123 | ok(($file = Mojo::File->new($json_2)->slurp), 'Slurp data'); |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 124 | ok(($json_2 = decode_json $file), 'decode json'); |
| 125 | |
| 126 | is($json_2->{data}->{tokenSource}, 'tree_tagger#tokens', 'TokenSource'); |
| 127 | is($json_2->{data}->{foundries}, 'base base/paragraphs base/sentences dereko dereko/structure malt malt/dependency treetagger treetagger/morpho treetagger/sentences', 'Foundries'); |
| 128 | is($json_2->{textSigle}, 'Corpus/Doc/0002', 'Sigle'); |
| 129 | }; |
| 130 | |
| 131 | ok(-d $output, 'Ouput directory exists'); |
Akron | 89df4fa | 2016-11-04 14:35:37 +0100 | [diff] [blame] | 132 | |
| 133 | |
| 134 | $input = catfile($f, '..', 'corpus', 'WDD15', 'A79', '83946'); |
| 135 | $call = join( |
| 136 | ' ', |
| 137 | 'perl', $script, |
| 138 | '--input' => $input |
| 139 | ); |
| 140 | |
| 141 | # Test without compression |
| 142 | { |
| 143 | local $SIG{__WARN__} = sub {}; |
| 144 | my $out = stderr_from(sub { system($call); }); |
| 145 | |
| 146 | like($out, qr!no base tokenization!s, $call); |
| 147 | }; |
| 148 | |
Akron | f624084 | 2017-02-17 23:45:26 +0100 | [diff] [blame] | 149 | my $input_quotes = catfile($f, '..', 'corpus', 'archive_quotes.zip'); |
| 150 | $call = join( |
| 151 | ' ', |
| 152 | 'perl', $script, |
| 153 | 'archive', |
| 154 | '--input' => $input_quotes, |
| 155 | '--output' => $output, |
| 156 | '-t' => 'Base#tokens_aggr' |
| 157 | ); |
| 158 | |
| 159 | # Test without parameters |
| 160 | stdout_like( |
| 161 | sub { |
| 162 | system($call); |
| 163 | }, |
| 164 | qr!Done\.!is, |
| 165 | $call |
| 166 | ); |
| 167 | |
Akron | 89df4fa | 2016-11-04 14:35:37 +0100 | [diff] [blame] | 168 | |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 169 | unlink($output); |
| 170 | |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 171 | |
| 172 | $input_quotes = "'".catfile($f, '..', 'corpus', 'archives', 'wpd15*.zip') . "'"; |
| 173 | |
| 174 | $call = join( |
| 175 | ' ', |
| 176 | 'perl', $script, |
| 177 | 'archive', |
| 178 | '--input' => $input_quotes, |
| 179 | '--output' => $output, |
| 180 | '-t' => 'Base#tokens_aggr' |
| 181 | ); |
| 182 | |
| 183 | # Test without parameters |
| 184 | stdout_like( |
| 185 | sub { |
| 186 | system($call); |
| 187 | }, |
Akron | 63f20d4 | 2017-04-10 23:40:29 +0200 | [diff] [blame] | 188 | 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, |
Akron | 821db3d | 2017-04-06 21:19:31 +0200 | [diff] [blame] | 189 | $call |
| 190 | ); |
| 191 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 192 | done_testing; |
| 193 | __END__ |