blob: 420e493ebea787511c1f72902cae766993a36085 [file] [log] [blame]
Akronb62d92a2020-03-01 16:32:00 +01001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
6use Log::Log4perl;
7
Akronfab17d32020-07-31 14:38:29 +02008if ($ENV{SKIP_REAL}) {
9 plan skip_all => 'Skip real tests';
10};
11
Akronb62d92a2020-03-01 16:32:00 +010012use utf8;
13use lib 'lib', '../lib';
14
15use File::Basename 'dirname';
16use File::Spec::Functions 'catdir';
17
18# 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
26use_ok('KorAP::XML::Krill');
27
Akron414ec952020-08-03 15:48:43 +020028my $path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1','00000');
Akronb62d92a2020-03-01 16:32:00 +010029
30ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
31ok($doc->parse, 'Parse document');
32
33is($doc->text_sigle, 'REDEW/DOC1/00000', 'Correct text sigle');
34is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
35is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
36
37my $meta = $doc->meta;
38ok(!$meta->{T_title}, 'Title'); # ???
39ok(!$meta->{T_sub_title}, 'SubTitle');
40ok(!$meta->{T_author}, 'Author');
41ok(!$meta->{A_editor}, 'Editor');
42ok(!$meta->{S_pub_place}, 'PubPlace');
Akron8ff58792020-04-17 16:51:55 +020043ok(!$meta->{A_publisher}, 'Publisher');
Akronb62d92a2020-03-01 16:32:00 +010044
45is($meta->{S_text_type}, '?', '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');
50
51ok(!$meta->{K_text_class}->[0], 'Correct Text Class');
52
Akron8ff58792020-04-17 16:51:55 +020053is($meta->{D_pub_date}, '00000000', 'Creation date'); # ???
Akronb62d92a2020-03-01 16:32:00 +010054is($meta->{D_creation_date}, '20200000', 'Creation date');
55is($meta->{S_availability}, 'QAO-NC', 'License'); # ???
56ok(!$meta->{A_pages}, 'Pages');
57
58ok(!$meta->{A_file_edition_statement}, 'File Statement');
59ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement');
60
61ok(!$meta->{A_reference}, 'Reference');
62ok(!$meta->{S_language}, 'Language'); # ???
63
64is($meta->{T_corpus_title}, 'Redewiedergabe', 'Correct Corpus title');
65ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title');
Akron8ff58792020-04-17 16:51:55 +020066ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
67ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akronb62d92a2020-03-01 16:32:00 +010068
69is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', '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');
73
74# Tokenization
75use_ok('KorAP::XML::Tokenizer');
76
77my ($token_base_foundry, $token_base_layer) = (qw/drukola Morpho/);
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), 'Cechov,_Anton_Pavlovic_Gram.tg4_1.xml 1886 1880 Gram Čechov, Anton Pavlovič yes yes Erzähltext digbi', 'Primary Data');
94
95is($output->{data}->{name}, 'tokens', 'tokenName');
96is($output->{data}->{tokenSource}, 'drukola#morpho', '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:Hörst', 'data');
102
103is($output->{textSigle}, 'REDEW/DOC1/00000', 'Correct text sigle');
104is($output->{docSigle}, 'REDEW/DOC1', 'Correct document sigle');
105is($output->{corpusSigle}, 'REDEW', 'Correct corpus sigle');
106
107ok(!$output->{title}, 'Title');
108ok(!$output->{subTitle}, 'Correct SubTitle');
109ok(!$output->{author}, 'Author');
110ok(!exists $output->{editor}, 'Publisher');
111
112# Add annotations
113$tokens->add('DRuKoLa', 'Morpho');
114$tokens->add('DeReKo', 'Structure');
115
116$output = decode_json( $tokens->to_json );
117
118my $first = $output->{data}->{stream}->[0];
119
120is('-:tokens$<i>13',$first->[0]);
Akrondec43122020-03-03 11:22:25 +0100121is('<>:base/s:t$<b>64<i>0<i>197<i>13<b>0',$first->[1]);
122is('<>:dereko/s:text$<b>64<i>0<i>197<i>13<b>0',$first->[2]);
123is('<>:dereko/s:body$<b>64<i>118<i>197<i>13<b>1',$first->[3]);
124is('<>:dereko/s:p$<b>64<i>118<i>197<i>13<b>2',$first->[4]);
125is('<>:dereko/s:said$<b>64<i>118<i>197<i>13<b>3<s>1',$first->[5]);
126is('@:dereko/s:level:1$<b>17<s>1<i>13',$first->[6]);
127is('@:dereko/s:content:speech$<b>17<s>1<i>13',$first->[7]);
128is('@:dereko/s:mode:direct$<b>17<s>1<i>13',$first->[8]);
129is('@:dereko/s:id:1$<b>17<s>1<i>13',$first->[9]);
Akronb62d92a2020-03-01 16:32:00 +0100130is('_0$<i>123<i>128',$first->[10]);
131is("drukola/l:H\x{f6}rst",$first->[11]);
132is('drukola/m:msd:rfpos',$first->[12]);
133is('drukola/m:sentstart:no',$first->[13]);
134is('drukola/m:stwr:direct.speech.1',$first->[14]);
135is('drukola/p:VVFIN',$first->[15]);
136is("i:h\x{f6}rst",$first->[16]);
137is("s:H\x{f6}rst",$first->[17]);
138
139my $nine = join(',', @{$output->{data}->{stream}->[9]});
140like($nine, qr{drukola\/l:nichts}, 'Nichts');
141like($nine, qr{_9\$<i>170<i>176}, 'Term boundaries');
Akrondec43122020-03-03 11:22:25 +0100142unlike($nine, qr{<>:dereko/s:said\$<b>64<i>176<i>196<i>13<b>4<s>1}, 'Term boundaries');
Akronb62d92a2020-03-01 16:32:00 +0100143
144my $ten = join(',', @{$output->{data}->{stream}->[10]});
145like($ten, qr{_10\$<i>177<i>180}, 'Term boundaries');
Akrondec43122020-03-03 11:22:25 +0100146like($ten, qr{<>:dereko/s:said\$<b>64<i>176<i>196<i>13<b>4<s>1}, 'Term boundaries');
Akronb62d92a2020-03-01 16:32:00 +0100147
148my $eleven = join(',', @{$output->{data}->{stream}->[11]});
149like($eleven, qr{_11\$<i>181<i>188}, 'Term boundaries');
150like($eleven, qr{<>:dereko/s:seg\$<b>64<i>180<i>188<i>12<b>5<s>1}, 'Segment');
151
152
153my $twelve = join(',', @{$output->{data}->{stream}->[12]});
154like($twelve, qr{_12\$<i>189<i>195}, 'Term boundaries');
155like($twelve, qr{drukola/l:Wort}, 'Lemma');
156like($twelve, qr{<>:dereko/s:seg\$<b>64<i>188<i>195<i>13<b>5<s>1}, 'Segment');
157
Akron8ff58792020-04-17 16:51:55 +0200158
159# Updated format:
Akron414ec952020-08-03 15:48:43 +0200160$path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1b','00011');
Akron8ff58792020-04-17 16:51:55 +0200161
162ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
163ok($doc->parse, 'Parse document');
164
165is($doc->text_sigle, 'REDEW/DOC1/00011', 'Correct text sigle');
166is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
167is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
168
169$meta = $doc->meta;
170
171is($meta->{A_distributor}, 'Institut für Deutsche Sprache', 'Distributor');
172is($meta->{D_pub_date}, '18730000', 'Publication date');
173is($meta->{D_creation_date}, '18730000', 'Publication date');
174is($meta->{S_pub_place_key}, 'DE', 'Publication place key');
175is($meta->{T_corpus_title}, 'Redewiedergabe', 'Title');
176is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Title');
177is($meta->{T_author}, 'Christen, Ada', 'Author');
178is($meta->{T_title}, 'Rahel', 'Author');
179is($meta->{S_availability}, 'QAO-NC-LOC:ids', 'Availability');
180is($meta->{S_text_type_art}, 'Erzähltext', 'Availability');
181
182# Tokenization
183use_ok('KorAP::XML::Tokenizer');
184
185($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
186
187# Get tokenization
188$tokens = KorAP::XML::Tokenizer->new(
189 path => $doc->path,
190 doc => $doc,
191 foundry => $token_base_foundry,
192 layer => $token_base_layer,
193 name => 'tokens'
194);
195
196ok($tokens, 'Token Object is fine');
197ok($tokens->parse, 'Token parsing is fine');
198
199$output = decode_json( $tokens->to_json );
200
201is(substr($output->{data}->{text}, 0, 100), 'Er hatte den Kopf weit nach rückwärts gebeugt, seine langen schwarzen Haare lockten sich über den li', 'Primary Data');
202
Akron28299f42020-04-17 17:54:33 +0200203use Log::Log4perl;
204
205Log::Log4perl->init({
206 'log4perl.rootLogger' => 'WARN, STDERR',
207 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
208 'log4perl.appender.STDERR.layout' => 'PatternLayout',
209 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
210});
211
212
Akron8ff58792020-04-17 16:51:55 +0200213# Add annotations
Akron28299f42020-04-17 17:54:33 +0200214ok($tokens->add('RWK', 'Morpho'));
215ok($tokens->add('RWK', 'Structure'));
Akron8ff58792020-04-17 16:51:55 +0200216
217$output = decode_json( $tokens->to_json );
218
219$first = $output->{data}->{stream}->[0];
220
Akron28299f42020-04-17 17:54:33 +0200221is('-:base/paragraphs$<i>2',$first->[0]);
222is('-:base/sentences$<i>21',$first->[1]);
223is('-:tokens$<i>522',$first->[2]);
224is('<>:base/s:s$<b>64<i>0<i>139<i>23<b>1',$first->[3]);
225is('<>:base/s:p$<b>64<i>0<i>2631<i>449<b>1',$first->[4]);
226is('<>:base/s:t$<b>64<i>0<i>3062<i>522<b>0',$first->[5]);
227is('_0$<i>0<i>2',$first->[6]);
228is('i:er',$first->[7]);
229is('rwk/l:er',$first->[8]);
Akronc4036442020-04-21 18:41:41 +0200230is('rwk/m:bc:PRO',$first->[9]);
231is('rwk/m:case:Nom',$first->[10]);
232is('rwk/m:gender:Masc',$first->[11]);
233is('rwk/m:number:Sg',$first->[12]);
234is('rwk/m:person:3',$first->[13]);
235is('rwk/m:type:Pers',$first->[14]);
236is('rwk/m:usage:Subst',$first->[15]);
237is('rwk/norm:Er',$first->[16]);
238is('rwk/p:PPER',$first->[17]);
239is('s:Er',$first->[18]);
Akron8ff58792020-04-17 16:51:55 +0200240
Akrone3e05362020-06-16 17:19:09 +0200241
242
243
244# Updated format:
Akron414ec952020-08-03 15:48:43 +0200245$path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1b','00011');
Akrone3e05362020-06-16 17:19:09 +0200246
247ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
248ok($doc->parse, 'Parse document');
249
250is($doc->text_sigle, 'REDEW/DOC1/00011', 'Correct text sigle');
251is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
252is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
253
254$meta = $doc->meta;
255
256is($meta->{A_distributor}, 'Institut für Deutsche Sprache', 'Distributor');
257is($meta->{D_pub_date}, '18730000', 'Publication date');
258is($meta->{D_creation_date}, '18730000', 'Publication date');
259is($meta->{S_pub_place_key}, 'DE', 'Publication place key');
260is($meta->{T_corpus_title}, 'Redewiedergabe', 'Title');
261is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Title');
262is($meta->{T_author}, 'Christen, Ada', 'Author');
263is($meta->{T_title}, 'Rahel', 'Author');
264is($meta->{S_availability}, 'QAO-NC-LOC:ids', 'Availability');
265is($meta->{S_text_type_art}, 'Erzähltext', 'Availability');
266
267# Tokenization
268use_ok('KorAP::XML::Tokenizer');
269
270($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
271
272# Get tokenization
273$tokens = KorAP::XML::Tokenizer->new(
274 path => $doc->path,
275 doc => $doc,
276 foundry => $token_base_foundry,
277 layer => $token_base_layer,
278 name => 'tokens'
279);
280
281ok($tokens, 'Token Object is fine');
282ok($tokens->parse, 'Token parsing is fine');
283
284$output = decode_json( $tokens->to_json );
285
286is(substr($output->{data}->{text}, 0, 100), 'Er hatte den Kopf weit nach rückwärts gebeugt, seine langen schwarzen Haare lockten sich über den li', 'Primary Data');
287
288use Log::Log4perl;
289
290Log::Log4perl->init({
291 'log4perl.rootLogger' => 'WARN, STDERR',
292 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
293 'log4perl.appender.STDERR.layout' => 'PatternLayout',
294 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
295});
296
297
298# Add annotations
299ok($tokens->add('RWK', 'Morpho'));
300ok($tokens->add('RWK', 'Structure'));
301
302$output = decode_json( $tokens->to_json );
303
304$first = $output->{data}->{stream}->[0];
305
306is('-:base/paragraphs$<i>2',$first->[0]);
307is('-:base/sentences$<i>21',$first->[1]);
308is('-:tokens$<i>522',$first->[2]);
309is('<>:base/s:s$<b>64<i>0<i>139<i>23<b>1',$first->[3]);
310is('<>:base/s:p$<b>64<i>0<i>2631<i>449<b>1',$first->[4]);
311is('<>:base/s:t$<b>64<i>0<i>3062<i>522<b>0',$first->[5]);
312is('_0$<i>0<i>2',$first->[6]);
313is('i:er',$first->[7]);
314is('rwk/l:er',$first->[8]);
315is('rwk/m:bc:PRO',$first->[9]);
316is('rwk/m:case:Nom',$first->[10]);
317is('rwk/m:gender:Masc',$first->[11]);
318is('rwk/m:number:Sg',$first->[12]);
319is('rwk/m:person:3',$first->[13]);
320is('rwk/m:type:Pers',$first->[14]);
321is('rwk/m:usage:Subst',$first->[15]);
322is('rwk/norm:Er',$first->[16]);
323is('rwk/p:PPER',$first->[17]);
324is('s:Er',$first->[18]);
325
326
Akron414ec952020-08-03 15:48:43 +0200327$path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1b','00001');
Akrone3e05362020-06-16 17:19:09 +0200328
329ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
330ok($doc->parse, 'Parse document');
331
332is($doc->text_sigle, 'REDEW/DOC1/00001', 'Correct text sigle');
333is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
334is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
335
336$meta = $doc->meta;
337
338is($meta->{A_distributor}, 'Institut für Deutsche Sprache', 'Distributor');
339is($meta->{D_pub_date}, '18950000', 'Publication date');
340is($meta->{D_creation_date}, '18950000', 'Publication date');
341is($meta->{S_pub_place_key}, 'DE', 'Publication place key');
342is($meta->{T_corpus_title}, 'Redewiedergabe', 'Title');
343is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Title');
344is($meta->{T_author}, 'Busch, Wilhelm', 'Author');
345is($meta->{T_title}, 'Der Schmetterling', 'Titel');
346is($meta->{S_availability}, 'QAO-NC-LOC:ids', 'Availability');
347is($meta->{S_text_type_art}, 'Erzähltext', 'Availability');
348
349# Tokenization
350use_ok('KorAP::XML::Tokenizer');
351
352($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
353
354# Get tokenization
355$tokens = KorAP::XML::Tokenizer->new(
356 path => $doc->path,
357 doc => $doc,
358 foundry => $token_base_foundry,
359 layer => $token_base_layer,
360 name => 'tokens'
361);
362
363ok($tokens, 'Token Object is fine');
364ok($tokens->parse, 'Token parsing is fine');
365
366$output = decode_json( $tokens->to_json );
367
368is(substr($output->{data}->{text}, 0, 100), 'Eier! Schinken! Franzwein! Flink, marsch!« schrie ihn gebieterisch der Nazi an und kniff dabei einen', 'Primary Data');
369
370# Add annotations
371ok($tokens->add('RWK', 'Morpho'));
372ok($tokens->add('RWK', 'Structure'));
373
374$output = decode_json( $tokens->to_json );
375
376$first = $output->{data}->{stream}->[0];
377
378is('-:base/paragraphs$<i>2',$first->[0]);
379is('-:base/sentences$<i>33',$first->[1]);
380is('-:tokens$<i>511',$first->[2]);
381is('<>:base/s:s$<b>64<i>0<i>6<i>2<b>1',$first->[3]);
382is('<>:base/s:p$<b>64<i>0<i>2010<i>307<b>1',$first->[4]);
383is('<>:base/s:t$<b>64<i>0<i>3246<i>511<b>0',$first->[5]);
384
385
Akron414ec952020-08-03 15:48:43 +0200386$path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1b','00558');
Akrone3e05362020-06-16 17:19:09 +0200387
388ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
389ok($doc->parse, 'Parse document');
390
391is($doc->text_sigle, 'REDEW/DOC1/00558', 'Correct text sigle');
392is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
393is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
394
395$meta = $doc->meta;
396
397# Tokenization
398use_ok('KorAP::XML::Tokenizer');
399
400($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
401
402# Get tokenization
403$tokens = KorAP::XML::Tokenizer->new(
404 path => $doc->path,
405 doc => $doc,
406 foundry => $token_base_foundry,
407 layer => $token_base_layer,
408 name => 'tokens'
409);
410
411ok($tokens, 'Token Object is fine');
412ok($tokens->parse, 'Token parsing is fine');
413
414$output = decode_json( $tokens->to_json );
415
416is(substr($output->{data}->{text}, 0, 100), 'Außer den sechs größten Vereinigungen haben sich 59 keiner Körperschaft angehörige Künstler angemeld', 'Primary Data');
417
418# Add annotations
419ok($tokens->add('RWK', 'Morpho'));
420ok($tokens->add('RWK', 'Structure'));
421
422$output = decode_json( $tokens->to_json );
423
424$first = $output->{data}->{stream}->[0];
425
426is('-:base/paragraphs$<i>2',$first->[0]);
427is('-:base/sentences$<i>68',$first->[1]);
428
Akronb62d92a2020-03-01 16:32:00 +0100429done_testing;