blob: 344c636fafd5ee2a059be3f196afb71c512e43e0 [file] [log] [blame]
Akrond3a0bad2016-02-26 14:07:58 +01001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
6
7use Benchmark qw/:hireswallclock/;
8
9my $t = Benchmark->new;
10
11use utf8;
12use lib 'lib', '../lib';
13
14use File::Basename 'dirname';
15use File::Spec::Functions 'catdir';
16
17use_ok('KorAP::XML::Krill');
18
Akrond3a0bad2016-02-26 14:07:58 +010019my $path = catdir(dirname(__FILE__), '../corpus/WPD/00001');
Akrond3a0bad2016-02-26 14:07:58 +010020
21ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
22ok($doc->parse, 'Parse document');
23
Akron1cd5b872016-03-22 00:23:46 +010024is($doc->text_sigle, 'WPD/AAA/00001', 'Correct text sigle');
25is($doc->doc_sigle, 'WPD/AAA', 'Correct document sigle');
Akrond3a0bad2016-02-26 14:07:58 +010026is($doc->corpus_sigle, 'WPD', 'Correct corpus sigle');
27
Akron35db6e32016-03-17 22:42:22 +010028my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010029is($meta->{T_title}, 'A', 'Title');
30is($meta->{S_pub_place}, 'URL:http://de.wikipedia.org', 'PubPlace');
31is($meta->{D_pub_date}, '20050328', 'Creation Date');
Akron7e2eb882017-01-18 17:28:07 +010032SKIP: {
33 skip 'Failure because corpus is no longer supported', 1;
Akron5eb3aa02019-01-25 18:30:47 +010034 ok(!$meta->{T_sub_title}, 'SubTitle');
Akron7e2eb882017-01-18 17:28:07 +010035};
Akron5eb3aa02019-01-25 18:30:47 +010036is($meta->{T_author}, 'Ruru; Jens.Ol; Aglarech; u.a.', 'Author');
Akrond3a0bad2016-02-26 14:07:58 +010037
Akron5eb3aa02019-01-25 18:30:47 +010038ok(!$meta->{T_doc_title}, 'Correct Doc title');
39ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title');
40ok(!$meta->{T_doc_author}, 'Correct Doc author');
41ok(!$meta->{A_doc_editor}, 'Correct Doc editor');
Akrond3a0bad2016-02-26 14:07:58 +010042
Akron5eb3aa02019-01-25 18:30:47 +010043ok(!$meta->{T_corpus_title}, 'Correct Corpus title');
44ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title');
Akrond3a0bad2016-02-26 14:07:58 +010045
46# Tokenization
47use_ok('KorAP::XML::Tokenizer');
48
49my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
50
51# Get tokenization
52my $tokens = KorAP::XML::Tokenizer->new(
53 path => $doc->path,
54 doc => $doc,
55 foundry => $token_base_foundry,
56 layer => $token_base_layer,
57 name => 'tokens'
58);
59ok($tokens, 'Token Object is fine');
60ok($tokens->parse, 'Token parsing is fine');
61
62my $output = $tokens->to_data;
63
64is(substr($output->{data}->{text}, 0, 100), 'A bzw. a ist der erste Buchstabe des lateinischen Alphabets und ein Vokal. Der Buchstabe A hat in de', 'Primary Data');
65is($output->{data}->{name}, 'tokens', 'tokenName');
66is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
67
68is($output->{version}, '0.03', 'version');
69is($output->{data}->{foundries}, '', 'Foundries');
70is($output->{data}->{layerInfos}, '', 'layerInfos');
71is($output->{data}->{stream}->[0]->[4], 's:A', 'data');
72
73$tokens->add('Mate', 'Dependency');
74
75my $stream = $tokens->to_data->{data}->{stream};
76
Akron75ba57d2016-03-07 23:36:27 +010077# This is not a goot relation example
78is($stream->[77]->[0],
79 '<:mate/d:--$<b>34<i>498<i>499<i>78<i>78',
80 'element to term');
Akron75ba57d2016-03-07 23:36:27 +010081is($stream->[78]->[0], '>:mate/d:--$<b>33<i>498<i>499<i>77<i>78', 'term to element');
Akrond3a0bad2016-02-26 14:07:58 +010082
Akronaf0ae3f2016-07-14 16:21:50 +020083$tokens->add('Base', 'Sentences');
84
85$stream = $tokens->to_data->{data}->{stream};
86
87is($stream->[0]->[2], '<>:base/s:s$<b>64<i>0<i>74<i>13<b>2', 'Text starts with sentence');
Akrond3a0bad2016-02-26 14:07:58 +010088
Akron6f9fef52016-11-03 17:06:40 +010089
90# Problematic document
91$path = catdir(dirname(__FILE__), '../corpus/WPD15/W28/65631');
92ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
93ok($doc->parse, 'Parse document');
94
95is($doc->text_sigle, 'WPD15/W28/65631', 'Correct text sigle');
96is($doc->doc_sigle, 'WPD15/W28', 'Correct document sigle');
97is($doc->corpus_sigle, 'WPD15', 'Correct corpus sigle');
98
99# Get tokenization
100$tokens = KorAP::XML::Tokenizer->new(
101 path => $doc->path,
102 doc => $doc,
103 foundry => 'Base',
104 layer => 'tokens_aggr',
105 name => 'tokens'
106);
107ok($tokens, 'Token Object is fine');
108ok($tokens->parse, 'Token parsing is fine');
109
110is($tokens->foundry, 'Base', 'Foundry');
111is($tokens->layer, 'tokens_aggr', 'Layer');
112
Akron6f9fef52016-11-03 17:06:40 +0100113ok($tokens->add('CoreNLP', 'Constituency'), 'Add Structure');
114
115$output = $tokens->to_data;
116
117is($output->{data}->{foundries}, 'corenlp corenlp/constituency', 'Foundries');
118is($output->{data}->{layerInfos}, 'corenlp/c=spans', 'layerInfos');
Akron5eb3aa02019-01-25 18:30:47 +0100119is($doc->meta->{A_editor}, 'wikipedia.org', 'Editor');
Akron6f9fef52016-11-03 17:06:40 +0100120
Akron56dfb312017-11-23 18:37:35 +0100121
122# Check offset problem
123$path = catdir(dirname(__FILE__), '../corpus/WPD15/U43/34816');
124ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
125ok($doc->parse, 'Parse document');
126
127is($doc->text_sigle, 'WPD15/U43/34816', 'Correct text sigle');
128
129# Tokenization
130use_ok('KorAP::XML::Tokenizer');
131
132$token_base_foundry = 'Base';
133
134# Get tokenization
135$tokens = KorAP::XML::Tokenizer->new(
136 path => $doc->path,
137 doc => $doc,
138 foundry => $token_base_foundry,
139 layer => $token_base_layer,
140 name => 'tokens'
141);
142ok($tokens, 'Token Object is fine');
143ok($tokens->parse, 'Token parsing is fine');
144
145$output = $tokens->to_data;
146$stream = $tokens->to_data->{data}->{stream};
147
148is($stream->[420]->[-1], 's:online', 'online');
149is($stream->[421]->[-1], 's:verfügbar', 'verfügbar');
150
Akrond3a0bad2016-02-26 14:07:58 +0100151done_testing;
152__END__
153
154
155
156