blob: 7e5642d9132f0d5bd9367a8d3dca386a9ac5b8c5 [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
Akron56deacb2020-08-10 10:03:55 +0200221is('-:base/paragraphs$<i>1',$first->[0]);
Akron28299f42020-04-17 17:54:33 +0200222is('-:base/sentences$<i>21',$first->[1]);
223is('-:tokens$<i>522',$first->[2]);
Akron56deacb2020-08-10 10:03:55 +0200224
Akron28299f42020-04-17 17:54:33 +0200225is('<>:base/s:s$<b>64<i>0<i>139<i>23<b>1',$first->[3]);
226is('<>:base/s:p$<b>64<i>0<i>2631<i>449<b>1',$first->[4]);
227is('<>:base/s:t$<b>64<i>0<i>3062<i>522<b>0',$first->[5]);
228is('_0$<i>0<i>2',$first->[6]);
229is('i:er',$first->[7]);
230is('rwk/l:er',$first->[8]);
Akronc4036442020-04-21 18:41:41 +0200231is('rwk/m:bc:PRO',$first->[9]);
232is('rwk/m:case:Nom',$first->[10]);
233is('rwk/m:gender:Masc',$first->[11]);
234is('rwk/m:number:Sg',$first->[12]);
235is('rwk/m:person:3',$first->[13]);
236is('rwk/m:type:Pers',$first->[14]);
237is('rwk/m:usage:Subst',$first->[15]);
238is('rwk/norm:Er',$first->[16]);
239is('rwk/p:PPER',$first->[17]);
240is('s:Er',$first->[18]);
Akron8ff58792020-04-17 16:51:55 +0200241
Akrone3e05362020-06-16 17:19:09 +0200242
243
244
245# Updated format:
Akron414ec952020-08-03 15:48:43 +0200246$path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1b','00011');
Akrone3e05362020-06-16 17:19:09 +0200247
248ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
249ok($doc->parse, 'Parse document');
250
251is($doc->text_sigle, 'REDEW/DOC1/00011', 'Correct text sigle');
252is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
253is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
254
255$meta = $doc->meta;
256
257is($meta->{A_distributor}, 'Institut für Deutsche Sprache', 'Distributor');
258is($meta->{D_pub_date}, '18730000', 'Publication date');
259is($meta->{D_creation_date}, '18730000', 'Publication date');
260is($meta->{S_pub_place_key}, 'DE', 'Publication place key');
261is($meta->{T_corpus_title}, 'Redewiedergabe', 'Title');
262is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Title');
263is($meta->{T_author}, 'Christen, Ada', 'Author');
264is($meta->{T_title}, 'Rahel', 'Author');
265is($meta->{S_availability}, 'QAO-NC-LOC:ids', 'Availability');
266is($meta->{S_text_type_art}, 'Erzähltext', 'Availability');
267
268# Tokenization
269use_ok('KorAP::XML::Tokenizer');
270
271($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
272
273# Get tokenization
274$tokens = KorAP::XML::Tokenizer->new(
275 path => $doc->path,
276 doc => $doc,
277 foundry => $token_base_foundry,
278 layer => $token_base_layer,
279 name => 'tokens'
280);
281
282ok($tokens, 'Token Object is fine');
283ok($tokens->parse, 'Token parsing is fine');
284
285$output = decode_json( $tokens->to_json );
286
287is(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');
288
289use Log::Log4perl;
290
291Log::Log4perl->init({
292 'log4perl.rootLogger' => 'WARN, STDERR',
293 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
294 'log4perl.appender.STDERR.layout' => 'PatternLayout',
295 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
296});
297
298
299# Add annotations
300ok($tokens->add('RWK', 'Morpho'));
301ok($tokens->add('RWK', 'Structure'));
302
303$output = decode_json( $tokens->to_json );
304
305$first = $output->{data}->{stream}->[0];
306
Akron56deacb2020-08-10 10:03:55 +0200307is('-:base/paragraphs$<i>1',$first->[0]);
Akrone3e05362020-06-16 17:19:09 +0200308is('-:base/sentences$<i>21',$first->[1]);
309is('-:tokens$<i>522',$first->[2]);
310is('<>:base/s:s$<b>64<i>0<i>139<i>23<b>1',$first->[3]);
311is('<>:base/s:p$<b>64<i>0<i>2631<i>449<b>1',$first->[4]);
312is('<>:base/s:t$<b>64<i>0<i>3062<i>522<b>0',$first->[5]);
313is('_0$<i>0<i>2',$first->[6]);
314is('i:er',$first->[7]);
315is('rwk/l:er',$first->[8]);
316is('rwk/m:bc:PRO',$first->[9]);
317is('rwk/m:case:Nom',$first->[10]);
318is('rwk/m:gender:Masc',$first->[11]);
319is('rwk/m:number:Sg',$first->[12]);
320is('rwk/m:person:3',$first->[13]);
321is('rwk/m:type:Pers',$first->[14]);
322is('rwk/m:usage:Subst',$first->[15]);
323is('rwk/norm:Er',$first->[16]);
324is('rwk/p:PPER',$first->[17]);
325is('s:Er',$first->[18]);
326
327
Akron414ec952020-08-03 15:48:43 +0200328$path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1b','00001');
Akrone3e05362020-06-16 17:19:09 +0200329
330ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
331ok($doc->parse, 'Parse document');
332
333is($doc->text_sigle, 'REDEW/DOC1/00001', 'Correct text sigle');
334is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
335is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
336
337$meta = $doc->meta;
338
339is($meta->{A_distributor}, 'Institut für Deutsche Sprache', 'Distributor');
340is($meta->{D_pub_date}, '18950000', 'Publication date');
341is($meta->{D_creation_date}, '18950000', 'Publication date');
342is($meta->{S_pub_place_key}, 'DE', 'Publication place key');
343is($meta->{T_corpus_title}, 'Redewiedergabe', 'Title');
344is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Title');
345is($meta->{T_author}, 'Busch, Wilhelm', 'Author');
346is($meta->{T_title}, 'Der Schmetterling', 'Titel');
347is($meta->{S_availability}, 'QAO-NC-LOC:ids', 'Availability');
348is($meta->{S_text_type_art}, 'Erzähltext', 'Availability');
349
350# Tokenization
351use_ok('KorAP::XML::Tokenizer');
352
353($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
354
355# Get tokenization
356$tokens = KorAP::XML::Tokenizer->new(
357 path => $doc->path,
358 doc => $doc,
359 foundry => $token_base_foundry,
360 layer => $token_base_layer,
361 name => 'tokens'
362);
363
364ok($tokens, 'Token Object is fine');
365ok($tokens->parse, 'Token parsing is fine');
366
367$output = decode_json( $tokens->to_json );
368
369is(substr($output->{data}->{text}, 0, 100), 'Eier! Schinken! Franzwein! Flink, marsch!« schrie ihn gebieterisch der Nazi an und kniff dabei einen', 'Primary Data');
370
371# Add annotations
372ok($tokens->add('RWK', 'Morpho'));
373ok($tokens->add('RWK', 'Structure'));
374
375$output = decode_json( $tokens->to_json );
376
377$first = $output->{data}->{stream}->[0];
378
Akron56deacb2020-08-10 10:03:55 +0200379is('-:base/paragraphs$<i>1',$first->[0]);
Akrone3e05362020-06-16 17:19:09 +0200380is('-:base/sentences$<i>33',$first->[1]);
381is('-:tokens$<i>511',$first->[2]);
382is('<>:base/s:s$<b>64<i>0<i>6<i>2<b>1',$first->[3]);
383is('<>:base/s:p$<b>64<i>0<i>2010<i>307<b>1',$first->[4]);
384is('<>:base/s:t$<b>64<i>0<i>3246<i>511<b>0',$first->[5]);
385
386
Akron414ec952020-08-03 15:48:43 +0200387$path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1b','00558');
Akrone3e05362020-06-16 17:19:09 +0200388
389ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
390ok($doc->parse, 'Parse document');
391
392is($doc->text_sigle, 'REDEW/DOC1/00558', 'Correct text sigle');
393is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
394is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
395
396$meta = $doc->meta;
397
398# Tokenization
399use_ok('KorAP::XML::Tokenizer');
400
401($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
402
403# Get tokenization
404$tokens = KorAP::XML::Tokenizer->new(
405 path => $doc->path,
406 doc => $doc,
407 foundry => $token_base_foundry,
408 layer => $token_base_layer,
409 name => 'tokens'
410);
411
412ok($tokens, 'Token Object is fine');
413ok($tokens->parse, 'Token parsing is fine');
414
415$output = decode_json( $tokens->to_json );
416
417is(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');
418
419# Add annotations
420ok($tokens->add('RWK', 'Morpho'));
421ok($tokens->add('RWK', 'Structure'));
422
423$output = decode_json( $tokens->to_json );
424
425$first = $output->{data}->{stream}->[0];
426
Akron56deacb2020-08-10 10:03:55 +0200427is('-:base/paragraphs$<i>1',$first->[0]);
Akrone3e05362020-06-16 17:19:09 +0200428is('-:base/sentences$<i>68',$first->[1]);
429
Akronb62d92a2020-03-01 16:32:00 +0100430done_testing;