blob: b375c24a1680a1bd78b826fa34e59ab70d7f7938 [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
8use utf8;
9use lib 'lib', '../lib';
10
11use File::Basename 'dirname';
12use File::Spec::Functions 'catdir';
13
Akrona5920b12016-06-29 18:51:21 +020014# Initialize log4perl object
15Log::Log4perl->init({
16 'log4perl.rootLogger' => 'ERROR, STDERR',
17 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
18 'log4perl.appender.STDERR.layout' => 'PatternLayout',
19 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
20});
21
Akron1924bbe2016-06-22 16:05:41 +020022use_ok('KorAP::XML::Krill');
23
24my $path = catdir(dirname(__FILE__), '../corpus/REI/BNG/00128');
25
26ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
27ok($doc->parse, 'Parse document');
28
29is($doc->text_sigle, 'REI/BNG/00128', 'Correct text sigle');
30is($doc->doc_sigle, 'REI/BNG', 'Correct document sigle');
31is($doc->corpus_sigle, 'REI', 'Correct corpus sigle');
32
33my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010034is($meta->{T_title}, 'Friedensgutachten der führenden Friedensforschungsinstitute', 'Title');
35is($meta->{T_sub_title}, 'Rede im Deutschen Bundestag am 14.06.2002', 'SubTitle');
36is($meta->{T_author}, 'Nachtwei, Winfried', 'Author');
37ok(!$meta->{A_editor}, 'Editor');
38is($meta->{S_pub_place}, 'Berlin', 'PubPlace');
39ok(!$meta->{A_publisher}, 'Publisher');
Akron1924bbe2016-06-22 16:05:41 +020040
Akron5eb3aa02019-01-25 18:30:47 +010041ok(!$meta->{S_text_type}, 'No Text Type');
42ok(!$meta->{S_text_type_art}, 'No Text Type Art');
43ok(!$meta->{S_text_type_ref}, 'No Text Type Ref');
44ok(!$meta->{S_text_domain}, 'No Text Domain');
45ok(!$meta->{S_text_column}, 'No Text Column');
Akron1924bbe2016-06-22 16:05:41 +020046
Akron5eb3aa02019-01-25 18:30:47 +010047is($meta->{K_text_class}->[0], 'politik', 'Correct Text Class');
48is($meta->{K_text_class}->[1], 'inland', 'Correct Text Class');
49ok(!$meta->{K_text_class}->[2], 'Correct Text Class');
Akron1924bbe2016-06-22 16:05:41 +020050
Akron5eb3aa02019-01-25 18:30:47 +010051is($meta->{D_pub_date}, '20020614', 'Creation date');
52is($meta->{D_creation_date}, '20020614', 'Creation date');
53is($meta->{S_availability}, 'CC-BY-SA', 'License');
54ok(!$meta->{A_pages}, 'Pages');
Akron1924bbe2016-06-22 16:05:41 +020055
Akron5eb3aa02019-01-25 18:30:47 +010056ok(!$meta->{A_file_edition_statement}, 'File Statement');
57ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement');
Akron1924bbe2016-06-22 16:05:41 +020058
Akron5eb3aa02019-01-25 18:30:47 +010059is($meta->{A_reference} . "\n", <<'REF', 'Reference');
Akron1924bbe2016-06-22 16:05:41 +020060Nachtwei, 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]
61REF
Akron5eb3aa02019-01-25 18:30:47 +010062is($meta->{S_language}, 'de', 'Language');
Akron1924bbe2016-06-22 16:05:41 +020063
Akron5eb3aa02019-01-25 18:30:47 +010064is($meta->{T_corpus_title}, 'Reden und Interviews', 'Correct Corpus title');
65ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title');
66ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
67ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akron1924bbe2016-06-22 16:05:41 +020068
Akron5eb3aa02019-01-25 18:30:47 +010069is($meta->{T_doc_title}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Correct Doc title');
70ok(!$meta->{T_doc_sub_title}, 'Correct Doc sub title');
71ok(!$meta->{T_doc_author}, 'Correct Doc author');
72ok(!$meta->{A_doc_editor}, 'Correct doc editor');
Akron1924bbe2016-06-22 16:05:41 +020073
74# Tokenization
75use_ok('KorAP::XML::Tokenizer');
76
77my ($token_base_foundry, $token_base_layer) = (qw/Base tokens_conservative/);
78
79# Get tokenization
80my $tokens = KorAP::XML::Tokenizer->new(
81 path => $doc->path,
82 doc => $doc,
83 foundry => $token_base_foundry,
84 layer => $token_base_layer,
85 name => 'tokens'
86);
87
88ok($tokens, 'Token Object is fine');
89ok($tokens->parse, 'Token parsing is fine');
90
91my $output = decode_json( $tokens->to_json );
92
93is(substr($output->{data}->{text}, 0, 100), 'Winfried Nachtwei, Friedensgutachten der führenden Friedensforschungsinstitute 14. Juni 2002 Vizeprä', 'Primary Data');
94
95is($output->{data}->{name}, 'tokens', 'tokenName');
96is($output->{data}->{tokenSource}, 'base#tokens_conservative', 'tokenSource');
97is($output->{version}, '0.03', 'version');
98
99is($output->{data}->{foundries}, '', 'Foundries');
100is($output->{data}->{layerInfos}, '', 'layerInfos');
101is($output->{data}->{stream}->[0]->[4], 's:Winfried', 'data');
102
103is($output->{textSigle}, 'REI/BNG/00128', 'Correct text sigle');
104is($output->{docSigle}, 'REI/BNG', 'Correct document sigle');
105is($output->{corpusSigle}, 'REI', 'Correct corpus sigle');
106
107is($output->{title}, 'Friedensgutachten der führenden Friedensforschungsinstitute', 'Title');
108is($output->{subTitle}, 'Rede im Deutschen Bundestag am 14.06.2002', 'Correct SubTitle');
109is($output->{author}, 'Nachtwei, Winfried', 'Author');
110ok(!exists $output->{editor}, 'Publisher');
111
112is($output->{pubPlace}, 'Berlin', 'PubPlace');
113ok(!exists $output->{publisher}, 'Publisher');
114
115ok(!exists $output->{textType}, 'Correct Text Type');
116ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
117ok(!exists $output->{textTypeRef}, 'Correct Text Type Ref');
118ok(!exists $output->{textDomain}, 'Correct Text Domain');
119
120is($output->{creationDate}, '20020614', 'Creation date');
121is($output->{availability}, 'CC-BY-SA', 'License');
122
123ok(!exists $output->{pages}, 'Pages');
124ok(!exists $output->{fileEditionStatement}, 'File Statement');
125ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
126
127is($output->{reference} . "\n", <<'REF', 'Reference');
128Nachtwei, 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]
129REF
130is($output->{language}, 'de', 'Language');
131
132is($output->{corpusTitle}, 'Reden und Interviews', 'Correct Corpus title');
133ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
134ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
135ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
136
137is($output->{docTitle}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Correct Doc title');
138ok(!exists $output->{docSubTitle}, 'Correct Doc sub title');
139ok(!exists $output->{docAuthor}, 'Correct Doc author');
140ok(!exists $output->{docEditor}, 'Correct doc editor');
141
142## Base
143$tokens->add('Base', 'Sentences');
144$tokens->add('Base', 'Paragraphs');
145
146$output = decode_json( $tokens->to_json );
147
148is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
149is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
150my $first_token = join('||', @{$output->{data}->{stream}->[0]});
151like($first_token, qr/s:Winfried/, 'data');
152like($first_token, qr/_0\$<i>0<i>8/, 'data');
153
154
Akrona5920b12016-06-29 18:51:21 +0200155# REI/RBR/00610
156$path = catdir(dirname(__FILE__), '../corpus/REI/RBR/00610');
157
158ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
159ok($doc->parse, 'Parse document');
160
161# Get tokenization
162$tokens = KorAP::XML::Tokenizer->new(
163 path => $doc->path,
164 doc => $doc,
165 foundry => $token_base_foundry,
166 layer => $token_base_layer,
167 name => 'tokens'
168);
169
170ok($tokens, 'Token Object is fine');
171ok($tokens->parse, 'Token parsing is fine');
172
173# Add annotations
174$tokens->add('Base', 'Sentences');
175$tokens->add('Base', 'Paragraphs');
176
177$tokens->add('CoreNLP', 'Constituency');
178$tokens->add('CoreNLP', 'Morpho');
179$tokens->add('CoreNLP', 'Sentences');
180
181$tokens->add('Malt', 'Dependency');
182
183$tokens->add('OpenNLP', 'Morpho');
184$tokens->add('OpenNLP', 'Sentences');
185
186$tokens->add('DeReKo', 'Structure');
187
188$tokens->add('TreeTagger', 'Morpho');
189$tokens->add('TreeTagger', 'Sentences');
190
191$output = decode_json( $tokens->to_json );
192
193my $first = $output->{data}->{stream}->[0];
194is('-:base/paragraphs$<i>31', $first->[0]);
195is('-:base/sentences$<i>168', $first->[1]);
196is('-:corenlp/sentences$<i>175', $first->[2]);
197is('-:opennlp/sentences$<i>169', $first->[3]);
198is('-:tokens$<i>2641', $first->[4]);
199is('-:tt/sentences$<i>196', $first->[5]);
200is('<:malt/d:PP$<b>32<i>4', $first->[6]);
201is('<>:corenlp/c:ROOT$<b>64<i>0<i>48<i>7<b>0', $first->[7]);
202is('<>:corenlp/s:s$<b>64<i>0<i>48<i>7<b>0', $first->[8]);
203is('<>:opennlp/s:s$<b>64<i>0<i>48<i>7<b>0', $first->[9]);
204is('<>:tt/s:s$<b>64<i>0<i>48<i>7<b>0', $first->[10]);
205is('<>:corenlp/c:S$<b>64<i>0<i>48<i>7<b>1', $first->[11]);
206is('<>:dereko/s:front$<b>64<i>0<i>91<i>11<b>1', $first->[12]);
207is('<>:base/s:s$<b>64<i>0<i>91<i>11<b>2', $first->[13]);
208is('<>:dereko/s:titlePage$<b>64<i>0<i>91<i>11<b>2<s>1', $first->[14]);
209is('<>:dereko/s:docTitle$<b>64<i>0<i>91<i>11<b>3', $first->[15]);
210is('<>:dereko/s:titlePart$<b>64<i>0<i>91<i>11<b>4<s>2', $first->[16]);
211is('<>:dereko/s:s$<b>64<i>0<i>91<i>11<b>5', $first->[17]);
212is('<>:base/s:t$<b>64<i>0<i>17859<i>2640<b>0', $first->[18]);
213is('>:malt/d:ROOT$<b>33<i>0<i>48<i>0<i>7', $first->[19]);
214is('<:malt/d:PP$<b>32<i>1', $first->[20]);
215is('<:malt/d:ROOT$<b>34<i>0<i>48<i>7<i>0', $first->[21]);
216is('@:dereko/s:id:rbr.00610-0-titlepage$<b>17<s>1<i>11', $first->[22]);
217is('@:dereko/s:type:unspecified$<b>17<s>2<i>11', $first->[23]);
218is('_0$<i>0<i>4', $first->[24]);
219is('corenlp/p:NN', $first->[25]);
220is('i:rede', $first->[26]);
221is('opennlp/p:NN', $first->[27]);
222is('s:Rede', $first->[28]);
Akron28dc17f2018-02-01 15:31:41 +0100223is('tt/l:Rede$<b>129<b>253', $first->[29]);
Akrona5920b12016-06-29 18:51:21 +0200224is('tt/p:NN$<b>129<b>253', $first->[30]);
225
226my $last = $output->{data}->{stream}->[-1];
227
228is('<>:dereko/s:text$<b>65<i>17859<i>17859<i>2640<b>0', $last->[0]);
229is('<>:dereko/s:back$<b>65<i>17859<i>17859<i>2640<b>1', $last->[1]);
230is('>:malt/d:APP$<b>32<i>2639', $last->[2]);
231is('_2640$<i>17851<i>17859', $last->[3]);
232is('corenlp/p:NE', $last->[4]);
233is("i:schr\x{f6}der", $last->[5]);
234is('opennlp/p:NE', $last->[6]);
235is("s:Schr\x{f6}der", $last->[7]);
Akron04261762018-01-29 20:16:39 +0100236is("tt/l:Schr\x{f6}der", $last->[8]);
Akron28dc17f2018-02-01 15:31:41 +0100237is('tt/p:NE', $last->[9]);
Akrona5920b12016-06-29 18:51:21 +0200238
239
240# REI/BNG/00071
241$path = catdir(dirname(__FILE__), '../corpus/REI/BNG/00071');
242
243ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
244ok($doc->parse, 'Parse document');
245
246# Get tokenization
247$tokens = KorAP::XML::Tokenizer->new(
248 path => $doc->path,
249 doc => $doc,
250 foundry => $token_base_foundry,
251 layer => $token_base_layer,
252 name => 'tokens'
253);
254
255ok($tokens, 'Token Object is fine');
256ok($tokens->parse, 'Token parsing is fine');
257
258# Add annotations
259$tokens->add('Base', 'Sentences');
260$tokens->add('Base', 'Paragraphs');
261
262$tokens->add('CoreNLP', 'Constituency');
263$tokens->add('CoreNLP', 'Morpho');
264$tokens->add('CoreNLP', 'Sentences');
265
266$tokens->add('Malt', 'Dependency');
267
268$tokens->add('OpenNLP', 'Morpho');
269$tokens->add('OpenNLP', 'Sentences');
270
271$tokens->add('DeReKo', 'Structure');
272
273$tokens->add('TreeTagger', 'Morpho');
274$tokens->add('TreeTagger', 'Sentences');
275
276$output = decode_json( $tokens->to_json );
277
278$first = $output->{data}->{stream}->[0];
279
280is('-:base/paragraphs$<i>41', $first->[0]);
281is('-:base/sentences$<i>73', $first->[1]);
282is('-:corenlp/sentences$<i>69', $first->[2]);
283is('-:opennlp/sentences$<i>65', $first->[3]);
284is('-:tokens$<i>1009', $first->[4]);
285is('-:tt/sentences$<i>95', $first->[5]);
286is('<:malt/d:APP$<b>32<i>1', $first->[6]);
287is('<>:corenlp/c:MPN$<b>64<i>0<i>16<i>2<b>3', $first->[7]);
288is('<>:base/s:s$<b>64<i>0<i>48<i>5<b>2', $first->[8]);
289is('<>:dereko/s:titlePart$<b>64<i>0<i>48<i>5<b>4<s>2', $first->[9]);
290is('<>:dereko/s:s$<b>64<i>0<i>48<i>5<b>5', $first->[10]);
291is('<>:corenlp/c:ROOT$<b>64<i>0<i>51<i>6<b>0', $first->[11]);
292is('<>:corenlp/s:s$<b>64<i>0<i>51<i>6<b>0', $first->[12]);
293is('<>:tt/s:s$<b>64<i>0<i>51<i>6<b>0', $first->[13]);
294is('<>:corenlp/c:NUR$<b>64<i>0<i>51<i>6<b>1', $first->[14]);
295is('<>:corenlp/c:NP$<b>64<i>0<i>50<i>6<b>2', $first->[15]);
296is('<>:dereko/s:front$<b>64<i>0<i>61<i>8<b>1', $first->[16]);
297is('<>:dereko/s:titlePage$<b>64<i>0<i>61<i>8<b>2<s>1', $first->[17]);
298is('<>:dereko/s:docTitle$<b>64<i>0<i>61<i>8<b>3', $first->[18]);
299is('<>:opennlp/s:s$<b>64<i>0<i>173<i>24<b>0', $first->[19]);
300is('<>:base/s:t$<b>64<i>0<i>7008<i>1008<b>0', $first->[20]);
301is('<>:dereko/s:text$<b>64<i>0<i>7008<i>1008<b>0', $first->[21]);
302is('>:malt/d:GMOD$<b>32<i>3', $first->[22]);
303is('<:malt/d:ROOT$<b>34<i>0<i>51<i>6<i>3', $first->[23]);
304is('@:dereko/s:id:bng.00071-0-titlepage$<b>17<s>1<i>8', $first->[24]);
305is('@:dereko/s:type:unspecified$<b>17<s>2<i>5', $first->[25]);
306is('_0$<i>0<i>9', $first->[26]);
307is('corenlp/p:NE', $first->[27]);
308is('i:christine', $first->[28]);
309is('opennlp/p:NE', $first->[29]);
310is('s:Christine', $first->[30]);
Akron04261762018-01-29 20:16:39 +0100311is('tt/l:Christine', $first->[31]);
Akron28dc17f2018-02-01 15:31:41 +0100312is('tt/p:NE', $first->[32]);
Akrona5920b12016-06-29 18:51:21 +0200313
314$last = $output->{data}->{stream}->[-1];
315is('<>:dereko/s:back$<b>65<i>7008<i>7008<i>1008<b>1', $last->[0]);
316is('<>:dereko/s:div$<b>65<i>7008<i>7008<i>1008<b>2<s>1', $last->[1]);
317is('@:dereko/s:n:1$<b>17<s>1', $last->[2]);
318is('@:dereko/s:type:footnotes$<b>17<s>1', $last->[3]);
319is('@:dereko/s:complete:y$<b>17<s>1', $last->[4]);
320is('_1008$<i>6990<i>7006', $last->[5]);
321is('corenlp/p:NN', $last->[6]);
322is('i:befreiungsschlag', $last->[7]);
323is('opennlp/p:NN', $last->[8]);
324is('s:Befreiungsschlag', $last->[9]);
325
Akron1924bbe2016-06-22 16:05:41 +0200326done_testing;
327__END__