blob: ab3df72855a4217bd759d45e8d2f4d7c84f79f7a [file] [log] [blame]
Akron1924bbe2016-06-22 16:05:41 +02001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
Akrona5920b12016-06-29 18:51:21 +02006use Log::Log4perl;
Akron1924bbe2016-06-22 16:05:41 +02007
Akronfab17d32020-07-31 14:38:29 +02008if ($ENV{SKIP_REAL}) {
9 plan skip_all => 'Skip real tests';
10};
11
Akron1924bbe2016-06-22 16:05:41 +020012use utf8;
13use lib 'lib', '../lib';
14
15use File::Basename 'dirname';
16use File::Spec::Functions 'catdir';
17
Akrona5920b12016-06-29 18:51:21 +020018# Initialize log4perl object
19Log::Log4perl->init({
20 'log4perl.rootLogger' => 'ERROR, STDERR',
21 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
22 'log4perl.appender.STDERR.layout' => 'PatternLayout',
23 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
24});
25
Akron1924bbe2016-06-22 16:05:41 +020026use_ok('KorAP::XML::Krill');
27
Akron414ec952020-08-03 15:48:43 +020028my $path = catdir(dirname(__FILE__), 'corpus','REI','BNG','00128');
Akron1924bbe2016-06-22 16:05:41 +020029
30ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
31ok($doc->parse, 'Parse document');
32
33is($doc->text_sigle, 'REI/BNG/00128', 'Correct text sigle');
34is($doc->doc_sigle, 'REI/BNG', 'Correct document sigle');
35is($doc->corpus_sigle, 'REI', 'Correct corpus sigle');
36
37my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010038is($meta->{T_title}, 'Friedensgutachten der führenden Friedensforschungsinstitute', 'Title');
39is($meta->{T_sub_title}, 'Rede im Deutschen Bundestag am 14.06.2002', 'SubTitle');
40is($meta->{T_author}, 'Nachtwei, Winfried', 'Author');
41ok(!$meta->{A_editor}, 'Editor');
42is($meta->{S_pub_place}, 'Berlin', 'PubPlace');
43ok(!$meta->{A_publisher}, 'Publisher');
Akron1924bbe2016-06-22 16:05:41 +020044
Akron5eb3aa02019-01-25 18:30:47 +010045ok(!$meta->{S_text_type}, 'No Text Type');
46ok(!$meta->{S_text_type_art}, 'No Text Type Art');
47ok(!$meta->{S_text_type_ref}, 'No Text Type Ref');
48ok(!$meta->{S_text_domain}, 'No Text Domain');
49ok(!$meta->{S_text_column}, 'No Text Column');
Akron1924bbe2016-06-22 16:05:41 +020050
Akron5eb3aa02019-01-25 18:30:47 +010051is($meta->{K_text_class}->[0], 'politik', 'Correct Text Class');
52is($meta->{K_text_class}->[1], 'inland', 'Correct Text Class');
53ok(!$meta->{K_text_class}->[2], 'Correct Text Class');
Akron1924bbe2016-06-22 16:05:41 +020054
Akron5eb3aa02019-01-25 18:30:47 +010055is($meta->{D_pub_date}, '20020614', 'Creation date');
56is($meta->{D_creation_date}, '20020614', 'Creation date');
57is($meta->{S_availability}, 'CC-BY-SA', 'License');
58ok(!$meta->{A_pages}, 'Pages');
Akron1924bbe2016-06-22 16:05:41 +020059
Akron5eb3aa02019-01-25 18:30:47 +010060ok(!$meta->{A_file_edition_statement}, 'File Statement');
61ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement');
Akron1924bbe2016-06-22 16:05:41 +020062
Akron5eb3aa02019-01-25 18:30:47 +010063is($meta->{A_reference} . "\n", <<'REF', 'Reference');
Akron1924bbe2016-06-22 16:05:41 +020064Nachtwei, Winfried: Friedensgutachten der führenden Friedensforschungsinstitute. Rede im Deutschen Bundestag am 14.06.2002, Hrsg: Bundestagsfraktion Bündnis 90/DIE GRÜNEN [Ausführliche Zitierung nicht verfügbar]
65REF
Akron5eb3aa02019-01-25 18:30:47 +010066is($meta->{S_language}, 'de', 'Language');
Akron1924bbe2016-06-22 16:05:41 +020067
Akron5eb3aa02019-01-25 18:30:47 +010068is($meta->{T_corpus_title}, 'Reden und Interviews', 'Correct Corpus title');
69ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title');
70ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
71ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akron1924bbe2016-06-22 16:05:41 +020072
Akron5eb3aa02019-01-25 18:30:47 +010073is($meta->{T_doc_title}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Correct Doc title');
74ok(!$meta->{T_doc_sub_title}, 'Correct Doc sub title');
75ok(!$meta->{T_doc_author}, 'Correct Doc author');
76ok(!$meta->{A_doc_editor}, 'Correct doc editor');
Akron1924bbe2016-06-22 16:05:41 +020077
78# Tokenization
79use_ok('KorAP::XML::Tokenizer');
80
81my ($token_base_foundry, $token_base_layer) = (qw/Base tokens_conservative/);
82
83# Get tokenization
84my $tokens = KorAP::XML::Tokenizer->new(
85 path => $doc->path,
86 doc => $doc,
87 foundry => $token_base_foundry,
88 layer => $token_base_layer,
89 name => 'tokens'
90);
91
92ok($tokens, 'Token Object is fine');
93ok($tokens->parse, 'Token parsing is fine');
94
95my $output = decode_json( $tokens->to_json );
96
97is(substr($output->{data}->{text}, 0, 100), 'Winfried Nachtwei, Friedensgutachten der führenden Friedensforschungsinstitute 14. Juni 2002 Vizeprä', 'Primary Data');
98
99is($output->{data}->{name}, 'tokens', 'tokenName');
100is($output->{data}->{tokenSource}, 'base#tokens_conservative', 'tokenSource');
101is($output->{version}, '0.03', 'version');
102
103is($output->{data}->{foundries}, '', 'Foundries');
104is($output->{data}->{layerInfos}, '', 'layerInfos');
105is($output->{data}->{stream}->[0]->[4], 's:Winfried', 'data');
106
107is($output->{textSigle}, 'REI/BNG/00128', 'Correct text sigle');
108is($output->{docSigle}, 'REI/BNG', 'Correct document sigle');
109is($output->{corpusSigle}, 'REI', 'Correct corpus sigle');
110
111is($output->{title}, 'Friedensgutachten der führenden Friedensforschungsinstitute', 'Title');
112is($output->{subTitle}, 'Rede im Deutschen Bundestag am 14.06.2002', 'Correct SubTitle');
113is($output->{author}, 'Nachtwei, Winfried', 'Author');
114ok(!exists $output->{editor}, 'Publisher');
115
116is($output->{pubPlace}, 'Berlin', 'PubPlace');
117ok(!exists $output->{publisher}, 'Publisher');
118
119ok(!exists $output->{textType}, 'Correct Text Type');
120ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
121ok(!exists $output->{textTypeRef}, 'Correct Text Type Ref');
122ok(!exists $output->{textDomain}, 'Correct Text Domain');
123
124is($output->{creationDate}, '20020614', 'Creation date');
125is($output->{availability}, 'CC-BY-SA', 'License');
126
127ok(!exists $output->{pages}, 'Pages');
128ok(!exists $output->{fileEditionStatement}, 'File Statement');
129ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
130
131is($output->{reference} . "\n", <<'REF', 'Reference');
132Nachtwei, Winfried: Friedensgutachten der führenden Friedensforschungsinstitute. Rede im Deutschen Bundestag am 14.06.2002, Hrsg: Bundestagsfraktion Bündnis 90/DIE GRÜNEN [Ausführliche Zitierung nicht verfügbar]
133REF
134is($output->{language}, 'de', 'Language');
135
136is($output->{corpusTitle}, 'Reden und Interviews', 'Correct Corpus title');
137ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
138ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
139ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
140
141is($output->{docTitle}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Correct Doc title');
142ok(!exists $output->{docSubTitle}, 'Correct Doc sub title');
143ok(!exists $output->{docAuthor}, 'Correct Doc author');
144ok(!exists $output->{docEditor}, 'Correct doc editor');
145
146## Base
147$tokens->add('Base', 'Sentences');
148$tokens->add('Base', 'Paragraphs');
149
150$output = decode_json( $tokens->to_json );
151
152is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
153is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
154my $first_token = join('||', @{$output->{data}->{stream}->[0]});
155like($first_token, qr/s:Winfried/, 'data');
156like($first_token, qr/_0\$<i>0<i>8/, 'data');
157
158
Akrona5920b12016-06-29 18:51:21 +0200159# REI/RBR/00610
Akron414ec952020-08-03 15:48:43 +0200160$path = catdir(dirname(__FILE__), 'corpus','REI','RBR','00610');
Akrona5920b12016-06-29 18:51:21 +0200161
162ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
163ok($doc->parse, 'Parse document');
164
165# Get tokenization
166$tokens = KorAP::XML::Tokenizer->new(
167 path => $doc->path,
168 doc => $doc,
169 foundry => $token_base_foundry,
170 layer => $token_base_layer,
171 name => 'tokens'
172);
173
174ok($tokens, 'Token Object is fine');
175ok($tokens->parse, 'Token parsing is fine');
176
177# Add annotations
178$tokens->add('Base', 'Sentences');
179$tokens->add('Base', 'Paragraphs');
180
181$tokens->add('CoreNLP', 'Constituency');
182$tokens->add('CoreNLP', 'Morpho');
183$tokens->add('CoreNLP', 'Sentences');
184
185$tokens->add('Malt', 'Dependency');
186
187$tokens->add('OpenNLP', 'Morpho');
188$tokens->add('OpenNLP', 'Sentences');
189
190$tokens->add('DeReKo', 'Structure');
191
192$tokens->add('TreeTagger', 'Morpho');
193$tokens->add('TreeTagger', 'Sentences');
194
195$output = decode_json( $tokens->to_json );
196
197my $first = $output->{data}->{stream}->[0];
198is('-:base/paragraphs$<i>31', $first->[0]);
199is('-:base/sentences$<i>168', $first->[1]);
200is('-:corenlp/sentences$<i>175', $first->[2]);
201is('-:opennlp/sentences$<i>169', $first->[3]);
202is('-:tokens$<i>2641', $first->[4]);
203is('-:tt/sentences$<i>196', $first->[5]);
204is('<:malt/d:PP$<b>32<i>4', $first->[6]);
205is('<>:corenlp/c:ROOT$<b>64<i>0<i>48<i>7<b>0', $first->[7]);
206is('<>:corenlp/s:s$<b>64<i>0<i>48<i>7<b>0', $first->[8]);
207is('<>:opennlp/s:s$<b>64<i>0<i>48<i>7<b>0', $first->[9]);
208is('<>:tt/s:s$<b>64<i>0<i>48<i>7<b>0', $first->[10]);
209is('<>:corenlp/c:S$<b>64<i>0<i>48<i>7<b>1', $first->[11]);
210is('<>:dereko/s:front$<b>64<i>0<i>91<i>11<b>1', $first->[12]);
211is('<>:base/s:s$<b>64<i>0<i>91<i>11<b>2', $first->[13]);
212is('<>:dereko/s:titlePage$<b>64<i>0<i>91<i>11<b>2<s>1', $first->[14]);
213is('<>:dereko/s:docTitle$<b>64<i>0<i>91<i>11<b>3', $first->[15]);
214is('<>:dereko/s:titlePart$<b>64<i>0<i>91<i>11<b>4<s>2', $first->[16]);
215is('<>:dereko/s:s$<b>64<i>0<i>91<i>11<b>5', $first->[17]);
Akrondec43122020-03-03 11:22:25 +0100216is('<>:base/s:t$<b>64<i>0<i>17859<i>2641<b>0', $first->[18]);
Akrona5920b12016-06-29 18:51:21 +0200217is('>:malt/d:ROOT$<b>33<i>0<i>48<i>0<i>7', $first->[19]);
218is('<:malt/d:PP$<b>32<i>1', $first->[20]);
219is('<:malt/d:ROOT$<b>34<i>0<i>48<i>7<i>0', $first->[21]);
220is('@:dereko/s:id:rbr.00610-0-titlepage$<b>17<s>1<i>11', $first->[22]);
221is('@:dereko/s:type:unspecified$<b>17<s>2<i>11', $first->[23]);
222is('_0$<i>0<i>4', $first->[24]);
223is('corenlp/p:NN', $first->[25]);
224is('i:rede', $first->[26]);
225is('opennlp/p:NN', $first->[27]);
226is('s:Rede', $first->[28]);
Akron28dc17f2018-02-01 15:31:41 +0100227is('tt/l:Rede$<b>129<b>253', $first->[29]);
Akrona5920b12016-06-29 18:51:21 +0200228is('tt/p:NN$<b>129<b>253', $first->[30]);
229
230my $last = $output->{data}->{stream}->[-1];
231
Akronb62d92a2020-03-01 16:32:00 +0100232# Milestones behind the final token are no longer indexed
233# is('<>:dereko/s:text$<b>65<i>17859<i>17859<i>2640<b>0', $last->[0]);
234# is('<>:dereko/s:back$<b>65<i>17859<i>17859<i>2640<b>1', $last->[1]);
235is('>:malt/d:APP$<b>32<i>2639', $last->[0]);
236is('_2640$<i>17851<i>17859', $last->[1]);
237is('corenlp/p:NE', $last->[2]);
238is("i:schr\x{f6}der", $last->[3]);
239is('opennlp/p:NE', $last->[4]);
240is("s:Schr\x{f6}der", $last->[5]);
241is("tt/l:Schr\x{f6}der", $last->[6]);
242is('tt/p:NE', $last->[7]);
Akrona5920b12016-06-29 18:51:21 +0200243
244
245# REI/BNG/00071
Akron414ec952020-08-03 15:48:43 +0200246$path = catdir(dirname(__FILE__), 'corpus','REI','BNG','00071');
Akrona5920b12016-06-29 18:51:21 +0200247
248ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
249ok($doc->parse, 'Parse document');
250
251# Get tokenization
252$tokens = KorAP::XML::Tokenizer->new(
253 path => $doc->path,
254 doc => $doc,
255 foundry => $token_base_foundry,
256 layer => $token_base_layer,
257 name => 'tokens'
258);
259
260ok($tokens, 'Token Object is fine');
261ok($tokens->parse, 'Token parsing is fine');
262
263# Add annotations
264$tokens->add('Base', 'Sentences');
265$tokens->add('Base', 'Paragraphs');
266
267$tokens->add('CoreNLP', 'Constituency');
268$tokens->add('CoreNLP', 'Morpho');
269$tokens->add('CoreNLP', 'Sentences');
270
271$tokens->add('Malt', 'Dependency');
272
273$tokens->add('OpenNLP', 'Morpho');
274$tokens->add('OpenNLP', 'Sentences');
275
276$tokens->add('DeReKo', 'Structure');
277
278$tokens->add('TreeTagger', 'Morpho');
279$tokens->add('TreeTagger', 'Sentences');
280
281$output = decode_json( $tokens->to_json );
282
283$first = $output->{data}->{stream}->[0];
284
285is('-:base/paragraphs$<i>41', $first->[0]);
286is('-:base/sentences$<i>73', $first->[1]);
287is('-:corenlp/sentences$<i>69', $first->[2]);
288is('-:opennlp/sentences$<i>65', $first->[3]);
289is('-:tokens$<i>1009', $first->[4]);
Akronb62d92a2020-03-01 16:32:00 +0100290is('-:tt/sentences$<i>94', $first->[5]);
Akrona5920b12016-06-29 18:51:21 +0200291is('<:malt/d:APP$<b>32<i>1', $first->[6]);
292is('<>:corenlp/c:MPN$<b>64<i>0<i>16<i>2<b>3', $first->[7]);
293is('<>:base/s:s$<b>64<i>0<i>48<i>5<b>2', $first->[8]);
294is('<>:dereko/s:titlePart$<b>64<i>0<i>48<i>5<b>4<s>2', $first->[9]);
295is('<>:dereko/s:s$<b>64<i>0<i>48<i>5<b>5', $first->[10]);
296is('<>:corenlp/c:ROOT$<b>64<i>0<i>51<i>6<b>0', $first->[11]);
297is('<>:corenlp/s:s$<b>64<i>0<i>51<i>6<b>0', $first->[12]);
298is('<>:tt/s:s$<b>64<i>0<i>51<i>6<b>0', $first->[13]);
299is('<>:corenlp/c:NUR$<b>64<i>0<i>51<i>6<b>1', $first->[14]);
300is('<>:corenlp/c:NP$<b>64<i>0<i>50<i>6<b>2', $first->[15]);
301is('<>:dereko/s:front$<b>64<i>0<i>61<i>8<b>1', $first->[16]);
302is('<>:dereko/s:titlePage$<b>64<i>0<i>61<i>8<b>2<s>1', $first->[17]);
303is('<>:dereko/s:docTitle$<b>64<i>0<i>61<i>8<b>3', $first->[18]);
304is('<>:opennlp/s:s$<b>64<i>0<i>173<i>24<b>0', $first->[19]);
Akrondec43122020-03-03 11:22:25 +0100305is('<>:base/s:t$<b>64<i>0<i>7008<i>1009<b>0', $first->[20]);
306is('<>:dereko/s:text$<b>64<i>0<i>7008<i>1009<b>0', $first->[21]);
Akrona5920b12016-06-29 18:51:21 +0200307is('>:malt/d:GMOD$<b>32<i>3', $first->[22]);
308is('<:malt/d:ROOT$<b>34<i>0<i>51<i>6<i>3', $first->[23]);
309is('@:dereko/s:id:bng.00071-0-titlepage$<b>17<s>1<i>8', $first->[24]);
310is('@:dereko/s:type:unspecified$<b>17<s>2<i>5', $first->[25]);
311is('_0$<i>0<i>9', $first->[26]);
312is('corenlp/p:NE', $first->[27]);
313is('i:christine', $first->[28]);
314is('opennlp/p:NE', $first->[29]);
315is('s:Christine', $first->[30]);
Akron04261762018-01-29 20:16:39 +0100316is('tt/l:Christine', $first->[31]);
Akron28dc17f2018-02-01 15:31:41 +0100317is('tt/p:NE', $first->[32]);
Akrona5920b12016-06-29 18:51:21 +0200318
319$last = $output->{data}->{stream}->[-1];
Akrondec43122020-03-03 11:22:25 +0100320# No longer indexed:
321#is('<>:dereko/s:back$<b>65<i>7008<i>7008<i>1009<b>1', $last->[0]);
322#is('<>:dereko/s:div$<b>65<i>7008<i>7008<i>1009<b>2<s>1', $last->[1]);
323#is('@:dereko/s:n:1$<b>17<s>1', $last->[2]);
324#is('@:dereko/s:type:footnotes$<b>17<s>1', $last->[3]);
325#is('@:dereko/s:complete:y$<b>17<s>1', $last->[4]);
326is('_1008$<i>6990<i>7006', $last->[0]);
327is('corenlp/p:NN', $last->[1]);
328is('i:befreiungsschlag', $last->[2]);
329is('opennlp/p:NN', $last->[3]);
330is('s:Befreiungsschlag', $last->[4]);
Akrona5920b12016-06-29 18:51:21 +0200331
Akron1924bbe2016-06-22 16:05:41 +0200332done_testing;
333__END__