blob: 8c0d16e2ce715acfc8a047e72aa16acb9a105127 [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', '00001');
Akron9c0488f2016-01-28 14:17:15 +010024
Akrone4c2e412016-01-28 15:10:50 +010025ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
Akron9c0488f2016-01-28 14:17:15 +010026ok($doc->parse, 'Parse document');
27
Akron1cd5b872016-03-22 00:23:46 +010028is($doc->text_sigle, 'BZK/D59/00001', '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}, 'Unser gemeinsames Werk wird siegreich sein', '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');
38ok(!$meta->{A_publisher}, 'Publisher');
Akron9c0488f2016-01-28 14:17:15 +010039
Akron5eb3aa02019-01-25 18:30:47 +010040is($meta->{S_text_type}, 'Zeitung: Tageszeitung', 'Correct Text Type');
Akron9c0488f2016-01-28 14:17:15 +010041
Akron5eb3aa02019-01-25 18:30:47 +010042ok(!$meta->{S_text_type_art}, 'Correct Text Type Art');
43is($meta->{S_text_type_ref}, 'Tageszeitung', 'Correct Text Type Ref');
44is($meta->{S_text_domain}, 'Politik', 'Correct Text Domain');
45is($meta->{S_text_column}, 'POLITIK', 'Correct Text Column');
46is($meta->{K_text_class}->[0], 'politik', 'Correct Text Class');
47is($meta->{K_text_class}->[1], 'ausland', 'Correct Text Class');
48ok(!$meta->{K_text_class}->[2], 'Correct Text Class');
Akron9c0488f2016-01-28 14:17:15 +010049
Akron5eb3aa02019-01-25 18:30:47 +010050is($meta->{D_pub_date}, '19590101', 'Creation date');
51is($meta->{D_creation_date}, '19590101', 'Creation date');
52is($meta->{S_availability}, 'ACA-NC-LC', 'License');
Akron35db6e32016-03-17 22:42:22 +010053ok(!$meta->{pages}, 'Pages');
Akron9c0488f2016-01-28 14:17:15 +010054
Akron5eb3aa02019-01-25 18:30:47 +010055ok(!$meta->{A_file_edition_statement}, 'File Statement');
56ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement');
Akron9c0488f2016-01-28 14:17:15 +010057
Akron5eb3aa02019-01-25 18:30:47 +010058is($meta->{A_reference} . "\n", <<'REF', 'Reference');
Akron9c0488f2016-01-28 14:17:15 +010059Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein
60REF
Akron5eb3aa02019-01-25 18:30:47 +010061is($meta->{S_language}, 'de', 'Language');
Akron9c0488f2016-01-28 14:17:15 +010062
Akron5eb3aa02019-01-25 18:30:47 +010063is($meta->{T_corpus_title}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
64ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title');
65ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
66ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akron9c0488f2016-01-28 14:17:15 +010067
Akron5eb3aa02019-01-25 18:30:47 +010068is($meta->{T_doc_title}, 'Neues Deutschland', 'Correct Doc title');
69is($meta->{T_doc_sub_title}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
70ok(!$meta->{T_doc_author}, 'Correct Doc author');
71ok(!$meta->{A_doc_editor}, 'Correct doc editor');
Akron9c0488f2016-01-28 14:17:15 +010072
73# Tokenization
Akrone4c2e412016-01-28 15:10:50 +010074use_ok('KorAP::XML::Tokenizer');
Akron9c0488f2016-01-28 14:17:15 +010075
76my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
77
78# Get tokenization
Akrone4c2e412016-01-28 15:10:50 +010079my $tokens = KorAP::XML::Tokenizer->new(
Akron9c0488f2016-01-28 14:17:15 +010080 path => $doc->path,
81 doc => $doc,
82 foundry => $token_base_foundry,
83 layer => $token_base_layer,
84 name => 'tokens'
85);
86ok($tokens, 'Token Object is fine');
87ok($tokens->parse, 'Token parsing is fine');
88
89my $output = decode_json( $tokens->to_json );
90
91is(substr($output->{data}->{text}, 0, 100), 'unser gemeinsames Werk wird siegreich sein Neujahrsbotschaft des Präsidenten der DeutschenDemokratis', 'Primary Data');
92is($output->{data}->{name}, 'tokens', 'tokenName');
93is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
94is($output->{version}, '0.03', 'version');
95is($output->{data}->{foundries}, '', 'Foundries');
96is($output->{data}->{layerInfos}, '', 'layerInfos');
Akron2d83a5a2016-02-26 00:21:16 +010097is($output->{data}->{stream}->[0]->[4], 's:unser', 'data');
Akron9c0488f2016-01-28 14:17:15 +010098
Akron1cd5b872016-03-22 00:23:46 +010099is($output->{textSigle}, 'BZK/D59/00001', 'Correct text sigle');
100is($output->{docSigle}, 'BZK/D59', 'Correct document sigle');
Akron9c0488f2016-01-28 14:17:15 +0100101is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle');
102
103is($output->{title}, 'Unser gemeinsames Werk wird siegreich sein', 'Title');
104ok(!exists $output->{subTitle}, 'No SubTitle');
105ok(!exists $output->{author}, 'Author');
106ok(!exists $output->{editor}, 'Publisher');
107
108is($output->{pubPlace}, 'Berlin', 'PubPlace');
Akron5eb3aa02019-01-25 18:30:47 +0100109ok(!exists $output->{A_publisher}, 'Publisher');
Akron9c0488f2016-01-28 14:17:15 +0100110
111is($output->{textType}, 'Zeitung: Tageszeitung', 'Correct Text Type');
112ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
113is($output->{textTypeRef}, 'Tageszeitung', 'Correct Text Type Ref');
114is($output->{textDomain}, 'Politik', 'Correct Text Domain');
115
116is($output->{creationDate}, '19590101', 'Creation date');
Akron6396c302016-03-18 16:05:39 +0100117is($output->{availability}, 'ACA-NC-LC', 'License');
Akron9c0488f2016-01-28 14:17:15 +0100118ok(!exists $output->{pages}, 'Pages');
119ok(!exists $output->{fileEditionStatement}, 'File Statement');
120ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
121
122is($output->{reference} . "\n", <<'REF', 'Reference');
123Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein
124REF
125is($output->{language}, 'de', 'Language');
126
127is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
128ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
129ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
130ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
131
132is($output->{docTitle}, 'Neues Deutschland', 'Correct Doc title');
133is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
134ok(!exists $output->{docAuthor}, 'Correct Doc author');
135ok(!exists $output->{docEditor}, 'Correct doc editor');
136
137## Base
138$tokens->add('Base', 'Sentences');
139$tokens->add('Base', 'Paragraphs');
140
141$output = decode_json( $tokens->to_json );
142
143
144is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
145is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
146my $first_token = join('||', @{$output->{data}->{stream}->[0]});
147like($first_token, qr/s:unser/, 'data');
148like($first_token, qr/_0\$<i>0<i>5/, 'data');
149
150## OpenNLP
151$tokens->add('OpenNLP', 'Sentences');
152
153$output = decode_json( $tokens->to_json );
154is($output->{data}->{foundries},
155 'base base/paragraphs base/sentences opennlp opennlp/sentences',
156 'Foundries');
157is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos');
158
159
160$tokens->add('OpenNLP', 'Morpho');
161$output = decode_json( $tokens->to_json );
162is($output->{data}->{foundries},
163 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
164 'Foundries');
165is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos');
166
167
168## Treetagger
169$tokens->add('TreeTagger', 'Sentences');
170$output = decode_json( $tokens->to_json );
171is($output->{data}->{foundries},
172 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
173 'Foundries');
174is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos');
175
176$tokens->add('TreeTagger', 'Morpho');
177$output = decode_json( $tokens->to_json );
178is($output->{data}->{foundries},
179 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
180 'Foundries');
181is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
182
183## CoreNLP
184$tokens->add('CoreNLP', 'NamedEntities');
185$output = decode_json( $tokens->to_json );
186is($output->{data}->{foundries},
187 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
188 'Foundries');
189is($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');
190
191$tokens->add('CoreNLP', 'Sentences');
192$output = decode_json( $tokens->to_json );
193is($output->{data}->{foundries},
194 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
195 'Foundries');
196is($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');
197
198$tokens->add('CoreNLP', 'Morpho');
199$output = decode_json( $tokens->to_json );
200like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries');
201like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
202
203$tokens->add('CoreNLP', 'Constituency');
204$output = decode_json( $tokens->to_json );
205like($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries');
206like($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos');
207
208## Glemm
209$tokens->add('Glemm', 'Morpho');
210$output = decode_json( $tokens->to_json );
211like($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries');
212like($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos');
213
214## Connexor
215$tokens->add('Connexor', 'Sentences');
216$output = decode_json( $tokens->to_json );
217like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries');
218like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos');
219
220$tokens->add('Connexor', 'Morpho');
221$output = decode_json( $tokens->to_json );
222like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries');
223like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos');
224like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos');
225like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos');
226
227$tokens->add('Connexor', 'Phrase');
228$output = decode_json( $tokens->to_json );
229like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries');
230like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos');
231
232$tokens->add('Connexor', 'Syntax');
233$output = decode_json( $tokens->to_json );
234like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries');
235like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos');
236
237## Mate - not in existence
238{
239 local $SIG{__WARN__} = sub {};
240 $tokens->add('Mate', 'Morpho');
241 $output = decode_json( $tokens->to_json );
242 unlike($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
243 unlike($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
244 unlike($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
245 unlike($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
246};
247
248# diag "No test for mate dependency";
249
250## XIP
251$tokens->add('XIP', 'Sentences');
252$output = decode_json( $tokens->to_json );
253like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries');
254like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos');
255
256$tokens->add('XIP', 'Morpho');
257$output = decode_json( $tokens->to_json );
258like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries');
259like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos');
260like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos');
261
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
270
271done_testing;
272__END__