blob: 47390ac63e83e7d73d4354b91c5bdaf5f708f916 [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
Nils Diewalddf1733f2014-11-01 17:25:12 +000068is(substr($output->{data}->{text}, 0, 100), 'Autobiographische einzelheiten Selbstschilderung (1) immer tätiger, nach innen und außen fortwirkend', 'Primary Data');
69is($output->{data}->{name}, 'tokens', 'tokenName');
70is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
Nils Diewald79a355c2014-10-30 00:52:36 +000071is($output->{version}, '0.02', 'version');
Nils Diewalddf1733f2014-11-01 17:25:12 +000072is($output->{data}->{foundries}, '', 'Foundries');
73is($output->{data}->{layerInfos}, '', 'layerInfos');
74is($output->{data}->{stream}->[0]->[3], 's:Autobiographische', 'data');
Nils Diewald79a355c2014-10-30 00:52:36 +000075
76is($output->{textSigle}, 'GOE_AGA.03828', 'Correct text sigle');
77is($output->{docSigle}, 'GOE_AGA', 'Correct document sigle');
78is($output->{corpusSigle}, 'GOE', 'Correct corpus sigle');
79
80is($output->{corpusTitle}, 'Goethes Werke', 'Correct Corpus title');
81is($output->{textType}, 'Autobiographie', 'Correct Text Type');
82is($output->{author}, 'Goethe, Johann Wolfgang von', 'Author');
83is($output->{reference} . "\n", <<'REF', 'Author');
84Goethe, 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
85REF
86is($output->{pubPlace}, 'München', 'PubPlace');
87is($output->{publisher}, 'Verlag C. H. Beck', 'Publisher');
88is($output->{collEditor}, 'Trunz, Erich', 'Editor');
89is($output->{language}, 'de', 'Language');
90is($output->{license}, 'QAO-NC', 'License');
91is($output->{creationDate}, '18200000', 'Creation Date');
92is($output->{pubDate}, '19820000', 'Creation Date');
93is($output->{title}, 'Autobiographische Einzelheiten', 'Title');
94is($output->{pages}, '529-547', 'Pages');
95
96
97## Base
98$tokens->add('Base', 'Sentences');
99$tokens->add('Base', 'Paragraphs');
100
101$output = decode_json( $tokens->to_json );
102
Nils Diewalddf1733f2014-11-01 17:25:12 +0000103is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
104is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
105my $first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewald79a355c2014-10-30 00:52:36 +0000106like($first_token, qr/s:Autobiographische/, 'data');
107like($first_token, qr/_0#0-17/, 'data');
Nils Diewalda5565f62014-10-30 23:20:58 +0000108like($first_token, qr!<>:base/s:s#0-30\$<i>2<b>2!, 'data');
109like($first_token, qr!<>:base\/s:t#0-35199\$<i>5226<b>0!, 'data');
Nils Diewald79a355c2014-10-30 00:52:36 +0000110
111## OpenNLP
112$tokens->add('OpenNLP', 'Sentences');
113
114$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000115is($output->{data}->{foundries},
Nils Diewald79a355c2014-10-30 00:52:36 +0000116 'base base/paragraphs base/sentences opennlp opennlp/sentences',
117 'Foundries');
Nils Diewalddf1733f2014-11-01 17:25:12 +0000118is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos');
119$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewald79a355c2014-10-30 00:52:36 +0000120like($first_token, qr!<>:opennlp/s:s#0-254\$<i>32!, 'data');
121
122$tokens->add('OpenNLP', 'Morpho');
123$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000124is($output->{data}->{foundries},
Nils Diewald79a355c2014-10-30 00:52:36 +0000125 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
126 'Foundries');
Nils Diewalddf1733f2014-11-01 17:25:12 +0000127is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos');
128$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewald79a355c2014-10-30 00:52:36 +0000129like($first_token, qr!opennlp/p:ADJA!, 'data');
130
131## Treetagger
132$tokens->add('TreeTagger', 'Sentences');
133$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000134is($output->{data}->{foundries},
Nils Diewald79a355c2014-10-30 00:52:36 +0000135 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
136 'Foundries');
Nils Diewalddf1733f2014-11-01 17:25:12 +0000137is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos');
138$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewalda5565f62014-10-30 23:20:58 +0000139like($first_token, qr!<>:tt/s:s#0-179\$<i>21<b>2!, 'data');
Nils Diewald79a355c2014-10-30 00:52:36 +0000140
141$tokens->add('TreeTagger', 'Morpho');
142$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000143is($output->{data}->{foundries},
Nils Diewald79a355c2014-10-30 00:52:36 +0000144 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
145 'Foundries');
Nils Diewalddf1733f2014-11-01 17:25:12 +0000146is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
147$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewald79a355c2014-10-30 00:52:36 +0000148like($first_token, qr!tt/l:autobiographisch\$<b>165!, 'data');
149like($first_token, qr!tt/p:ADJA\$<b>165!, 'data');
150like($first_token, qr!tt/l:Autobiographische\$<b>89!, 'data');
151like($first_token, qr!tt/p:NN\$<b>89!, 'data');
152
Nils Diewald79a355c2014-10-30 00:52:36 +0000153## CoreNLP
154$tokens->add('CoreNLP', 'NamedEntities');
155$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000156is($output->{data}->{foundries},
Nils Diewald79a355c2014-10-30 00:52:36 +0000157 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
158 'Foundries');
Nils Diewalddf1733f2014-11-01 17:25:12 +0000159is($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');
Nils Diewald79a355c2014-10-30 00:52:36 +0000160
161diag "Missing test for NamedEntities";
162
163# Problematic:
Nils Diewalddf1733f2014-11-01 17:25:12 +0000164# diag Dumper $output->{data}->{stream}->[180];
165# diag Dumper $output->{data}->{stream}->[341];
Nils Diewald79a355c2014-10-30 00:52:36 +0000166
167$tokens->add('CoreNLP', 'Sentences');
168$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000169is($output->{data}->{foundries},
Nils Diewald79a355c2014-10-30 00:52:36 +0000170 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
171 'Foundries');
Nils Diewalddf1733f2014-11-01 17:25:12 +0000172is($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');
173$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewald79a355c2014-10-30 00:52:36 +0000174like($first_token, qr!<>:corenlp/s:s#0-254\$<i>32!, 'data');
175
Nils Diewald79a355c2014-10-30 00:52:36 +0000176$tokens->add('CoreNLP', 'Morpho');
177$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000178like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries');
179like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
180$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewald79a355c2014-10-30 00:52:36 +0000181like($first_token, qr!corenlp/p:ADJA!, 'data');
182
Nils Diewalda5565f62014-10-30 23:20:58 +0000183$tokens->add('CoreNLP', 'Constituency');
184$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000185like($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries');
186like($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos');
187$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewald90a23f22014-10-31 02:16:14 +0000188like($first_token, qr!<>:corenlp/c:NP#0-17\$<i>1<b>6!, 'data');
189like($first_token, qr!<>:corenlp/c:CNP#0-17\$<i>1<b>7!, 'data');
190like($first_token, qr!<>:corenlp/c:NP#0-17\$<i>1<b>8!, 'data');
191like($first_token, qr!<>:corenlp/c:AP#0-17\$<i>1<b>9!, 'data');
192like($first_token, qr!<>:corenlp/c:PP#0-50\$<i>3<b>4!, 'data');
193like($first_token, qr!<>:corenlp/c:S#0-50\$<i>3<b>5!, 'data');
194like($first_token, qr!<>:corenlp/c:PP#0-58\$<i>5<b>2!, 'data');
195like($first_token, qr!<>:corenlp/c:S#0-58\$<i>5<b>3!, 'data');
196like($first_token, qr!<>:corenlp/c:ROOT#0-254\$<i>32<b>0!, 'data');
197like($first_token, qr!<>:corenlp/c:S#0-254\$<i>32<b>1!, 'data');
Nils Diewald79a355c2014-10-30 00:52:36 +0000198
199## Glemm
200$tokens->add('Glemm', 'Morpho');
201$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000202like($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries');
203like($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos');
204$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewald79a355c2014-10-30 00:52:36 +0000205like($first_token, qr!glemm/l:__autobiographisch!, 'data');
206like($first_token, qr!glemm/l:\+_Auto!, 'data');
207like($first_token, qr!glemm/l:\+_biographisch!, 'data');
208like($first_token, qr!glemm/l:\+\+Biograph!, 'data');
209like($first_token, qr!glemm/l:\+\+-isch!, 'data');
210
Nils Diewald79a355c2014-10-30 00:52:36 +0000211## Connexor
212$tokens->add('Connexor', 'Sentences');
213$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000214like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries');
215like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos');
216$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewalda5565f62014-10-30 23:20:58 +0000217like($first_token, qr!<>:cnx/s:s#0-179\$<i>21<b>2!, 'data');
Nils Diewald79a355c2014-10-30 00:52:36 +0000218
219$tokens->add('Connexor', 'Morpho');
220$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000221like($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$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewald79a355c2014-10-30 00:52:36 +0000226like($first_token, qr!cnx/l:autobiografisch!, 'data');
227like($first_token, qr!cnx/p:A!, 'data');
228
229$tokens->add('Connexor', 'Phrase');
230$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000231like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries');
232like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos');
233$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewald79a355c2014-10-30 00:52:36 +0000234like($first_token, qr!<>:cnx/c:np#0-30\$<i>2!, 'data');
235
Nils Diewald79a355c2014-10-30 00:52:36 +0000236$tokens->add('Connexor', 'Syntax');
237$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000238like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries');
239like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos');
240$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewald79a355c2014-10-30 00:52:36 +0000241like($first_token, qr!cnx/syn:\@PREMOD!, 'data');
242
243## Mate
244$tokens->add('Mate', 'Morpho');
245$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000246like($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
247like($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
248like($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
249like($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
250$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewalda5565f62014-10-30 23:20:58 +0000251like($first_token, qr!mate/l:autobiographisch!, 'data');
252like($first_token, qr!mate/p:NN!, 'data');
253like($first_token, qr!mate/m:case:nom!, 'data');
254like($first_token, qr!mate/m:number:pl!, 'data');
255like($first_token, qr!mate/m:gender:\*!, 'data');
256
257
Nils Diewald90a23f22014-10-31 02:16:14 +0000258diag "No test for mate dependency";
Nils Diewalda5565f62014-10-30 23:20:58 +0000259
260## XIP
261$tokens->add('XIP', 'Sentences');
262$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000263like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries');
264like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos');
265$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewalda5565f62014-10-30 23:20:58 +0000266like($first_token, qr!<>:xip/s:s#0-179\$<i>21!, 'data');
267
268$tokens->add('XIP', 'Morpho');
269$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000270like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries');
271like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos');
272like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos');
273$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewalda5565f62014-10-30 23:20:58 +0000274like($first_token, qr!<>:xip/s:s#0-179\$<i>21!, 'data');
275
276
Nils Diewalda5565f62014-10-30 23:20:58 +0000277$tokens->add('XIP', 'Constituency');
278$output = decode_json( $tokens->to_json );
Nils Diewalddf1733f2014-11-01 17:25:12 +0000279like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries');
280like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos');
281$first_token = join('||', @{$output->{data}->{stream}->[0]});
Nils Diewalda5565f62014-10-30 23:20:58 +0000282like($first_token, qr!<>:xip/c:NP#0-17\$<i>1<b>1!, 'data');
283like($first_token, qr!<>:xip/c:AP#0-17\$<i>1<b>2!, 'data');
284like($first_token, qr!<>:xip/c:ADJ#0-17\$<i>1<b>3!, 'data');
285like($first_token, qr!<>:xip/c:TOP#0-179\$<i>21<b>0!, 'data');
Nils Diewald79a355c2014-10-30 00:52:36 +0000286
Nils Diewald90a23f22014-10-31 02:16:14 +0000287diag "No test for xip dependency";
Nils Diewald79a355c2014-10-30 00:52:36 +0000288
Nils Diewalddf1733f2014-11-01 17:25:12 +0000289# diag Dumper $output->{data}->{stream}->[0];
Nils Diewald90a23f22014-10-31 02:16:14 +0000290
291# print timestr(timediff(Benchmark->new, $t));
Nils Diewald79a355c2014-10-30 00:52:36 +0000292
Nils Diewald79a355c2014-10-30 00:52:36 +0000293done_testing;
294__END__