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', 'GOE2', 'AGA', '03828'); |
| 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' => 'Base#tokens_aggr.xml', |
| 37 | '-bs' => 'DeReKo#Structure', |
| 38 | '-bp' => 'DeReKo#Structure', |
| 39 | '-l' => 'INFO' |
| 40 | ); |
| 41 | |
| 42 | # Test without compression |
| 43 | stderr_like( |
| 44 | sub { |
| 45 | system($call); |
| 46 | }, |
| 47 | qr!The code took!, |
| 48 | $call |
| 49 | ); |
| 50 | |
| 51 | ok(-f $output, 'Output does exist'); |
| 52 | ok((my $file = Mojo::File->new($output)->slurp), 'Slurp data'); |
| 53 | ok((my $json = decode_json $file), 'decode json'); |
| 54 | is($json->{textType}, 'Autobiographie', 'text type'); |
| 55 | is($json->{title}, 'Autobiographische Einzelheiten', 'Title'); |
| 56 | is($json->{data}->{tokenSource}, 'base#tokens_aggr', 'Title'); |
| 57 | is($json->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base-sentences-paragraphs marmot marmot/morpho', 'Foundries'); |
| 58 | my $stream = $json->{data}->{stream}; |
| 59 | my $token = $stream->[0]; |
| 60 | is($token->[0], '-:base/paragraphs$<i>14', 'Paragraphs'); |
| 61 | is($token->[1], '-:base/sentences$<i>215', 'Sentences'); |
| 62 | |
| 63 | is($token->[5], '<>:base/s:s$<b>64<i>0<i>30<i>2<b>2', 'struct'); |
| 64 | is($token->[7], '<>:dereko/s:s$<b>64<i>0<i>30<i>2<b>4', 'struct'); |
| 65 | is($token->[8], '<>:base/s:t$<b>64<i>0<i>35242<i>5239<b>0', 'struct'); |
| 66 | |
| 67 | $token = $stream->[4]; |
| 68 | is($token->[0], '<>:base/s:s$<b>64<i>53<i>254<i>32<b>2', 'struct'); |
| 69 | is($token->[1], '<>:dereko/s:s$<b>64<i>53<i>254<i>32<b>5<s>1', 'struct'); |
| 70 | is($token->[2], '<>:base/s:p$<b>64<i>53<i>3299<i>504<b>1', 'struct'); |
| 71 | is($token->[3], '<>:dereko/s:p$<b>64<i>53<i>3299<i>504<b>4', 'struct'); |
| 72 | |
| 73 | done_testing; |
| 74 | |
| 75 | __END__ |