blob: bb5a2f231f63376eaf6da9f3ef51fc704dbd7530 [file] [log] [blame]
Akron9c0488f2016-01-28 14:17:15 +01001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
Nils Diewaldb3e9ccd2016-10-24 15:16:52 +02006use Log::Log4perl;
Akron9c0488f2016-01-28 14:17:15 +01007
Akronfab17d32020-07-31 14:38:29 +02008if ($ENV{SKIP_REAL}) {
9 plan skip_all => 'Skip real tests';
10};
11
Akron9c0488f2016-01-28 14:17:15 +010012use Benchmark qw/:hireswallclock/;
13
14my $t = Benchmark->new;
15
16use utf8;
17use lib 'lib', '../lib';
18
Nils Diewaldb3e9ccd2016-10-24 15:16:52 +020019#Log::Log4perl->init({
20# 'log4perl.rootLogger' => 'DEBUG, STDERR',
21# 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
22# 'log4perl.appender.STDERR.layout' => 'PatternLayout',
23# 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
24#});
25
Akron9c0488f2016-01-28 14:17:15 +010026use File::Basename 'dirname';
27use File::Spec::Functions 'catdir';
28
Akrone4c2e412016-01-28 15:10:50 +010029use_ok('KorAP::XML::Krill');
Akron9c0488f2016-01-28 14:17:15 +010030
Nils Diewaldb3e9ccd2016-10-24 15:16:52 +020031my $path = catdir(dirname(__FILE__), '..', 'corpus', 'BZK', 'D59', '00001');
Akron9c0488f2016-01-28 14:17:15 +010032
Akrone4c2e412016-01-28 15:10:50 +010033ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
Akron9c0488f2016-01-28 14:17:15 +010034ok($doc->parse, 'Parse document');
35
Akron1cd5b872016-03-22 00:23:46 +010036is($doc->text_sigle, 'BZK/D59/00001', 'Correct text sigle');
37is($doc->doc_sigle, 'BZK/D59', 'Correct document sigle');
Akron9c0488f2016-01-28 14:17:15 +010038is($doc->corpus_sigle, 'BZK', 'Correct corpus sigle');
39
Akron35db6e32016-03-17 22:42:22 +010040my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010041is($meta->{T_title}, 'Unser gemeinsames Werk wird siegreich sein', 'Title');
42ok(!$meta->{T_sub_title}, 'No SubTitle');
43ok(!$meta->{T_author}, 'Author');
44ok(!$meta->{A_editor}, 'Editor');
45is($meta->{S_pub_place}, 'Berlin', 'PubPlace');
46ok(!$meta->{A_publisher}, 'Publisher');
Akron9c0488f2016-01-28 14:17:15 +010047
Akron5eb3aa02019-01-25 18:30:47 +010048is($meta->{S_text_type}, 'Zeitung: Tageszeitung', 'Correct Text Type');
Akron9c0488f2016-01-28 14:17:15 +010049
Akron5eb3aa02019-01-25 18:30:47 +010050ok(!$meta->{S_text_type_art}, 'Correct Text Type Art');
51is($meta->{S_text_type_ref}, 'Tageszeitung', 'Correct Text Type Ref');
52is($meta->{S_text_domain}, 'Politik', 'Correct Text Domain');
53is($meta->{S_text_column}, 'POLITIK', 'Correct Text Column');
54is($meta->{K_text_class}->[0], 'politik', 'Correct Text Class');
55is($meta->{K_text_class}->[1], 'ausland', 'Correct Text Class');
56ok(!$meta->{K_text_class}->[2], 'Correct Text Class');
Akron9c0488f2016-01-28 14:17:15 +010057
Akron5eb3aa02019-01-25 18:30:47 +010058is($meta->{D_pub_date}, '19590101', 'Creation date');
59is($meta->{D_creation_date}, '19590101', 'Creation date');
60is($meta->{S_availability}, 'ACA-NC-LC', 'License');
Akron35db6e32016-03-17 22:42:22 +010061ok(!$meta->{pages}, 'Pages');
Akron9c0488f2016-01-28 14:17:15 +010062
Akron5eb3aa02019-01-25 18:30:47 +010063ok(!$meta->{A_file_edition_statement}, 'File Statement');
64ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement');
Akron9c0488f2016-01-28 14:17:15 +010065
Akron5eb3aa02019-01-25 18:30:47 +010066is($meta->{A_reference} . "\n", <<'REF', 'Reference');
Akron9c0488f2016-01-28 14:17:15 +010067Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein
68REF
Akron5eb3aa02019-01-25 18:30:47 +010069is($meta->{S_language}, 'de', 'Language');
Akron9c0488f2016-01-28 14:17:15 +010070
Akron5eb3aa02019-01-25 18:30:47 +010071is($meta->{T_corpus_title}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
72ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title');
73ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
74ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akron9c0488f2016-01-28 14:17:15 +010075
Akron5eb3aa02019-01-25 18:30:47 +010076is($meta->{T_doc_title}, 'Neues Deutschland', 'Correct Doc title');
77is($meta->{T_doc_sub_title}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
78ok(!$meta->{T_doc_author}, 'Correct Doc author');
79ok(!$meta->{A_doc_editor}, 'Correct doc editor');
Akron9c0488f2016-01-28 14:17:15 +010080
81# Tokenization
Akrone4c2e412016-01-28 15:10:50 +010082use_ok('KorAP::XML::Tokenizer');
Akron9c0488f2016-01-28 14:17:15 +010083
84my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
85
86# Get tokenization
Akrone4c2e412016-01-28 15:10:50 +010087my $tokens = KorAP::XML::Tokenizer->new(
Akron9c0488f2016-01-28 14:17:15 +010088 path => $doc->path,
89 doc => $doc,
90 foundry => $token_base_foundry,
91 layer => $token_base_layer,
92 name => 'tokens'
93);
94ok($tokens, 'Token Object is fine');
95ok($tokens->parse, 'Token parsing is fine');
96
97my $output = decode_json( $tokens->to_json );
98
99is(substr($output->{data}->{text}, 0, 100), 'unser gemeinsames Werk wird siegreich sein Neujahrsbotschaft des Präsidenten der DeutschenDemokratis', 'Primary Data');
100is($output->{data}->{name}, 'tokens', 'tokenName');
101is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
102is($output->{version}, '0.03', 'version');
103is($output->{data}->{foundries}, '', 'Foundries');
104is($output->{data}->{layerInfos}, '', 'layerInfos');
Akron2d83a5a2016-02-26 00:21:16 +0100105is($output->{data}->{stream}->[0]->[4], 's:unser', 'data');
Akron9c0488f2016-01-28 14:17:15 +0100106
Akron1cd5b872016-03-22 00:23:46 +0100107is($output->{textSigle}, 'BZK/D59/00001', 'Correct text sigle');
108is($output->{docSigle}, 'BZK/D59', 'Correct document sigle');
Akron9c0488f2016-01-28 14:17:15 +0100109is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle');
110
111is($output->{title}, 'Unser gemeinsames Werk wird siegreich sein', 'Title');
112ok(!exists $output->{subTitle}, 'No SubTitle');
113ok(!exists $output->{author}, 'Author');
114ok(!exists $output->{editor}, 'Publisher');
115
116is($output->{pubPlace}, 'Berlin', 'PubPlace');
Akron5eb3aa02019-01-25 18:30:47 +0100117ok(!exists $output->{A_publisher}, 'Publisher');
Akron9c0488f2016-01-28 14:17:15 +0100118
119is($output->{textType}, 'Zeitung: Tageszeitung', 'Correct Text Type');
120ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
121is($output->{textTypeRef}, 'Tageszeitung', 'Correct Text Type Ref');
122is($output->{textDomain}, 'Politik', 'Correct Text Domain');
123
124is($output->{creationDate}, '19590101', 'Creation date');
Akron6396c302016-03-18 16:05:39 +0100125is($output->{availability}, 'ACA-NC-LC', 'License');
Akron9c0488f2016-01-28 14:17:15 +0100126ok(!exists $output->{pages}, 'Pages');
127ok(!exists $output->{fileEditionStatement}, 'File Statement');
128ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
129
130is($output->{reference} . "\n", <<'REF', 'Reference');
131Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein
132REF
133is($output->{language}, 'de', 'Language');
134
135is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
136ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
137ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
138ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
139
140is($output->{docTitle}, 'Neues Deutschland', 'Correct Doc title');
141is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
142ok(!exists $output->{docAuthor}, 'Correct Doc author');
143ok(!exists $output->{docEditor}, 'Correct doc editor');
144
145## Base
146$tokens->add('Base', 'Sentences');
147$tokens->add('Base', 'Paragraphs');
148
149$output = decode_json( $tokens->to_json );
150
151
152is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
153is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
154my $first_token = join('||', @{$output->{data}->{stream}->[0]});
155like($first_token, qr/s:unser/, 'data');
156like($first_token, qr/_0\$<i>0<i>5/, 'data');
157
158## OpenNLP
159$tokens->add('OpenNLP', 'Sentences');
160
161$output = decode_json( $tokens->to_json );
162is($output->{data}->{foundries},
163 'base base/paragraphs base/sentences opennlp opennlp/sentences',
164 'Foundries');
165is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos');
166
167
168$tokens->add('OpenNLP', 'Morpho');
169$output = decode_json( $tokens->to_json );
170is($output->{data}->{foundries},
171 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
172 'Foundries');
173is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos');
174
175
176## Treetagger
177$tokens->add('TreeTagger', 'Sentences');
178$output = decode_json( $tokens->to_json );
179is($output->{data}->{foundries},
180 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
181 'Foundries');
182is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos');
183
184$tokens->add('TreeTagger', 'Morpho');
185$output = decode_json( $tokens->to_json );
186is($output->{data}->{foundries},
187 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
188 'Foundries');
189is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
190
191## CoreNLP
192$tokens->add('CoreNLP', 'NamedEntities');
193$output = decode_json( $tokens->to_json );
194is($output->{data}->{foundries},
195 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
196 'Foundries');
197is($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');
198
199$tokens->add('CoreNLP', 'Sentences');
200$output = decode_json( $tokens->to_json );
201is($output->{data}->{foundries},
202 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
203 'Foundries');
204is($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');
205
206$tokens->add('CoreNLP', 'Morpho');
207$output = decode_json( $tokens->to_json );
208like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries');
209like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
210
211$tokens->add('CoreNLP', 'Constituency');
212$output = decode_json( $tokens->to_json );
213like($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries');
214like($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos');
215
216## Glemm
217$tokens->add('Glemm', 'Morpho');
218$output = decode_json( $tokens->to_json );
219like($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries');
220like($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos');
221
222## Connexor
223$tokens->add('Connexor', 'Sentences');
224$output = decode_json( $tokens->to_json );
225like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries');
226like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos');
227
228$tokens->add('Connexor', 'Morpho');
229$output = decode_json( $tokens->to_json );
230like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries');
231like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos');
232like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos');
233like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos');
234
235$tokens->add('Connexor', 'Phrase');
236$output = decode_json( $tokens->to_json );
237like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries');
238like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos');
239
240$tokens->add('Connexor', 'Syntax');
241$output = decode_json( $tokens->to_json );
242like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries');
243like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos');
244
245## Mate - not in existence
246{
247 local $SIG{__WARN__} = sub {};
248 $tokens->add('Mate', 'Morpho');
249 $output = decode_json( $tokens->to_json );
250 unlike($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
251 unlike($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
252 unlike($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
253 unlike($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
254};
255
256# diag "No test for mate dependency";
257
258## XIP
259$tokens->add('XIP', 'Sentences');
260$output = decode_json( $tokens->to_json );
261like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries');
262like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos');
263
264$tokens->add('XIP', 'Morpho');
265$output = decode_json( $tokens->to_json );
266like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries');
267like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos');
268like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos');
269
270
271$tokens->add('XIP', 'Constituency');
272$output = decode_json( $tokens->to_json );
273like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries');
274like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos');
275
276# diag "No test for xip dependency";
277
278
279done_testing;
280__END__