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