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