blob: 14437f3eecf302001eb2e6daf21629ea57b69227 [file] [log] [blame]
Nils Diewald79a355c2014-10-30 00:52:36 +00001#!/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
Nils Diewalda5565f62014-10-30 23:20:58 +000010use Benchmark qw/:hireswallclock/;
11
12my $t = Benchmark->new;
13
Nils Diewald79a355c2014-10-30 00:52:36 +000014use utf8;
15use lib 'lib', '../lib';
16
17use File::Basename 'dirname';
18use File::Spec::Functions 'catdir';
19
20use_ok('KorAP::Document');
21
22# GOE/AGA/03828
23my $path = catdir(dirname(__FILE__), 'GOE/AGA/03828');
Nils Diewalda0e8d722014-11-01 01:18:25 +000024# my $path = '/home/ndiewald/Repositories/korap/KorAP-sandbox/KorAP-lucene-indexer/t/GOE/AGA/03828';
Nils Diewald79a355c2014-10-30 00:52:36 +000025
26ok(my $doc = KorAP::Document->new( path => $path . '/' ), 'Load Korap::Document');
27ok($doc->parse, 'Parse document');
28
29is($doc->text_sigle, 'GOE_AGA.03828', 'Correct text sigle');
30is($doc->doc_sigle, 'GOE_AGA', 'Correct document sigle');
31is($doc->corpus_sigle, 'GOE', 'Correct corpus sigle');
32
33is($doc->corpus_title, 'Goethes Werke', 'Correct Corpus title');
34is($doc->text_type, 'Autobiographie', 'Correct Text Type');
Nils Diewaldebdc52d2014-10-31 17:29:23 +000035is($doc->author, 'Goethe, Johann Wolfgang von', 'Author');
Nils Diewald79a355c2014-10-30 00:52:36 +000036is($doc->reference . "\n", <<'REF', 'Author');
37Goethe, Johann Wolfgang von: Autobiographische Einzelheiten, (Geschrieben bis 1832), In: Goethe, Johann Wolfgang von: Goethes Werke, Bd. 10, Autobiographische Schriften II, Hrsg.: Trunz, Erich. München: Verlag C. H. Beck, 1982, S. 529-547
38REF
39is($doc->pub_place, 'München', 'PubPlace');
40is($doc->publisher, 'Verlag C. H. Beck', 'Publisher');
41is($doc->coll_editor, 'Trunz, Erich', 'Editor');
42is($doc->language, 'de', 'Language');
43is($doc->license, 'QAO-NC', 'License');
44is($doc->creation_date, '18200000', 'Creation Date');
45is($doc->pub_date, '19820000', 'Creation Date');
46is($doc->title, 'Autobiographische Einzelheiten', 'Title');
47is($doc->pages, '529-547', 'Pages');
48
49# Tokenization
50use_ok('KorAP::Tokenizer');
51
52my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
53
54# Get tokenization
55my $tokens = KorAP::Tokenizer->new(
56 path => $doc->path,
57 doc => $doc,
58 foundry => $token_base_foundry,
59 layer => $token_base_layer,
60 name => 'tokens'
61);
62ok($tokens, 'Token Object is fine');
63ok($tokens->parse, 'Token parsing is fine');
64
65my $output = decode_json( $tokens->to_json );
66
67
68is(substr($output->{primaryData}, 0, 100), 'Autobiographische einzelheiten Selbstschilderung (1) immer tätiger, nach innen und außen fortwirkend', 'Primary Data');
69is($output->{tokenName}, 'tokens', 'tokenName');
70is($output->{tokenSource}, 'opennlp#tokens', 'tokenSource');
71is($output->{version}, '0.02', 'version');
72
73is($output->{foundries}, '', 'Foundries');
74is($output->{layerInfos}, '', 'layerInfos');
Nils Diewalda5565f62014-10-30 23:20:58 +000075is($output->{data}->[0]->[3], 's:Autobiographische', 'data');
Nils Diewald79a355c2014-10-30 00:52:36 +000076
77is($output->{textSigle}, 'GOE_AGA.03828', 'Correct text sigle');
78is($output->{docSigle}, 'GOE_AGA', 'Correct document sigle');
79is($output->{corpusSigle}, 'GOE', 'Correct corpus sigle');
80
81is($output->{corpusTitle}, 'Goethes Werke', 'Correct Corpus title');
82is($output->{textType}, 'Autobiographie', 'Correct Text Type');
83is($output->{author}, 'Goethe, Johann Wolfgang von', 'Author');
84is($output->{reference} . "\n", <<'REF', 'Author');
85Goethe, Johann Wolfgang von: Autobiographische Einzelheiten, (Geschrieben bis 1832), In: Goethe, Johann Wolfgang von: Goethes Werke, Bd. 10, Autobiographische Schriften II, Hrsg.: Trunz, Erich. München: Verlag C. H. Beck, 1982, S. 529-547
86REF
87is($output->{pubPlace}, 'München', 'PubPlace');
88is($output->{publisher}, 'Verlag C. H. Beck', 'Publisher');
89is($output->{collEditor}, 'Trunz, Erich', 'Editor');
90is($output->{language}, 'de', 'Language');
91is($output->{license}, 'QAO-NC', 'License');
92is($output->{creationDate}, '18200000', 'Creation Date');
93is($output->{pubDate}, '19820000', 'Creation Date');
94is($output->{title}, 'Autobiographische Einzelheiten', 'Title');
95is($output->{pages}, '529-547', 'Pages');
96
97
98## Base
99$tokens->add('Base', 'Sentences');
100$tokens->add('Base', 'Paragraphs');
101
102$output = decode_json( $tokens->to_json );
103
104is($output->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
105is($output->{layerInfos}, 'base/s=spans', 'layerInfos');
106my $first_token = join('||', @{$output->{data}->[0]});
107like($first_token, qr/s:Autobiographische/, 'data');
108like($first_token, qr/_0#0-17/, 'data');
Nils Diewalda5565f62014-10-30 23:20:58 +0000109like($first_token, qr!<>:base/s:s#0-30\$<i>2<b>2!, 'data');
110like($first_token, qr!<>:base\/s:t#0-35199\$<i>5226<b>0!, 'data');
Nils Diewald79a355c2014-10-30 00:52:36 +0000111
112## OpenNLP
113$tokens->add('OpenNLP', 'Sentences');
114
115$output = decode_json( $tokens->to_json );
116is($output->{foundries},
117 'base base/paragraphs base/sentences opennlp opennlp/sentences',
118 'Foundries');
119is($output->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos');
120$first_token = join('||', @{$output->{data}->[0]});
121like($first_token, qr!<>:opennlp/s:s#0-254\$<i>32!, 'data');
122
123$tokens->add('OpenNLP', 'Morpho');
124$output = decode_json( $tokens->to_json );
125is($output->{foundries},
126 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
127 'Foundries');
128is($output->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos');
129$first_token = join('||', @{$output->{data}->[0]});
130like($first_token, qr!opennlp/p:ADJA!, 'data');
131
132## Treetagger
133$tokens->add('TreeTagger', 'Sentences');
134$output = decode_json( $tokens->to_json );
135is($output->{foundries},
136 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
137 'Foundries');
138is($output->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos');
139$first_token = join('||', @{$output->{data}->[0]});
Nils Diewalda5565f62014-10-30 23:20:58 +0000140like($first_token, qr!<>:tt/s:s#0-179\$<i>21<b>2!, 'data');
Nils Diewald79a355c2014-10-30 00:52:36 +0000141
142$tokens->add('TreeTagger', 'Morpho');
143$output = decode_json( $tokens->to_json );
144is($output->{foundries},
145 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
146 'Foundries');
147is($output->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
148$first_token = join('||', @{$output->{data}->[0]});
149like($first_token, qr!tt/l:autobiographisch\$<b>165!, 'data');
150like($first_token, qr!tt/p:ADJA\$<b>165!, 'data');
151like($first_token, qr!tt/l:Autobiographische\$<b>89!, 'data');
152like($first_token, qr!tt/p:NN\$<b>89!, 'data');
153
Nils Diewald79a355c2014-10-30 00:52:36 +0000154## CoreNLP
155$tokens->add('CoreNLP', 'NamedEntities');
156$output = decode_json( $tokens->to_json );
157is($output->{foundries},
158 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
159 'Foundries');
160is($output->{layerInfos}, 'base/s=spans corenlp/ne=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
161
162diag "Missing test for NamedEntities";
163
164# Problematic:
165# diag Dumper $output->{data}->[180];
166# diag Dumper $output->{data}->[341];
167
168$tokens->add('CoreNLP', 'Sentences');
169$output = decode_json( $tokens->to_json );
170is($output->{foundries},
171 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
172 'Foundries');
173is($output->{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');
174$first_token = join('||', @{$output->{data}->[0]});
175like($first_token, qr!<>:corenlp/s:s#0-254\$<i>32!, 'data');
176
Nils Diewald79a355c2014-10-30 00:52:36 +0000177$tokens->add('CoreNLP', 'Morpho');
178$output = decode_json( $tokens->to_json );
179like($output->{foundries}, qr!corenlp/morpho!, 'Foundries');
180like($output->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
181$first_token = join('||', @{$output->{data}->[0]});
182like($first_token, qr!corenlp/p:ADJA!, 'data');
183
Nils Diewalda5565f62014-10-30 23:20:58 +0000184$tokens->add('CoreNLP', 'Constituency');
185$output = decode_json( $tokens->to_json );
186like($output->{foundries}, qr!corenlp/constituency!, 'Foundries');
187like($output->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos');
188$first_token = join('||', @{$output->{data}->[0]});
Nils Diewald90a23f22014-10-31 02:16:14 +0000189like($first_token, qr!<>:corenlp/c:NP#0-17\$<i>1<b>6!, 'data');
190like($first_token, qr!<>:corenlp/c:CNP#0-17\$<i>1<b>7!, 'data');
191like($first_token, qr!<>:corenlp/c:NP#0-17\$<i>1<b>8!, 'data');
192like($first_token, qr!<>:corenlp/c:AP#0-17\$<i>1<b>9!, 'data');
193like($first_token, qr!<>:corenlp/c:PP#0-50\$<i>3<b>4!, 'data');
194like($first_token, qr!<>:corenlp/c:S#0-50\$<i>3<b>5!, 'data');
195like($first_token, qr!<>:corenlp/c:PP#0-58\$<i>5<b>2!, 'data');
196like($first_token, qr!<>:corenlp/c:S#0-58\$<i>5<b>3!, 'data');
197like($first_token, qr!<>:corenlp/c:ROOT#0-254\$<i>32<b>0!, 'data');
198like($first_token, qr!<>:corenlp/c:S#0-254\$<i>32<b>1!, 'data');
Nils Diewald79a355c2014-10-30 00:52:36 +0000199
200## Glemm
201$tokens->add('Glemm', 'Morpho');
202$output = decode_json( $tokens->to_json );
203like($output->{foundries}, qr!glemm/morpho!, 'Foundries');
204like($output->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos');
205$first_token = join('||', @{$output->{data}->[0]});
206like($first_token, qr!glemm/l:__autobiographisch!, 'data');
207like($first_token, qr!glemm/l:\+_Auto!, 'data');
208like($first_token, qr!glemm/l:\+_biographisch!, 'data');
209like($first_token, qr!glemm/l:\+\+Biograph!, 'data');
210like($first_token, qr!glemm/l:\+\+-isch!, 'data');
211
Nils Diewald79a355c2014-10-30 00:52:36 +0000212## Connexor
213$tokens->add('Connexor', 'Sentences');
214$output = decode_json( $tokens->to_json );
215like($output->{foundries}, qr!connexor/sentences!, 'Foundries');
216like($output->{layerInfos}, qr!cnx/s=spans!, 'layerInfos');
217$first_token = join('||', @{$output->{data}->[0]});
Nils Diewalda5565f62014-10-30 23:20:58 +0000218like($first_token, qr!<>:cnx/s:s#0-179\$<i>21<b>2!, 'data');
Nils Diewald79a355c2014-10-30 00:52:36 +0000219
220$tokens->add('Connexor', 'Morpho');
221$output = decode_json( $tokens->to_json );
222like($output->{foundries}, qr!connexor/morpho!, 'Foundries');
223like($output->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos');
224like($output->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos');
225like($output->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos');
226$first_token = join('||', @{$output->{data}->[0]});
227like($first_token, qr!cnx/l:autobiografisch!, 'data');
228like($first_token, qr!cnx/p:A!, 'data');
229
230$tokens->add('Connexor', 'Phrase');
231$output = decode_json( $tokens->to_json );
232like($output->{foundries}, qr!connexor/phrase!, 'Foundries');
233like($output->{layerInfos}, qr!cnx/c=spans!, 'layerInfos');
234$first_token = join('||', @{$output->{data}->[0]});
235like($first_token, qr!<>:cnx/c:np#0-30\$<i>2!, 'data');
236
Nils Diewald79a355c2014-10-30 00:52:36 +0000237$tokens->add('Connexor', 'Syntax');
238$output = decode_json( $tokens->to_json );
239like($output->{foundries}, qr!connexor/syntax!, 'Foundries');
240like($output->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos');
241$first_token = join('||', @{$output->{data}->[0]});
242like($first_token, qr!cnx/syn:\@PREMOD!, 'data');
243
244## Mate
245$tokens->add('Mate', 'Morpho');
246$output = decode_json( $tokens->to_json );
247like($output->{foundries}, qr!mate/morpho!, 'Foundries');
248like($output->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
249like($output->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
250like($output->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
251$first_token = join('||', @{$output->{data}->[0]});
Nils Diewalda5565f62014-10-30 23:20:58 +0000252like($first_token, qr!mate/l:autobiographisch!, 'data');
253like($first_token, qr!mate/p:NN!, 'data');
254like($first_token, qr!mate/m:case:nom!, 'data');
255like($first_token, qr!mate/m:number:pl!, 'data');
256like($first_token, qr!mate/m:gender:\*!, 'data');
257
258
Nils Diewald90a23f22014-10-31 02:16:14 +0000259diag "No test for mate dependency";
Nils Diewalda5565f62014-10-30 23:20:58 +0000260
261## XIP
262$tokens->add('XIP', 'Sentences');
263$output = decode_json( $tokens->to_json );
264like($output->{foundries}, qr!xip/sentences!, 'Foundries');
265like($output->{layerInfos}, qr!xip/s=spans!, 'layerInfos');
266$first_token = join('||', @{$output->{data}->[0]});
267like($first_token, qr!<>:xip/s:s#0-179\$<i>21!, 'data');
268
269$tokens->add('XIP', 'Morpho');
270$output = decode_json( $tokens->to_json );
271like($output->{foundries}, qr!xip/morpho!, 'Foundries');
272like($output->{layerInfos}, qr!xip/l=tokens!, 'layerInfos');
273like($output->{layerInfos}, qr!xip/p=tokens!, 'layerInfos');
274$first_token = join('||', @{$output->{data}->[0]});
275like($first_token, qr!<>:xip/s:s#0-179\$<i>21!, 'data');
276
277
Nils Diewalda5565f62014-10-30 23:20:58 +0000278$tokens->add('XIP', 'Constituency');
279$output = decode_json( $tokens->to_json );
280like($output->{foundries}, qr!xip/constituency!, 'Foundries');
281like($output->{layerInfos}, qr!xip/c=spans!, 'layerInfos');
282$first_token = join('||', @{$output->{data}->[0]});
283like($first_token, qr!<>:xip/c:NP#0-17\$<i>1<b>1!, 'data');
284like($first_token, qr!<>:xip/c:AP#0-17\$<i>1<b>2!, 'data');
285like($first_token, qr!<>:xip/c:ADJ#0-17\$<i>1<b>3!, 'data');
286like($first_token, qr!<>:xip/c:TOP#0-179\$<i>21<b>0!, 'data');
Nils Diewald79a355c2014-10-30 00:52:36 +0000287
Nils Diewald90a23f22014-10-31 02:16:14 +0000288diag "No test for xip dependency";
Nils Diewald79a355c2014-10-30 00:52:36 +0000289
Nils Diewald90a23f22014-10-31 02:16:14 +0000290# diag Dumper $output->{data}->[0];
291
292# print timestr(timediff(Benchmark->new, $t));
Nils Diewald79a355c2014-10-30 00:52:36 +0000293
Nils Diewald79a355c2014-10-30 00:52:36 +0000294done_testing;
295__END__