blob: acda3b6a21c1929bd8fdc9623da93c5c2f93cafa [file] [log] [blame]
Akron1924bbe2016-06-22 16:05:41 +02001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
Akron1924bbe2016-06-22 16:05:41 +02006
Akronfab17d32020-07-31 14:38:29 +02007if ($ENV{SKIP_REAL}) {
8 plan skip_all => 'Skip real tests';
9};
10
Akron1924bbe2016-06-22 16:05:41 +020011use utf8;
12use lib 'lib', '../lib';
13
14use File::Basename 'dirname';
15use File::Spec::Functions 'catdir';
16
17use_ok('KorAP::XML::Krill');
18
Akron414ec952020-08-03 15:48:43 +020019my $path = catdir(dirname(__FILE__), 'corpus','REI','BNG','00128');
Akron1924bbe2016-06-22 16:05:41 +020020
21ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
22ok($doc->parse, 'Parse document');
23
24is($doc->text_sigle, 'REI/BNG/00128', 'Correct text sigle');
25is($doc->doc_sigle, 'REI/BNG', 'Correct document sigle');
26is($doc->corpus_sigle, 'REI', 'Correct corpus sigle');
27
28my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010029is($meta->{T_title}, 'Friedensgutachten der führenden Friedensforschungsinstitute', 'Title');
30is($meta->{T_sub_title}, 'Rede im Deutschen Bundestag am 14.06.2002', 'SubTitle');
31is($meta->{T_author}, 'Nachtwei, Winfried', 'Author');
32ok(!$meta->{A_editor}, 'Editor');
33is($meta->{S_pub_place}, 'Berlin', 'PubPlace');
34ok(!$meta->{A_publisher}, 'Publisher');
Akron1924bbe2016-06-22 16:05:41 +020035
Akron5eb3aa02019-01-25 18:30:47 +010036ok(!$meta->{S_text_type}, 'No Text Type');
37ok(!$meta->{S_text_type_art}, 'No Text Type Art');
38ok(!$meta->{S_text_type_ref}, 'No Text Type Ref');
39ok(!$meta->{S_text_domain}, 'No Text Domain');
40ok(!$meta->{S_text_column}, 'No Text Column');
Akron1924bbe2016-06-22 16:05:41 +020041
Akron5eb3aa02019-01-25 18:30:47 +010042is($meta->{K_text_class}->[0], 'politik', 'Correct Text Class');
43is($meta->{K_text_class}->[1], 'inland', 'Correct Text Class');
44ok(!$meta->{K_text_class}->[2], 'Correct Text Class');
Akron1924bbe2016-06-22 16:05:41 +020045
Akron5eb3aa02019-01-25 18:30:47 +010046is($meta->{D_pub_date}, '20020614', 'Creation date');
47is($meta->{D_creation_date}, '20020614', 'Creation date');
48is($meta->{S_availability}, 'CC-BY-SA', 'License');
49ok(!$meta->{A_pages}, 'Pages');
Akron1924bbe2016-06-22 16:05:41 +020050
Akron5eb3aa02019-01-25 18:30:47 +010051ok(!$meta->{A_file_edition_statement}, 'File Statement');
52ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement');
Akron1924bbe2016-06-22 16:05:41 +020053
Akron5eb3aa02019-01-25 18:30:47 +010054is($meta->{A_reference} . "\n", <<'REF', 'Reference');
Akron1924bbe2016-06-22 16:05:41 +020055Nachtwei, 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]
56REF
Akron5eb3aa02019-01-25 18:30:47 +010057is($meta->{S_language}, 'de', 'Language');
Akron1924bbe2016-06-22 16:05:41 +020058
Akron5eb3aa02019-01-25 18:30:47 +010059is($meta->{T_corpus_title}, 'Reden und Interviews', 'Correct Corpus title');
60ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title');
61ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
62ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akron1924bbe2016-06-22 16:05:41 +020063
Akron5eb3aa02019-01-25 18:30:47 +010064is($meta->{T_doc_title}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Correct Doc title');
65ok(!$meta->{T_doc_sub_title}, 'Correct Doc sub title');
66ok(!$meta->{T_doc_author}, 'Correct Doc author');
67ok(!$meta->{A_doc_editor}, 'Correct doc editor');
Akron1924bbe2016-06-22 16:05:41 +020068
69# Tokenization
70use_ok('KorAP::XML::Tokenizer');
71
72my ($token_base_foundry, $token_base_layer) = (qw/Base tokens_conservative/);
73
74# Get tokenization
75my $tokens = KorAP::XML::Tokenizer->new(
76 path => $doc->path,
77 doc => $doc,
78 foundry => $token_base_foundry,
79 layer => $token_base_layer,
80 name => 'tokens'
81);
82
83ok($tokens, 'Token Object is fine');
84ok($tokens->parse, 'Token parsing is fine');
85
86my $output = decode_json( $tokens->to_json );
87
88is(substr($output->{data}->{text}, 0, 100), 'Winfried Nachtwei, Friedensgutachten der führenden Friedensforschungsinstitute 14. Juni 2002 Vizeprä', 'Primary Data');
89
90is($output->{data}->{name}, 'tokens', 'tokenName');
91is($output->{data}->{tokenSource}, 'base#tokens_conservative', 'tokenSource');
92is($output->{version}, '0.03', 'version');
93
94is($output->{data}->{foundries}, '', 'Foundries');
95is($output->{data}->{layerInfos}, '', 'layerInfos');
96is($output->{data}->{stream}->[0]->[4], 's:Winfried', 'data');
97
98is($output->{textSigle}, 'REI/BNG/00128', 'Correct text sigle');
99is($output->{docSigle}, 'REI/BNG', 'Correct document sigle');
100is($output->{corpusSigle}, 'REI', 'Correct corpus sigle');
101
102is($output->{title}, 'Friedensgutachten der führenden Friedensforschungsinstitute', 'Title');
103is($output->{subTitle}, 'Rede im Deutschen Bundestag am 14.06.2002', 'Correct SubTitle');
104is($output->{author}, 'Nachtwei, Winfried', 'Author');
105ok(!exists $output->{editor}, 'Publisher');
106
107is($output->{pubPlace}, 'Berlin', 'PubPlace');
108ok(!exists $output->{publisher}, 'Publisher');
109
110ok(!exists $output->{textType}, 'Correct Text Type');
111ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
112ok(!exists $output->{textTypeRef}, 'Correct Text Type Ref');
113ok(!exists $output->{textDomain}, 'Correct Text Domain');
114
115is($output->{creationDate}, '20020614', 'Creation date');
116is($output->{availability}, 'CC-BY-SA', 'License');
117
118ok(!exists $output->{pages}, 'Pages');
119ok(!exists $output->{fileEditionStatement}, 'File Statement');
120ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
121
122is($output->{reference} . "\n", <<'REF', 'Reference');
123Nachtwei, 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]
124REF
125is($output->{language}, 'de', 'Language');
126
127is($output->{corpusTitle}, 'Reden und Interviews', 'Correct Corpus title');
128ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
129ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
130ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
131
132is($output->{docTitle}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Correct Doc title');
133ok(!exists $output->{docSubTitle}, 'Correct Doc sub title');
134ok(!exists $output->{docAuthor}, 'Correct Doc author');
135ok(!exists $output->{docEditor}, 'Correct doc editor');
136
137## Base
138$tokens->add('Base', 'Sentences');
139$tokens->add('Base', 'Paragraphs');
140
141$output = decode_json( $tokens->to_json );
142
143is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
144is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
145my $first_token = join('||', @{$output->{data}->{stream}->[0]});
146like($first_token, qr/s:Winfried/, 'data');
147like($first_token, qr/_0\$<i>0<i>8/, 'data');
148
149
Akrona5920b12016-06-29 18:51:21 +0200150# REI/RBR/00610
Akron414ec952020-08-03 15:48:43 +0200151$path = catdir(dirname(__FILE__), 'corpus','REI','RBR','00610');
Akrona5920b12016-06-29 18:51:21 +0200152
153ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
154ok($doc->parse, 'Parse document');
155
156# Get tokenization
157$tokens = KorAP::XML::Tokenizer->new(
158 path => $doc->path,
159 doc => $doc,
160 foundry => $token_base_foundry,
161 layer => $token_base_layer,
162 name => 'tokens'
163);
164
165ok($tokens, 'Token Object is fine');
166ok($tokens->parse, 'Token parsing is fine');
167
168# Add annotations
169$tokens->add('Base', 'Sentences');
170$tokens->add('Base', 'Paragraphs');
171
172$tokens->add('CoreNLP', 'Constituency');
173$tokens->add('CoreNLP', 'Morpho');
174$tokens->add('CoreNLP', 'Sentences');
175
176$tokens->add('Malt', 'Dependency');
177
178$tokens->add('OpenNLP', 'Morpho');
179$tokens->add('OpenNLP', 'Sentences');
180
181$tokens->add('DeReKo', 'Structure');
182
183$tokens->add('TreeTagger', 'Morpho');
184$tokens->add('TreeTagger', 'Sentences');
185
186$output = decode_json( $tokens->to_json );
187
188my $first = $output->{data}->{stream}->[0];
189is('-:base/paragraphs$<i>31', $first->[0]);
190is('-:base/sentences$<i>168', $first->[1]);
191is('-:corenlp/sentences$<i>175', $first->[2]);
192is('-:opennlp/sentences$<i>169', $first->[3]);
193is('-:tokens$<i>2641', $first->[4]);
194is('-:tt/sentences$<i>196', $first->[5]);
195is('<:malt/d:PP$<b>32<i>4', $first->[6]);
196is('<>:corenlp/c:ROOT$<b>64<i>0<i>48<i>7<b>0', $first->[7]);
197is('<>:corenlp/s:s$<b>64<i>0<i>48<i>7<b>0', $first->[8]);
198is('<>:opennlp/s:s$<b>64<i>0<i>48<i>7<b>0', $first->[9]);
199is('<>:tt/s:s$<b>64<i>0<i>48<i>7<b>0', $first->[10]);
200is('<>:corenlp/c:S$<b>64<i>0<i>48<i>7<b>1', $first->[11]);
201is('<>:dereko/s:front$<b>64<i>0<i>91<i>11<b>1', $first->[12]);
202is('<>:base/s:s$<b>64<i>0<i>91<i>11<b>2', $first->[13]);
203is('<>:dereko/s:titlePage$<b>64<i>0<i>91<i>11<b>2<s>1', $first->[14]);
204is('<>:dereko/s:docTitle$<b>64<i>0<i>91<i>11<b>3', $first->[15]);
205is('<>:dereko/s:titlePart$<b>64<i>0<i>91<i>11<b>4<s>2', $first->[16]);
206is('<>:dereko/s:s$<b>64<i>0<i>91<i>11<b>5', $first->[17]);
Akrondec43122020-03-03 11:22:25 +0100207is('<>:base/s:t$<b>64<i>0<i>17859<i>2641<b>0', $first->[18]);
Akrona5920b12016-06-29 18:51:21 +0200208is('>:malt/d:ROOT$<b>33<i>0<i>48<i>0<i>7', $first->[19]);
209is('<:malt/d:PP$<b>32<i>1', $first->[20]);
210is('<:malt/d:ROOT$<b>34<i>0<i>48<i>7<i>0', $first->[21]);
211is('@:dereko/s:id:rbr.00610-0-titlepage$<b>17<s>1<i>11', $first->[22]);
212is('@:dereko/s:type:unspecified$<b>17<s>2<i>11', $first->[23]);
213is('_0$<i>0<i>4', $first->[24]);
214is('corenlp/p:NN', $first->[25]);
215is('i:rede', $first->[26]);
216is('opennlp/p:NN', $first->[27]);
217is('s:Rede', $first->[28]);
Akron28dc17f2018-02-01 15:31:41 +0100218is('tt/l:Rede$<b>129<b>253', $first->[29]);
Akrona5920b12016-06-29 18:51:21 +0200219is('tt/p:NN$<b>129<b>253', $first->[30]);
220
221my $last = $output->{data}->{stream}->[-1];
222
Akronb62d92a2020-03-01 16:32:00 +0100223# Milestones behind the final token are no longer indexed
224# is('<>:dereko/s:text$<b>65<i>17859<i>17859<i>2640<b>0', $last->[0]);
225# is('<>:dereko/s:back$<b>65<i>17859<i>17859<i>2640<b>1', $last->[1]);
226is('>:malt/d:APP$<b>32<i>2639', $last->[0]);
227is('_2640$<i>17851<i>17859', $last->[1]);
228is('corenlp/p:NE', $last->[2]);
229is("i:schr\x{f6}der", $last->[3]);
230is('opennlp/p:NE', $last->[4]);
231is("s:Schr\x{f6}der", $last->[5]);
232is("tt/l:Schr\x{f6}der", $last->[6]);
233is('tt/p:NE', $last->[7]);
Akrona5920b12016-06-29 18:51:21 +0200234
235
236# REI/BNG/00071
Akron414ec952020-08-03 15:48:43 +0200237$path = catdir(dirname(__FILE__), 'corpus','REI','BNG','00071');
Akrona5920b12016-06-29 18:51:21 +0200238
239ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
240ok($doc->parse, 'Parse document');
241
242# Get tokenization
243$tokens = KorAP::XML::Tokenizer->new(
244 path => $doc->path,
245 doc => $doc,
246 foundry => $token_base_foundry,
247 layer => $token_base_layer,
248 name => 'tokens'
249);
250
251ok($tokens, 'Token Object is fine');
252ok($tokens->parse, 'Token parsing is fine');
253
254# Add annotations
255$tokens->add('Base', 'Sentences');
256$tokens->add('Base', 'Paragraphs');
257
258$tokens->add('CoreNLP', 'Constituency');
259$tokens->add('CoreNLP', 'Morpho');
260$tokens->add('CoreNLP', 'Sentences');
261
262$tokens->add('Malt', 'Dependency');
263
264$tokens->add('OpenNLP', 'Morpho');
265$tokens->add('OpenNLP', 'Sentences');
266
267$tokens->add('DeReKo', 'Structure');
268
269$tokens->add('TreeTagger', 'Morpho');
270$tokens->add('TreeTagger', 'Sentences');
271
272$output = decode_json( $tokens->to_json );
273
274$first = $output->{data}->{stream}->[0];
275
276is('-:base/paragraphs$<i>41', $first->[0]);
277is('-:base/sentences$<i>73', $first->[1]);
278is('-:corenlp/sentences$<i>69', $first->[2]);
279is('-:opennlp/sentences$<i>65', $first->[3]);
280is('-:tokens$<i>1009', $first->[4]);
Akronb62d92a2020-03-01 16:32:00 +0100281is('-:tt/sentences$<i>94', $first->[5]);
Akrona5920b12016-06-29 18:51:21 +0200282is('<:malt/d:APP$<b>32<i>1', $first->[6]);
283is('<>:corenlp/c:MPN$<b>64<i>0<i>16<i>2<b>3', $first->[7]);
284is('<>:base/s:s$<b>64<i>0<i>48<i>5<b>2', $first->[8]);
285is('<>:dereko/s:titlePart$<b>64<i>0<i>48<i>5<b>4<s>2', $first->[9]);
286is('<>:dereko/s:s$<b>64<i>0<i>48<i>5<b>5', $first->[10]);
287is('<>:corenlp/c:ROOT$<b>64<i>0<i>51<i>6<b>0', $first->[11]);
288is('<>:corenlp/s:s$<b>64<i>0<i>51<i>6<b>0', $first->[12]);
289is('<>:tt/s:s$<b>64<i>0<i>51<i>6<b>0', $first->[13]);
290is('<>:corenlp/c:NUR$<b>64<i>0<i>51<i>6<b>1', $first->[14]);
291is('<>:corenlp/c:NP$<b>64<i>0<i>50<i>6<b>2', $first->[15]);
292is('<>:dereko/s:front$<b>64<i>0<i>61<i>8<b>1', $first->[16]);
293is('<>:dereko/s:titlePage$<b>64<i>0<i>61<i>8<b>2<s>1', $first->[17]);
294is('<>:dereko/s:docTitle$<b>64<i>0<i>61<i>8<b>3', $first->[18]);
295is('<>:opennlp/s:s$<b>64<i>0<i>173<i>24<b>0', $first->[19]);
Akrondec43122020-03-03 11:22:25 +0100296is('<>:base/s:t$<b>64<i>0<i>7008<i>1009<b>0', $first->[20]);
297is('<>:dereko/s:text$<b>64<i>0<i>7008<i>1009<b>0', $first->[21]);
Akrona5920b12016-06-29 18:51:21 +0200298is('>:malt/d:GMOD$<b>32<i>3', $first->[22]);
299is('<:malt/d:ROOT$<b>34<i>0<i>51<i>6<i>3', $first->[23]);
300is('@:dereko/s:id:bng.00071-0-titlepage$<b>17<s>1<i>8', $first->[24]);
301is('@:dereko/s:type:unspecified$<b>17<s>2<i>5', $first->[25]);
302is('_0$<i>0<i>9', $first->[26]);
303is('corenlp/p:NE', $first->[27]);
304is('i:christine', $first->[28]);
305is('opennlp/p:NE', $first->[29]);
306is('s:Christine', $first->[30]);
Akron04261762018-01-29 20:16:39 +0100307is('tt/l:Christine', $first->[31]);
Akron28dc17f2018-02-01 15:31:41 +0100308is('tt/p:NE', $first->[32]);
Akrona5920b12016-06-29 18:51:21 +0200309
310$last = $output->{data}->{stream}->[-1];
Akrondec43122020-03-03 11:22:25 +0100311# No longer indexed:
312#is('<>:dereko/s:back$<b>65<i>7008<i>7008<i>1009<b>1', $last->[0]);
313#is('<>:dereko/s:div$<b>65<i>7008<i>7008<i>1009<b>2<s>1', $last->[1]);
314#is('@:dereko/s:n:1$<b>17<s>1', $last->[2]);
315#is('@:dereko/s:type:footnotes$<b>17<s>1', $last->[3]);
316#is('@:dereko/s:complete:y$<b>17<s>1', $last->[4]);
317is('_1008$<i>6990<i>7006', $last->[0]);
318is('corenlp/p:NN', $last->[1]);
319is('i:befreiungsschlag', $last->[2]);
320is('opennlp/p:NN', $last->[3]);
321is('s:Befreiungsschlag', $last->[4]);
Akrona5920b12016-06-29 18:51:21 +0200322
Akron0ffbd522021-02-16 12:01:19 +0100323
324# Check with negative level (required for wikidemo conversion)
325$path = catdir(dirname(__FILE__), 'corpus','REI','RBP','00007');
326
327ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
328ok($doc->parse, 'Parse document');
329
330is($doc->text_sigle, 'REI/RBP/00007', 'Correct text sigle');
331is($doc->doc_sigle, 'REI/RBP', 'Correct document sigle');
332is($doc->corpus_sigle, 'REI', 'Correct corpus sigle');
333
334$meta = $doc->meta;
335is($meta->{T_title}, 'Ansprache von Bundespräsident Richard von Weizsäcker bei einem Abendessen, gegeben von Königin Beatrix und Prinz Claus im Königlichen Palais Op de Dam', 'Title');
336ok(!$meta->{T_sub_title}, 'SubTitle');
337is($meta->{T_author}, 'Richard von Weizsäcker', 'Author');
338ok(!$meta->{A_editor}, 'Editor');
339is($meta->{S_pub_place}, 'Bonnn', 'PubPlace'); # sic!
340ok(!$meta->{A_publisher}, 'Publisher');
341
342ok(!$meta->{S_text_type}, 'No Text Type');
343ok(!$meta->{S_text_type_art}, 'No Text Type Art');
344ok(!$meta->{S_text_type_ref}, 'No Text Type Ref');
345ok(!$meta->{S_text_domain}, 'No Text Domain');
346ok(!$meta->{S_text_column}, 'No Text Column');
347
348is($meta->{K_text_class}->[0], 'politik', 'Correct Text Class');
349is($meta->{K_text_class}->[1], 'ausland', 'Correct Text Class');
350ok(!$meta->{K_text_class}->[2], 'Correct Text Class');
351
352is($meta->{D_pub_date}, '19850530', 'Creation date');
353is($meta->{D_creation_date}, '19850530', 'Creation date');
354is($meta->{S_availability}, 'CC-BY-SA', 'License');
355ok(!$meta->{A_pages}, 'Pages');
356
357ok(!$meta->{A_file_edition_statement}, 'File Statement');
358ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement');
359
360# Get tokenization
361$tokens = KorAP::XML::Tokenizer->new(
362 path => $doc->path,
363 doc => $doc,
364 foundry => $token_base_foundry,
365 layer => 'tokens',
366 name => 'tokens'
367);
368
369ok($tokens, 'Token Object is fine');
370ok($tokens->parse, 'Token parsing is fine');
371ok(!$tokens->error);
372
373$tokens->add('DeReKo', 'Structure', 'base-sentences-paragraphs-pagebreaks');
374ok(!$tokens->error);
375
376$output = decode_json( $tokens->to_json );
377
378is(substr($output->{data}->{text}, 0, 100), 'Ansprache von Bundespräsident Richard von Weizsäcker bei einem Abendessen, gegeben von Königin Beatr', 'Primary Data');
379
380is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base-sentences-paragraphs-pagebreaks', 'Foundries');
381is($output->{data}->{layerInfos}, 'dereko/s=spans', 'layerInfos');
382
383my $stream = $output->{data}->{stream};
384
385is($stream->[0]->[0], '-:base/paragraphs$<i>3');
386is($stream->[0]->[1], '-:base/sentences$<i>16');
387is($stream->[0]->[2], '-:tokens$<i>418');
388is($stream->[0]->[7], '<>:base/s:s$<b>64<i>0<i>353<i>53<b>2');
389is($stream->[0]->[8], '<>:base/s:t$<b>64<i>0<i>2664<i>418<b>0');
390
391is(index(join('',@{$stream->[0]}), '<>:dereko/s:s$'), -1);
392
Akron1924bbe2016-06-22 16:05:41 +0200393done_testing;
394__END__