blob: 88e36de31a91df8c975bdc2832b44e0794fb5e49 [file] [log] [blame]
Akron29fc6b72016-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
Akron8fa76bc2016-01-28 15:10:50 +010017use_ok('KorAP::XML::Krill');
Akron29fc6b72016-01-28 14:17:15 +010018
19# GOE/AGA/03828
20my $path = catdir(dirname(__FILE__), '../corpus/WDD/G27/38989');
21
Akron8fa76bc2016-01-28 15:10:50 +010022ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
Akron29fc6b72016-01-28 14:17:15 +010023ok($doc->parse, 'Parse document');
24
25is($doc->text_sigle, 'WDD11_G27.38989', 'Correct text sigle');
26is($doc->doc_sigle, 'WDD11_G27', 'Correct document sigle');
27is($doc->corpus_sigle, 'WDD11', 'Correct corpus sigle');
28
29is($doc->title, 'Diskussion:Gunter A. Pilz', 'Title');
30ok(!$doc->sub_title, 'No SubTitle');
31is($doc->author, '€pa, u.a.', 'Author');
32ok(!$doc->editor, 'Publisher');
33
34is($doc->pub_place, 'URL:http://de.wikipedia.org', 'PubPlace');
35is($doc->publisher, 'Wikipedia', 'Publisher');
36is($doc->text_type, 'Diskussionen zu Enzyklopädie-Artikeln', 'Correct Text Type');
37ok(!$doc->text_type_art, 'Correct Text Type Art');
38ok(!$doc->text_type_ref, 'Correct Text Type Ref');
39ok(!$doc->text_domain, 'Correct Text Domain');
40is($doc->creation_date, '20070707', 'Creation date');
41is($doc->license, 'CC-BY-SA', 'License');
42ok(!$doc->pages, 'Pages');
43ok(!$doc->file_edition_statement, 'File Statement');
44ok(!$doc->bibl_edition_statement, 'Bibl Statement');
45is($doc->reference . "\n", <<'REF', 'Reference');
46Diskussion:Gunter A. Pilz, In: Wikipedia - URL:http://de.wikipedia.org/wiki/Diskussion:Gunter_A._Pilz: Wikipedia, 2007
47REF
48is($doc->language, 'de', 'Language');
49
50is($doc->corpus_title, 'Wikipedia', 'Correct Corpus title');
51ok(!$doc->corpus_sub_title, 'Correct Corpus sub title');
52ok(!$doc->corpus_author, 'Correct Corpus author');
53is($doc->corpus_editor, 'wikipedia.org', 'Correct Corpus editor');
54
55is($doc->doc_title, 'Wikipedia, Diskussionen zu Artikeln mit Anfangsbuchstabe G, Teil 27', 'Correct Doc title');
56ok(!$doc->doc_sub_title, 'Correct Doc sub title');
57ok(!$doc->doc_author, 'Correct Doc author');
58ok(!$doc->doc_editor, 'Correct doc editor');
59
60# Tokenization
Akron8fa76bc2016-01-28 15:10:50 +010061use_ok('KorAP::XML::Tokenizer');
Akron29fc6b72016-01-28 14:17:15 +010062
63my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
64
65# Get tokenization
Akron8fa76bc2016-01-28 15:10:50 +010066my $tokens = KorAP::XML::Tokenizer->new(
Akron29fc6b72016-01-28 14:17:15 +010067 path => $doc->path,
68 doc => $doc,
69 foundry => $token_base_foundry,
70 layer => $token_base_layer,
71 name => 'tokens'
72);
73ok($tokens, 'Token Object is fine');
74ok($tokens->parse, 'Token parsing is fine');
75
76my $output = decode_json( $tokens->to_json );
77
78is(substr($output->{data}->{text}, 0, 100), '{{War Löschkandidat|6. Juli 2007|(erl., bleibt)}}', 'Primary Data');
79is($output->{data}->{name}, 'tokens', 'tokenName');
80is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
81is($output->{version}, '0.03', 'version');
82is($output->{data}->{foundries}, '', 'Foundries');
83is($output->{data}->{layerInfos}, '', 'layerInfos');
84is($output->{data}->{stream}->[0]->[3], 's:{War', 'data');
85
86is($output->{textSigle}, 'WDD11_G27.38989', 'Correct text sigle');
87is($output->{docSigle}, 'WDD11_G27', 'Correct document sigle');
88is($output->{corpusSigle}, 'WDD11', 'Correct corpus sigle');
89
90is($output->{title}, 'Diskussion:Gunter A. Pilz', 'Title');
91ok(!$output->{subTitle}, 'No SubTitle');
92is($output->{author}, '€pa, u.a.', 'Author');
93ok(!$output->{editor}, 'Editor');
94
95is($output->{pubPlace}, 'URL:http://de.wikipedia.org', 'PubPlace');
96is($output->{publisher}, 'Wikipedia', 'Publisher');
97is($output->{textType}, 'Diskussionen zu Enzyklopädie-Artikeln', 'Correct Text Type');
98ok(!$output->{textTypeArt}, 'Correct Text Type Art');
99ok(!$output->{textTypeRef}, 'Correct Text Type Ref');
100ok(!$output->{textDomain}, 'Correct Text Domain');
101is($output->{creationDate}, '20070707', 'Creation date');
102is($output->{license}, 'CC-BY-SA', 'License');
103ok(!$output->{pages}, 'Pages');
104ok(!$output->{fileEditionStatement}, 'File Statement');
105ok(!$output->{biblEditionStatement}, 'Bibl Statement');
106is($output->{reference} . "\n", <<'REF', 'Reference');
107Diskussion:Gunter A. Pilz, In: Wikipedia - URL:http://de.wikipedia.org/wiki/Diskussion:Gunter_A._Pilz: Wikipedia, 2007
108REF
109is($output->{language}, 'de', 'Language');
110
111is($output->{corpusTitle}, 'Wikipedia', 'Correct Corpus title');
112ok(!$output->{corpusSubTitle}, 'Correct Corpus sub title');
113ok(!$output->{corpusAuthor}, 'Correct Corpus author');
114is($output->{corpusEditor}, 'wikipedia.org', 'Correct Corpus editor');
115
116is($output->{docTitle}, 'Wikipedia, Diskussionen zu Artikeln mit Anfangsbuchstabe G, Teil 27', 'Correct Doc title');
117ok(!$output->{docSubTitle}, 'Correct Doc sub title');
118ok(!$output->{docAuthor}, 'Correct Doc author');
119ok(!$output->{docEditor}, 'Correct doc editor');
120
121## Base
122$tokens->add('Base', 'Sentences');
123
124$tokens->add('Base', 'Paragraphs');
125
126$output = decode_json( $tokens->to_json );
127
128is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
129is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
130my $first_token = join('||', @{$output->{data}->{stream}->[0]});
Akron00dbba52016-02-14 01:42:20 +0100131like($first_token, qr/s:\{War/, 'data');
Akron29fc6b72016-01-28 14:17:15 +0100132like($first_token, qr/_0\$<i>1<i>5/, 'data');
133
134
135## OpenNLP
136$tokens->add('OpenNLP', 'Sentences');
137
138$output = decode_json( $tokens->to_json );
139is($output->{data}->{foundries},
140 'base base/paragraphs base/sentences opennlp opennlp/sentences',
141 'Foundries');
142is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos');
143
144
145$tokens->add('OpenNLP', 'Morpho');
146$output = decode_json( $tokens->to_json );
147is($output->{data}->{foundries},
148 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
149 'Foundries');
150is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos');
151
152
153## Treetagger
154$tokens->add('TreeTagger', 'Sentences');
155$output = decode_json( $tokens->to_json );
156is($output->{data}->{foundries},
157 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
158 'Foundries');
159is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos');
160
161$tokens->add('TreeTagger', 'Morpho');
162$output = decode_json( $tokens->to_json );
163is($output->{data}->{foundries},
164 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
165 'Foundries');
166is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
167
168## CoreNLP
169{
170 local $SIG{__WARN__} = sub {};
171 $tokens->add('CoreNLP', 'NamedEntities');
172};
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
180{
181 local $SIG{__WARN__} = sub {};
182 $tokens->add('CoreNLP', 'Sentences');
183};
184$output = decode_json( $tokens->to_json );
185is($output->{data}->{foundries},
186 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
187 'Foundries');
188is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
189
190{
191 local $SIG{__WARN__} = sub {};
192 $tokens->add('CoreNLP', 'Morpho');
193};
194$output = decode_json( $tokens->to_json );
195unlike($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries');
196unlike($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
197
198{
199 local $SIG{__WARN__} = sub {};
200 $tokens->add('CoreNLP', 'Constituency');
201};
202$output = decode_json( $tokens->to_json );
203unlike($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries');
204unlike($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos');
205
206## Glemm
207{
208 local $SIG{__WARN__} = sub {};
209 $tokens->add('Glemm', 'Morpho');
210};
211$output = decode_json( $tokens->to_json );
212unlike($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries');
213unlike($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos');
214
215## Connexor
216$tokens->add('Connexor', 'Sentences');
217$output = decode_json( $tokens->to_json );
218like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries');
219like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos');
220
221$tokens->add('Connexor', 'Morpho');
222$output = decode_json( $tokens->to_json );
223like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries');
224like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos');
225like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos');
226like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos');
227
228$tokens->add('Connexor', 'Phrase');
229$output = decode_json( $tokens->to_json );
230like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries');
231like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos');
232
233$tokens->add('Connexor', 'Syntax');
234$output = decode_json( $tokens->to_json );
235like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries');
236like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos');
237
238## Mate
239$tokens->add('Mate', 'Morpho');
240$output = decode_json( $tokens->to_json );
241like($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
242like($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
243like($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
244like($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
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$tokens->add('XIP', 'Constituency');
261$output = decode_json( $tokens->to_json );
262like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries');
263like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos');
264
265# diag "No test for xip dependency";
266
267done_testing;
268__END__