blob: 517f9bee7a5903fe950732ffe6927e7c85fe866d [file] [log] [blame]
Akrond3a0bad2016-02-26 14:07:58 +01001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
6
7use Benchmark qw/:hireswallclock/;
8
9my $t = Benchmark->new;
10
11use utf8;
12use lib 'lib', '../lib';
13
14use File::Basename 'dirname';
15use File::Spec::Functions 'catdir';
16
17use_ok('KorAP::XML::Krill');
18
Akrond3a0bad2016-02-26 14:07:58 +010019my $path = catdir(dirname(__FILE__), '../corpus/WPD/00001');
Akrond3a0bad2016-02-26 14:07:58 +010020
21ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
22ok($doc->parse, 'Parse document');
23
Akron1cd5b872016-03-22 00:23:46 +010024is($doc->text_sigle, 'WPD/AAA/00001', 'Correct text sigle');
25is($doc->doc_sigle, 'WPD/AAA', 'Correct document sigle');
Akrond3a0bad2016-02-26 14:07:58 +010026is($doc->corpus_sigle, 'WPD', 'Correct corpus sigle');
27
Akron35db6e32016-03-17 22:42:22 +010028my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010029is($meta->{T_title}, 'A', 'Title');
30is($meta->{S_pub_place}, 'URL:http://de.wikipedia.org', 'PubPlace');
31is($meta->{D_pub_date}, '20050328', 'Creation Date');
Akron7e2eb882017-01-18 17:28:07 +010032SKIP: {
33 skip 'Failure because corpus is no longer supported', 1;
Akron5eb3aa02019-01-25 18:30:47 +010034 ok(!$meta->{T_sub_title}, 'SubTitle');
Akron7e2eb882017-01-18 17:28:07 +010035};
Akron5eb3aa02019-01-25 18:30:47 +010036is($meta->{T_author}, 'Ruru; Jens.Ol; Aglarech; u.a.', 'Author');
Akrond3a0bad2016-02-26 14:07:58 +010037
Akron5eb3aa02019-01-25 18:30:47 +010038ok(!$meta->{T_doc_title}, 'Correct Doc title');
39ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title');
40ok(!$meta->{T_doc_author}, 'Correct Doc author');
41ok(!$meta->{A_doc_editor}, 'Correct Doc editor');
Akrond3a0bad2016-02-26 14:07:58 +010042
Akron5eb3aa02019-01-25 18:30:47 +010043ok(!$meta->{T_corpus_title}, 'Correct Corpus title');
44ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title');
Akrond3a0bad2016-02-26 14:07:58 +010045
Akron6bf3cc92019-02-07 12:11:20 +010046# This link is broken, but that's due to the data
47is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http://de.wikipedia.org', 'No link');
48
Akrond3a0bad2016-02-26 14:07:58 +010049# Tokenization
50use_ok('KorAP::XML::Tokenizer');
51
52my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
53
54# Get tokenization
55my $tokens = KorAP::XML::Tokenizer->new(
56 path => $doc->path,
57 doc => $doc,
58 foundry => $token_base_foundry,
59 layer => $token_base_layer,
60 name => 'tokens'
61);
62ok($tokens, 'Token Object is fine');
63ok($tokens->parse, 'Token parsing is fine');
64
65my $output = $tokens->to_data;
66
67is(substr($output->{data}->{text}, 0, 100), 'A bzw. a ist der erste Buchstabe des lateinischen Alphabets und ein Vokal. Der Buchstabe A hat in de', 'Primary Data');
68is($output->{data}->{name}, 'tokens', 'tokenName');
69is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
70
71is($output->{version}, '0.03', 'version');
72is($output->{data}->{foundries}, '', 'Foundries');
73is($output->{data}->{layerInfos}, '', 'layerInfos');
74is($output->{data}->{stream}->[0]->[4], 's:A', 'data');
75
76$tokens->add('Mate', 'Dependency');
77
78my $stream = $tokens->to_data->{data}->{stream};
79
Akron75ba57d2016-03-07 23:36:27 +010080# This is not a goot relation example
81is($stream->[77]->[0],
82 '<:mate/d:--$<b>34<i>498<i>499<i>78<i>78',
83 'element to term');
Akron75ba57d2016-03-07 23:36:27 +010084is($stream->[78]->[0], '>:mate/d:--$<b>33<i>498<i>499<i>77<i>78', 'term to element');
Akrond3a0bad2016-02-26 14:07:58 +010085
Akronaf0ae3f2016-07-14 16:21:50 +020086$tokens->add('Base', 'Sentences');
87
88$stream = $tokens->to_data->{data}->{stream};
89
90is($stream->[0]->[2], '<>:base/s:s$<b>64<i>0<i>74<i>13<b>2', 'Text starts with sentence');
Akrond3a0bad2016-02-26 14:07:58 +010091
Akron6f9fef52016-11-03 17:06:40 +010092
93# Problematic document
94$path = catdir(dirname(__FILE__), '../corpus/WPD15/W28/65631');
95ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
96ok($doc->parse, 'Parse document');
97
98is($doc->text_sigle, 'WPD15/W28/65631', 'Correct text sigle');
99is($doc->doc_sigle, 'WPD15/W28', 'Correct document sigle');
100is($doc->corpus_sigle, 'WPD15', 'Correct corpus sigle');
101
Akron6bf3cc92019-02-07 12:11:20 +0100102$meta = $doc->meta;
103is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http://de.wikipedia.org/wiki/Wolfgang_Krebs_(Schauspieler)', 'link');
104
Akron6f9fef52016-11-03 17:06:40 +0100105# Get tokenization
106$tokens = KorAP::XML::Tokenizer->new(
107 path => $doc->path,
108 doc => $doc,
109 foundry => 'Base',
110 layer => 'tokens_aggr',
111 name => 'tokens'
112);
113ok($tokens, 'Token Object is fine');
114ok($tokens->parse, 'Token parsing is fine');
115
116is($tokens->foundry, 'Base', 'Foundry');
117is($tokens->layer, 'tokens_aggr', 'Layer');
118
Akron6f9fef52016-11-03 17:06:40 +0100119ok($tokens->add('CoreNLP', 'Constituency'), 'Add Structure');
120
121$output = $tokens->to_data;
122
123is($output->{data}->{foundries}, 'corenlp corenlp/constituency', 'Foundries');
124is($output->{data}->{layerInfos}, 'corenlp/c=spans', 'layerInfos');
Akron5eb3aa02019-01-25 18:30:47 +0100125is($doc->meta->{A_editor}, 'wikipedia.org', 'Editor');
Akron6f9fef52016-11-03 17:06:40 +0100126
Akron56dfb312017-11-23 18:37:35 +0100127
128# Check offset problem
129$path = catdir(dirname(__FILE__), '../corpus/WPD15/U43/34816');
130ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
131ok($doc->parse, 'Parse document');
132
133is($doc->text_sigle, 'WPD15/U43/34816', 'Correct text sigle');
134
Akron6bf3cc92019-02-07 12:11:20 +0100135$meta = $doc->meta;
136is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http://de.wikipedia.org/wiki/Universitätsbibliothek_Augsburg', 'link');
137
Akron56dfb312017-11-23 18:37:35 +0100138# Tokenization
139use_ok('KorAP::XML::Tokenizer');
140
141$token_base_foundry = 'Base';
142
143# Get tokenization
144$tokens = KorAP::XML::Tokenizer->new(
145 path => $doc->path,
146 doc => $doc,
147 foundry => $token_base_foundry,
148 layer => $token_base_layer,
149 name => 'tokens'
150);
151ok($tokens, 'Token Object is fine');
152ok($tokens->parse, 'Token parsing is fine');
153
154$output = $tokens->to_data;
155$stream = $tokens->to_data->{data}->{stream};
156
157is($stream->[420]->[-1], 's:online', 'online');
158is($stream->[421]->[-1], 's:verfügbar', 'verfügbar');
159
Akrond3a0bad2016-02-26 14:07:58 +0100160done_testing;
161__END__
162
163
164
165