blob: 3e39924682a868352a20fdaf2635fd4f74c96e6e [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
Akron1cd5b872016-03-22 00:23:46 +010024is($doc->text_sigle, 'BZK/D59/00089', 'Correct text sigle');
25is($doc->doc_sigle, 'BZK/D59', 'Correct document sigle');
Akron9c0488f2016-01-28 14:17:15 +010026is($doc->corpus_sigle, 'BZK', 'Correct corpus sigle');
27
Akron35db6e32016-03-17 22:42:22 +010028my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010029is($meta->{T_title}, 'Saragat-Partei zerfällt', 'Title');
30ok(!$meta->{T_sub_title}, 'No SubTitle');
31ok(!$meta->{T_author}, 'Author');
32ok(!$meta->{A_editor}, 'Editor');
33is($meta->{S_pub_place}, 'Berlin', 'PubPlace');
34is($meta->{D_pub_date}, '19590219', 'PubDate');
35ok(!$meta->{A_publisher}, 'Publisher');
Akron9c0488f2016-01-28 14:17:15 +010036
Akron5eb3aa02019-01-25 18:30:47 +010037is($meta->{S_text_type}, 'Zeitung: Tageszeitung', 'Correct Text Type');
Akron9c0488f2016-01-28 14:17:15 +010038
Akron5eb3aa02019-01-25 18:30:47 +010039ok(!$meta->{S_text_type_art}, 'Correct Text Type Art');
40is($meta->{S_text_type_ref}, 'Tageszeitung', 'Correct Text Type Ref');
41is($meta->{S_text_domain}, 'Politik', 'Correct Text Domain');
42is($meta->{S_text_column}, 'POLITIK', 'Correct Text Column');
43is($meta->{K_text_class}->[0], 'politik', 'Correct Text Class');
44is($meta->{K_text_class}->[1], 'ausland', 'Correct Text Class');
45ok(!$meta->{K_text_class}->[2], 'Correct Text Class');
Akron9c0488f2016-01-28 14:17:15 +010046
47
Akron5eb3aa02019-01-25 18:30:47 +010048is($meta->{D_creation_date}, '19590219', 'Creation date');
49is($meta->{S_availability}, 'ACA-NC-LC', 'License');
Akron35db6e32016-03-17 22:42:22 +010050ok(!$meta->{pages}, 'Pages');
Akron9c0488f2016-01-28 14:17:15 +010051
Akron5eb3aa02019-01-25 18:30:47 +010052ok(!$meta->{A_file_edition_statement}, 'File Statement');
53ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement');
Akron9c0488f2016-01-28 14:17:15 +010054
Akron5eb3aa02019-01-25 18:30:47 +010055is($meta->{A_reference} . "\n", <<'REF', 'Reference');
Akron9c0488f2016-01-28 14:17:15 +010056Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt
57REF
Akron5eb3aa02019-01-25 18:30:47 +010058is($meta->{S_language}, 'de', 'Language');
Akron9c0488f2016-01-28 14:17:15 +010059
Akron5eb3aa02019-01-25 18:30:47 +010060is($meta->{T_corpus_title}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
61ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title');
62ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
63ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akron9c0488f2016-01-28 14:17:15 +010064
Akron5eb3aa02019-01-25 18:30:47 +010065is($meta->{T_doc_title}, 'Neues Deutschland', 'Correct Doc title');
66is($meta->{T_doc_sub_title}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
67ok(!$meta->{T_doc_author}, 'Correct Doc author');
68ok(!$meta->{A_doc_editor}, 'Correct doc editor');
Akron9c0488f2016-01-28 14:17:15 +010069
70# Tokenization
Akrone4c2e412016-01-28 15:10:50 +010071use_ok('KorAP::XML::Tokenizer');
Akron9c0488f2016-01-28 14:17:15 +010072
73my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
74
75# Get tokenization
Akrone4c2e412016-01-28 15:10:50 +010076my $tokens = KorAP::XML::Tokenizer->new(
Akron9c0488f2016-01-28 14:17:15 +010077 path => $doc->path,
78 doc => $doc,
79 foundry => $token_base_foundry,
80 layer => $token_base_layer,
81 name => 'tokens'
82);
83ok($tokens, 'Token Object is fine');
84ok($tokens->parse, 'Token parsing is fine');
85
86my $output = decode_json( $tokens->to_json );
87
88is(substr($output->{data}->{text}, 0, 100), 'Saragat-Partei zerfällt Rom (ADN) die von dem Rechtssozialisten Saragat geführte Sozialdemokratische', 'Primary Data');
89is($output->{data}->{name}, 'tokens', 'tokenName');
90is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
91is($output->{version}, '0.03', 'version');
92is($output->{data}->{foundries}, '', 'Foundries');
93is($output->{data}->{layerInfos}, '', 'layerInfos');
Akron2d83a5a2016-02-26 00:21:16 +010094is($output->{data}->{stream}->[0]->[4], 's:Saragat-Partei', 'data');
Akron9c0488f2016-01-28 14:17:15 +010095
Akron1cd5b872016-03-22 00:23:46 +010096is($output->{textSigle}, 'BZK/D59/00089', 'Correct text sigle');
97is($output->{docSigle}, 'BZK/D59', 'Correct document sigle');
Akron9c0488f2016-01-28 14:17:15 +010098is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle');
99
100is($output->{title}, 'Saragat-Partei zerfällt', 'Title');
101ok(!exists $output->{subTitle}, 'No SubTitle');
102ok(!exists $output->{author}, 'Author');
103ok(!exists $output->{editor}, 'Publisher');
104
105is($output->{pubPlace}, 'Berlin', 'PubPlace');
106ok(!exists $output->{publisher}, 'Publisher');
107
108is($output->{textType}, 'Zeitung: Tageszeitung', 'Correct Text Type');
109ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
110is($output->{textTypeRef}, 'Tageszeitung', 'Correct Text Type Ref');
111is($output->{textDomain}, 'Politik', 'Correct Text Domain');
112is($output->{textClass}, 'politik ausland', 'Correct Text Domain');
113
114is($output->{creationDate}, '19590219', 'Creation date');
Akron6396c302016-03-18 16:05:39 +0100115is($output->{availability}, 'ACA-NC-LC', 'License');
Akron9c0488f2016-01-28 14:17:15 +0100116ok(!exists $output->{pages}, 'Pages');
117ok(!exists $output->{fileEditionStatement}, 'File Statement');
118ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
119
120is($output->{reference} . "\n", <<'REF', 'Reference');
121Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt
122REF
123is($output->{language}, 'de', 'Language');
124
125is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
126ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
127ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
128ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
129
130is($output->{docTitle}, 'Neues Deutschland', 'Correct Doc title');
131is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
132ok(!exists $output->{docAuthor}, 'Correct Doc author');
133ok(!exists $output->{docEditor}, 'Correct doc editor');
134
135## Base
136$tokens->add('Base', 'Sentences');
137$tokens->add('Base', 'Paragraphs');
138
139$output = decode_json( $tokens->to_json );
140
141is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
142is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
143my $first_token = join('||', @{$output->{data}->{stream}->[0]});
144like($first_token, qr/s:Saragat-Partei/, 'data');
145like($first_token, qr/_0\$<i>0<i>14/, 'data');
146
147## OpenNLP
148$tokens->add('OpenNLP', 'Sentences');
149
150$output = decode_json( $tokens->to_json );
151is($output->{data}->{foundries},
152 'base base/paragraphs base/sentences opennlp opennlp/sentences',
153 'Foundries');
154is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos');
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## 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
233$tokens->add('Mate', 'Morpho');
234$output = decode_json( $tokens->to_json );
235like($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
236like($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
237like($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
238like($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
239
240# diag "No test for mate dependency";
241
242## XIP
243$tokens->add('XIP', 'Sentences');
244$output = decode_json( $tokens->to_json );
245like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries');
246like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos');
247
248$tokens->add('XIP', 'Morpho');
249$output = decode_json( $tokens->to_json );
250like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries');
251like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos');
252like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos');
253
254$tokens->add('XIP', 'Constituency');
255$output = decode_json( $tokens->to_json );
256like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries');
257like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos');
258
259# diag "No test for xip dependency";
260
261done_testing;
262__END__