Akron | e1dbc38 | 2016-07-08 22:24:52 +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::Util qw/slurp/; |
| 8 | use Mojo::JSON qw/decode_json/; |
| 9 | use IO::Uncompress::Gunzip; |
| 10 | use Test::More; |
| 11 | |
| 12 | my $f = dirname(__FILE__); |
| 13 | my $script = catfile($f, '..', '..', 'script', 'korapxml2krill'); |
| 14 | my $input = catdir($f, '..', 'annotation', 'corpus', 'doc', '0001'); |
| 15 | my $output = tmpnam(); |
| 16 | |
| 17 | ok(-f $script, 'Script found'); |
| 18 | ok(-d $input, 'Input directory found'); |
| 19 | |
| 20 | my $call = 'perl '; |
| 21 | $call .= $script . ' '; |
| 22 | $call .= "--input $input "; |
| 23 | $call .= "--output $output "; |
| 24 | $call .= '-t OpenNLP#Tokens '; |
| 25 | |
| 26 | system($call); |
| 27 | |
| 28 | ok(my $file = slurp $output, 'Slurp data'); |
| 29 | ok(my $json = decode_json $file, 'decode json'); |
| 30 | is($json->{textType}, 'Zeitung: Tageszeitung', 'text type'); |
| 31 | is($json->{title}, 'Beispiel Text', 'Title'); |
| 32 | is($json->{data}->{tokenSource}, 'opennlp#tokens', 'Title'); |
| 33 | is($json->{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'); |
| 34 | like($json->{data}->{text}, qr/^Zum letzten kulturellen/, 'Foundries'); |
| 35 | is($json->{data}->{stream}->[0]->[0], '-:base/paragraphs$<i>1', 'Paragraphs'); |
| 36 | |
| 37 | system($call . ' -z'); |
| 38 | |
| 39 | my $gz = IO::Uncompress::Gunzip->new($output); |
| 40 | ok($gz->read($file), 'Uncompress'); |
| 41 | |
| 42 | ok($json = decode_json $file, 'decode json'); |
| 43 | is($json->{textType}, 'Zeitung: Tageszeitung', 'text type'); |
| 44 | is($json->{title}, 'Beispiel Text', 'Title'); |
| 45 | is($json->{data}->{tokenSource}, 'opennlp#tokens', 'Title'); |
| 46 | is($json->{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'); |
| 47 | like($json->{data}->{text}, qr/^Zum letzten kulturellen/, 'Foundries'); |
| 48 | is($json->{data}->{stream}->[0]->[0], '-:base/paragraphs$<i>1', 'Paragraphs'); |
| 49 | |
| 50 | |
| 51 | done_testing; |
| 52 | __END__ |