Akron | 05ba547 | 2016-07-05 21:12:26 +0200 | [diff] [blame^] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | use utf8; |
| 5 | use Log::Log4perl; |
| 6 | use Data::Dumper; |
| 7 | |
| 8 | Log::Log4perl->init({ |
| 9 | 'log4perl.rootLogger' => 'ERROR, STDERR', |
| 10 | 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels', |
| 11 | 'log4perl.appender.STDERR.layout' => 'PatternLayout', |
| 12 | 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n' |
| 13 | }); |
| 14 | |
| 15 | use File::Basename 'dirname'; |
| 16 | use File::Spec::Functions qw/catdir catfile/; |
| 17 | use Test::More; |
| 18 | use Scalar::Util qw/weaken/; |
| 19 | use Data::Dumper; |
| 20 | use lib 't/annotation'; |
| 21 | use File::Temp qw/tempdir/; |
| 22 | |
| 23 | use_ok('KorAP::XML::Annotation::MDParser::Dependency'); |
| 24 | use_ok('KorAP::XML::Archive'); |
| 25 | use_ok('KorAP::XML::Krill'); |
| 26 | use_ok('KorAP::XML::Tokenizer'); |
| 27 | |
| 28 | my $name = 'wpd15-single'; |
| 29 | my @path = (dirname(__FILE__), '..', 'corpus','archives'); |
| 30 | |
| 31 | my $file = catfile(@path, $name . '.zip'); |
| 32 | ok(my $archive = KorAP::XML::Archive->new($file), 'Create archive'); |
| 33 | |
| 34 | ok($archive->attach('#' . catfile(@path, $name . '.mdparser.zip')), 'Attach mdparser archive'); |
| 35 | |
| 36 | my $dir = tempdir(); |
| 37 | |
| 38 | my $f_path = 'WPD15/A00/00081'; |
| 39 | $archive->extract($f_path, $dir); |
| 40 | |
| 41 | ok(my $doc = KorAP::XML::Krill->new( path => $dir . '/' . $f_path)); |
| 42 | |
| 43 | ok($doc->parse, 'Krill parser works'); |
| 44 | |
| 45 | my $tokens = KorAP::XML::Tokenizer->new( |
| 46 | path => $doc->path, |
| 47 | doc => $doc, |
| 48 | foundry => 'Base', |
| 49 | layer => 'Tokens', |
| 50 | name => 'tokens' |
| 51 | ) or return; |
| 52 | |
| 53 | $tokens->parse or return; |
| 54 | |
| 55 | ok($tokens->add('MDParser', 'Dependency'), 'Add Dependency'); |
| 56 | |
| 57 | my $data = $tokens->to_data->{data}; |
| 58 | |
| 59 | |
| 60 | is($data->{tokenSource}, 'base#tokens', 'TokenSource'); |
| 61 | like($data->{foundries}, qr!mdparser/dependency!, 'foundries'); |
| 62 | like($data->{layerInfos}, qr!mdp/d=rels!, 'foundries'); |
| 63 | |
| 64 | my $stream = $data->{stream}; |
| 65 | |
| 66 | # diag Dumper $stream->[0]; |
| 67 | |
| 68 | done_testing; |
| 69 | __END__ |