Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [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 /; |
Akron | 3ec0a1c | 2017-01-18 14:41:55 +0100 | [diff] [blame] | 7 | use Mojo::File; |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 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 | my $f = dirname(__FILE__); |
| 16 | my $script = catfile($f, '..', '..', 'script', 'korapxml2krill'); |
| 17 | |
| 18 | my $input = catdir($f, '..', 'corpus', 'GOE2', 'AGA', '03828'); |
| 19 | ok(-d $input, 'Input directory found'); |
| 20 | |
| 21 | my $output = tmpnam(); |
| 22 | |
| 23 | ok(!-f $output, 'Output does not exist'); |
| 24 | |
| 25 | my $call = join( |
| 26 | ' ', |
| 27 | 'perl', $script, |
| 28 | '--input' => $input, |
| 29 | '--output' => $output, |
| 30 | '-t' => 'Base#tokens_aggr', |
| 31 | '-bs' => 'DeReKo#Structure', |
| 32 | '-bp' => 'DeReKo#Structure', |
| 33 | '-l' => 'INFO' |
| 34 | ); |
| 35 | |
| 36 | # Test without compression |
| 37 | stderr_like( |
| 38 | sub { |
| 39 | system($call); |
| 40 | }, |
| 41 | qr!The code took!, |
| 42 | $call |
| 43 | ); |
| 44 | |
| 45 | ok(-f $output, 'Output does exist'); |
Akron | 3ec0a1c | 2017-01-18 14:41:55 +0100 | [diff] [blame] | 46 | ok((my $file = Mojo::File->new($output)->slurp), 'Slurp data'); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 47 | ok((my $json = decode_json $file), 'decode json'); |
| 48 | is($json->{textType}, 'Autobiographie', 'text type'); |
| 49 | is($json->{title}, 'Autobiographische Einzelheiten', 'Title'); |
| 50 | is($json->{data}->{tokenSource}, 'base#tokens_aggr', 'Title'); |
Akron | 3bd942f | 2017-02-20 20:09:14 +0100 | [diff] [blame] | 51 | is($json->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base-sentences-paragraphs marmot marmot/morpho', 'Foundries'); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 52 | my $stream = $json->{data}->{stream}; |
| 53 | my $token = $stream->[0]; |
| 54 | is($token->[0], '-:base/paragraphs$<i>14', 'Paragraphs'); |
| 55 | is($token->[1], '-:base/sentences$<i>215', 'Sentences'); |
| 56 | |
| 57 | is($token->[5], '<>:base/s:s$<b>64<i>0<i>30<i>2<b>2', 'struct'); |
| 58 | is($token->[7], '<>:dereko/s:s$<b>64<i>0<i>30<i>2<b>4', 'struct'); |
Akron | d35d2d3 | 2017-02-13 16:57:42 +0100 | [diff] [blame] | 59 | is($token->[8], '<>:base/s:t$<b>64<i>0<i>35242<i>5238<b>0', 'struct'); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 60 | |
| 61 | $token = $stream->[4]; |
| 62 | is($token->[0], '<>:base/s:s$<b>64<i>53<i>254<i>32<b>2', 'struct'); |
| 63 | is($token->[1], '<>:dereko/s:s$<b>64<i>53<i>254<i>32<b>5<s>1', 'struct'); |
| 64 | is($token->[2], '<>:base/s:p$<b>64<i>53<i>3299<i>504<b>1', 'struct'); |
| 65 | is($token->[3], '<>:dereko/s:p$<b>64<i>53<i>3299<i>504<b>4', 'struct'); |
| 66 | |
| 67 | done_testing; |
| 68 | |
| 69 | __END__ |