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/; |
| 7 | use Mojo::Util qw/slurp/; |
| 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 | }, |
| 34 | qr!archive.+?Process an!s, |
| 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'); |
| 69 | ok((my $file = slurp $json), 'Slurp data'); |
| 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 | |
| 114 | ok(($file = slurp $json_1), 'Slurp data'); |
| 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'); |
| 122 | ok(($file = slurp $json_2), 'Slurp data'); |
| 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'); |
| 131 | unlink($output); |
| 132 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 133 | done_testing; |
| 134 | __END__ |