blob: a590d441bcd5448e1b251db97d29e4d1832f6874 [file] [log] [blame]
Nils Diewald90410c22014-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/00001');
23
24ok(my $doc = KorAP::Document->new( path => $path . '/' ), 'Load Korap::Document');
25ok($doc->parse, 'Parse document');
26
27is($doc->text_sigle, 'BZK_D59.00001', 'Correct text sigle');
28is($doc->doc_sigle, 'BZK_D59', 'Correct document sigle');
29is($doc->corpus_sigle, 'BZK', 'Correct corpus sigle');
30
31is($doc->title, 'Unser gemeinsames Werk wird siegreich sein', 'Title');
32ok(!$doc->sub_title, 'No SubTitle');
33ok(!$doc->author, 'Author');
34ok(!$doc->editor, 'Editor');
35is($doc->pub_place, 'Berlin', 'PubPlace');
36ok(!$doc->publisher, 'Publisher');
37
38is($doc->text_type, 'Zeitung: Tageszeitung', 'Correct Text Type');
39
40ok(!$doc->text_type_art, 'Correct Text Type Art');
41is($doc->text_type_ref, 'Tageszeitung', 'Correct Text Type Ref');
42is($doc->text_domain, 'Politik', 'Correct Text Domain');
43is($doc->text_column, 'POLITIK', 'Correct Text Column');
44is($doc->text_class->[0], 'politik', 'Correct Text Class');
45is($doc->text_class->[1], 'ausland', 'Correct Text Class');
46ok(!$doc->text_class->[2], 'Correct Text Class');
47
48is($doc->pub_date, '19590101', 'Creation date');
49is($doc->creation_date, '19590101', 'Creation date');
50is($doc->license, 'ACA-NC-LC', 'License');
51ok(!$doc->pages, 'Pages');
52
53ok(!$doc->file_edition_statement, 'File Statement');
54ok(!$doc->bibl_edition_statement, 'Bibl Statement');
55
56is($doc->reference . "\n", <<'REF', 'Reference');
57Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein
58REF
59is($doc->language, 'de', 'Language');
60
61is($doc->corpus_title, 'Bonner Zeitungskorpus', 'Correct Corpus title');
62ok(!$doc->corpus_sub_title, 'Correct Corpus sub title');
63ok(!$doc->corpus_author, 'Correct Corpus author');
64ok(!$doc->corpus_editor, 'Correct Corpus editor');
65
Nils Diewaldfeccbb12015-06-18 20:06:45 +000066is($doc->doc_title, 'Neues Deutschland, Jahrgangsquerschnitt 1959', 'Correct Doc title');
Nils Diewald90410c22014-11-03 21:04:05 +000067is($doc->doc_sub_title, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
68ok(!$doc->doc_author, 'Correct Doc author');
69ok(!$doc->doc_editor, 'Correct doc editor');
70
71# Tokenization
72use_ok('KorAP::Tokenizer');
73
74my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
75
76# Get tokenization
77my $tokens = KorAP::Tokenizer->new(
78 path => $doc->path,
79 doc => $doc,
80 foundry => $token_base_foundry,
81 layer => $token_base_layer,
82 name => 'tokens'
83);
84ok($tokens, 'Token Object is fine');
85ok($tokens->parse, 'Token parsing is fine');
86
87my $output = decode_json( $tokens->to_json );
88
89is(substr($output->{data}->{text}, 0, 100), 'unser gemeinsames Werk wird siegreich sein Neujahrsbotschaft des Präsidenten der DeutschenDemokratis', 'Primary Data');
90is($output->{data}->{name}, 'tokens', 'tokenName');
91is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
92is($output->{version}, '0.02', 'version');
93is($output->{data}->{foundries}, '', 'Foundries');
94is($output->{data}->{layerInfos}, '', 'layerInfos');
95is($output->{data}->{stream}->[0]->[3], 's:unser', 'data');
96
97is($output->{textSigle}, 'BZK_D59.00001', 'Correct text sigle');
98is($output->{docSigle}, 'BZK_D59', 'Correct document sigle');
99is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle');
100
101is($output->{title}, 'Unser gemeinsames Werk wird siegreich sein', 'Title');
102ok(!exists $output->{subTitle}, 'No SubTitle');
103ok(!exists $output->{author}, 'Author');
104ok(!exists $output->{editor}, 'Publisher');
105
106is($output->{pubPlace}, 'Berlin', 'PubPlace');
107ok(!exists $output->{publisher}, 'Publisher');
108
109is($output->{textType}, 'Zeitung: Tageszeitung', 'Correct Text Type');
110ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
111is($output->{textTypeRef}, 'Tageszeitung', 'Correct Text Type Ref');
112is($output->{textDomain}, 'Politik', 'Correct Text Domain');
113
114is($output->{creationDate}, '19590101', 'Creation date');
115is($output->{license}, 'ACA-NC-LC', 'License');
116ok(!exists $output->{pages}, 'Pages');
117ok(!exists $output->{fileEditionStatement}, 'File Statement');
118ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
119
120is($output->{reference} . "\n", <<'REF', 'Reference');
121Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein
122REF
123is($output->{language}, 'de', 'Language');
124
125is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title');
126ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
127ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
128ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
129
Nils Diewaldfeccbb12015-06-18 20:06:45 +0000130is($output->{docTitle}, 'Neues Deutschland, Jahrgangsquerschnitt 1959', 'Correct Doc title');
Nils Diewald90410c22014-11-03 21:04:05 +0000131is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title');
132ok(!exists $output->{docAuthor}, 'Correct Doc author');
133ok(!exists $output->{docEditor}, 'Correct doc editor');
134
135## Base
136$tokens->add('Base', 'Sentences');
137$tokens->add('Base', 'Paragraphs');
138
139$output = decode_json( $tokens->to_json );
140
141is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
142is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
143my $first_token = join('||', @{$output->{data}->{stream}->[0]});
144like($first_token, qr/s:unser/, 'data');
145like($first_token, qr/_0#0-5/, 'data');
146
147## OpenNLP
148$tokens->add('OpenNLP', 'Sentences');
149
150$output = decode_json( $tokens->to_json );
151is($output->{data}->{foundries},
152 'base base/paragraphs base/sentences opennlp opennlp/sentences',
153 'Foundries');
154is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos');
155
156
157$tokens->add('OpenNLP', 'Morpho');
158$output = decode_json( $tokens->to_json );
159is($output->{data}->{foundries},
160 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
161 'Foundries');
162is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos');
163
164## Treetagger
165$tokens->add('TreeTagger', 'Sentences');
166$output = decode_json( $tokens->to_json );
167is($output->{data}->{foundries},
168 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
169 'Foundries');
170is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos');
171
172$tokens->add('TreeTagger', 'Morpho');
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## CoreNLP
180$tokens->add('CoreNLP', 'NamedEntities');
181$output = decode_json( $tokens->to_json );
182is($output->{data}->{foundries},
183 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
184 'Foundries');
185is($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');
186
187$tokens->add('CoreNLP', 'Sentences');
188$output = decode_json( $tokens->to_json );
189is($output->{data}->{foundries},
190 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
191 'Foundries');
192is($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');
193
194$tokens->add('CoreNLP', 'Morpho');
195$output = decode_json( $tokens->to_json );
196like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries');
197like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
198
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 );
237unlike($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
238unlike($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
239unlike($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
240unlike($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__