blob: ea81cf406f86d7eac8cb5d8d1ce5ab23bd9698ac [file] [log] [blame]
Akron9c0488f2016-01-28 14:17:15 +01001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
6
Akronfab17d32020-07-31 14:38:29 +02007if ($ENV{SKIP_REAL}) {
8 plan skip_all => 'Skip real tests';
9};
10
Akron9c0488f2016-01-28 14:17:15 +010011use Benchmark qw/:hireswallclock/;
12
13my $t = Benchmark->new;
14
15use utf8;
16use lib 'lib', '../lib';
17
18use File::Basename 'dirname';
19use File::Spec::Functions 'catdir';
20
Akrone4c2e412016-01-28 15:10:50 +010021use_ok('KorAP::XML::Krill');
Akron9c0488f2016-01-28 14:17:15 +010022
Akron414ec952020-08-03 15:48:43 +020023my $path = catdir(dirname(__FILE__), 'corpus','BZK','D59','00089');
Akron9c0488f2016-01-28 14:17:15 +010024
Akrone4c2e412016-01-28 15:10:50 +010025ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::XML::Krill');
Akron9c0488f2016-01-28 14:17:15 +010026ok($doc->parse, 'Parse document');
27
Akron1cd5b872016-03-22 00:23:46 +010028is($doc->text_sigle, 'BZK/D59/00089', 'Correct text sigle');
29is($doc->doc_sigle, 'BZK/D59', 'Correct document sigle');
Akron9c0488f2016-01-28 14:17:15 +010030is($doc->corpus_sigle, 'BZK', 'Correct corpus sigle');
31
Akron35db6e32016-03-17 22:42:22 +010032my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010033is($meta->{T_title}, 'Saragat-Partei zerfällt', 'Title');
34ok(!$meta->{T_sub_title}, 'No SubTitle');
35ok(!$meta->{T_author}, 'Author');
36ok(!$meta->{A_editor}, 'Editor');
37is($meta->{S_pub_place}, 'Berlin', 'PubPlace');
38is($meta->{D_pub_date}, '19590219', 'PubDate');
39ok(!$meta->{A_publisher}, 'Publisher');
Akron9c0488f2016-01-28 14:17:15 +010040
Akron9d01c1e2024-07-25 18:29:10 +020041is($meta->{K_award}->[0], 'Deutscher Buchpreis 2023', 'Award');
42is($meta->{K_award}->[1], 'Booker price 2024', 'Award');
43
Akron5eb3aa02019-01-25 18:30:47 +010044is($meta->{S_text_type}, 'Zeitung: Tageszeitung', 'Correct Text Type');
Akron9c0488f2016-01-28 14:17:15 +010045
Akron5eb3aa02019-01-25 18:30:47 +010046ok(!$meta->{S_text_type_art}, 'Correct Text Type Art');
47is($meta->{S_text_type_ref}, 'Tageszeitung', 'Correct Text Type Ref');
48is($meta->{S_text_domain}, 'Politik', 'Correct Text Domain');
49is($meta->{S_text_column}, 'POLITIK', 'Correct Text Column');
50is($meta->{K_text_class}->[0], 'politik', 'Correct Text Class');
51is($meta->{K_text_class}->[1], 'ausland', 'Correct Text Class');
52ok(!$meta->{K_text_class}->[2], 'Correct Text Class');
Akron9c0488f2016-01-28 14:17:15 +010053
Akron5eb3aa02019-01-25 18:30:47 +010054is($meta->{D_creation_date}, '19590219', 'Creation date');
55is($meta->{S_availability}, 'ACA-NC-LC', 'License');
Akron35db6e32016-03-17 22:42:22 +010056ok(!$meta->{pages}, 'Pages');
Akron9c0488f2016-01-28 14:17:15 +010057
Akron5eb3aa02019-01-25 18:30:47 +010058ok(!$meta->{A_file_edition_statement}, 'File Statement');
59ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement');
Akron9c0488f2016-01-28 14:17:15 +010060
Akron5eb3aa02019-01-25 18:30:47 +010061is($meta->{A_reference} . "\n", <<'REF', 'Reference');
Akron9c0488f2016-01-28 14:17:15 +010062Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt
63REF
Akron5eb3aa02019-01-25 18:30:47 +010064is($meta->{S_language}, 'de', 'Language');
Akron9c0488f2016-01-28 14:17:15 +010065
Akron5eb3aa02019-01-25 18:30:47 +010066is($meta->{T_corpus_title}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
67ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title');
68ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
69ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akron9c0488f2016-01-28 14:17:15 +010070
Akron5eb3aa02019-01-25 18:30:47 +010071is($meta->{T_doc_title}, 'Neues Deutschland', 'Correct Doc title');
72is($meta->{T_doc_sub_title}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
73ok(!$meta->{T_doc_author}, 'Correct Doc author');
74ok(!$meta->{A_doc_editor}, 'Correct doc editor');
Akron9c0488f2016-01-28 14:17:15 +010075
Akron1f951222024-07-25 17:45:21 +020076is($meta->{A_URN},'data:application/x.korap-link;title=urn%3Anbn%3Ade%3A101%3A1-2019012904515398173807,http%3A%2F%2Fnbn-resolving.de%2Furn%3Anbn%3Ade%3A101%3A1-2019012904515398173807');
77is($meta->{S_ISBN},'978-3-7325-6705-8');
78
Akron9c0488f2016-01-28 14:17:15 +010079# Tokenization
Akrone4c2e412016-01-28 15:10:50 +010080use_ok('KorAP::XML::Tokenizer');
Akron9c0488f2016-01-28 14:17:15 +010081
82my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
83
84# Get tokenization
Akrone4c2e412016-01-28 15:10:50 +010085my $tokens = KorAP::XML::Tokenizer->new(
Akron9c0488f2016-01-28 14:17:15 +010086 path => $doc->path,
87 doc => $doc,
88 foundry => $token_base_foundry,
89 layer => $token_base_layer,
90 name => 'tokens'
91);
92ok($tokens, 'Token Object is fine');
93ok($tokens->parse, 'Token parsing is fine');
94
95my $output = decode_json( $tokens->to_json );
96
97is(substr($output->{data}->{text}, 0, 100), 'Saragat-Partei zerfällt Rom (ADN) die von dem Rechtssozialisten Saragat geführte Sozialdemokratische', 'Primary Data');
98is($output->{data}->{name}, 'tokens', 'tokenName');
99is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
100is($output->{version}, '0.03', 'version');
101is($output->{data}->{foundries}, '', 'Foundries');
102is($output->{data}->{layerInfos}, '', 'layerInfos');
Akron2d83a5a2016-02-26 00:21:16 +0100103is($output->{data}->{stream}->[0]->[4], 's:Saragat-Partei', 'data');
Akron9c0488f2016-01-28 14:17:15 +0100104
Akron1cd5b872016-03-22 00:23:46 +0100105is($output->{textSigle}, 'BZK/D59/00089', 'Correct text sigle');
106is($output->{docSigle}, 'BZK/D59', 'Correct document sigle');
Akron9c0488f2016-01-28 14:17:15 +0100107is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle');
108
109is($output->{title}, 'Saragat-Partei zerfällt', 'Title');
110ok(!exists $output->{subTitle}, 'No SubTitle');
111ok(!exists $output->{author}, 'Author');
112ok(!exists $output->{editor}, 'Publisher');
113
114is($output->{pubPlace}, 'Berlin', 'PubPlace');
115ok(!exists $output->{publisher}, 'Publisher');
116
117is($output->{textType}, 'Zeitung: Tageszeitung', 'Correct Text Type');
118ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
119is($output->{textTypeRef}, 'Tageszeitung', 'Correct Text Type Ref');
120is($output->{textDomain}, 'Politik', 'Correct Text Domain');
121is($output->{textClass}, 'politik ausland', 'Correct Text Domain');
122
123is($output->{creationDate}, '19590219', 'Creation date');
Akron6396c302016-03-18 16:05:39 +0100124is($output->{availability}, 'ACA-NC-LC', 'License');
Akron9c0488f2016-01-28 14:17:15 +0100125ok(!exists $output->{pages}, 'Pages');
126ok(!exists $output->{fileEditionStatement}, 'File Statement');
127ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
128
129is($output->{reference} . "\n", <<'REF', 'Reference');
130Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt
131REF
132is($output->{language}, 'de', 'Language');
133
134is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
135ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
136ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
137ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
138
139is($output->{docTitle}, 'Neues Deutschland', 'Correct Doc title');
140is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
141ok(!exists $output->{docAuthor}, 'Correct Doc author');
142ok(!exists $output->{docEditor}, 'Correct doc editor');
143
144## Base
145$tokens->add('Base', 'Sentences');
146$tokens->add('Base', 'Paragraphs');
147
148$output = decode_json( $tokens->to_json );
149
150is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
151is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
152my $first_token = join('||', @{$output->{data}->{stream}->[0]});
153like($first_token, qr/s:Saragat-Partei/, 'data');
154like($first_token, qr/_0\$<i>0<i>14/, 'data');
155
156## OpenNLP
157$tokens->add('OpenNLP', 'Sentences');
158
159$output = decode_json( $tokens->to_json );
160is($output->{data}->{foundries},
161 'base base/paragraphs base/sentences opennlp opennlp/sentences',
162 'Foundries');
163is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos');
164
165$tokens->add('OpenNLP', 'Morpho');
166$output = decode_json( $tokens->to_json );
167is($output->{data}->{foundries},
168 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
169 'Foundries');
170is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos');
171
172## Treetagger
173$tokens->add('TreeTagger', 'Sentences');
174$output = decode_json( $tokens->to_json );
175is($output->{data}->{foundries},
176 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
177 'Foundries');
178is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos');
179
180$tokens->add('TreeTagger', 'Morpho');
181$output = decode_json( $tokens->to_json );
182is($output->{data}->{foundries},
183 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
184 'Foundries');
185is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
186
187## CoreNLP
188$tokens->add('CoreNLP', 'NamedEntities');
189$output = decode_json( $tokens->to_json );
190is($output->{data}->{foundries},
191 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
192 'Foundries');
193is($output->{data}->{layerInfos}, 'base/s=spans corenlp/ne=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
194
195$tokens->add('CoreNLP', 'Sentences');
196$output = decode_json( $tokens->to_json );
197is($output->{data}->{foundries},
198 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
199 'Foundries');
200is($output->{data}->{layerInfos}, 'base/s=spans corenlp/ne=tokens corenlp/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
201
202$tokens->add('CoreNLP', 'Morpho');
203$output = decode_json( $tokens->to_json );
204like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries');
205like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
206
207$tokens->add('CoreNLP', 'Constituency');
208$output = decode_json( $tokens->to_json );
209like($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries');
210like($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos');
211
212## Glemm
213$tokens->add('Glemm', 'Morpho');
214$output = decode_json( $tokens->to_json );
215like($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries');
216like($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos');
217
218## Connexor
219$tokens->add('Connexor', 'Sentences');
220$output = decode_json( $tokens->to_json );
221like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries');
222like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos');
223
224$tokens->add('Connexor', 'Morpho');
225$output = decode_json( $tokens->to_json );
226like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries');
227like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos');
228like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos');
229like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos');
230
231$tokens->add('Connexor', 'Phrase');
232$output = decode_json( $tokens->to_json );
233like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries');
234like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos');
235
236$tokens->add('Connexor', 'Syntax');
237$output = decode_json( $tokens->to_json );
238like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries');
239like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos');
240
241## Mate
242$tokens->add('Mate', 'Morpho');
243$output = decode_json( $tokens->to_json );
244like($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
245like($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
246like($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
247like($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
248
249# diag "No test for mate dependency";
250
251## XIP
252$tokens->add('XIP', 'Sentences');
253$output = decode_json( $tokens->to_json );
254like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries');
255like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos');
256
257$tokens->add('XIP', 'Morpho');
258$output = decode_json( $tokens->to_json );
259like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries');
260like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos');
261like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos');
262
263$tokens->add('XIP', 'Constituency');
264$output = decode_json( $tokens->to_json );
265like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries');
266like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos');
267
268# diag "No test for xip dependency";
269
270done_testing;
271__END__