blob: e6ef8d5b453a49049ae2b8cc4a226527f3166ea9 [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/00001');
20
Akrone4c2e412016-01-28 15:10:50 +010021ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
Akron9c0488f2016-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
Akron35db6e32016-03-17 22:42:22 +010028my $meta = $doc->meta;
29is($meta->{title}, 'Unser gemeinsames Werk wird siegreich sein', 'Title');
30ok(!$meta->{sub_title}, 'No SubTitle');
31ok(!$meta->{author}, 'Author');
32ok(!$meta->{editor}, 'Editor');
33is($meta->{pub_place}, 'Berlin', 'PubPlace');
34ok(!$meta->{publisher}, 'Publisher');
Akron9c0488f2016-01-28 14:17:15 +010035
Akron35db6e32016-03-17 22:42:22 +010036is($meta->{text_type}, 'Zeitung: Tageszeitung', 'Correct Text Type');
Akron9c0488f2016-01-28 14:17:15 +010037
Akron35db6e32016-03-17 22:42:22 +010038ok(!$meta->{text_type_art}, 'Correct Text Type Art');
39is($meta->{text_type_ref}, 'Tageszeitung', 'Correct Text Type Ref');
40is($meta->{text_domain}, 'Politik', 'Correct Text Domain');
41is($meta->{text_column}, 'POLITIK', 'Correct Text Column');
42is($meta->{text_class}->[0], 'politik', 'Correct Text Class');
43is($meta->{text_class}->[1], 'ausland', 'Correct Text Class');
44ok(!$meta->{text_class}->[2], 'Correct Text Class');
Akron9c0488f2016-01-28 14:17:15 +010045
Akron35db6e32016-03-17 22:42:22 +010046is($meta->{pub_date}, '19590101', 'Creation date');
47is($meta->{creation_date}, '19590101', 'Creation date');
48is($meta->{license}, 'ACA-NC-LC', 'License');
49ok(!$meta->{pages}, 'Pages');
Akron9c0488f2016-01-28 14:17:15 +010050
Akron35db6e32016-03-17 22:42:22 +010051ok(!$meta->{file_edition_statement}, 'File Statement');
52ok(!$meta->{bibl_edition_statement}, 'Bibl Statement');
Akron9c0488f2016-01-28 14:17:15 +010053
Akron35db6e32016-03-17 22:42:22 +010054is($meta->{reference} . "\n", <<'REF', 'Reference');
Akron9c0488f2016-01-28 14:17:15 +010055Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein
56REF
Akron35db6e32016-03-17 22:42:22 +010057is($meta->{language}, 'de', 'Language');
Akron9c0488f2016-01-28 14:17:15 +010058
Akron35db6e32016-03-17 22:42:22 +010059is($meta->{corpus_title}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
60ok(!$meta->{corpus_sub_title}, 'Correct Corpus sub title');
61ok(!$meta->{corpus_author}, 'Correct Corpus author');
62ok(!$meta->{corpus_editor}, 'Correct Corpus editor');
Akron9c0488f2016-01-28 14:17:15 +010063
Akron35db6e32016-03-17 22:42:22 +010064is($meta->{doc_title}, 'Neues Deutschland', 'Correct Doc title');
65is($meta->{doc_sub_title}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
66ok(!$meta->{doc_author}, 'Correct Doc author');
67ok(!$meta->{doc_editor}, 'Correct doc editor');
Akron9c0488f2016-01-28 14:17:15 +010068
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), 'unser gemeinsames Werk wird siegreich sein Neujahrsbotschaft des Präsidenten der DeutschenDemokratis', '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');
Akron2d83a5a2016-02-26 00:21:16 +010093is($output->{data}->{stream}->[0]->[4], 's:unser', 'data');
Akron9c0488f2016-01-28 14:17:15 +010094
95is($output->{textSigle}, 'BZK_D59.00001', 'Correct text sigle');
96is($output->{docSigle}, 'BZK_D59', 'Correct document sigle');
97is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle');
98
99is($output->{title}, 'Unser gemeinsames Werk wird siegreich sein', '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');
111
112is($output->{creationDate}, '19590101', 'Creation date');
113is($output->{license}, 'ACA-NC-LC', 'License');
114ok(!exists $output->{pages}, 'Pages');
115ok(!exists $output->{fileEditionStatement}, 'File Statement');
116ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
117
118is($output->{reference} . "\n", <<'REF', 'Reference');
119Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein
120REF
121is($output->{language}, 'de', 'Language');
122
123is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
124ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
125ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
126ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
127
128is($output->{docTitle}, 'Neues Deutschland', 'Correct Doc title');
129is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
130ok(!exists $output->{docAuthor}, 'Correct Doc author');
131ok(!exists $output->{docEditor}, 'Correct doc editor');
132
133## Base
134$tokens->add('Base', 'Sentences');
135$tokens->add('Base', 'Paragraphs');
136
137$output = decode_json( $tokens->to_json );
138
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:unser/, 'data');
144like($first_token, qr/_0\$<i>0<i>5/, '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
156$tokens->add('OpenNLP', 'Morpho');
157$output = decode_json( $tokens->to_json );
158is($output->{data}->{foundries},
159 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
160 'Foundries');
161is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos');
162
163
164## Treetagger
165$tokens->add('TreeTagger', 'Sentences');
166$output = decode_json( $tokens->to_json );
167is($output->{data}->{foundries},
168 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
169 'Foundries');
170is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos');
171
172$tokens->add('TreeTagger', 'Morpho');
173$output = decode_json( $tokens->to_json );
174is($output->{data}->{foundries},
175 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
176 'Foundries');
177is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
178
179## CoreNLP
180$tokens->add('CoreNLP', 'NamedEntities');
181$output = decode_json( $tokens->to_json );
182is($output->{data}->{foundries},
183 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
184 'Foundries');
185is($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');
186
187$tokens->add('CoreNLP', 'Sentences');
188$output = decode_json( $tokens->to_json );
189is($output->{data}->{foundries},
190 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
191 'Foundries');
192is($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');
193
194$tokens->add('CoreNLP', 'Morpho');
195$output = decode_json( $tokens->to_json );
196like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries');
197like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
198
199$tokens->add('CoreNLP', 'Constituency');
200$output = decode_json( $tokens->to_json );
201like($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries');
202like($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos');
203
204## Glemm
205$tokens->add('Glemm', 'Morpho');
206$output = decode_json( $tokens->to_json );
207like($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries');
208like($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos');
209
210## Connexor
211$tokens->add('Connexor', 'Sentences');
212$output = decode_json( $tokens->to_json );
213like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries');
214like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos');
215
216$tokens->add('Connexor', 'Morpho');
217$output = decode_json( $tokens->to_json );
218like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries');
219like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos');
220like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos');
221like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos');
222
223$tokens->add('Connexor', 'Phrase');
224$output = decode_json( $tokens->to_json );
225like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries');
226like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos');
227
228$tokens->add('Connexor', 'Syntax');
229$output = decode_json( $tokens->to_json );
230like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries');
231like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos');
232
233## Mate - not in existence
234{
235 local $SIG{__WARN__} = sub {};
236 $tokens->add('Mate', 'Morpho');
237 $output = decode_json( $tokens->to_json );
238 unlike($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
239 unlike($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
240 unlike($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
241 unlike($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
242};
243
244# diag "No test for mate dependency";
245
246## XIP
247$tokens->add('XIP', 'Sentences');
248$output = decode_json( $tokens->to_json );
249like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries');
250like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos');
251
252$tokens->add('XIP', 'Morpho');
253$output = decode_json( $tokens->to_json );
254like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries');
255like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos');
256like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos');
257
258
259$tokens->add('XIP', 'Constituency');
260$output = decode_json( $tokens->to_json );
261like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries');
262like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos');
263
264# diag "No test for xip dependency";
265
266
267done_testing;
268__END__