blob: d250a7c2f3aeda4acadda72505400cccd694da1c [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
54
Akron5eb3aa02019-01-25 18:30:47 +010055is($meta->{D_creation_date}, '19590219', 'Creation date');
56is($meta->{S_availability}, 'ACA-NC-LC', 'License');
Akron35db6e32016-03-17 22:42:22 +010057ok(!$meta->{pages}, 'Pages');
Akron9c0488f2016-01-28 14:17:15 +010058
Akron5eb3aa02019-01-25 18:30:47 +010059ok(!$meta->{A_file_edition_statement}, 'File Statement');
60ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement');
Akron9c0488f2016-01-28 14:17:15 +010061
Akron5eb3aa02019-01-25 18:30:47 +010062is($meta->{A_reference} . "\n", <<'REF', 'Reference');
Akron9c0488f2016-01-28 14:17:15 +010063Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt
64REF
Akron5eb3aa02019-01-25 18:30:47 +010065is($meta->{S_language}, 'de', 'Language');
Akron9c0488f2016-01-28 14:17:15 +010066
Akron5eb3aa02019-01-25 18:30:47 +010067is($meta->{T_corpus_title}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
68ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title');
69ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
70ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akron9c0488f2016-01-28 14:17:15 +010071
Akron5eb3aa02019-01-25 18:30:47 +010072is($meta->{T_doc_title}, 'Neues Deutschland', 'Correct Doc title');
73is($meta->{T_doc_sub_title}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
74ok(!$meta->{T_doc_author}, 'Correct Doc author');
75ok(!$meta->{A_doc_editor}, 'Correct doc editor');
Akron9c0488f2016-01-28 14:17:15 +010076
77# Tokenization
Akrone4c2e412016-01-28 15:10:50 +010078use_ok('KorAP::XML::Tokenizer');
Akron9c0488f2016-01-28 14:17:15 +010079
80my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
81
82# Get tokenization
Akrone4c2e412016-01-28 15:10:50 +010083my $tokens = KorAP::XML::Tokenizer->new(
Akron9c0488f2016-01-28 14:17:15 +010084 path => $doc->path,
85 doc => $doc,
86 foundry => $token_base_foundry,
87 layer => $token_base_layer,
88 name => 'tokens'
89);
90ok($tokens, 'Token Object is fine');
91ok($tokens->parse, 'Token parsing is fine');
92
93my $output = decode_json( $tokens->to_json );
94
95is(substr($output->{data}->{text}, 0, 100), 'Saragat-Partei zerfällt Rom (ADN) die von dem Rechtssozialisten Saragat geführte Sozialdemokratische', 'Primary Data');
96is($output->{data}->{name}, 'tokens', 'tokenName');
97is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
98is($output->{version}, '0.03', 'version');
99is($output->{data}->{foundries}, '', 'Foundries');
100is($output->{data}->{layerInfos}, '', 'layerInfos');
Akron2d83a5a2016-02-26 00:21:16 +0100101is($output->{data}->{stream}->[0]->[4], 's:Saragat-Partei', 'data');
Akron9c0488f2016-01-28 14:17:15 +0100102
Akron1cd5b872016-03-22 00:23:46 +0100103is($output->{textSigle}, 'BZK/D59/00089', 'Correct text sigle');
104is($output->{docSigle}, 'BZK/D59', 'Correct document sigle');
Akron9c0488f2016-01-28 14:17:15 +0100105is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle');
106
107is($output->{title}, 'Saragat-Partei zerfällt', 'Title');
108ok(!exists $output->{subTitle}, 'No SubTitle');
109ok(!exists $output->{author}, 'Author');
110ok(!exists $output->{editor}, 'Publisher');
111
112is($output->{pubPlace}, 'Berlin', 'PubPlace');
113ok(!exists $output->{publisher}, 'Publisher');
114
115is($output->{textType}, 'Zeitung: Tageszeitung', 'Correct Text Type');
116ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
117is($output->{textTypeRef}, 'Tageszeitung', 'Correct Text Type Ref');
118is($output->{textDomain}, 'Politik', 'Correct Text Domain');
119is($output->{textClass}, 'politik ausland', 'Correct Text Domain');
120
121is($output->{creationDate}, '19590219', 'Creation date');
Akron6396c302016-03-18 16:05:39 +0100122is($output->{availability}, 'ACA-NC-LC', 'License');
Akron9c0488f2016-01-28 14:17:15 +0100123ok(!exists $output->{pages}, 'Pages');
124ok(!exists $output->{fileEditionStatement}, 'File Statement');
125ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
126
127is($output->{reference} . "\n", <<'REF', 'Reference');
128Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt
129REF
130is($output->{language}, 'de', 'Language');
131
132is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
133ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
134ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
135ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
136
137is($output->{docTitle}, 'Neues Deutschland', 'Correct Doc title');
138is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
139ok(!exists $output->{docAuthor}, 'Correct Doc author');
140ok(!exists $output->{docEditor}, 'Correct doc editor');
141
142## Base
143$tokens->add('Base', 'Sentences');
144$tokens->add('Base', 'Paragraphs');
145
146$output = decode_json( $tokens->to_json );
147
148is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
149is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
150my $first_token = join('||', @{$output->{data}->{stream}->[0]});
151like($first_token, qr/s:Saragat-Partei/, 'data');
152like($first_token, qr/_0\$<i>0<i>14/, 'data');
153
154## OpenNLP
155$tokens->add('OpenNLP', 'Sentences');
156
157$output = decode_json( $tokens->to_json );
158is($output->{data}->{foundries},
159 'base base/paragraphs base/sentences opennlp opennlp/sentences',
160 'Foundries');
161is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos');
162
163$tokens->add('OpenNLP', 'Morpho');
164$output = decode_json( $tokens->to_json );
165is($output->{data}->{foundries},
166 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
167 'Foundries');
168is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos');
169
170## Treetagger
171$tokens->add('TreeTagger', 'Sentences');
172$output = decode_json( $tokens->to_json );
173is($output->{data}->{foundries},
174 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
175 'Foundries');
176is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos');
177
178$tokens->add('TreeTagger', 'Morpho');
179$output = decode_json( $tokens->to_json );
180is($output->{data}->{foundries},
181 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
182 'Foundries');
183is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
184
185## CoreNLP
186$tokens->add('CoreNLP', 'NamedEntities');
187$output = decode_json( $tokens->to_json );
188is($output->{data}->{foundries},
189 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
190 'Foundries');
191is($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');
192
193$tokens->add('CoreNLP', 'Sentences');
194$output = decode_json( $tokens->to_json );
195is($output->{data}->{foundries},
196 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
197 'Foundries');
198is($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');
199
200$tokens->add('CoreNLP', 'Morpho');
201$output = decode_json( $tokens->to_json );
202like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries');
203like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
204
205$tokens->add('CoreNLP', 'Constituency');
206$output = decode_json( $tokens->to_json );
207like($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries');
208like($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos');
209
210## Glemm
211$tokens->add('Glemm', 'Morpho');
212$output = decode_json( $tokens->to_json );
213like($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries');
214like($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos');
215
216## Connexor
217$tokens->add('Connexor', 'Sentences');
218$output = decode_json( $tokens->to_json );
219like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries');
220like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos');
221
222$tokens->add('Connexor', 'Morpho');
223$output = decode_json( $tokens->to_json );
224like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries');
225like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos');
226like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos');
227like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos');
228
229$tokens->add('Connexor', 'Phrase');
230$output = decode_json( $tokens->to_json );
231like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries');
232like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos');
233
234$tokens->add('Connexor', 'Syntax');
235$output = decode_json( $tokens->to_json );
236like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries');
237like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos');
238
239## Mate
240$tokens->add('Mate', 'Morpho');
241$output = decode_json( $tokens->to_json );
242like($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
243like($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
244like($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
245like($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
246
247# diag "No test for mate dependency";
248
249## XIP
250$tokens->add('XIP', 'Sentences');
251$output = decode_json( $tokens->to_json );
252like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries');
253like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos');
254
255$tokens->add('XIP', 'Morpho');
256$output = decode_json( $tokens->to_json );
257like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries');
258like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos');
259like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos');
260
261$tokens->add('XIP', 'Constituency');
262$output = decode_json( $tokens->to_json );
263like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries');
264like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos');
265
266# diag "No test for xip dependency";
267
268done_testing;
269__END__