blob: d7d6f2a714aea70bfaa4a9e51962cdd17f32c655 [file] [log] [blame]
Akronb62d92a2020-03-01 16:32:00 +01001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
Akronb62d92a2020-03-01 16:32:00 +01006
Akronfab17d32020-07-31 14:38:29 +02007if ($ENV{SKIP_REAL}) {
8 plan skip_all => 'Skip real tests';
9};
10
Akronb62d92a2020-03-01 16:32:00 +010011use utf8;
12use lib 'lib', '../lib';
13
14use File::Basename 'dirname';
15use File::Spec::Functions 'catdir';
16
Akronb62d92a2020-03-01 16:32:00 +010017use_ok('KorAP::XML::Krill');
18
Akron414ec952020-08-03 15:48:43 +020019my $path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1','00000');
Akronb62d92a2020-03-01 16:32:00 +010020
21ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
22ok($doc->parse, 'Parse document');
23
24is($doc->text_sigle, 'REDEW/DOC1/00000', 'Correct text sigle');
25is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
26is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
27
28my $meta = $doc->meta;
Marc Kupietz400590b2022-12-23 16:02:36 +010029is($meta->{T_title}, 'Gram', 'Title'); # ???
Akronb62d92a2020-03-01 16:32:00 +010030ok(!$meta->{T_sub_title}, 'SubTitle');
31ok(!$meta->{T_author}, 'Author');
32ok(!$meta->{A_editor}, 'Editor');
33ok(!$meta->{S_pub_place}, 'PubPlace');
Akron8ff58792020-04-17 16:51:55 +020034ok(!$meta->{A_publisher}, 'Publisher');
Akronb62d92a2020-03-01 16:32:00 +010035
36is($meta->{S_text_type}, '?', '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');
41
42ok(!$meta->{K_text_class}->[0], 'Correct Text Class');
43
Akron8ff58792020-04-17 16:51:55 +020044is($meta->{D_pub_date}, '00000000', 'Creation date'); # ???
Akronb62d92a2020-03-01 16:32:00 +010045is($meta->{D_creation_date}, '20200000', 'Creation date');
46is($meta->{S_availability}, 'QAO-NC', 'License'); # ???
47ok(!$meta->{A_pages}, 'Pages');
48
49ok(!$meta->{A_file_edition_statement}, 'File Statement');
50ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement');
51
52ok(!$meta->{A_reference}, 'Reference');
53ok(!$meta->{S_language}, 'Language'); # ???
54
55is($meta->{T_corpus_title}, 'Redewiedergabe', 'Correct Corpus title');
56ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title');
Akron8ff58792020-04-17 16:51:55 +020057ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
58ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akronb62d92a2020-03-01 16:32:00 +010059
60is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Correct Doc title');
61ok(!$meta->{T_doc_sub_title}, 'Correct Doc sub title');
62ok(!$meta->{T_doc_author}, 'Correct Doc author');
63ok(!$meta->{A_doc_editor}, 'Correct doc editor');
64
65# Tokenization
66use_ok('KorAP::XML::Tokenizer');
67
68my ($token_base_foundry, $token_base_layer) = (qw/drukola Morpho/);
69
70# Get tokenization
71my $tokens = KorAP::XML::Tokenizer->new(
72 path => $doc->path,
73 doc => $doc,
74 foundry => $token_base_foundry,
75 layer => $token_base_layer,
76 name => 'tokens'
77);
78
79ok($tokens, 'Token Object is fine');
80ok($tokens->parse, 'Token parsing is fine');
81
82my $output = decode_json( $tokens->to_json );
83
84is(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');
85
86is($output->{data}->{name}, 'tokens', 'tokenName');
87is($output->{data}->{tokenSource}, 'drukola#morpho', 'tokenSource');
88is($output->{version}, '0.03', 'version');
89
90is($output->{data}->{foundries}, '', 'Foundries');
91is($output->{data}->{layerInfos}, '', 'layerInfos');
92is($output->{data}->{stream}->[0]->[4], 's:Hörst', 'data');
93
94is($output->{textSigle}, 'REDEW/DOC1/00000', 'Correct text sigle');
95is($output->{docSigle}, 'REDEW/DOC1', 'Correct document sigle');
96is($output->{corpusSigle}, 'REDEW', 'Correct corpus sigle');
97
Marc Kupietz400590b2022-12-23 16:02:36 +010098is($output->{title}, 'Gram', 'Title');
Akronb62d92a2020-03-01 16:32:00 +010099ok(!$output->{subTitle}, 'Correct SubTitle');
100ok(!$output->{author}, 'Author');
101ok(!exists $output->{editor}, 'Publisher');
102
103# Add annotations
104$tokens->add('DRuKoLa', 'Morpho');
105$tokens->add('DeReKo', 'Structure');
106
107$output = decode_json( $tokens->to_json );
108
109my $first = $output->{data}->{stream}->[0];
110
111is('-:tokens$<i>13',$first->[0]);
Akrondec43122020-03-03 11:22:25 +0100112is('<>:base/s:t$<b>64<i>0<i>197<i>13<b>0',$first->[1]);
113is('<>:dereko/s:text$<b>64<i>0<i>197<i>13<b>0',$first->[2]);
114is('<>:dereko/s:body$<b>64<i>118<i>197<i>13<b>1',$first->[3]);
115is('<>:dereko/s:p$<b>64<i>118<i>197<i>13<b>2',$first->[4]);
116is('<>:dereko/s:said$<b>64<i>118<i>197<i>13<b>3<s>1',$first->[5]);
117is('@:dereko/s:level:1$<b>17<s>1<i>13',$first->[6]);
118is('@:dereko/s:content:speech$<b>17<s>1<i>13',$first->[7]);
119is('@:dereko/s:mode:direct$<b>17<s>1<i>13',$first->[8]);
120is('@:dereko/s:id:1$<b>17<s>1<i>13',$first->[9]);
Akronb62d92a2020-03-01 16:32:00 +0100121is('_0$<i>123<i>128',$first->[10]);
122is("drukola/l:H\x{f6}rst",$first->[11]);
123is('drukola/m:msd:rfpos',$first->[12]);
124is('drukola/m:sentstart:no',$first->[13]);
125is('drukola/m:stwr:direct.speech.1',$first->[14]);
126is('drukola/p:VVFIN',$first->[15]);
127is("i:h\x{f6}rst",$first->[16]);
128is("s:H\x{f6}rst",$first->[17]);
129
130my $nine = join(',', @{$output->{data}->{stream}->[9]});
131like($nine, qr{drukola\/l:nichts}, 'Nichts');
132like($nine, qr{_9\$<i>170<i>176}, 'Term boundaries');
Akrondec43122020-03-03 11:22:25 +0100133unlike($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 +0100134
135my $ten = join(',', @{$output->{data}->{stream}->[10]});
136like($ten, qr{_10\$<i>177<i>180}, 'Term boundaries');
Akrondec43122020-03-03 11:22:25 +0100137like($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 +0100138
139my $eleven = join(',', @{$output->{data}->{stream}->[11]});
140like($eleven, qr{_11\$<i>181<i>188}, 'Term boundaries');
141like($eleven, qr{<>:dereko/s:seg\$<b>64<i>180<i>188<i>12<b>5<s>1}, 'Segment');
142
143
144my $twelve = join(',', @{$output->{data}->{stream}->[12]});
145like($twelve, qr{_12\$<i>189<i>195}, 'Term boundaries');
146like($twelve, qr{drukola/l:Wort}, 'Lemma');
147like($twelve, qr{<>:dereko/s:seg\$<b>64<i>188<i>195<i>13<b>5<s>1}, 'Segment');
148
Akron8ff58792020-04-17 16:51:55 +0200149
150# Updated format:
Akron414ec952020-08-03 15:48:43 +0200151$path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1b','00011');
Akron8ff58792020-04-17 16:51:55 +0200152
153ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
154ok($doc->parse, 'Parse document');
155
156is($doc->text_sigle, 'REDEW/DOC1/00011', 'Correct text sigle');
157is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
158is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
159
160$meta = $doc->meta;
161
162is($meta->{A_distributor}, 'Institut für Deutsche Sprache', 'Distributor');
163is($meta->{D_pub_date}, '18730000', 'Publication date');
164is($meta->{D_creation_date}, '18730000', 'Publication date');
165is($meta->{S_pub_place_key}, 'DE', 'Publication place key');
166is($meta->{T_corpus_title}, 'Redewiedergabe', 'Title');
167is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Title');
168is($meta->{T_author}, 'Christen, Ada', 'Author');
169is($meta->{T_title}, 'Rahel', 'Author');
170is($meta->{S_availability}, 'QAO-NC-LOC:ids', 'Availability');
171is($meta->{S_text_type_art}, 'Erzähltext', 'Availability');
172
173# Tokenization
174use_ok('KorAP::XML::Tokenizer');
175
176($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
177
178# Get tokenization
179$tokens = KorAP::XML::Tokenizer->new(
180 path => $doc->path,
181 doc => $doc,
182 foundry => $token_base_foundry,
183 layer => $token_base_layer,
184 name => 'tokens'
185);
186
187ok($tokens, 'Token Object is fine');
188ok($tokens->parse, 'Token parsing is fine');
189
190$output = decode_json( $tokens->to_json );
191
192is(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');
193
194# Add annotations
Akron28299f42020-04-17 17:54:33 +0200195ok($tokens->add('RWK', 'Morpho'));
196ok($tokens->add('RWK', 'Structure'));
Akron8ff58792020-04-17 16:51:55 +0200197
198$output = decode_json( $tokens->to_json );
199
200$first = $output->{data}->{stream}->[0];
201
Akron56deacb2020-08-10 10:03:55 +0200202is('-:base/paragraphs$<i>1',$first->[0]);
Akron28299f42020-04-17 17:54:33 +0200203is('-:base/sentences$<i>21',$first->[1]);
204is('-:tokens$<i>522',$first->[2]);
Akron56deacb2020-08-10 10:03:55 +0200205
Akron28299f42020-04-17 17:54:33 +0200206is('<>:base/s:s$<b>64<i>0<i>139<i>23<b>1',$first->[3]);
207is('<>:base/s:p$<b>64<i>0<i>2631<i>449<b>1',$first->[4]);
208is('<>:base/s:t$<b>64<i>0<i>3062<i>522<b>0',$first->[5]);
209is('_0$<i>0<i>2',$first->[6]);
210is('i:er',$first->[7]);
211is('rwk/l:er',$first->[8]);
Akronc4036442020-04-21 18:41:41 +0200212is('rwk/m:bc:PRO',$first->[9]);
213is('rwk/m:case:Nom',$first->[10]);
214is('rwk/m:gender:Masc',$first->[11]);
215is('rwk/m:number:Sg',$first->[12]);
216is('rwk/m:person:3',$first->[13]);
217is('rwk/m:type:Pers',$first->[14]);
218is('rwk/m:usage:Subst',$first->[15]);
219is('rwk/norm:Er',$first->[16]);
220is('rwk/p:PPER',$first->[17]);
221is('s:Er',$first->[18]);
Akron8ff58792020-04-17 16:51:55 +0200222
Akrone3e05362020-06-16 17:19:09 +0200223
224
225
226# Updated format:
Akron414ec952020-08-03 15:48:43 +0200227$path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1b','00011');
Akrone3e05362020-06-16 17:19:09 +0200228
229ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
230ok($doc->parse, 'Parse document');
231
232is($doc->text_sigle, 'REDEW/DOC1/00011', 'Correct text sigle');
233is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
234is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
235
236$meta = $doc->meta;
237
238is($meta->{A_distributor}, 'Institut für Deutsche Sprache', 'Distributor');
239is($meta->{D_pub_date}, '18730000', 'Publication date');
240is($meta->{D_creation_date}, '18730000', 'Publication date');
241is($meta->{S_pub_place_key}, 'DE', 'Publication place key');
242is($meta->{T_corpus_title}, 'Redewiedergabe', 'Title');
243is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Title');
244is($meta->{T_author}, 'Christen, Ada', 'Author');
245is($meta->{T_title}, 'Rahel', 'Author');
246is($meta->{S_availability}, 'QAO-NC-LOC:ids', 'Availability');
247is($meta->{S_text_type_art}, 'Erzähltext', 'Availability');
248
249# Tokenization
250use_ok('KorAP::XML::Tokenizer');
251
252($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
253
254# Get tokenization
255$tokens = KorAP::XML::Tokenizer->new(
256 path => $doc->path,
257 doc => $doc,
258 foundry => $token_base_foundry,
259 layer => $token_base_layer,
260 name => 'tokens'
261);
262
263ok($tokens, 'Token Object is fine');
264ok($tokens->parse, 'Token parsing is fine');
265
266$output = decode_json( $tokens->to_json );
267
268is(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');
269
Akrone3e05362020-06-16 17:19:09 +0200270# Add annotations
271ok($tokens->add('RWK', 'Morpho'));
272ok($tokens->add('RWK', 'Structure'));
273
274$output = decode_json( $tokens->to_json );
275
276$first = $output->{data}->{stream}->[0];
277
Akron56deacb2020-08-10 10:03:55 +0200278is('-:base/paragraphs$<i>1',$first->[0]);
Akrone3e05362020-06-16 17:19:09 +0200279is('-:base/sentences$<i>21',$first->[1]);
280is('-:tokens$<i>522',$first->[2]);
281is('<>:base/s:s$<b>64<i>0<i>139<i>23<b>1',$first->[3]);
282is('<>:base/s:p$<b>64<i>0<i>2631<i>449<b>1',$first->[4]);
283is('<>:base/s:t$<b>64<i>0<i>3062<i>522<b>0',$first->[5]);
284is('_0$<i>0<i>2',$first->[6]);
285is('i:er',$first->[7]);
286is('rwk/l:er',$first->[8]);
287is('rwk/m:bc:PRO',$first->[9]);
288is('rwk/m:case:Nom',$first->[10]);
289is('rwk/m:gender:Masc',$first->[11]);
290is('rwk/m:number:Sg',$first->[12]);
291is('rwk/m:person:3',$first->[13]);
292is('rwk/m:type:Pers',$first->[14]);
293is('rwk/m:usage:Subst',$first->[15]);
294is('rwk/norm:Er',$first->[16]);
295is('rwk/p:PPER',$first->[17]);
296is('s:Er',$first->[18]);
297
298
Akron414ec952020-08-03 15:48:43 +0200299$path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1b','00001');
Akrone3e05362020-06-16 17:19:09 +0200300
301ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
302ok($doc->parse, 'Parse document');
303
304is($doc->text_sigle, 'REDEW/DOC1/00001', 'Correct text sigle');
305is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
306is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
307
308$meta = $doc->meta;
309
310is($meta->{A_distributor}, 'Institut für Deutsche Sprache', 'Distributor');
311is($meta->{D_pub_date}, '18950000', 'Publication date');
312is($meta->{D_creation_date}, '18950000', 'Publication date');
313is($meta->{S_pub_place_key}, 'DE', 'Publication place key');
314is($meta->{T_corpus_title}, 'Redewiedergabe', 'Title');
315is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Title');
316is($meta->{T_author}, 'Busch, Wilhelm', 'Author');
317is($meta->{T_title}, 'Der Schmetterling', 'Titel');
318is($meta->{S_availability}, 'QAO-NC-LOC:ids', 'Availability');
319is($meta->{S_text_type_art}, 'Erzähltext', 'Availability');
320
321# Tokenization
322use_ok('KorAP::XML::Tokenizer');
323
324($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
325
326# Get tokenization
327$tokens = KorAP::XML::Tokenizer->new(
328 path => $doc->path,
329 doc => $doc,
330 foundry => $token_base_foundry,
331 layer => $token_base_layer,
332 name => 'tokens'
333);
334
335ok($tokens, 'Token Object is fine');
336ok($tokens->parse, 'Token parsing is fine');
337
338$output = decode_json( $tokens->to_json );
339
340is(substr($output->{data}->{text}, 0, 100), 'Eier! Schinken! Franzwein! Flink, marsch!« schrie ihn gebieterisch der Nazi an und kniff dabei einen', 'Primary Data');
341
342# Add annotations
343ok($tokens->add('RWK', 'Morpho'));
344ok($tokens->add('RWK', 'Structure'));
345
346$output = decode_json( $tokens->to_json );
347
348$first = $output->{data}->{stream}->[0];
349
Akron56deacb2020-08-10 10:03:55 +0200350is('-:base/paragraphs$<i>1',$first->[0]);
Akrone3e05362020-06-16 17:19:09 +0200351is('-:base/sentences$<i>33',$first->[1]);
352is('-:tokens$<i>511',$first->[2]);
353is('<>:base/s:s$<b>64<i>0<i>6<i>2<b>1',$first->[3]);
354is('<>:base/s:p$<b>64<i>0<i>2010<i>307<b>1',$first->[4]);
355is('<>:base/s:t$<b>64<i>0<i>3246<i>511<b>0',$first->[5]);
356
357
Akron414ec952020-08-03 15:48:43 +0200358$path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1b','00558');
Akrone3e05362020-06-16 17:19:09 +0200359
360ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
361ok($doc->parse, 'Parse document');
362
363is($doc->text_sigle, 'REDEW/DOC1/00558', 'Correct text sigle');
364is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle');
365is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle');
366
367$meta = $doc->meta;
368
369# Tokenization
370use_ok('KorAP::XML::Tokenizer');
371
372($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/);
373
374# Get tokenization
375$tokens = KorAP::XML::Tokenizer->new(
376 path => $doc->path,
377 doc => $doc,
378 foundry => $token_base_foundry,
379 layer => $token_base_layer,
380 name => 'tokens'
381);
382
383ok($tokens, 'Token Object is fine');
384ok($tokens->parse, 'Token parsing is fine');
385
386$output = decode_json( $tokens->to_json );
387
388is(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');
389
390# Add annotations
391ok($tokens->add('RWK', 'Morpho'));
392ok($tokens->add('RWK', 'Structure'));
393
394$output = decode_json( $tokens->to_json );
395
396$first = $output->{data}->{stream}->[0];
397
Akron56deacb2020-08-10 10:03:55 +0200398is('-:base/paragraphs$<i>1',$first->[0]);
Akrone3e05362020-06-16 17:19:09 +0200399is('-:base/sentences$<i>68',$first->[1]);
400
Akronb62d92a2020-03-01 16:32:00 +0100401done_testing;