blob: 8e50e0d28b0fc4786b50f6b22479f54d08c38d1c [file] [log] [blame]
Akron3741f8b2016-12-21 19:55:21 +01001#/usr/bin/env perl
2use strict;
3use warnings;
4use File::Basename 'dirname';
5use File::Spec::Functions qw/catdir catfile/;
6use File::Temp qw/ :POSIX /;
Akron3ec0a1c2017-01-18 14:41:55 +01007use Mojo::File;
Akron3741f8b2016-12-21 19:55:21 +01008use Mojo::JSON qw/decode_json/;
9use IO::Uncompress::Gunzip;
10use Test::More;
11use Test::Output;
12use Data::Dumper;
13use utf8;
14
15my $f = dirname(__FILE__);
16my $script = catfile($f, '..', '..', 'script', 'korapxml2krill');
17
18my $input = catdir($f, '..', 'corpus', 'GOE2', 'AGA', '03828');
19ok(-d $input, 'Input directory found');
20
21my $output = tmpnam();
22
23ok(!-f $output, 'Output does not exist');
24
25my $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
37stderr_like(
38 sub {
39 system($call);
40 },
41 qr!The code took!,
42 $call
43);
44
45ok(-f $output, 'Output does exist');
Akron3ec0a1c2017-01-18 14:41:55 +010046ok((my $file = Mojo::File->new($output)->slurp), 'Slurp data');
Akron3741f8b2016-12-21 19:55:21 +010047ok((my $json = decode_json $file), 'decode json');
48is($json->{textType}, 'Autobiographie', 'text type');
49is($json->{title}, 'Autobiographische Einzelheiten', 'Title');
50is($json->{data}->{tokenSource}, 'base#tokens_aggr', 'Title');
Akron3bd942f2017-02-20 20:09:14 +010051is($json->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base-sentences-paragraphs marmot marmot/morpho', 'Foundries');
Akron3741f8b2016-12-21 19:55:21 +010052my $stream = $json->{data}->{stream};
53my $token = $stream->[0];
54is($token->[0], '-:base/paragraphs$<i>14', 'Paragraphs');
55is($token->[1], '-:base/sentences$<i>215', 'Sentences');
56
57is($token->[5], '<>:base/s:s$<b>64<i>0<i>30<i>2<b>2', 'struct');
58is($token->[7], '<>:dereko/s:s$<b>64<i>0<i>30<i>2<b>4', 'struct');
Akrond35d2d32017-02-13 16:57:42 +010059is($token->[8], '<>:base/s:t$<b>64<i>0<i>35242<i>5238<b>0', 'struct');
Akron3741f8b2016-12-21 19:55:21 +010060
61$token = $stream->[4];
62is($token->[0], '<>:base/s:s$<b>64<i>53<i>254<i>32<b>2', 'struct');
63is($token->[1], '<>:dereko/s:s$<b>64<i>53<i>254<i>32<b>5<s>1', 'struct');
64is($token->[2], '<>:base/s:p$<b>64<i>53<i>3299<i>504<b>1', 'struct');
65is($token->[3], '<>:dereko/s:p$<b>64<i>53<i>3299<i>504<b>4', 'struct');
66
67done_testing;
68
69__END__