blob: 9fde91e4465ccc8d18de33b68aff90e4badf0d12 [file] [log] [blame]
Marc Kupietz400590b2022-12-23 16:02:36 +01001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
6
7if ($ENV{SKIP_REAL}) {
8 plan skip_all => 'Skip real tests';
9};
10
11use Benchmark qw/:hireswallclock/;
12
13my $t = Benchmark->new;
14
15use utf8;
16use lib 'lib', '../lib';
17
18use File::Basename 'dirname';
19use File::Spec::Functions 'catdir';
20
21use_ok('KorAP::XML::Krill');
22
23my $path = catdir(dirname(__FILE__), 'corpus','ICCGER','DeReKo-WPD17','A00-82293');
24
25ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
26ok($doc->parse, 'Parse document');
27
28is($doc->text_sigle, 'ICCGER/DeReKo-WPD17/A00-82293', 'Correct text sigle');
29is($doc->doc_sigle, 'ICCGER/DeReKo-WPD17', 'Correct document sigle');
30is($doc->corpus_sigle, 'ICCGER', 'Correct corpus sigle');
31
32my $meta = $doc->meta;
33
34is($meta->{T_title}, 'WPD17/A00.82293 Abbildungsfehler, In: Wikipedia - URL:http://de.wikipedia.org/wiki/Abbildungsfehler: Wikipedia, 2017 [Extract]', 'Title');
35is($meta->{S_pub_place}, undef, 'PubPlace');
36is($meta->{D_pub_date}, undef, 'Creation Date');
37is($meta->{S_text_type}, undef, 'Text type');
38is($meta->{T_author}, undef, 'Author');
39is($meta->{S_language}, undef, 'Language');
40is($meta->{T_doc_title}, undef, 'Correct Doc title');
41ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title');
42ok(!$meta->{T_doc_author}, 'Correct Doc author');
43ok(!$meta->{A_doc_editor}, 'Correct Doc editor');
44
45# Tokenization
46use_ok('KorAP::XML::Tokenizer');
47
48my ($token_base_foundry, $token_base_layer) = (qw/Base tokens/);
49
50# Get tokenization
51my $tokens = KorAP::XML::Tokenizer->new(
52 path => $doc->path,
53 doc => $doc,
54 foundry => $token_base_foundry,
55 layer => $token_base_layer,
56 name => 'tokens'
57);
58
59ok($tokens, 'Token Object is fine');
60ok($tokens->parse, 'Token parsing is fine');
61
62my $output = decode_json( $tokens->to_json );
63
64is(substr($output->{data}->{text}, 0, 100), 'Es ist aber möglich, die Abbildungsfehler gegenüber einem einfachen System aus einer einzelnen Linse', 'Primary Data');
65
66is($output->{data}->{name}, 'tokens', 'tokenName');
67is($output->{data}->{tokenSource}, 'base#tokens', 'tokenSource');
68is($output->{version}, '0.03', 'version');
69
70is($output->{data}->{foundries}, '', 'Foundries');
71is($output->{data}->{layerInfos}, '', 'layerInfos');
72is($output->{data}->{stream}->[0]->[4], 's:Es', 'data');
73
74is($output->{textSigle}, 'ICCGER/DeReKo-WPD17/A00-82293', 'Correct text sigle');
75is($output->{docSigle}, 'ICCGER/DeReKo-WPD17', 'Correct document sigle');
76is($output->{corpusSigle}, 'ICCGER', 'Correct corpus sigle');
77
78is($output->{title}, 'WPD17/A00.82293 Abbildungsfehler, In: Wikipedia - URL:http://de.wikipedia.org/wiki/Abbildungsfehler: Wikipedia, 2017 [Extract]', 'Title');
79ok(!exists $output->{subTitle}, 'Correct SubTitle');
80ok(!exists $output->{author}, 'Author');
81ok(!exists $output->{editor}, 'Publisher');
82
83ok(!exists $output->{pubPlace}, 'PubPlace');
84ok(!exists $output->{publisher}, 'Publisher');
85
86ok(!exists $output->{textType}, 'Correct Text Type');
87ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
88ok(!exists $output->{textTypeRef}, 'Correct Text Type Ref');
89ok(!exists $output->{textDomain}, 'Correct Text Domain');
90
91ok(!exists $output->{creationDate}, 'Creation date');
92ok(!exists $output->{availability}, 'License');
93
94ok(!exists $output->{pages}, 'Pages');
95ok(!exists $output->{fileEditionStatement}, 'File Statement');
96ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
97
98ok(!exists $output->{reference}, 'Reference');
99ok(!exists $output->{language}, 'Language');
100
101ok(!exists $output->{corpusTitle}, 'Correct Corpus title');
102ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
103ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
104ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
105
106ok(!exists $output->{docTitle}, 'Correct Doc title');
107ok(!exists $output->{docSubTitle}, 'Correct Doc sub title');
108ok(!exists $output->{docAuthor}, 'Correct Doc author');
109ok(!exists $output->{docEditor}, 'Correct doc editor');
110
111## Base
112$tokens->add('DeReKo', 'Structure');
113
114$output = decode_json( $tokens->to_json );
115
116is($output->{data}->{foundries}, 'dereko dereko/structure', 'Foundries');
117is($output->{data}->{layerInfos}, 'dereko/s=spans', 'layerInfos');
118my $first_token = join('||', @{$output->{data}->{stream}->[0]});
119like($first_token, qr/<>:dereko\/s:s\$<b>64<i>0<i>145<i>21<b>4/, 'data');
120like($first_token, qr/s:Es/, 'data');
121
122# Add annotations
123$tokens->add('UDPipe', 'Dependency');
124$tokens->add('UDPipe', 'Morpho');
125
126$output = decode_json( $tokens->to_json );
127
128my $first = $output->{data}->{stream}->[0];
129
130is('-:tokens$<i>1878', $first->[0]);
131is('<:ud/d:root$<b>34<i>0<i>145<i>21<i>3', $first->[1]);
132is('<>:dereko/s:s$<b>64<i>0<i>145<i>21<b>4', $first->[2]);
133is('<>:dereko/s:p$<b>64<i>0<i>484<i>61<b>3', $first->[3]);
134is('<>:dereko/s:div$<b>64<i>0<i>782<i>96<b>2<s>1', $first->[4]);
135is('<>:base/s:t$<b>64<i>0<i>15402<i>1878<b>0', $first->[5]);
136is('<>:dereko/s:text$<b>64<i>0<i>15402<i>1878<b>0', $first->[6]);
137is('<>:dereko/s:body$<b>64<i>0<i>15402<i>1878<b>1', $first->[7]);
138is('>:ud/d:expl$<b>32<i>3', $first->[8]);
139is('@:dereko/s:type:fix2$<b>17<s>1<i>96', $first->[9]);
140is('_0$<i>0<i>2', $first->[10]);
141is('i:es', $first->[11]);
142is('s:Es', $first->[12]);
143is('ud/l:Es', $first->[13]);
144is('ud/m:case:nom', $first->[14]);
145is('ud/m:gender:neut', $first->[15]);
146is('ud/m:number:sing', $first->[16]);
147is('ud/m:person:3', $first->[17]);
148is('ud/m:prontype:prs', $first->[18]);
149is('ud/p:PRON', $first->[19]);
150ok(!$first->[20]);
151
152my $last = $output->{data}->{stream}->[-1];
153
154is('>:ud/d:advmod$<b>32<i>1876', $last->[0]);
155is('_1877$<i>15397<i>15401', $last->[1]);
156is('i:auch', $last->[2]);
157is('s:auch', $last->[3]);
158is('ud/l:auch', $last->[4]);
159is('ud/p:ADV', $last->[5]);
160ok(!$last->[6]);
161
162done_testing;
163__END__