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