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