blob: e2d69842dafc5f27b4bf911a2dfddac3e804eb60 [file] [log] [blame]
Nils Diewald32e30f02014-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
10use utf8;
11use lib 'lib', '../lib';
12
13use File::Basename 'dirname';
14use File::Spec::Functions 'catdir';
15
16use_ok('KorAP::Document');
17
18# GOE/AGA/03828
19my $path = catdir(dirname(__FILE__), 'GOE/AGA/03828');
20
21ok(my $doc = KorAP::Document->new( path => $path . '/' ), 'Load Korap::Document');
22ok($doc->parse, 'Parse document');
23
24is($doc->text_sigle, 'GOE_AGA.03828', 'Correct text sigle');
25is($doc->doc_sigle, 'GOE_AGA', 'Correct document sigle');
26is($doc->corpus_sigle, 'GOE', 'Correct corpus sigle');
27
28is($doc->corpus_title, 'Goethes Werke', 'Correct Corpus title');
29is($doc->text_type, 'Autobiographie', 'Correct Text Type');
30is($doc->author->[0], 'Goethe, Johann Wolfgang von', 'Author');
31is($doc->reference . "\n", <<'REF', 'Author');
32Goethe, 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
33REF
34is($doc->pub_place, 'München', 'PubPlace');
35is($doc->publisher, 'Verlag C. H. Beck', 'Publisher');
36is($doc->coll_editor, 'Trunz, Erich', 'Editor');
37is($doc->language, 'de', 'Language');
38is($doc->license, 'QAO-NC', 'License');
39is($doc->creation_date, '18200000', 'Creation Date');
40is($doc->pub_date, '19820000', 'Creation Date');
41is($doc->title, 'Autobiographische Einzelheiten', 'Title');
42is($doc->pages, '529-547', 'Pages');
43
44# Tokenization
45use_ok('KorAP::Tokenizer');
46
47my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
48
49# Get tokenization
50my $tokens = KorAP::Tokenizer->new(
51 path => $doc->path,
52 doc => $doc,
53 foundry => $token_base_foundry,
54 layer => $token_base_layer,
55 name => 'tokens'
56);
57ok($tokens, 'Token Object is fine');
58ok($tokens->parse, 'Token parsing is fine');
59
60my $output = decode_json( $tokens->to_json );
61
62
63is(substr($output->{primaryData}, 0, 100), 'Autobiographische einzelheiten Selbstschilderung (1) immer tätiger, nach innen und außen fortwirkend', 'Primary Data');
64is($output->{tokenName}, 'tokens', 'tokenName');
65is($output->{tokenSource}, 'opennlp#tokens', 'tokenSource');
66is($output->{version}, '0.02', 'version');
67
68is($output->{foundries}, '', 'Foundries');
69is($output->{layerInfos}, '', 'layerInfos');
70is($output->{data}->[0]->[0], 's:Autobiographische', 'data');
71
72is($output->{textSigle}, 'GOE_AGA.03828', 'Correct text sigle');
73is($output->{docSigle}, 'GOE_AGA', 'Correct document sigle');
74is($output->{corpusSigle}, 'GOE', 'Correct corpus sigle');
75
76is($output->{corpusTitle}, 'Goethes Werke', 'Correct Corpus title');
77is($output->{textType}, 'Autobiographie', 'Correct Text Type');
78is($output->{author}, 'Goethe, Johann Wolfgang von', 'Author');
79is($output->{reference} . "\n", <<'REF', 'Author');
80Goethe, 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
81REF
82is($output->{pubPlace}, 'München', 'PubPlace');
83is($output->{publisher}, 'Verlag C. H. Beck', 'Publisher');
84is($output->{collEditor}, 'Trunz, Erich', 'Editor');
85is($output->{language}, 'de', 'Language');
86is($output->{license}, 'QAO-NC', 'License');
87is($output->{creationDate}, '18200000', 'Creation Date');
88is($output->{pubDate}, '19820000', 'Creation Date');
89is($output->{title}, 'Autobiographische Einzelheiten', 'Title');
90is($output->{pages}, '529-547', 'Pages');
91
92
93## Base
94$tokens->add('Base', 'Sentences');
95$tokens->add('Base', 'Paragraphs');
96
97$output = decode_json( $tokens->to_json );
98
99is($output->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
100is($output->{layerInfos}, 'base/s=spans', 'layerInfos');
101my $first_token = join('||', @{$output->{data}->[0]});
102like($first_token, qr/s:Autobiographische/, 'data');
103like($first_token, qr/_0#0-17/, 'data');
104like($first_token, qr!<>:base/s:s#0-30\$<i>2!, 'data');
105like($first_token, qr!<>:base\/s:t#0-35199\$<i>5226!, 'data');
106
107## OpenNLP
108$tokens->add('OpenNLP', 'Sentences');
109
110$output = decode_json( $tokens->to_json );
111is($output->{foundries},
112 'base base/paragraphs base/sentences opennlp opennlp/sentences',
113 'Foundries');
114is($output->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos');
115$first_token = join('||', @{$output->{data}->[0]});
116like($first_token, qr!<>:opennlp/s:s#0-254\$<i>32!, 'data');
117
118$tokens->add('OpenNLP', 'Morpho');
119$output = decode_json( $tokens->to_json );
120is($output->{foundries},
121 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
122 'Foundries');
123is($output->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos');
124$first_token = join('||', @{$output->{data}->[0]});
125like($first_token, qr!opennlp/p:ADJA!, 'data');
126
127## Treetagger
128$tokens->add('TreeTagger', 'Sentences');
129$output = decode_json( $tokens->to_json );
130is($output->{foundries},
131 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
132 'Foundries');
133is($output->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos');
134$first_token = join('||', @{$output->{data}->[0]});
135like($first_token, qr!<>:tt/s:s#0-179\$<i>21!, 'data');
136
137
138$tokens->add('TreeTagger', 'Morpho');
139$output = decode_json( $tokens->to_json );
140is($output->{foundries},
141 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
142 'Foundries');
143is($output->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
144$first_token = join('||', @{$output->{data}->[0]});
145like($first_token, qr!tt/l:autobiographisch\$<b>165!, 'data');
146like($first_token, qr!tt/p:ADJA\$<b>165!, 'data');
147like($first_token, qr!tt/l:Autobiographische\$<b>89!, 'data');
148like($first_token, qr!tt/p:NN\$<b>89!, 'data');
149
150
151## CoreNLP
152$tokens->add('CoreNLP', 'NamedEntities');
153$output = decode_json( $tokens->to_json );
154is($output->{foundries},
155 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
156 'Foundries');
157is($output->{layerInfos}, 'base/s=spans corenlp/ne=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
158
159diag "Missing test for NamedEntities";
160
161# Problematic:
162# diag Dumper $output->{data}->[180];
163# diag Dumper $output->{data}->[341];
164
165$tokens->add('CoreNLP', 'Sentences');
166$output = decode_json( $tokens->to_json );
167is($output->{foundries},
168 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
169 'Foundries');
170is($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');
171$first_token = join('||', @{$output->{data}->[0]});
172like($first_token, qr!<>:corenlp/s:s#0-254\$<i>32!, 'data');
173
174
175$tokens->add('CoreNLP', 'Morpho');
176$output = decode_json( $tokens->to_json );
177like($output->{foundries}, qr!corenlp/morpho!, 'Foundries');
178like($output->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
179$first_token = join('||', @{$output->{data}->[0]});
180like($first_token, qr!corenlp/p:ADJA!, 'data');
181
182fail('Check for Constiuency!');
183
184## Glemm
185$tokens->add('Glemm', 'Morpho');
186$output = decode_json( $tokens->to_json );
187like($output->{foundries}, qr!glemm/morpho!, 'Foundries');
188like($output->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos');
189$first_token = join('||', @{$output->{data}->[0]});
190like($first_token, qr!glemm/l:__autobiographisch!, 'data');
191like($first_token, qr!glemm/l:\+_Auto!, 'data');
192like($first_token, qr!glemm/l:\+_biographisch!, 'data');
193like($first_token, qr!glemm/l:\+\+Biograph!, 'data');
194like($first_token, qr!glemm/l:\+\+-isch!, 'data');
195
196
197## Connexor
198$tokens->add('Connexor', 'Sentences');
199$output = decode_json( $tokens->to_json );
200like($output->{foundries}, qr!connexor/sentences!, 'Foundries');
201like($output->{layerInfos}, qr!cnx/s=spans!, 'layerInfos');
202$first_token = join('||', @{$output->{data}->[0]});
203like($first_token, qr!<>:cnx/s:s#0-179\$<i>21!, 'data');
204
205
206$tokens->add('Connexor', 'Morpho');
207$output = decode_json( $tokens->to_json );
208like($output->{foundries}, qr!connexor/morpho!, 'Foundries');
209like($output->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos');
210like($output->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos');
211like($output->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos');
212$first_token = join('||', @{$output->{data}->[0]});
213like($first_token, qr!cnx/l:autobiografisch!, 'data');
214like($first_token, qr!cnx/p:A!, 'data');
215
216$tokens->add('Connexor', 'Phrase');
217$output = decode_json( $tokens->to_json );
218like($output->{foundries}, qr!connexor/phrase!, 'Foundries');
219like($output->{layerInfos}, qr!cnx/c=spans!, 'layerInfos');
220$first_token = join('||', @{$output->{data}->[0]});
221like($first_token, qr!<>:cnx/c:np#0-30\$<i>2!, 'data');
222
223
224$tokens->add('Connexor', 'Syntax');
225$output = decode_json( $tokens->to_json );
226like($output->{foundries}, qr!connexor/syntax!, 'Foundries');
227like($output->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos');
228$first_token = join('||', @{$output->{data}->[0]});
229like($first_token, qr!cnx/syn:\@PREMOD!, 'data');
230
231## Mate
232$tokens->add('Mate', 'Morpho');
233$output = decode_json( $tokens->to_json );
234like($output->{foundries}, qr!mate/morpho!, 'Foundries');
235like($output->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
236like($output->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
237like($output->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
238$first_token = join('||', @{$output->{data}->[0]});
239like($first_token, qr!---!, 'data');
240
241diag Dumper $output->{data}->[0];
242
243
244diag "Use token-ids in tokens!";
245diag "Sort tokens based on positions!";
246
247done_testing;
248__END__