blob: 89af4d89bdf00ace3097b96b1d2e8937a59ec795 [file] [log] [blame]
Nils Diewaldc95607a2014-11-03 21:04:05 +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 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__), 'BZK/D59/00089');
23
24ok(my $doc = KorAP::Document->new( path => $path . '/' ), 'Load Korap::Document');
25ok($doc->parse, 'Parse document');
26
27is($doc->text_sigle, 'BZK_D59.00089', 'Correct text sigle');
28is($doc->doc_sigle, 'BZK_D59', 'Correct document sigle');
29is($doc->corpus_sigle, 'BZK', 'Correct corpus sigle');
30
31is($doc->title, 'Saragat-Partei zerfällt', 'Title');
32ok(!$doc->sub_title, 'No SubTitle');
33ok(!$doc->author, 'Author');
34ok(!$doc->editor, 'Editor');
35is($doc->pub_place, 'Berlin', 'PubPlace');
36is($doc->pub_date, '19590219', 'PubDate');
37ok(!$doc->publisher, 'Publisher');
38
39is($doc->text_type, 'Zeitung: Tageszeitung', 'Correct Text Type');
40
41ok(!$doc->text_type_art, 'Correct Text Type Art');
42is($doc->text_type_ref, 'Tageszeitung', 'Correct Text Type Ref');
43is($doc->text_domain, 'Politik', 'Correct Text Domain');
44is($doc->text_column, 'POLITIK', 'Correct Text Column');
45is($doc->text_class->[0], 'politik', 'Correct Text Class');
46is($doc->text_class->[1], 'ausland', 'Correct Text Class');
47ok(!$doc->text_class->[2], 'Correct Text Class');
48
49
50is($doc->creation_date, '19590219', 'Creation date');
51is($doc->license, 'ACA-NC-LC', 'License');
52ok(!$doc->pages, 'Pages');
53
54ok(!$doc->file_edition_statement, 'File Statement');
55ok(!$doc->bibl_edition_statement, 'Bibl Statement');
56
57is($doc->reference . "\n", <<'REF', 'Reference');
58Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt
59REF
60is($doc->language, 'de', 'Language');
61
62is($doc->corpus_title, 'Bonner Zeitungskorpus', 'Correct Corpus title');
63ok(!$doc->corpus_sub_title, 'Correct Corpus sub title');
64ok(!$doc->corpus_author, 'Correct Corpus author');
65ok(!$doc->corpus_editor, 'Correct Corpus editor');
66
67is($doc->doc_title, 'Neues Deutschland', 'Correct Doc title');
68is($doc->doc_sub_title, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
69ok(!$doc->doc_author, 'Correct Doc author');
70ok(!$doc->doc_editor, 'Correct doc editor');
71
72# Tokenization
73use_ok('KorAP::Tokenizer');
74
75my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
76
77# Get tokenization
78my $tokens = KorAP::Tokenizer->new(
79 path => $doc->path,
80 doc => $doc,
81 foundry => $token_base_foundry,
82 layer => $token_base_layer,
83 name => 'tokens'
84);
85ok($tokens, 'Token Object is fine');
86ok($tokens->parse, 'Token parsing is fine');
87
88my $output = decode_json( $tokens->to_json );
89
90is(substr($output->{data}->{text}, 0, 100), 'Saragat-Partei zerfällt Rom (ADN) die von dem Rechtssozialisten Saragat geführte Sozialdemokratische', 'Primary Data');
91is($output->{data}->{name}, 'tokens', 'tokenName');
92is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
93is($output->{version}, '0.02', 'version');
94is($output->{data}->{foundries}, '', 'Foundries');
95is($output->{data}->{layerInfos}, '', 'layerInfos');
96is($output->{data}->{stream}->[0]->[3], 's:Saragat-Partei', 'data');
97
98is($output->{textSigle}, 'BZK_D59.00089', 'Correct text sigle');
99is($output->{docSigle}, 'BZK_D59', 'Correct document sigle');
100is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle');
101
102is($output->{title}, 'Saragat-Partei zerfällt', 'Title');
103ok(!exists $output->{subTitle}, 'No SubTitle');
104ok(!exists $output->{author}, 'Author');
105ok(!exists $output->{editor}, 'Publisher');
106
107is($output->{pubPlace}, 'Berlin', 'PubPlace');
108ok(!exists $output->{publisher}, 'Publisher');
109
110is($output->{textType}, 'Zeitung: Tageszeitung', 'Correct Text Type');
111ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
112is($output->{textTypeRef}, 'Tageszeitung', 'Correct Text Type Ref');
113is($output->{textDomain}, 'Politik', 'Correct Text Domain');
114is($output->{textClass}, 'politik ausland', 'Correct Text Domain');
115
116is($output->{creationDate}, '19590219', 'Creation date');
117is($output->{license}, 'ACA-NC-LC', 'License');
118ok(!exists $output->{pages}, 'Pages');
119ok(!exists $output->{fileEditionStatement}, 'File Statement');
120ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
121
122is($output->{reference} . "\n", <<'REF', 'Reference');
123Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt
124REF
125is($output->{language}, 'de', 'Language');
126
127is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
128ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
129ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
130ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
131
132is($output->{docTitle}, 'Neues Deutschland', 'Correct Doc title');
133is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
134ok(!exists $output->{docAuthor}, 'Correct Doc author');
135ok(!exists $output->{docEditor}, 'Correct doc editor');
136
137## Base
138$tokens->add('Base', 'Sentences');
139$tokens->add('Base', 'Paragraphs');
140
141$output = decode_json( $tokens->to_json );
142
143is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
144is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
145my $first_token = join('||', @{$output->{data}->{stream}->[0]});
146like($first_token, qr/s:Saragat-Partei/, 'data');
147like($first_token, qr/_0#0-14/, 'data');
148
149## OpenNLP
150$tokens->add('OpenNLP', 'Sentences');
151
152$output = decode_json( $tokens->to_json );
153is($output->{data}->{foundries},
154 'base base/paragraphs base/sentences opennlp opennlp/sentences',
155 'Foundries');
156is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos');
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## Treetagger
166$tokens->add('TreeTagger', 'Sentences');
167$output = decode_json( $tokens->to_json );
168is($output->{data}->{foundries},
169 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
170 'Foundries');
171is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos');
172
173$tokens->add('TreeTagger', 'Morpho');
174$output = decode_json( $tokens->to_json );
175is($output->{data}->{foundries},
176 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
177 'Foundries');
178is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos');
179
180## CoreNLP
181$tokens->add('CoreNLP', 'NamedEntities');
182$output = decode_json( $tokens->to_json );
183is($output->{data}->{foundries},
184 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
185 'Foundries');
186is($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');
187
188$tokens->add('CoreNLP', 'Sentences');
189$output = decode_json( $tokens->to_json );
190is($output->{data}->{foundries},
191 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
192 'Foundries');
193is($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');
194
195$tokens->add('CoreNLP', 'Morpho');
196$output = decode_json( $tokens->to_json );
197like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries');
198like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
199
200$tokens->add('CoreNLP', 'Constituency');
201$output = decode_json( $tokens->to_json );
202like($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries');
203like($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos');
204
205## Glemm
206$tokens->add('Glemm', 'Morpho');
207$output = decode_json( $tokens->to_json );
208like($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries');
209like($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos');
210
211## Connexor
212$tokens->add('Connexor', 'Sentences');
213$output = decode_json( $tokens->to_json );
214like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries');
215like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos');
216
217$tokens->add('Connexor', 'Morpho');
218$output = decode_json( $tokens->to_json );
219like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries');
220like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos');
221like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos');
222like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos');
223
224$tokens->add('Connexor', 'Phrase');
225$output = decode_json( $tokens->to_json );
226like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries');
227like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos');
228
229$tokens->add('Connexor', 'Syntax');
230$output = decode_json( $tokens->to_json );
231like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries');
232like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos');
233
234## Mate
235$tokens->add('Mate', 'Morpho');
236$output = decode_json( $tokens->to_json );
237like($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
238like($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
239like($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
240like($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos');
241
242diag "No test for mate dependency";
243
244## XIP
245$tokens->add('XIP', 'Sentences');
246$output = decode_json( $tokens->to_json );
247like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries');
248like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos');
249
250$tokens->add('XIP', 'Morpho');
251$output = decode_json( $tokens->to_json );
252like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries');
253like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos');
254like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos');
255
256
257$tokens->add('XIP', 'Constituency');
258$output = decode_json( $tokens->to_json );
259like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries');
260like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos');
261
262diag "No test for xip dependency";
263
264
265done_testing;
266__END__