blob: d957b6b9d970e30c7da152a051f474b8fbcdaf08 [file] [log] [blame]
Akron9c0488f2016-01-28 14:17:15 +01001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
6
Akronfab17d32020-07-31 14:38:29 +02007if ($ENV{SKIP_REAL}) {
8 plan skip_all => 'Skip real tests';
9};
10
Akron9c0488f2016-01-28 14:17:15 +010011use Benchmark qw/:hireswallclock/;
12
13my $t = Benchmark->new;
14
15use utf8;
16use lib 'lib', '../lib';
17
18use File::Basename 'dirname';
19use File::Spec::Functions 'catdir';
20
Akrone4c2e412016-01-28 15:10:50 +010021use_ok('KorAP::XML::Krill');
Akron9c0488f2016-01-28 14:17:15 +010022
23my $path = catdir(dirname(__FILE__), '../corpus/BZK/D59/00089');
24
Akrone4c2e412016-01-28 15:10:50 +010025ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::XML::Krill');
Akron9c0488f2016-01-28 14:17:15 +010026ok($doc->parse, 'Parse document');
27
Akron1cd5b872016-03-22 00:23:46 +010028is($doc->text_sigle, 'BZK/D59/00089', 'Correct text sigle');
29is($doc->doc_sigle, 'BZK/D59', 'Correct document sigle');
Akron9c0488f2016-01-28 14:17:15 +010030is($doc->corpus_sigle, 'BZK', 'Correct corpus sigle');
31
Akron35db6e32016-03-17 22:42:22 +010032my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010033is($meta->{T_title}, 'Saragat-Partei zerfällt', 'Title');
34ok(!$meta->{T_sub_title}, 'No SubTitle');
35ok(!$meta->{T_author}, 'Author');
36ok(!$meta->{A_editor}, 'Editor');
37is($meta->{S_pub_place}, 'Berlin', 'PubPlace');
38is($meta->{D_pub_date}, '19590219', 'PubDate');
39ok(!$meta->{A_publisher}, 'Publisher');
Akron9c0488f2016-01-28 14:17:15 +010040
Akron5eb3aa02019-01-25 18:30:47 +010041is($meta->{S_text_type}, 'Zeitung: Tageszeitung', 'Correct Text Type');
Akron9c0488f2016-01-28 14:17:15 +010042
Akron5eb3aa02019-01-25 18:30:47 +010043ok(!$meta->{S_text_type_art}, 'Correct Text Type Art');
44is($meta->{S_text_type_ref}, 'Tageszeitung', 'Correct Text Type Ref');
45is($meta->{S_text_domain}, 'Politik', 'Correct Text Domain');
46is($meta->{S_text_column}, 'POLITIK', 'Correct Text Column');
47is($meta->{K_text_class}->[0], 'politik', 'Correct Text Class');
48is($meta->{K_text_class}->[1], 'ausland', 'Correct Text Class');
49ok(!$meta->{K_text_class}->[2], 'Correct Text Class');
Akron9c0488f2016-01-28 14:17:15 +010050
51
Akron5eb3aa02019-01-25 18:30:47 +010052is($meta->{D_creation_date}, '19590219', 'Creation date');
53is($meta->{S_availability}, 'ACA-NC-LC', 'License');
Akron35db6e32016-03-17 22:42:22 +010054ok(!$meta->{pages}, 'Pages');
Akron9c0488f2016-01-28 14:17:15 +010055
Akron5eb3aa02019-01-25 18:30:47 +010056ok(!$meta->{A_file_edition_statement}, 'File Statement');
57ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement');
Akron9c0488f2016-01-28 14:17:15 +010058
Akron5eb3aa02019-01-25 18:30:47 +010059is($meta->{A_reference} . "\n", <<'REF', 'Reference');
Akron9c0488f2016-01-28 14:17:15 +010060Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt
61REF
Akron5eb3aa02019-01-25 18:30:47 +010062is($meta->{S_language}, 'de', 'Language');
Akron9c0488f2016-01-28 14:17:15 +010063
Akron5eb3aa02019-01-25 18:30:47 +010064is($meta->{T_corpus_title}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
65ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title');
66ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
67ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akron9c0488f2016-01-28 14:17:15 +010068
Akron5eb3aa02019-01-25 18:30:47 +010069is($meta->{T_doc_title}, 'Neues Deutschland', 'Correct Doc title');
70is($meta->{T_doc_sub_title}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
71ok(!$meta->{T_doc_author}, 'Correct Doc author');
72ok(!$meta->{A_doc_editor}, 'Correct doc editor');
Akron9c0488f2016-01-28 14:17:15 +010073
74# Tokenization
Akrone4c2e412016-01-28 15:10:50 +010075use_ok('KorAP::XML::Tokenizer');
Akron9c0488f2016-01-28 14:17:15 +010076
77my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
78
79# Get tokenization
Akrone4c2e412016-01-28 15:10:50 +010080my $tokens = KorAP::XML::Tokenizer->new(
Akron9c0488f2016-01-28 14:17:15 +010081 path => $doc->path,
82 doc => $doc,
83 foundry => $token_base_foundry,
84 layer => $token_base_layer,
85 name => 'tokens'
86);
87ok($tokens, 'Token Object is fine');
88ok($tokens->parse, 'Token parsing is fine');
89
90my $output = decode_json( $tokens->to_json );
91
92is(substr($output->{data}->{text}, 0, 100), 'Saragat-Partei zerfällt Rom (ADN) die von dem Rechtssozialisten Saragat geführte Sozialdemokratische', 'Primary Data');
93is($output->{data}->{name}, 'tokens', 'tokenName');
94is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
95is($output->{version}, '0.03', 'version');
96is($output->{data}->{foundries}, '', 'Foundries');
97is($output->{data}->{layerInfos}, '', 'layerInfos');
Akron2d83a5a2016-02-26 00:21:16 +010098is($output->{data}->{stream}->[0]->[4], 's:Saragat-Partei', 'data');
Akron9c0488f2016-01-28 14:17:15 +010099
Akron1cd5b872016-03-22 00:23:46 +0100100is($output->{textSigle}, 'BZK/D59/00089', 'Correct text sigle');
101is($output->{docSigle}, 'BZK/D59', 'Correct document sigle');
Akron9c0488f2016-01-28 14:17:15 +0100102is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle');
103
104is($output->{title}, 'Saragat-Partei zerfällt', 'Title');
105ok(!exists $output->{subTitle}, 'No SubTitle');
106ok(!exists $output->{author}, 'Author');
107ok(!exists $output->{editor}, 'Publisher');
108
109is($output->{pubPlace}, 'Berlin', 'PubPlace');
110ok(!exists $output->{publisher}, 'Publisher');
111
112is($output->{textType}, 'Zeitung: Tageszeitung', 'Correct Text Type');
113ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
114is($output->{textTypeRef}, 'Tageszeitung', 'Correct Text Type Ref');
115is($output->{textDomain}, 'Politik', 'Correct Text Domain');
116is($output->{textClass}, 'politik ausland', 'Correct Text Domain');
117
118is($output->{creationDate}, '19590219', 'Creation date');
Akron6396c302016-03-18 16:05:39 +0100119is($output->{availability}, 'ACA-NC-LC', 'License');
Akron9c0488f2016-01-28 14:17:15 +0100120ok(!exists $output->{pages}, 'Pages');
121ok(!exists $output->{fileEditionStatement}, 'File Statement');
122ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
123
124is($output->{reference} . "\n", <<'REF', 'Reference');
125Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt
126REF
127is($output->{language}, 'de', 'Language');
128
129is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
130ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
131ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
132ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
133
134is($output->{docTitle}, 'Neues Deutschland', 'Correct Doc title');
135is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
136ok(!exists $output->{docAuthor}, 'Correct Doc author');
137ok(!exists $output->{docEditor}, 'Correct doc editor');
138
139## Base
140$tokens->add('Base', 'Sentences');
141$tokens->add('Base', 'Paragraphs');
142
143$output = decode_json( $tokens->to_json );
144
145is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
146is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
147my $first_token = join('||', @{$output->{data}->{stream}->[0]});
148like($first_token, qr/s:Saragat-Partei/, 'data');
149like($first_token, qr/_0\$<i>0<i>14/, 'data');
150
151## OpenNLP
152$tokens->add('OpenNLP', 'Sentences');
153
154$output = decode_json( $tokens->to_json );
155is($output->{data}->{foundries},
156 'base base/paragraphs base/sentences opennlp opennlp/sentences',
157 'Foundries');
158is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos');
159
160$tokens->add('OpenNLP', 'Morpho');
161$output = decode_json( $tokens->to_json );
162is($output->{data}->{foundries},
163 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
164 'Foundries');
165is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos');
166
167## Treetagger
168$tokens->add('TreeTagger', 'Sentences');
169$output = decode_json( $tokens->to_json );
170is($output->{data}->{foundries},
171 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
172 'Foundries');
173is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos');
174
175$tokens->add('TreeTagger', 'Morpho');
176$output = decode_json( $tokens->to_json );
177is($output->{data}->{foundries},
178 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
179 'Foundries');
180is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
181
182## CoreNLP
183$tokens->add('CoreNLP', 'NamedEntities');
184$output = decode_json( $tokens->to_json );
185is($output->{data}->{foundries},
186 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
187 'Foundries');
188is($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');
189
190$tokens->add('CoreNLP', 'Sentences');
191$output = decode_json( $tokens->to_json );
192is($output->{data}->{foundries},
193 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
194 'Foundries');
195is($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');
196
197$tokens->add('CoreNLP', 'Morpho');
198$output = decode_json( $tokens->to_json );
199like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries');
200like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
201
202$tokens->add('CoreNLP', 'Constituency');
203$output = decode_json( $tokens->to_json );
204like($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries');
205like($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos');
206
207## Glemm
208$tokens->add('Glemm', 'Morpho');
209$output = decode_json( $tokens->to_json );
210like($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries');
211like($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos');
212
213## Connexor
214$tokens->add('Connexor', 'Sentences');
215$output = decode_json( $tokens->to_json );
216like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries');
217like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos');
218
219$tokens->add('Connexor', 'Morpho');
220$output = decode_json( $tokens->to_json );
221like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries');
222like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos');
223like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos');
224like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos');
225
226$tokens->add('Connexor', 'Phrase');
227$output = decode_json( $tokens->to_json );
228like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries');
229like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos');
230
231$tokens->add('Connexor', 'Syntax');
232$output = decode_json( $tokens->to_json );
233like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries');
234like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos');
235
236## Mate
237$tokens->add('Mate', 'Morpho');
238$output = decode_json( $tokens->to_json );
239like($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
240like($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
241like($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
242like($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
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$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
265done_testing;
266__END__