blob: f45200fce8921d8695b74d9f73f1877485436c5b [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
8use Benchmark qw/:hireswallclock/;
9
10my $t = Benchmark->new;
11
12use utf8;
13use lib 'lib', '../lib';
14
Nils Diewaldb3e9ccd2016-10-24 15:16:52 +020015#Log::Log4perl->init({
16# 'log4perl.rootLogger' => 'DEBUG, STDERR',
17# 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
18# 'log4perl.appender.STDERR.layout' => 'PatternLayout',
19# 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
20#});
21
Akron9c0488f2016-01-28 14:17:15 +010022use File::Basename 'dirname';
23use File::Spec::Functions 'catdir';
24
Akrone4c2e412016-01-28 15:10:50 +010025use_ok('KorAP::XML::Krill');
Akron9c0488f2016-01-28 14:17:15 +010026
Nils Diewaldb3e9ccd2016-10-24 15:16:52 +020027my $path = catdir(dirname(__FILE__), '..', 'corpus', 'BZK', 'D59', '00001');
Akron9c0488f2016-01-28 14:17:15 +010028
Akrone4c2e412016-01-28 15:10:50 +010029ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
Akron9c0488f2016-01-28 14:17:15 +010030ok($doc->parse, 'Parse document');
31
Akron1cd5b872016-03-22 00:23:46 +010032is($doc->text_sigle, 'BZK/D59/00001', 'Correct text sigle');
33is($doc->doc_sigle, 'BZK/D59', 'Correct document sigle');
Akron9c0488f2016-01-28 14:17:15 +010034is($doc->corpus_sigle, 'BZK', 'Correct corpus sigle');
35
Akron35db6e32016-03-17 22:42:22 +010036my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010037is($meta->{T_title}, 'Unser gemeinsames Werk wird siegreich sein', 'Title');
38ok(!$meta->{T_sub_title}, 'No SubTitle');
39ok(!$meta->{T_author}, 'Author');
40ok(!$meta->{A_editor}, 'Editor');
41is($meta->{S_pub_place}, 'Berlin', 'PubPlace');
42ok(!$meta->{A_publisher}, 'Publisher');
Akron9c0488f2016-01-28 14:17:15 +010043
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_pub_date}, '19590101', 'Creation date');
55is($meta->{D_creation_date}, '19590101', '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], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein
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), 'unser gemeinsames Werk wird siegreich sein Neujahrsbotschaft des Präsidenten der DeutschenDemokratis', '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:unser', 'data');
Akron9c0488f2016-01-28 14:17:15 +0100102
Akron1cd5b872016-03-22 00:23:46 +0100103is($output->{textSigle}, 'BZK/D59/00001', '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}, 'Unser gemeinsames Werk wird siegreich sein', 'Title');
108ok(!exists $output->{subTitle}, 'No SubTitle');
109ok(!exists $output->{author}, 'Author');
110ok(!exists $output->{editor}, 'Publisher');
111
112is($output->{pubPlace}, 'Berlin', 'PubPlace');
Akron5eb3aa02019-01-25 18:30:47 +0100113ok(!exists $output->{A_publisher}, 'Publisher');
Akron9c0488f2016-01-28 14:17:15 +0100114
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');
119
120is($output->{creationDate}, '19590101', 'Creation date');
Akron6396c302016-03-18 16:05:39 +0100121is($output->{availability}, 'ACA-NC-LC', 'License');
Akron9c0488f2016-01-28 14:17:15 +0100122ok(!exists $output->{pages}, 'Pages');
123ok(!exists $output->{fileEditionStatement}, 'File Statement');
124ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
125
126is($output->{reference} . "\n", <<'REF', 'Reference');
127Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein
128REF
129is($output->{language}, 'de', 'Language');
130
131is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
132ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
133ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
134ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
135
136is($output->{docTitle}, 'Neues Deutschland', 'Correct Doc title');
137is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
138ok(!exists $output->{docAuthor}, 'Correct Doc author');
139ok(!exists $output->{docEditor}, 'Correct doc editor');
140
141## Base
142$tokens->add('Base', 'Sentences');
143$tokens->add('Base', 'Paragraphs');
144
145$output = decode_json( $tokens->to_json );
146
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:unser/, 'data');
152like($first_token, qr/_0\$<i>0<i>5/, '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
164$tokens->add('OpenNLP', 'Morpho');
165$output = decode_json( $tokens->to_json );
166is($output->{data}->{foundries},
167 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
168 'Foundries');
169is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos');
170
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 - not in existence
242{
243 local $SIG{__WARN__} = sub {};
244 $tokens->add('Mate', 'Morpho');
245 $output = decode_json( $tokens->to_json );
246 unlike($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
247 unlike($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
248 unlike($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
249 unlike($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
250};
251
252# diag "No test for mate dependency";
253
254## XIP
255$tokens->add('XIP', 'Sentences');
256$output = decode_json( $tokens->to_json );
257like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries');
258like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos');
259
260$tokens->add('XIP', 'Morpho');
261$output = decode_json( $tokens->to_json );
262like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries');
263like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos');
264like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos');
265
266
267$tokens->add('XIP', 'Constituency');
268$output = decode_json( $tokens->to_json );
269like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries');
270like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos');
271
272# diag "No test for xip dependency";
273
274
275done_testing;
276__END__