Akron | 405f0c5 | 2016-07-07 17:56:16 +0200 | [diff] [blame^] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | use Test::More; |
| 5 | use File::Basename 'dirname'; |
| 6 | use File::Spec::Functions 'catdir'; |
| 7 | use File::Temp qw/ :POSIX /; |
| 8 | use Mojo::Util qw/slurp/; |
| 9 | use Mojo::JSON qw/decode_json/; |
| 10 | |
| 11 | use_ok('KorAP::XML::Batch::File'); |
| 12 | |
| 13 | ok(my $bf = KorAP::XML::Batch::File->new( |
| 14 | overwrite => 1, |
| 15 | foundry => 'OpenNLP', |
| 16 | layer => 'Tokens' |
| 17 | ), 'Construct new batch file object'); |
| 18 | |
| 19 | # gzip => 1, |
| 20 | |
| 21 | my $path = catdir(dirname(__FILE__), 'annotation', 'corpus', 'doc', '0001'); |
| 22 | |
| 23 | my $output = tmpnam(); |
| 24 | ok($bf->process($path => $output), 'Process file'); |
| 25 | |
| 26 | ok(-f $output, 'File exists'); |
| 27 | |
| 28 | ok(my $file = slurp $output, 'Slurp data'); |
| 29 | |
| 30 | ok(my $json = decode_json $file, 'decode json'); |
| 31 | |
| 32 | is($json->{textType}, 'Zeitung: Tageszeitung', 'text type'); |
| 33 | is($json->{title}, 'Beispiel Text', 'Title'); |
| 34 | is($json->{data}->{tokenSource}, 'opennlp#tokens', 'Title'); |
| 35 | is($json->{data}->{foundries}, '', 'Foundries'); |
| 36 | like($json->{data}->{text}, qr/^Zum letzten kulturellen/, 'Foundries'); |
| 37 | is($json->{data}->{stream}->[0]->[0], '-:tokens$<i>18', 'Tokens'); |
| 38 | is($json->{data}->{stream}->[0]->[1], '<>:base/s:t$<b>64<i>0<i>129<i>17<b>0', 'Data'); |
| 39 | |
| 40 | done_testing; |
| 41 | __END__ |