blob: c0401c15e524f8887313b0f2bdbd04295ea4a210 [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
8use utf8;
9use lib 'lib', '../lib';
10
11use File::Basename 'dirname';
12use File::Spec::Functions 'catdir';
13
14# 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
22use_ok('KorAP::XML::Krill');
23
24my $path = catdir(dirname(__FILE__), '../corpus/REDEW/DOC1/00000');
25
26ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
27ok($doc->parse, 'Parse document');
28
29is($doc->text_sigle, 'REDEW/DOC1/00000', 'Correct text sigle');
30is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
31is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
32
33my $meta = $doc->meta;
34ok(!$meta->{T_title}, 'Title'); # ???
35ok(!$meta->{T_sub_title}, 'SubTitle');
36ok(!$meta->{T_author}, 'Author');
37ok(!$meta->{A_editor}, 'Editor');
38ok(!$meta->{S_pub_place}, 'PubPlace');
Akron8ff58792020-04-17 16:51:55 +020039ok(!$meta->{A_publisher}, 'Publisher');
Akronb62d92a2020-03-01 16:32:00 +010040
41is($meta->{S_text_type}, '?', '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');
46
47ok(!$meta->{K_text_class}->[0], 'Correct Text Class');
48
Akron8ff58792020-04-17 16:51:55 +020049is($meta->{D_pub_date}, '00000000', 'Creation date'); # ???
Akronb62d92a2020-03-01 16:32:00 +010050is($meta->{D_creation_date}, '20200000', 'Creation date');
51is($meta->{S_availability}, 'QAO-NC', 'License'); # ???
52ok(!$meta->{A_pages}, 'Pages');
53
54ok(!$meta->{A_file_edition_statement}, 'File Statement');
55ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement');
56
57ok(!$meta->{A_reference}, 'Reference');
58ok(!$meta->{S_language}, 'Language'); # ???
59
60is($meta->{T_corpus_title}, 'Redewiedergabe', 'Correct Corpus title');
61ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title');
Akron8ff58792020-04-17 16:51:55 +020062ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
63ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akronb62d92a2020-03-01 16:32:00 +010064
65is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Correct Doc title');
66ok(!$meta->{T_doc_sub_title}, 'Correct Doc sub title');
67ok(!$meta->{T_doc_author}, 'Correct Doc author');
68ok(!$meta->{A_doc_editor}, 'Correct doc editor');
69
70# Tokenization
71use_ok('KorAP::XML::Tokenizer');
72
73my ($token_base_foundry, $token_base_layer) = (qw/drukola Morpho/);
74
75# Get tokenization
76my $tokens = KorAP::XML::Tokenizer->new(
77 path => $doc->path,
78 doc => $doc,
79 foundry => $token_base_foundry,
80 layer => $token_base_layer,
81 name => 'tokens'
82);
83
84ok($tokens, 'Token Object is fine');
85ok($tokens->parse, 'Token parsing is fine');
86
87my $output = decode_json( $tokens->to_json );
88
89is(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');
90
91is($output->{data}->{name}, 'tokens', 'tokenName');
92is($output->{data}->{tokenSource}, 'drukola#morpho', 'tokenSource');
93is($output->{version}, '0.03', 'version');
94
95is($output->{data}->{foundries}, '', 'Foundries');
96is($output->{data}->{layerInfos}, '', 'layerInfos');
97is($output->{data}->{stream}->[0]->[4], 's:Hörst', 'data');
98
99is($output->{textSigle}, 'REDEW/DOC1/00000', 'Correct text sigle');
100is($output->{docSigle}, 'REDEW/DOC1', 'Correct document sigle');
101is($output->{corpusSigle}, 'REDEW', 'Correct corpus sigle');
102
103ok(!$output->{title}, 'Title');
104ok(!$output->{subTitle}, 'Correct SubTitle');
105ok(!$output->{author}, 'Author');
106ok(!exists $output->{editor}, 'Publisher');
107
108# Add annotations
109$tokens->add('DRuKoLa', 'Morpho');
110$tokens->add('DeReKo', 'Structure');
111
112$output = decode_json( $tokens->to_json );
113
114my $first = $output->{data}->{stream}->[0];
115
116is('-:tokens$<i>13',$first->[0]);
Akrondec43122020-03-03 11:22:25 +0100117is('<>:base/s:t$<b>64<i>0<i>197<i>13<b>0',$first->[1]);
118is('<>:dereko/s:text$<b>64<i>0<i>197<i>13<b>0',$first->[2]);
119is('<>:dereko/s:body$<b>64<i>118<i>197<i>13<b>1',$first->[3]);
120is('<>:dereko/s:p$<b>64<i>118<i>197<i>13<b>2',$first->[4]);
121is('<>:dereko/s:said$<b>64<i>118<i>197<i>13<b>3<s>1',$first->[5]);
122is('@:dereko/s:level:1$<b>17<s>1<i>13',$first->[6]);
123is('@:dereko/s:content:speech$<b>17<s>1<i>13',$first->[7]);
124is('@:dereko/s:mode:direct$<b>17<s>1<i>13',$first->[8]);
125is('@:dereko/s:id:1$<b>17<s>1<i>13',$first->[9]);
Akronb62d92a2020-03-01 16:32:00 +0100126is('_0$<i>123<i>128',$first->[10]);
127is("drukola/l:H\x{f6}rst",$first->[11]);
128is('drukola/m:msd:rfpos',$first->[12]);
129is('drukola/m:sentstart:no',$first->[13]);
130is('drukola/m:stwr:direct.speech.1',$first->[14]);
131is('drukola/p:VVFIN',$first->[15]);
132is("i:h\x{f6}rst",$first->[16]);
133is("s:H\x{f6}rst",$first->[17]);
134
135my $nine = join(',', @{$output->{data}->{stream}->[9]});
136like($nine, qr{drukola\/l:nichts}, 'Nichts');
137like($nine, qr{_9\$<i>170<i>176}, 'Term boundaries');
Akrondec43122020-03-03 11:22:25 +0100138unlike($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 +0100139
140my $ten = join(',', @{$output->{data}->{stream}->[10]});
141like($ten, qr{_10\$<i>177<i>180}, 'Term boundaries');
Akrondec43122020-03-03 11:22:25 +0100142like($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 +0100143
144my $eleven = join(',', @{$output->{data}->{stream}->[11]});
145like($eleven, qr{_11\$<i>181<i>188}, 'Term boundaries');
146like($eleven, qr{<>:dereko/s:seg\$<b>64<i>180<i>188<i>12<b>5<s>1}, 'Segment');
147
148
149my $twelve = join(',', @{$output->{data}->{stream}->[12]});
150like($twelve, qr{_12\$<i>189<i>195}, 'Term boundaries');
151like($twelve, qr{drukola/l:Wort}, 'Lemma');
152like($twelve, qr{<>:dereko/s:seg\$<b>64<i>188<i>195<i>13<b>5<s>1}, 'Segment');
153
Akron8ff58792020-04-17 16:51:55 +0200154
155# Updated format:
156$path = catdir(dirname(__FILE__), '../corpus/REDEW/DOC1b/00011');
157
158ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
159ok($doc->parse, 'Parse document');
160
161is($doc->text_sigle, 'REDEW/DOC1/00011', 'Correct text sigle');
162is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
163is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
164
165$meta = $doc->meta;
166
167is($meta->{A_distributor}, 'Institut für Deutsche Sprache', 'Distributor');
168is($meta->{D_pub_date}, '18730000', 'Publication date');
169is($meta->{D_creation_date}, '18730000', 'Publication date');
170is($meta->{S_pub_place_key}, 'DE', 'Publication place key');
171is($meta->{T_corpus_title}, 'Redewiedergabe', 'Title');
172is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Title');
173is($meta->{T_author}, 'Christen, Ada', 'Author');
174is($meta->{T_title}, 'Rahel', 'Author');
175is($meta->{S_availability}, 'QAO-NC-LOC:ids', 'Availability');
176is($meta->{S_text_type_art}, 'Erzähltext', 'Availability');
177
178# Tokenization
179use_ok('KorAP::XML::Tokenizer');
180
181($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
182
183# Get tokenization
184$tokens = KorAP::XML::Tokenizer->new(
185 path => $doc->path,
186 doc => $doc,
187 foundry => $token_base_foundry,
188 layer => $token_base_layer,
189 name => 'tokens'
190);
191
192ok($tokens, 'Token Object is fine');
193ok($tokens->parse, 'Token parsing is fine');
194
195$output = decode_json( $tokens->to_json );
196
197is(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');
198
Akron28299f42020-04-17 17:54:33 +0200199use Log::Log4perl;
200
201Log::Log4perl->init({
202 'log4perl.rootLogger' => 'WARN, STDERR',
203 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
204 'log4perl.appender.STDERR.layout' => 'PatternLayout',
205 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
206});
207
208
Akron8ff58792020-04-17 16:51:55 +0200209# Add annotations
Akron28299f42020-04-17 17:54:33 +0200210ok($tokens->add('RWK', 'Morpho'));
211ok($tokens->add('RWK', 'Structure'));
Akron8ff58792020-04-17 16:51:55 +0200212
213$output = decode_json( $tokens->to_json );
214
215$first = $output->{data}->{stream}->[0];
216
Akron28299f42020-04-17 17:54:33 +0200217is('-:base/paragraphs$<i>2',$first->[0]);
218is('-:base/sentences$<i>21',$first->[1]);
219is('-:tokens$<i>522',$first->[2]);
220is('<>:base/s:s$<b>64<i>0<i>139<i>23<b>1',$first->[3]);
221is('<>:base/s:p$<b>64<i>0<i>2631<i>449<b>1',$first->[4]);
222is('<>:base/s:t$<b>64<i>0<i>3062<i>522<b>0',$first->[5]);
223is('_0$<i>0<i>2',$first->[6]);
224is('i:er',$first->[7]);
225is('rwk/l:er',$first->[8]);
Akronc4036442020-04-21 18:41:41 +0200226is('rwk/m:bc:PRO',$first->[9]);
227is('rwk/m:case:Nom',$first->[10]);
228is('rwk/m:gender:Masc',$first->[11]);
229is('rwk/m:number:Sg',$first->[12]);
230is('rwk/m:person:3',$first->[13]);
231is('rwk/m:type:Pers',$first->[14]);
232is('rwk/m:usage:Subst',$first->[15]);
233is('rwk/norm:Er',$first->[16]);
234is('rwk/p:PPER',$first->[17]);
235is('s:Er',$first->[18]);
Akron8ff58792020-04-17 16:51:55 +0200236
Akrone3e05362020-06-16 17:19:09 +0200237
238
239
240# Updated format:
241$path = catdir(dirname(__FILE__), '../corpus/REDEW/DOC1b/00011');
242
243ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
244ok($doc->parse, 'Parse document');
245
246is($doc->text_sigle, 'REDEW/DOC1/00011', 'Correct text sigle');
247is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
248is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
249
250$meta = $doc->meta;
251
252is($meta->{A_distributor}, 'Institut für Deutsche Sprache', 'Distributor');
253is($meta->{D_pub_date}, '18730000', 'Publication date');
254is($meta->{D_creation_date}, '18730000', 'Publication date');
255is($meta->{S_pub_place_key}, 'DE', 'Publication place key');
256is($meta->{T_corpus_title}, 'Redewiedergabe', 'Title');
257is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Title');
258is($meta->{T_author}, 'Christen, Ada', 'Author');
259is($meta->{T_title}, 'Rahel', 'Author');
260is($meta->{S_availability}, 'QAO-NC-LOC:ids', 'Availability');
261is($meta->{S_text_type_art}, 'Erzähltext', 'Availability');
262
263# Tokenization
264use_ok('KorAP::XML::Tokenizer');
265
266($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
267
268# Get tokenization
269$tokens = KorAP::XML::Tokenizer->new(
270 path => $doc->path,
271 doc => $doc,
272 foundry => $token_base_foundry,
273 layer => $token_base_layer,
274 name => 'tokens'
275);
276
277ok($tokens, 'Token Object is fine');
278ok($tokens->parse, 'Token parsing is fine');
279
280$output = decode_json( $tokens->to_json );
281
282is(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');
283
284use Log::Log4perl;
285
286Log::Log4perl->init({
287 'log4perl.rootLogger' => 'WARN, STDERR',
288 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
289 'log4perl.appender.STDERR.layout' => 'PatternLayout',
290 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
291});
292
293
294# Add annotations
295ok($tokens->add('RWK', 'Morpho'));
296ok($tokens->add('RWK', 'Structure'));
297
298$output = decode_json( $tokens->to_json );
299
300$first = $output->{data}->{stream}->[0];
301
302is('-:base/paragraphs$<i>2',$first->[0]);
303is('-:base/sentences$<i>21',$first->[1]);
304is('-:tokens$<i>522',$first->[2]);
305is('<>:base/s:s$<b>64<i>0<i>139<i>23<b>1',$first->[3]);
306is('<>:base/s:p$<b>64<i>0<i>2631<i>449<b>1',$first->[4]);
307is('<>:base/s:t$<b>64<i>0<i>3062<i>522<b>0',$first->[5]);
308is('_0$<i>0<i>2',$first->[6]);
309is('i:er',$first->[7]);
310is('rwk/l:er',$first->[8]);
311is('rwk/m:bc:PRO',$first->[9]);
312is('rwk/m:case:Nom',$first->[10]);
313is('rwk/m:gender:Masc',$first->[11]);
314is('rwk/m:number:Sg',$first->[12]);
315is('rwk/m:person:3',$first->[13]);
316is('rwk/m:type:Pers',$first->[14]);
317is('rwk/m:usage:Subst',$first->[15]);
318is('rwk/norm:Er',$first->[16]);
319is('rwk/p:PPER',$first->[17]);
320is('s:Er',$first->[18]);
321
322
323$path = catdir(dirname(__FILE__), '../corpus/REDEW/DOC1b/00001');
324
325ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
326ok($doc->parse, 'Parse document');
327
328is($doc->text_sigle, 'REDEW/DOC1/00001', 'Correct text sigle');
329is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
330is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
331
332$meta = $doc->meta;
333
334is($meta->{A_distributor}, 'Institut für Deutsche Sprache', 'Distributor');
335is($meta->{D_pub_date}, '18950000', 'Publication date');
336is($meta->{D_creation_date}, '18950000', 'Publication date');
337is($meta->{S_pub_place_key}, 'DE', 'Publication place key');
338is($meta->{T_corpus_title}, 'Redewiedergabe', 'Title');
339is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Title');
340is($meta->{T_author}, 'Busch, Wilhelm', 'Author');
341is($meta->{T_title}, 'Der Schmetterling', 'Titel');
342is($meta->{S_availability}, 'QAO-NC-LOC:ids', 'Availability');
343is($meta->{S_text_type_art}, 'Erzähltext', 'Availability');
344
345# Tokenization
346use_ok('KorAP::XML::Tokenizer');
347
348($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
349
350# Get tokenization
351$tokens = KorAP::XML::Tokenizer->new(
352 path => $doc->path,
353 doc => $doc,
354 foundry => $token_base_foundry,
355 layer => $token_base_layer,
356 name => 'tokens'
357);
358
359ok($tokens, 'Token Object is fine');
360ok($tokens->parse, 'Token parsing is fine');
361
362$output = decode_json( $tokens->to_json );
363
364is(substr($output->{data}->{text}, 0, 100), 'Eier! Schinken! Franzwein! Flink, marsch!« schrie ihn gebieterisch der Nazi an und kniff dabei einen', 'Primary Data');
365
366# Add annotations
367ok($tokens->add('RWK', 'Morpho'));
368ok($tokens->add('RWK', 'Structure'));
369
370$output = decode_json( $tokens->to_json );
371
372$first = $output->{data}->{stream}->[0];
373
374is('-:base/paragraphs$<i>2',$first->[0]);
375is('-:base/sentences$<i>33',$first->[1]);
376is('-:tokens$<i>511',$first->[2]);
377is('<>:base/s:s$<b>64<i>0<i>6<i>2<b>1',$first->[3]);
378is('<>:base/s:p$<b>64<i>0<i>2010<i>307<b>1',$first->[4]);
379is('<>:base/s:t$<b>64<i>0<i>3246<i>511<b>0',$first->[5]);
380
381
382$path = catdir(dirname(__FILE__), '../corpus/REDEW/DOC1b/00558');
383
384ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
385ok($doc->parse, 'Parse document');
386
387is($doc->text_sigle, 'REDEW/DOC1/00558', 'Correct text sigle');
388is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
389is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
390
391$meta = $doc->meta;
392
393# Tokenization
394use_ok('KorAP::XML::Tokenizer');
395
396($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
397
398# Get tokenization
399$tokens = KorAP::XML::Tokenizer->new(
400 path => $doc->path,
401 doc => $doc,
402 foundry => $token_base_foundry,
403 layer => $token_base_layer,
404 name => 'tokens'
405);
406
407ok($tokens, 'Token Object is fine');
408ok($tokens->parse, 'Token parsing is fine');
409
410$output = decode_json( $tokens->to_json );
411
412is(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');
413
414# Add annotations
415ok($tokens->add('RWK', 'Morpho'));
416ok($tokens->add('RWK', 'Structure'));
417
418$output = decode_json( $tokens->to_json );
419
420$first = $output->{data}->{stream}->[0];
421
422is('-:base/paragraphs$<i>2',$first->[0]);
423is('-:base/sentences$<i>68',$first->[1]);
424
Akronb62d92a2020-03-01 16:32:00 +0100425done_testing;