| Akron | 414ec95 | 2020-08-03 15:48:43 +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/ :POSIX /; |
| 7 | use Mojo::File; |
| 8 | use Mojo::JSON qw/decode_json/; |
| 9 | use IO::Uncompress::Gunzip; |
| 10 | use Test::More; |
| 11 | use Test::Output; |
| 12 | use Data::Dumper; |
| 13 | use utf8; |
| 14 | |
| 15 | if ($ENV{SKIP_SCRIPT} || $ENV{SKIP_REAL}) { |
| 16 | plan skip_all => 'Skip script/real tests'; |
| 17 | }; |
| 18 | |
| 19 | my $f = dirname(__FILE__); |
| 20 | my $script = catfile($f, '..', '..', '..', 'script', 'korapxml2krill'); |
| 21 | |
| 22 | my $input = catdir($f, '..', 'corpus', 'WPD', '00001'); |
| 23 | ok(-d $input, 'Input directory found'); |
| 24 | |
| 25 | my $output = tmpnam(); |
| 26 | my $cache = tmpnam(); |
| 27 | |
| 28 | ok(!-f $output, 'Output does not exist'); |
| 29 | |
| 30 | my $call = join( |
| 31 | ' ', |
| 32 | 'perl', $script, |
| 33 | '--input' => $input, |
| 34 | '--output' => $output, |
| 35 | '--cache' => $cache, |
| 36 | '-t' => 'OpenNLP#tokens', |
| 37 | '-l' => 'INFO' |
| 38 | ); |
| 39 | |
| 40 | # Test without compression |
| 41 | stderr_like( |
| 42 | sub { |
| 43 | system($call); |
| 44 | }, |
| 45 | qr!The code took!, |
| 46 | $call |
| 47 | ); |
| 48 | |
| 49 | ok(-f $output, 'Output does exist'); |
| 50 | ok((my $file = Mojo::File->new($output)->slurp), 'Slurp data'); |
| 51 | ok((my $json = decode_json $file), 'decode json'); |
| 52 | is($json->{textSigle}, 'WPD/AAA/00001', 'text sigle'); |
| 53 | is($json->{title}, 'A', 'Title'); |
| 54 | is($json->{data}->{tokenSource}, 'opennlp#tokens', 'Title'); |
| 55 | is($json->{data}->{foundries}, 'base base/paragraphs base/sentences connexor connexor/morpho connexor/phrase connexor/sentences connexor/syntax corenlp corenlp/sentences dereko dereko/structure mate mate/dependency mate/morpho opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences xip xip/constituency xip/morpho xip/sentences', 'Foundries'); |
| 56 | my $stream = $json->{data}->{stream}; |
| 57 | my $token = $stream->[12]; |
| 58 | is($token->[16], 's:Vokal', 'Token'); |
| 59 | $token = $stream->[13]; |
| 60 | is($token->[23], 's:Der', 'Token'); |
| 61 | |
| 62 | |
| 63 | $call = join( |
| 64 | ' ', |
| 65 | 'perl', $script, |
| 66 | '--input' => $input, |
| 67 | '--output' => $output, |
| 68 | '--cache' => $cache, |
| 69 | '-t' => 'OpenNLP#tokens', |
| 70 | '-l' => 'INFO', |
| 71 | '-w' => '', |
| 72 | '-nwt' => '' |
| 73 | ); |
| 74 | |
| 75 | # Test without compression |
| 76 | stderr_like( |
| 77 | sub { |
| 78 | system($call); |
| 79 | }, |
| 80 | qr!The code took!, |
| 81 | $call |
| 82 | ); |
| 83 | |
| 84 | ok(-f $output, 'Output does exist'); |
| 85 | ok(($file = Mojo::File->new($output)->slurp), 'Slurp data'); |
| 86 | ok(($json = decode_json $file), 'decode json'); |
| 87 | $stream = $json->{data}->{stream}; |
| 88 | $token = $stream->[12]; |
| 89 | is($token->[17], 's:Vokal', 'Token'); |
| 90 | $token = $stream->[13]; |
| 91 | is($token->[7], 's:.', 'Token'); |
| 92 | is($token->[11], 'xip/p:PUNCT', 'Token'); |
| 93 | $token = $stream->[14]; |
| 94 | is($token->[23], 's:Der', 'Token'); |
| 95 | |
| 96 | |
| 97 | done_testing; |
| 98 | |
| 99 | __END__ |