blob: b12244998f6b58d7c207f7d4b2dfbbde5d42de74 [file] [log] [blame]
Akron414ec952020-08-03 15:48:43 +02001use strict;
2use warnings;
3use utf8;
4use Test::More;
5use Benchmark ':hireswallclock';
6use Mojo::DOM;
7use Mojo::File;
8use Mojo::ByteStream 'b';
9use Data::Dumper;
10use lib 'lib', '../lib';
11
12if ($ENV{SKIP_REAL}) {
13 plan skip_all => 'Skip real tests';
14};
15
16use File::Basename 'dirname';
17use File::Spec::Functions 'catdir';
18
19use_ok('KorAP::XML::Krill');
20
21# WPD/00001
22my $path = catdir(dirname(__FILE__), 'corpus','WPD','00001');
23ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
24like($doc->path, qr!\Q$path\E/!, 'Path');
25
26ok($doc = KorAP::XML::Krill->new( path => $path ), 'Load Korap::Document');
27like($doc->path, qr!\Q$path\E/$!, 'Path');
28
29ok($doc->parse, 'Parse document');
30
31# Metdata
32is($doc->text_sigle, 'WPD/AAA/00001', 'ID');
33
34my $meta = $doc->meta;
35is($meta->{T_title}, 'A', 'title');
36
37ok(!$meta->{T_sub_title}, 'subTitle');
38is($doc->corpus_sigle, 'WPD', 'corpusID');
39is($meta->{D_pub_date}, '20050328', 'pubDate');
40is($meta->{S_pub_place}, 'URL:http://de.wikipedia.org', 'pubPlace');
41is($meta->{K_text_class}->[0], 'freizeit-unterhaltung', 'TextClass');
42is($meta->{K_text_class}->[1], 'reisen', 'TextClass');
43is($meta->{K_text_class}->[2], 'wissenschaft', 'TextClass');
44is($meta->{K_text_class}->[3], 'populaerwissenschaft', 'TextClass');
45ok(!$meta->{K_text_class}->[4], 'TextClass');
46is($meta->{T_author}, 'Ruru; Jens.Ol; Aglarech; u.a.', 'author');
47
48
49#is($doc->author->[0], 'Ruru', 'author');
50#is($doc->author->[1], 'Jens.Ol', 'author');
51#is($doc->author->[2], 'Aglarech', 'author');
52#ok(!$doc->author->[3], 'author');
53
54# Additional information
55is($meta->{A_editor}, 'wikipedia.org', 'Editor');
56is($meta->{A_publisher}, 'Wikipedia', 'Publisher');
57is($meta->{D_creation_date}, '20050000', 'Creation date');
58ok(!$meta->{S_text_type}, 'No text_type');
59ok(!$meta->{S_text_type_art}, 'no text_type art');
60ok(!$meta->{S_text_type_ref}, 'no text_type ref');
61ok(!$meta->{S_text_domain}, 'no text_domain');
62ok(!$meta->{S_text_column}, 'no text_column');
63ok(!$meta->keywords('K_keywords'), 'no keywords');
64is($meta->keywords('K_text_class'), 'freizeit-unterhaltung reisen wissenschaft populaerwissenschaft', 'no text classes');
65
66#is($doc->coll_title, 'Wikipedia', 'Collection title');
67#is($doc->coll_sub_title, 'Die freie Enzyklopädie', 'Collection subtitle');
68#is($doc->coll_editor, 'wikipedia.org', 'Collection editor');
69#ok(!$doc->coll_author, 'Collection author');
70
71# A01/13047
72$path = catdir(dirname(__FILE__), 'corpus','A01','13047');
73ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
74
75ok($doc->parse, 'Parse document');
76$meta = $doc->meta;
77is($meta->{T_title}, 'Fischer und Kolp im Sonnenhügel', 'title');
78
79ok(!$meta->{T_sub_title}, 'subTitle');
80is($doc->text_sigle, 'A01/APR/13047', 'ID');
81is($doc->corpus_sigle, 'A01', 'corpusID');
82is($meta->{D_pub_date}, '20010402', 'pubDate');
83ok(!$meta->{S_pub_place}, 'pubPlace');
84is($meta->{K_text_class}->[0], 'freizeit-unterhaltung', 'TextClass');
85is($meta->{K_text_class}->[1], 'vereine-veranstaltungen', 'TextClass');
86ok(!$meta->{K_text_class}->[2], 'TextClass');
87ok(!$meta->{T_author}, 'author');
88
89# Additional information
90ok(!$meta->{A_editor}, 'Editor');
91ok(!$meta->{A_publisher}, 'Publisher');
92is($meta->{D_creation_date}, '20010402', 'Creation date');
93#ok(!$doc->coll_title, 'Collection title');
94#ok(!$doc->coll_sub_title, 'Collection subtitle');
95#ok(!$doc->coll_editor, 'Collection editor');
96#ok(!$doc->coll_author, 'Collection author');
97ok(!$meta->{S_text_type}, 'text_type');
98is($meta->{S_text_type_art}, 'Bericht', 'text_type art');
99
100# ERL/0001
101$path = catdir(dirname(__FILE__), 'corpus','ERL','00001');
102ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
103
104ok($doc->parse, 'Parse document');
105
106$meta = $doc->meta;
107is($meta->{T_title}, 'Amtsblatt des Landesbezirks Baden [diverse Erlasse]', 'title'); # Amtsblatt des Landesbezirks Baden [diverse Erlasse]
108# MK2/ERL.00001
109
110ok(!$meta->{T_sub_title}, 'subTitle');
111is($doc->text_sigle, 'MK2/ERL/00001', 'ID');
112is($doc->corpus_sigle, 'MK2', 'corpusID');
113is($meta->{D_pub_date}, '00000000', 'pubDate');
114is($meta->{S_pub_place}, 'Karlsruhe', 'pubPlace');
115is($meta->{K_text_class}->[0], 'politik', 'TextClass');
116is($meta->{K_text_class}->[1], 'kommunalpolitik', 'TextClass');
117ok(!$meta->{K_text_class}->[2], 'TextClass');
118ok(!$meta->{T_author}, 'author');
119
120# Additional information
121ok(!$meta->{A_editor}, 'Editor');
122is($meta->{A_publisher}, 'Badenia Verlag und Druckerei', 'Publisher');
123is($meta->{D_creation_date}, '19600000', 'Creation date');
124
125# !!!
126# diag 'Non-acceptance of creation date ranges may be temporary';
127
128
129#ok(!$doc->coll_title, 'Collection title');
130#ok(!$doc->coll_sub_title, 'Collection subtitle');
131#ok(!$doc->coll_editor, 'Collection editor');
132#ok(!$doc->coll_author, 'Collection author');
133is($meta->{S_text_type}, 'Erlass', 'text_type');
134ok(!$meta->{S_text_type_art}, 'text_type art');
135
136
137# A01/02035-substring
138$path = catdir(dirname(__FILE__), 'corpus','A00','02035-substring');
139ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
140ok($doc->parse, 'Parse document');
141
142$meta = $doc->meta;
143
144is($meta->{T_title}, 'St. Galler Tagblatt, 11.01.2000, Ressort: TB-RSP (Abk.)', 'title'); # A00/JAN.02035
145ok(!$meta->{T_sub_title}, 'subTitle');
146is($doc->text_sigle, 'A00/JAN/02035', 'ID');
147is($doc->corpus_sigle, 'A00', 'corpusID');
148is($meta->{D_pub_date}, '20000111', 'pubDate');
149ok(!$meta->{S_pub_place}, 'pubPlace');
150is($meta->{K_text_class}->[0], 'sport', 'TextClass');
151is($meta->{K_text_class}->[1], 'ballsport', 'TextClass');
152ok(!$meta->{K_text_class}->[2], 'TextClass');
153ok(!$meta->{T_author}, 'author');
154
155# Additional information
156ok(!$meta->{A_editor}, 'Editor');
157ok(!$meta->{A_publisher}, 'Publisher');
158is($meta->{D_creation_date}, "20000111", 'Creation date');
159#ok(!$doc->coll_title, 'Collection title');
160#ok(!$doc->coll_sub_title, 'Collection subtitle');
161#ok(!$doc->coll_editor, 'Collection editor');
162#ok(!$doc->coll_author, 'Collection author');
163ok(!$meta->{S_text_type}, 'text_type');
164is($meta->{S_text_type_art}, 'Bericht', 'text_type art');
165
166# A01/02873-meta
167$path = catdir(dirname(__FILE__), 'corpus','A00','02873-meta');
168ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
169ok($doc->parse, 'Parse document');
170$meta = $doc->meta;
171
172is($meta->{T_title}, 'Tradition und Moderne', 'title');
173ok(!$meta->{T_sub_title}, 'subTitle');
174is($doc->text_sigle, 'A00/JAN/02873', 'ID');
175is($doc->corpus_sigle, 'A00', 'corpusID');
176is($meta->{D_pub_date}, '20000113', 'pubDate');
177ok(!$meta->{S_pub_place}, 'pubPlace');
178is($meta->{K_text_class}->[0], 'kultur', 'TextClass');
179is($meta->{K_text_class}->[1], 'film', 'TextClass');
180ok(!$meta->{K_text_class}->[2], 'TextClass');
181ok(!$meta->{T_author}, 'author');
182
183
184# Additional information
185ok(!$meta->{A_editor}, 'Editor');
186ok(!$meta->{A_publisher}, 'Publisher');
187is($meta->{D_creation_date}, "20000113", 'Creation date');
188#ok(!$doc->coll_title, 'Collection title');
189#ok(!$doc->coll_sub_title, 'Collection subtitle');
190#ok(!$doc->coll_editor, 'Collection editor');
191#ok(!$doc->coll_author, 'Collection author');
192ok(!$meta->{S_text_type}, 'text_type');
193is($meta->{S_text_type_art}, 'Bericht', 'text_type art');
194
195
196# A01/05663-unbalanced
197$path = catdir(dirname(__FILE__), 'corpus','A00','05663-unbalanced');
198ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
199ok($doc->parse, 'Parse document');
200$meta = $doc->meta;
201
202is($meta->{T_title}, 'Mehr Arbeitslose im Dezember', 'title');
203ok(!$meta->{T_sub_title}, 'subTitle');
204is($doc->text_sigle, 'A00/JAN/05663', 'ID');
205is($doc->corpus_sigle, 'A00', 'corpusID');
206is($meta->{D_pub_date}, '20000124', 'pubDate');
207ok(!$meta->{S_pub_place}, 'pubPlace');
208is($meta->{K_text_class}->[0], 'gesundheit-ernaehrung', 'TextClass');
209is($meta->{K_text_class}->[1], 'gesundheit', 'TextClass');
210ok(!$meta->{K_text_class}->[2], 'TextClass');
211ok(!$meta->{T_author}, 'author');
212
213
214# Additional information
215ok(!$meta->{A_editor}, 'Editor');
216ok(!$meta->{A_publisher}, 'Publisher');
217is($meta->{D_creation_date}, "20000124", 'Creation date');
218#ok(!$doc->coll_title, 'Collection title');
219#ok(!$doc->coll_sub_title, 'Collection subtitle');
220#ok(!$doc->coll_editor, 'Collection editor');
221#ok(!$doc->coll_author, 'Collection author');
222ok(!$meta->{S_text_type}, 'text_type');
223is($meta->{S_text_type_art}, 'Bericht', 'text_type art');
224
225# A01/07452-deep
226$path = catdir(dirname(__FILE__), 'corpus','A00','07452-deep');
227ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
228ok($doc->parse, 'Parse document');
229$meta = $doc->meta;
230
231is($meta->{T_title}, 'Wil im Dezember 1999', 'title');
232ok(!$meta->{T_sub_title}, 'subTitle');
233is($doc->text_sigle, 'A00/JAN/07452', 'ID');
234is($doc->corpus_sigle, 'A00', 'corpusID');
235is($meta->{D_pub_date}, '20000129', 'pubDate');
236ok(!$meta->{S_pub_place}, 'pubPlace');
237is($meta->{K_text_class}->[0], 'politik', 'TextClass');
238is($meta->{K_text_class}->[1], 'kommunalpolitik', 'TextClass');
239ok(!$meta->{K_text_class}->[2], 'TextClass');
240ok(!$meta->{T_author}, 'author');
241
242
243# Additional information
244ok(!$meta->{A_editor}, 'Editor');
245ok(!$meta->{A_publisher}, 'Publisher');
246is($meta->{D_creation_date}, "20000129", 'Creation date');
247#ok(!$doc->coll_title, 'Collection title');
248#ok(!$doc->coll_sub_title, 'Collection subtitle');
249#ok(!$doc->coll_editor, 'Collection editor');
250#ok(!$doc->coll_author, 'Collection author');
251ok(!$meta->{S_text_type}, 'text_type');
252is($meta->{S_text_type_art}, 'Bericht', 'text_type art');
253
254# Multipath headers
255$path = catdir(dirname(__FILE__), 'corpus','VDI','JAN','00001');
256ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
257like($doc->path, qr!\Q$path\E/!, 'Path');
258
259ok($doc = KorAP::XML::Krill->new( path => $path ), 'Load Korap::Document');
260like($doc->path, qr!\Q$path\E/$!, 'Path');
261
262ok($doc->parse, 'Parse document');
263$meta = $doc->meta;
264
265is($doc->text_sigle, 'VDI14/JAN/00001', 'text sigle');
266is($doc->doc_sigle, 'VDI14/JAN', 'doc sigle');
267is($meta->corpus_sigle, 'VDI14', 'corpus sigle');
268
269is($meta->{T_title}, '10- Zz mit Zahl', 'title');
270
271ok(!$meta->{T_sub_title}, 'subtitle');
272is($meta->{D_pub_date}, '20140117', 'pubdate');
273is($meta->{S_pub_place}, 'Düsseldorf', 'pubplace');
274is($meta->{T_author}, 'Windhövel, Kerstin', 'author');
275is($meta->{A_publisher}, 'VDI Verlag GmbH', 'publisher');
276ok(!$meta->{A_editor}, 'editor');
277
278ok(!$meta->{S_text_type}, 'text type');
279ok(!$meta->{S_text_type_art}, 'text type art');
280ok(!$meta->{S_text_type_ref}, 'text type ref');
281ok(!$meta->{S_text_column}, 'text column');
282ok(!$meta->{S_text_domain}, 'text domain');
283ok(!$meta->{D_creation_date}, 'creation date');
284ok(!$meta->{S_availability}, 'License');
285ok(!$meta->{pages}, 'Pages');
286ok(!$meta->{A_file_edition_statement}, 'file edition statement');
287ok(!$meta->{A_bibl_edition_statement}, 'bibl edition statement');
288is($meta->{A_reference}, 'VDI nachrichten, 17.01.2014, S. 10; 10- Zz mit Zahl [Ausführliche Zitierung nicht verfügbar]', 'Reference');
289
290ok(!$doc->{S_language}, 'Language');
291# !!!
292# diag 'This may be "de" in the future';
293
294is($meta->{T_doc_title}, 'VDI nachrichten, Januar 2014', 'Doc title');
295ok(!$meta->{T_doc_sub_title}, 'Doc Sub title');
296ok(!$meta->{A_doc_editor}, 'Doc editor');
297ok(!$meta->{T_doc_author}, 'Doc author');
298
299is($meta->{T_corpus_title}, 'VDI nachrichten', 'Corpus title');
300ok(!$meta->{T_corpus_sub_title}, 'Corpus Sub title');
301is($meta->{A_corpus_editor}, 'Verein Deutscher Ingenieure', 'Corpus editor');
302ok(!$meta->{T_corpus_author}, 'Corpus author');
303
304is($meta->keywords('K_keywords'), '', 'Keywords');
305is($meta->keywords('K_text_class'), 'Freizeit-Unterhaltung Reisen Politik Ausland', 'Text class');
306
307# WDD
308$path = catdir(dirname(__FILE__), 'corpus','WDD','G27','38989');
309ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
310like($doc->path, qr!\Q$path\E/!, 'Path');
311ok($doc->parse, 'Parse document');
312$meta = $doc->meta;
313
314is($doc->text_sigle, 'WDD11/G27/38989', 'text sigle');
315is($doc->doc_sigle, 'WDD11/G27', 'doc sigle');
316is($doc->corpus_sigle, 'WDD11', 'corpus sigle');
317
318is($meta->{T_title}, 'Diskussion:Gunter A. Pilz', 'title');
319ok(!$meta->{T_sub_title}, 'subtitle');
320is($meta->{D_pub_date}, '20111029', 'pubdate');
321is($meta->{S_pub_place}, 'URL:http://de.wikipedia.org', 'pubplace');
322
323is($meta->{T_author}, '€pa, u.a.', 'author');
324is($meta->{A_publisher}, 'Wikipedia', 'publisher');
325is($meta->{A_editor}, 'wikipedia.org', 'Editor');
326
327is($meta->{S_text_type}, 'Diskussionen zu Enzyklopädie-Artikeln', 'text type');
328ok(!$meta->{S_text_type_art}, 'text type art');
329ok(!$meta->{S_text_type_ref}, 'text type ref');
330ok(!$meta->{S_text_column}, 'text column');
331ok(!$meta->{S_text_domain}, 'text domain');
332
333is($meta->{D_creation_date}, '20070707', 'creation date');
334is($meta->{S_availability}, 'CC-BY-SA', 'License');
335ok(!$meta->{pages}, 'Pages');
336ok(!$meta->{A_file_edition_statement}, 'file edition statement');
337ok(!$meta->{A_bibl_edition_statement}, 'bibl edition statement');
338is($meta->{A_reference}, 'Diskussion:Gunter A. Pilz, In: Wikipedia - URL:http://de.wikipedia.org/wiki/Diskussion:Gunter_A._Pilz: Wikipedia, 2007', 'Reference');
339
340is($meta->{S_language}, 'de', 'Language');
341
342is($meta->{T_doc_title}, 'Wikipedia, Diskussionen zu Artikeln mit Anfangsbuchstabe G, Teil 27', 'Doc title');
343ok(!$meta->{T_doc_sub_title}, 'Doc Sub title');
344ok(!$meta->{A_doc_editor}, 'Doc editor');
345ok(!$meta->{T_doc_author}, 'Doc author');
346
347is($meta->{T_corpus_title}, 'Wikipedia', 'Corpus title');
348ok(!$meta->{T_corpus_sub_title}, 'Corpus Sub title');
349is($meta->{A_corpus_editor}, 'wikipedia.org', 'Corpus editor');
350ok(!$meta->{T_corpus_author}, 'Corpus author');
351
352is($meta->keywords('keywords'), '', 'Keywords');
353is($meta->keywords('text_class'), '', 'Text class');
354
355is($meta->{S_availability}, 'CC-BY-SA', 'Availability');
356
357use_ok('KorAP::XML::Meta::I5');
358
359$path = catdir(dirname(__FILE__), 'corpus', 'I5', 'rei-example.i5');
360ok($meta = KorAP::XML::Meta::I5->new, 'Construct meta object');
361my $dom = Mojo::DOM->new->parse(Mojo::File->new($path)->slurp);
362ok($meta->parse($dom->at('idsHeader'), 'corpus'), 'Parse corpus header');
363
364my $hash = $meta->to_hash;
365is($hash->{S_availability}, 'CC-BY-SA', 'Availability');
366is($hash->{S_language}, 'de', 'Language');
367is($hash->{T_corpus_title}, 'Reden und Interviews', 'Corpus title');
368is($hash->{corpus_sigle}, 'REI', 'Corpus Sigle');
369
370ok($meta->parse($dom->find('idsHeader')->[1], 'doc'), 'Parse corpus header');
371
372$hash = $meta->to_hash;
373is($hash->{S_availability}, 'CC-BY-SA', 'Availability');
374is($hash->{S_language}, 'de', 'Language');
375is($hash->{T_corpus_title}, 'Reden und Interviews', 'Corpus title');
376is($hash->{corpus_sigle}, 'REI', 'Corpus Sigle');
377is($hash->{doc_sigle}, 'REI/BNG', 'Document Sigle');
378is($hash->{T_doc_title}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Document Sigle');
379
380ok($meta->parse($dom->find('idsHeader')->[2], 'text'), 'Parse corpus header');
381
382$hash = $meta->to_hash;
383is($hash->{S_availability}, 'CC-BY-SA', 'Availability');
384is($hash->{S_language}, 'de', 'Language');
385is($hash->{T_corpus_title}, 'Reden und Interviews', 'Corpus title');
386is($hash->{corpus_sigle}, 'REI', 'Corpus Sigle');
387is($hash->{doc_sigle}, 'REI/BNG', 'Document Sigle');
388is($hash->{T_doc_title}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Document Sigle');
389
390is($hash->{text_sigle}, 'REI/BNG/00001');
391is($hash->{T_title}, 'Energiewirtschaft');
392is($hash->{T_sub_title}, 'Rede im Deutschen Bundestag am 19.01.2002');
393is($hash->{D_creation_date}, '20020119');
394is($hash->{D_pub_date}, '20020119');
395is($hash->{S_pub_place_key}, 'DE');
396is($hash->{A_reference}, 'Hustedt, Michaele: Energiewirtschaft. Rede im Deutschen Bundestag am 19.01.2002, Hrsg: Bundestagsfraktion Bündnis 90/DIE GRÜNEN [Ausführliche Zitierung nicht verfügbar]');
397is($hash->{K_text_class}->[0], 'politik');
398is($hash->{K_text_class}->[1], 'inland');
399is($hash->{T_author}, 'Hustedt, Michaele');
400is($hash->{S_pub_place}, 'Berlin');
401
402
403# UMB45/D38/00001
404$path = catdir(dirname(__FILE__), 'corpus','UMB45','D38','00001');
405ok($doc = KorAP::XML::Krill->new( path => $path), 'Load Korap::Document');
406like($doc->path, qr!\Q$path\E/!, 'Path');
407
408ok($doc->parse, 'Parse document');
409$meta = $doc->meta;
410
411is($doc->text_sigle, 'UMB45/D38/00001', 'text sigle');
412is($doc->doc_sigle, 'UMB45/D38', 'doc sigle');
413is($doc->corpus_sigle, 'UMB45', 'corpus sigle');
414
415is($meta->{T_title}, 'In: Über Schuld und Aufgabe der geistigen Führungsschicht im deutschen politischen Leben der Gegenwart. - Göttingen, 1955', 'title');
416
417
418done_testing;
419__END__
420
421
422