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; |
| 13 | use utf8; |
| 14 | |
| 15 | my $f = dirname(__FILE__); |
| 16 | my $script = catfile($f, '..', '..', 'script', 'korapxml2krill'); |
| 17 | |
| 18 | my $call = join( |
| 19 | ' ', |
| 20 | 'perl', $script, |
| 21 | 'archive' |
| 22 | ); |
| 23 | |
| 24 | # Test without parameters |
| 25 | stdout_like( |
| 26 | sub { |
| 27 | system($call); |
| 28 | }, |
| 29 | qr!archive.+?Process an!s, |
| 30 | $call |
| 31 | ); |
| 32 | |
| 33 | my $input = catfile($f, '..', 'corpus', 'archive.zip'); |
| 34 | ok(-f $input, 'Input archive found'); |
| 35 | |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 36 | my $output = File::Temp->newdir(CLEANUP => 0); |
| 37 | $output->unlink_on_destroy(0); |
| 38 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 39 | ok(-d $output, 'Output directory exists'); |
| 40 | |
| 41 | $call = join( |
| 42 | ' ', |
| 43 | 'perl', $script, |
| 44 | 'archive', |
| 45 | '--input' => $input, |
| 46 | '--output' => $output, |
| 47 | '-t' => 'Base#tokens_aggr', |
| 48 | '-m' => 'Sgbr' |
| 49 | ); |
| 50 | |
| 51 | # Test without compression |
| 52 | my $json; |
| 53 | { |
| 54 | local $SIG{__WARN__} = sub {}; |
| 55 | my $out = stdout_from(sub { system($call); }); |
| 56 | |
| 57 | like($out, qr!TEST-BSP-1\.json!s, $call); |
| 58 | |
| 59 | $out =~ m!Processed (.+?\.json)!; |
| 60 | $json = $1; |
| 61 | }; |
| 62 | |
| 63 | ok(-f $json, 'Json file exists'); |
| 64 | ok((my $file = slurp $json), 'Slurp data'); |
| 65 | ok(($json = decode_json $file), 'decode json'); |
| 66 | |
| 67 | is($json->{data}->{tokenSource}, 'base#tokens_aggr', 'Title'); |
| 68 | is($json->{data}->{foundries}, 'base base/paragraphs base/sentences dereko dereko/structure sgbr sgbr/lemma sgbr/morpho', 'Foundries'); |
| 69 | is($json->{sgbrKodex}, 'M', 'Kodex meta data'); |
| 70 | |
Akron | 3ec4897 | 2016-08-17 23:24:52 +0200 | [diff] [blame] | 71 | |
| 72 | # Use directory |
| 73 | $input = catdir($f, '..', 'annotation', 'corpus'); |
| 74 | |
| 75 | $call = join( |
| 76 | ' ', |
| 77 | 'perl', $script, |
| 78 | 'archive', |
| 79 | '--input' => $input, |
| 80 | '--output' => $output, |
| 81 | '-t' => 'Tree_Tagger#Tokens', |
| 82 | '-j' => 4 # 4 jobs! |
| 83 | ); |
| 84 | |
| 85 | my ($json_1, $json_2); |
| 86 | |
| 87 | { |
| 88 | local $SIG{__WARN__} = sub {}; |
| 89 | |
| 90 | # That's not really stable on slow machines! |
| 91 | my $out = stdout_from(sub { system($call); }); |
| 92 | |
| 93 | ok($out =~ m!\[\$(\d+?):1\/2\]!s, $call . ' pid 1'); |
| 94 | my $pid1 = $1; |
| 95 | ok($out =~ m!\[\$(\d+?):2\/2\]!s, $call . ' pid 2'); |
| 96 | my $pid2 = $1; |
| 97 | |
| 98 | isnt($pid1, $pid2, 'No PID match'); |
| 99 | |
| 100 | ok($out =~ m!Processed .+?\/corpus-doc-0001\.json!s, $call); |
| 101 | ok($out =~ m!Processed .+?\/corpus-doc-0002\.json!s, $call); |
| 102 | |
| 103 | ok(-d $output, 'Temporary directory still exists'); |
| 104 | my $json_1 = catfile($output, 'corpus-doc-0001.json'); |
| 105 | ok(-f $json_1, 'Json file exists 1'); |
| 106 | my $json_2 = catfile($output, 'corpus-doc-0002.json'); |
| 107 | ok(-f $json_2, 'Json file exists 2'); |
| 108 | |
| 109 | ok(($file = slurp $json_1), 'Slurp data'); |
| 110 | ok(($json_1 = decode_json $file), 'decode json'); |
| 111 | |
| 112 | is($json_1->{data}->{tokenSource}, 'tree_tagger#tokens', 'TokenSource'); |
| 113 | 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'); |
| 114 | is($json_1->{textSigle}, 'Corpus/Doc/0001', 'Sigle'); |
| 115 | |
| 116 | ok(-f $json_2, 'Json file exists'); |
| 117 | ok(($file = slurp $json_2), 'Slurp data'); |
| 118 | ok(($json_2 = decode_json $file), 'decode json'); |
| 119 | |
| 120 | is($json_2->{data}->{tokenSource}, 'tree_tagger#tokens', 'TokenSource'); |
| 121 | is($json_2->{data}->{foundries}, 'base base/paragraphs base/sentences dereko dereko/structure malt malt/dependency treetagger treetagger/morpho treetagger/sentences', 'Foundries'); |
| 122 | is($json_2->{textSigle}, 'Corpus/Doc/0002', 'Sigle'); |
| 123 | }; |
| 124 | |
| 125 | ok(-d $output, 'Ouput directory exists'); |
| 126 | unlink($output); |
| 127 | |
Akron | 7d4cdd8 | 2016-08-17 21:39:45 +0200 | [diff] [blame] | 128 | done_testing; |
| 129 | __END__ |