blob: acaf6688701a76e29d7561b7968f5fa2ca60d0ee [file] [log] [blame]
Akron29fc6b72016-01-28 14:17:15 +01001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
6
7use Benchmark qw/:hireswallclock/;
8
9my $t = Benchmark->new;
10
11use utf8;
12use lib 'lib', '../lib';
13
14use File::Basename 'dirname';
15use File::Spec::Functions 'catdir';
16
Akron8fa76bc2016-01-28 15:10:50 +010017use_ok('KorAP::XML::Krill');
Akron29fc6b72016-01-28 14:17:15 +010018
19my $path = catdir(dirname(__FILE__), '../corpus/BZK/D59/00001');
20
Akron8fa76bc2016-01-28 15:10:50 +010021ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
Akron29fc6b72016-01-28 14:17:15 +010022ok($doc->parse, 'Parse document');
23
24is($doc->text_sigle, 'BZK_D59.00001', 'Correct text sigle');
25is($doc->doc_sigle, 'BZK_D59', 'Correct document sigle');
26is($doc->corpus_sigle, 'BZK', 'Correct corpus sigle');
27
28is($doc->title, 'Unser gemeinsames Werk wird siegreich sein', 'Title');
29ok(!$doc->sub_title, 'No SubTitle');
30ok(!$doc->author, 'Author');
31ok(!$doc->editor, 'Editor');
32is($doc->pub_place, 'Berlin', 'PubPlace');
33ok(!$doc->publisher, 'Publisher');
34
35is($doc->text_type, 'Zeitung: Tageszeitung', 'Correct Text Type');
36
37ok(!$doc->text_type_art, 'Correct Text Type Art');
38is($doc->text_type_ref, 'Tageszeitung', 'Correct Text Type Ref');
39is($doc->text_domain, 'Politik', 'Correct Text Domain');
40is($doc->text_column, 'POLITIK', 'Correct Text Column');
41is($doc->text_class->[0], 'politik', 'Correct Text Class');
42is($doc->text_class->[1], 'ausland', 'Correct Text Class');
43ok(!$doc->text_class->[2], 'Correct Text Class');
44
45is($doc->pub_date, '19590101', 'Creation date');
46is($doc->creation_date, '19590101', 'Creation date');
47is($doc->license, 'ACA-NC-LC', 'License');
48ok(!$doc->pages, 'Pages');
49
50ok(!$doc->file_edition_statement, 'File Statement');
51ok(!$doc->bibl_edition_statement, 'Bibl Statement');
52
53is($doc->reference . "\n", <<'REF', 'Reference');
54Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein
55REF
56is($doc->language, 'de', 'Language');
57
58is($doc->corpus_title, 'Bonner Zeitungskorpus', 'Correct Corpus title');
59ok(!$doc->corpus_sub_title, 'Correct Corpus sub title');
60ok(!$doc->corpus_author, 'Correct Corpus author');
61ok(!$doc->corpus_editor, 'Correct Corpus editor');
62
63is($doc->doc_title, 'Neues Deutschland', 'Correct Doc title');
64is($doc->doc_sub_title, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
65ok(!$doc->doc_author, 'Correct Doc author');
66ok(!$doc->doc_editor, 'Correct doc editor');
67
68# Tokenization
Akron8fa76bc2016-01-28 15:10:50 +010069use_ok('KorAP::XML::Tokenizer');
Akron29fc6b72016-01-28 14:17:15 +010070
71my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
72
73# Get tokenization
Akron8fa76bc2016-01-28 15:10:50 +010074my $tokens = KorAP::XML::Tokenizer->new(
Akron29fc6b72016-01-28 14:17:15 +010075 path => $doc->path,
76 doc => $doc,
77 foundry => $token_base_foundry,
78 layer => $token_base_layer,
79 name => 'tokens'
80);
81ok($tokens, 'Token Object is fine');
82ok($tokens->parse, 'Token parsing is fine');
83
84my $output = decode_json( $tokens->to_json );
85
86is(substr($output->{data}->{text}, 0, 100), 'unser gemeinsames Werk wird siegreich sein Neujahrsbotschaft des Präsidenten der DeutschenDemokratis', 'Primary Data');
87is($output->{data}->{name}, 'tokens', 'tokenName');
88is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
89is($output->{version}, '0.03', 'version');
90is($output->{data}->{foundries}, '', 'Foundries');
91is($output->{data}->{layerInfos}, '', 'layerInfos');
92is($output->{data}->{stream}->[0]->[3], 's:unser', 'data');
93
94is($output->{textSigle}, 'BZK_D59.00001', 'Correct text sigle');
95is($output->{docSigle}, 'BZK_D59', 'Correct document sigle');
96is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle');
97
98is($output->{title}, 'Unser gemeinsames Werk wird siegreich sein', 'Title');
99ok(!exists $output->{subTitle}, 'No SubTitle');
100ok(!exists $output->{author}, 'Author');
101ok(!exists $output->{editor}, 'Publisher');
102
103is($output->{pubPlace}, 'Berlin', 'PubPlace');
104ok(!exists $output->{publisher}, 'Publisher');
105
106is($output->{textType}, 'Zeitung: Tageszeitung', 'Correct Text Type');
107ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
108is($output->{textTypeRef}, 'Tageszeitung', 'Correct Text Type Ref');
109is($output->{textDomain}, 'Politik', 'Correct Text Domain');
110
111is($output->{creationDate}, '19590101', 'Creation date');
112is($output->{license}, 'ACA-NC-LC', 'License');
113ok(!exists $output->{pages}, 'Pages');
114ok(!exists $output->{fileEditionStatement}, 'File Statement');
115ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
116
117is($output->{reference} . "\n", <<'REF', 'Reference');
118Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein
119REF
120is($output->{language}, 'de', 'Language');
121
122is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
123ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
124ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
125ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
126
127is($output->{docTitle}, 'Neues Deutschland', 'Correct Doc title');
128is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
129ok(!exists $output->{docAuthor}, 'Correct Doc author');
130ok(!exists $output->{docEditor}, 'Correct doc editor');
131
132## Base
133$tokens->add('Base', 'Sentences');
134$tokens->add('Base', 'Paragraphs');
135
136$output = decode_json( $tokens->to_json );
137
138
139is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
140is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
141my $first_token = join('||', @{$output->{data}->{stream}->[0]});
142like($first_token, qr/s:unser/, 'data');
143like($first_token, qr/_0\$<i>0<i>5/, 'data');
144
145## OpenNLP
146$tokens->add('OpenNLP', 'Sentences');
147
148$output = decode_json( $tokens->to_json );
149is($output->{data}->{foundries},
150 'base base/paragraphs base/sentences opennlp opennlp/sentences',
151 'Foundries');
152is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos');
153
154
155$tokens->add('OpenNLP', 'Morpho');
156$output = decode_json( $tokens->to_json );
157is($output->{data}->{foundries},
158 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
159 'Foundries');
160is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos');
161
162
163## Treetagger
164$tokens->add('TreeTagger', 'Sentences');
165$output = decode_json( $tokens->to_json );
166is($output->{data}->{foundries},
167 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
168 'Foundries');
169is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos');
170
171$tokens->add('TreeTagger', 'Morpho');
172$output = decode_json( $tokens->to_json );
173is($output->{data}->{foundries},
174 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
175 'Foundries');
176is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
177
178## CoreNLP
179$tokens->add('CoreNLP', 'NamedEntities');
180$output = decode_json( $tokens->to_json );
181is($output->{data}->{foundries},
182 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
183 'Foundries');
184is($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');
185
186$tokens->add('CoreNLP', 'Sentences');
187$output = decode_json( $tokens->to_json );
188is($output->{data}->{foundries},
189 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
190 'Foundries');
191is($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');
192
193$tokens->add('CoreNLP', 'Morpho');
194$output = decode_json( $tokens->to_json );
195like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries');
196like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
197
198$tokens->add('CoreNLP', 'Constituency');
199$output = decode_json( $tokens->to_json );
200like($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries');
201like($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos');
202
203## Glemm
204$tokens->add('Glemm', 'Morpho');
205$output = decode_json( $tokens->to_json );
206like($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries');
207like($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos');
208
209## Connexor
210$tokens->add('Connexor', 'Sentences');
211$output = decode_json( $tokens->to_json );
212like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries');
213like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos');
214
215$tokens->add('Connexor', 'Morpho');
216$output = decode_json( $tokens->to_json );
217like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries');
218like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos');
219like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos');
220like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos');
221
222$tokens->add('Connexor', 'Phrase');
223$output = decode_json( $tokens->to_json );
224like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries');
225like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos');
226
227$tokens->add('Connexor', 'Syntax');
228$output = decode_json( $tokens->to_json );
229like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries');
230like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos');
231
232## Mate - not in existence
233{
234 local $SIG{__WARN__} = sub {};
235 $tokens->add('Mate', 'Morpho');
236 $output = decode_json( $tokens->to_json );
237 unlike($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
238 unlike($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
239 unlike($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
240 unlike($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
241};
242
243# diag "No test for mate dependency";
244
245## XIP
246$tokens->add('XIP', 'Sentences');
247$output = decode_json( $tokens->to_json );
248like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries');
249like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos');
250
251$tokens->add('XIP', 'Morpho');
252$output = decode_json( $tokens->to_json );
253like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries');
254like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos');
255like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos');
256
257
258$tokens->add('XIP', 'Constituency');
259$output = decode_json( $tokens->to_json );
260like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries');
261like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos');
262
263# diag "No test for xip dependency";
264
265
266done_testing;
267__END__