blob: 865203780dbdcb2eec5ee23ca3778c1816cf2f15 [file] [log] [blame]
Akron88d063a2022-03-21 15:10:01 +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 utf8;
12use lib 'lib', '../lib';
13
14use File::Basename 'dirname';
15use File::Spec::Functions 'catdir';
16
17use_ok('KorAP::XML::Krill');
Akron527af142022-07-21 15:40:06 +020018use_ok('KorAP::XML::Annotation::NKJP::NamedEntities');
Akron88d063a2022-03-21 15:10:01 +010019
20my $path = catdir(dirname(__FILE__), 'corpus','NKJP','NKJP','KOT');
21
22ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
23ok($doc->parse, 'Parse document');
24
25is($doc->text_sigle, 'NKJP/NKJP/KOT', 'Correct text sigle');
26is($doc->doc_sigle, 'NKJP/NKJP', 'Correct document sigle');
27is($doc->corpus_sigle, 'NKJP', 'Correct corpus sigle');
28
29my $meta = $doc->meta;
30
31is($meta->{T_title}, 'TEI P5 encoded version of sample(s) of "Kot"', 'Title');
32ok(!$meta->{T_sub_title}, 'SubTitle');
33ok(!$meta->{T_author}, 'Author');
34ok(!$meta->{A_editor}, 'Editor');
35ok(!$meta->{S_pub_place}, 'PubPlace');
36ok(!$meta->{A_publisher}, 'Publisher');
37
38ok(!$meta->{S_text_type}, 'No Text Type');
39ok(!$meta->{S_text_type_art}, 'No Text Type Art');
40ok(!$meta->{S_text_type_ref}, 'No Text Type Ref');
41ok(!$meta->{S_text_domain}, 'No Text Domain');
42ok(!$meta->{S_text_column}, 'No Text Column');
43
44
45# Tokenization
46use_ok('KorAP::XML::Tokenizer');
47
48my ($token_base_foundry, $token_base_layer) = (qw/nkjp Morpho/);
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,
Akron527af142022-07-21 15:40:06 +020056 name => 'tokens',
Akron88d063a2022-03-21 15:10:01 +010057);
58ok($tokens, 'Token Object is fine');
59ok($tokens->parse, 'Token parsing is fine');
60
61my $output = decode_json( $tokens->to_json );
62
63is($output->{data}->{stream}->[0]->[0], '-:tokens$<i>43', 't');
64is($output->{data}->{stream}->[0]->[3], 'i:nie', 't');
65is($output->{data}->{stream}->[1]->[2], 's:zdążyła', 't');
66
67## Base
68ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'));
Akron527af142022-07-21 15:40:06 +020069ok($tokens->add('NKJP', 'Morpho'), 'Add Morpho');
Akron88d063a2022-03-21 15:10:01 +010070
71$output = $tokens->to_data;
72
73is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs nkjp nkjp/morpho', 'Foundries');
74
75is($output->{data}->{layerInfos}, 'dereko/s=spans nkjp/l=tokens nkjp/m=tokens nkjp/p=tokens', 'layerInfos');
76
77my $token = join('||', @{$output->{data}->{stream}->[7]});
78
79like($token, qr!<>:dereko\/s:seg\$<b>64!);
80like($token, qr!<>:dereko\/s:seg\$<b>64!);
81like($token, qr!iadu!);
82like($token, qr!nkjp\/lad!);
83like($token, qr!nkjp\/m:sg:gen:m3!);
84like($token, qr!nkjp\/p:subst!);
85like($token, qr!sadu!);
86
Akronafb98562022-06-08 14:45:09 +020087
88# KolakowskiOco
89$path = catdir(dirname(__FILE__), 'corpus','NKJP','NKJP','KolakowskiOco');
90
91ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
92ok($doc->parse, 'Parse document');
93
94is($doc->text_sigle, 'NKJP/NKJP/KolakowskiOco', 'Correct text sigle');
95is($doc->doc_sigle, 'NKJP/NKJP', 'Correct document sigle');
96is($doc->corpus_sigle, 'NKJP', 'Correct corpus sigle');
97
98$meta = $doc->meta;
99
100is($meta->{T_title}, 'TEI P5 encoded version of sample(s) of "O co nas pytają wielcy filozofowie. Seria 3 "', 'Title');
101ok(!$meta->{T_sub_title}, 'SubTitle');
102ok(!$meta->{T_author}, 'Author');
103ok(!$meta->{A_editor}, 'Editor');
104ok(!$meta->{S_pub_place}, 'PubPlace');
105ok(!$meta->{A_publisher}, 'Publisher');
106
107ok(!$meta->{S_text_type}, 'No Text Type');
108ok(!$meta->{S_text_type_art}, 'No Text Type Art');
109ok(!$meta->{S_text_type_ref}, 'No Text Type Ref');
110ok(!$meta->{S_text_domain}, 'No Text Domain');
111ok(!$meta->{S_text_column}, 'No Text Column');
112
113# Get tokenization
114$tokens = KorAP::XML::Tokenizer->new(
115 path => $doc->path,
116 doc => $doc,
117 foundry => $token_base_foundry,
118 layer => $token_base_layer,
119 name => 'tokens'
120);
121ok($tokens, 'Token Object is fine');
122ok($tokens->parse, 'Token parsing is fine');
123
124$output = decode_json( $tokens->to_json );
125
126is($output->{data}->{stream}->[0]->[0], '-:tokens$<i>117', 't');
127is($output->{data}->{stream}->[0]->[3], 'i:czy', 't');
128is($output->{data}->{stream}->[1]->[2], 's:zdarza', 't');
129
130## Base
131ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'));
Akron527af142022-07-21 15:40:06 +0200132ok($tokens->add('NKJP', 'Morpho'), 'Add Morpho');
133ok($tokens->add('NKJP', 'NamedEntities'), 'Add NamedEntities');
Akronafb98562022-06-08 14:45:09 +0200134
135$output = $tokens->to_data;
136
Akron527af142022-07-21 15:40:06 +0200137is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs nkjp nkjp/morpho nkjp/namedentities', 'Foundries');
Akronafb98562022-06-08 14:45:09 +0200138
Akron527af142022-07-21 15:40:06 +0200139is($output->{data}->{layerInfos}, 'dereko/s=spans nkjp/l=tokens nkjp/m=tokens nkjp/ne=tokens nkjp/p=tokens', 'layerInfos');
Akronafb98562022-06-08 14:45:09 +0200140
141$token = join('||', @{$output->{data}->{stream}->[5]});
142
143like($token, qr!<>:dereko/s:seg\$<b>64<i>23<i>28<i>6<b>4<s>1!);
144like($token, qr!_5\$<i>23<i>28!);
145like($token, qr!i:takie!);
146like($token, qr!nkjp/l:taki!);
147like($token, qr!nkjp/m:sg:nom:n:pos!);
148like($token, qr!nkjp/p:adj!);
149like($token, qr!s:takie!);
150
Akron527af142022-07-21 15:40:06 +0200151$token = join('||', @{$output->{data}->{stream}->[67]});
152
153like($token, qr!<>:dereko/s:seg\$<b>64<i>464<i>475<i>68<b>4<s>1!);
154like($token, qr!\@:dereko\/s:corresp:ann_segmentation\.xml\\#segm_2\.2-seg\$<b>17<s>1<i>68!);
155like($token, qr!\@:dereko\/s:id:morph_2\.2-seg\$<b>17<s>1<i>68!);
156like($token, qr!_67\$<i>464<i>475!);
157like($token, qr!i:kierkegaard!);
158like($token, qr!nkjp/l:Kierkegaard!);
159like($token, qr!nkjp/m:sg:nom:m1!);
160like($token, qr!nkjp/ne:persName:surname!);
161like($token, qr!nkjp/p:subst!);
162like($token, qr!s:Kierkegaard!);
163
Akron88d063a2022-03-21 15:10:01 +0100164done_testing;
165__END__
166