blob: de9144cb9cbf87baa53da46fddaa6099ce094505 [file] [log] [blame]
Akron05ba5472016-07-05 21:12:26 +02001#!/usr/bin/env perl
2use strict;
3use warnings;
4use utf8;
5use Log::Log4perl;
6use Data::Dumper;
7
8Log::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
15use File::Basename 'dirname';
16use File::Spec::Functions qw/catdir catfile/;
17use Test::More;
18use Scalar::Util qw/weaken/;
19use Data::Dumper;
20use lib 't/annotation';
21use File::Temp qw/tempdir/;
22
Nils Diewaldb3e9ccd2016-10-24 15:16:52 +020023use KorAP::XML::Archive;
Akron05ba5472016-07-05 21:12:26 +020024
25my $name = 'wpd15-single';
26my @path = (dirname(__FILE__), '..', 'corpus','archives');
27
28my $file = catfile(@path, $name . '.zip');
Nils Diewaldb3e9ccd2016-10-24 15:16:52 +020029my $archive = KorAP::XML::Archive->new($file);
30
31unless ($archive->test_unzip) {
32 plan skip_all => 'unzip not found';
33};
34
35use_ok('KorAP::XML::Annotation::MDParser::Dependency');
36use_ok('KorAP::XML::Krill');
37use_ok('KorAP::XML::Tokenizer');
38
Akron05ba5472016-07-05 21:12:26 +020039
40ok($archive->attach('#' . catfile(@path, $name . '.mdparser.zip')), 'Attach mdparser archive');
41
42my $dir = tempdir();
43
44my $f_path = 'WPD15/A00/00081';
Akron955b75b2019-02-21 14:28:41 +010045$archive->extract_sigle([$f_path], $dir);
Akron05ba5472016-07-05 21:12:26 +020046
47ok(my $doc = KorAP::XML::Krill->new( path => $dir . '/' . $f_path));
48
49ok($doc->parse, 'Krill parser works');
50
51my $tokens = KorAP::XML::Tokenizer->new(
52 path => $doc->path,
53 doc => $doc,
54 foundry => 'Base',
55 layer => 'Tokens',
56 name => 'tokens'
57) or return;
58
59$tokens->parse or return;
60
61ok($tokens->add('MDParser', 'Dependency'), 'Add Dependency');
62
63my $data = $tokens->to_data->{data};
64
65
66is($data->{tokenSource}, 'base#tokens', 'TokenSource');
67like($data->{foundries}, qr!mdparser/dependency!, 'foundries');
68like($data->{layerInfos}, qr!mdp/d=rels!, 'foundries');
69
70my $stream = $data->{stream};
71
Akrona86d94a2016-07-06 14:23:12 +020072is($stream->[0]->[0], '-:tokens$<i>3555', 'Token count');
73
Akron918ce422017-06-16 20:28:43 +020074is($stream->[-1]->[-1], 's:978-3-89487-607-4', 'Last token');
75
Akrona86d94a2016-07-06 14:23:12 +020076# Term-to-term
77is($stream->[0]->[1], '<:mdp/d:NMOD$<b>32<i>5', 'Term-to-Term');
78is($stream->[5]->[0], '>:mdp/d:NMOD$<b>32<i>0', 'Term-to-Term');
79
80# Element-to-term
81is($stream->[0]->[8], '<:mdp/d:ROOT$<b>34<i>0<i>317<i>40<i>0', 'Element-to-Term');
82is($stream->[0]->[10], '>:mdp/d:ROOT$<b>33<i>0<i>317<i>0<i>40', 'Term-to-Element');
83
84
85is($stream->[-1]->[0], '>:mdp/d:ROOT$<b>33<i>26130<i>26153<i>3553<i>3554', 'Term-to-Element');
86is($stream->[3553]->[1], '<:mdp/d:ROOT$<b>34<i>26130<i>26153<i>3554<i>3553', 'Element-to-Term');
Akron05ba5472016-07-05 21:12:26 +020087
88done_testing;
89__END__