blob: bd2d8e59ade0dba7c4d983f42371cb742fd0a4a0 [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 /;
7use Mojo::Util qw/slurp/;
8use 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');
46ok((my $file = slurp $output), 'Slurp data');
47ok((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');
51is($json->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base-sentences-paragraphs', 'Foundries');
52my $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');
59is($token->[8], '<>:base/s:t$<b>64<i>0<i>35250<i>5238<b>0', 'struct');
60
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__