blob: aa9f5dfbcdc6a0d4df4846158d02197d06f9f138 [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');
Akron64f7fae2022-07-27 12:45:33 +020018use_ok('KorAP::XML::Meta::I5');
Akron1a2535d2022-07-28 16:31:43 +020019use_ok('KorAP::XML::Meta::NKJP');
Akron527af142022-07-21 15:40:06 +020020use_ok('KorAP::XML::Annotation::NKJP::NamedEntities');
Akron88d063a2022-03-21 15:10:01 +010021
22my $path = catdir(dirname(__FILE__), 'corpus','NKJP','NKJP','KOT');
23
Akron1a2535d2022-07-28 16:31:43 +020024ok(my $doc = KorAP::XML::Krill->new( path => $path . '/', meta_type => 'NKJP' ), 'Load Korap::Document');
Akron88d063a2022-03-21 15:10:01 +010025ok($doc->parse, 'Parse document');
26
27is($doc->text_sigle, 'NKJP/NKJP/KOT', 'Correct text sigle');
28is($doc->doc_sigle, 'NKJP/NKJP', 'Correct document sigle');
29is($doc->corpus_sigle, 'NKJP', 'Correct corpus sigle');
30
31my $meta = $doc->meta;
32
33is($meta->{T_title}, 'TEI P5 encoded version of sample(s) of "Kot"', 'Title');
Akron64f7fae2022-07-27 12:45:33 +020034is($meta->{T_corpus_title}, 'Narodowy Korpus Języka Polskiego -- podkorpus zawierający 1 milion słów', 'Title');
35
Akron1a2535d2022-07-28 16:31:43 +020036is($meta->{K_nkjp_channel}->[0], 'miesiecznik', 'NKJP-Channel');
37ok(!$meta->{K_nkjp_channel}->[1], 'NKJP-Channel');
38is($meta->{K_nkjp_type}->[0], 'publicystyka i wiadomości prasowe', 'NKJP-Type');
39ok(!$meta->{K_nkjp_type}->[1], 'NKJP-Type');
40
41ok($doc = KorAP::XML::Krill->new( path => $path . '/', meta_type => 'NKJP', lang => 'en' ), 'Load Korap::Document');
Akron64f7fae2022-07-27 12:45:33 +020042ok($doc->parse, 'Parse document');
43$meta = $doc->meta;
44
45is($meta->{T_title}, 'TEI P5 encoded version of sample(s) of "Kot"', 'Title');
46is($meta->{T_corpus_title}, 'National Corpus of Polish -- the 1 million word subcorpus', 'Language sensitive Title');
47
Akron88d063a2022-03-21 15:10:01 +010048ok(!$meta->{T_sub_title}, 'SubTitle');
49ok(!$meta->{T_author}, 'Author');
50ok(!$meta->{A_editor}, 'Editor');
51ok(!$meta->{S_pub_place}, 'PubPlace');
52ok(!$meta->{A_publisher}, 'Publisher');
53
54ok(!$meta->{S_text_type}, 'No Text Type');
55ok(!$meta->{S_text_type_art}, 'No Text Type Art');
56ok(!$meta->{S_text_type_ref}, 'No Text Type Ref');
57ok(!$meta->{S_text_domain}, 'No Text Domain');
58ok(!$meta->{S_text_column}, 'No Text Column');
59
Akron1a2535d2022-07-28 16:31:43 +020060is($meta->{K_nkjp_channel}->[0], 'monthly', 'NKJP-Channel');
61ok(!$meta->{K_nkjp_channel}->[1], 'NKJP-Channel');
62is($meta->{K_nkjp_type}->[0], 'journalism', 'NKJP-Type');
63ok(!$meta->{K_nkjp_type}->[1], 'NKJP-Type');
Akron88d063a2022-03-21 15:10:01 +010064
65# Tokenization
66use_ok('KorAP::XML::Tokenizer');
67
68my ($token_base_foundry, $token_base_layer) = (qw/nkjp Morpho/);
69
70# Get tokenization
71my $tokens = KorAP::XML::Tokenizer->new(
72 path => $doc->path,
73 doc => $doc,
74 foundry => $token_base_foundry,
75 layer => $token_base_layer,
Akron527af142022-07-21 15:40:06 +020076 name => 'tokens',
Akron88d063a2022-03-21 15:10:01 +010077);
78ok($tokens, 'Token Object is fine');
79ok($tokens->parse, 'Token parsing is fine');
80
81my $output = decode_json( $tokens->to_json );
82
83is($output->{data}->{stream}->[0]->[0], '-:tokens$<i>43', 't');
84is($output->{data}->{stream}->[0]->[3], 'i:nie', 't');
85is($output->{data}->{stream}->[1]->[2], 's:zdążyła', 't');
86
87## Base
88ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'));
Akron527af142022-07-21 15:40:06 +020089ok($tokens->add('NKJP', 'Morpho'), 'Add Morpho');
Akron88d063a2022-03-21 15:10:01 +010090
91$output = $tokens->to_data;
92
93is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs nkjp nkjp/morpho', 'Foundries');
94
Akronddf33192022-08-08 16:44:39 +020095is($output->{data}->{layerInfos}, 'dereko/s=spans nkjp/l=tokens nkjp/m=tokens nkjp/ov=tokens nkjp/p=tokens', 'layerInfos');
Akron88d063a2022-03-21 15:10:01 +010096
97my $token = join('||', @{$output->{data}->{stream}->[7]});
98
99like($token, qr!<>:dereko\/s:seg\$<b>64!);
100like($token, qr!<>:dereko\/s:seg\$<b>64!);
101like($token, qr!iadu!);
102like($token, qr!nkjp\/lad!);
103like($token, qr!nkjp\/m:sg:gen:m3!);
104like($token, qr!nkjp\/p:subst!);
105like($token, qr!sadu!);
106
Akronafb98562022-06-08 14:45:09 +0200107
108# KolakowskiOco
109$path = catdir(dirname(__FILE__), 'corpus','NKJP','NKJP','KolakowskiOco');
110
Akron1a2535d2022-07-28 16:31:43 +0200111ok($doc = KorAP::XML::Krill->new( path => $path . '/', meta_type => 'NKJP', lang => 'pl'), 'Load Korap::Document');
Akronafb98562022-06-08 14:45:09 +0200112ok($doc->parse, 'Parse document');
113
114is($doc->text_sigle, 'NKJP/NKJP/KolakowskiOco', 'Correct text sigle');
115is($doc->doc_sigle, 'NKJP/NKJP', 'Correct document sigle');
116is($doc->corpus_sigle, 'NKJP', 'Correct corpus sigle');
117
118$meta = $doc->meta;
119
120is($meta->{T_title}, 'TEI P5 encoded version of sample(s) of "O co nas pytają wielcy filozofowie. Seria 3 "', 'Title');
121ok(!$meta->{T_sub_title}, 'SubTitle');
122ok(!$meta->{T_author}, 'Author');
123ok(!$meta->{A_editor}, 'Editor');
124ok(!$meta->{S_pub_place}, 'PubPlace');
125ok(!$meta->{A_publisher}, 'Publisher');
126
127ok(!$meta->{S_text_type}, 'No Text Type');
128ok(!$meta->{S_text_type_art}, 'No Text Type Art');
129ok(!$meta->{S_text_type_ref}, 'No Text Type Ref');
130ok(!$meta->{S_text_domain}, 'No Text Domain');
131ok(!$meta->{S_text_column}, 'No Text Column');
132
Akron1a2535d2022-07-28 16:31:43 +0200133is($meta->{K_nkjp_channel}->[0], 'książka', 'NKJP-Channel');
134ok(!$meta->{K_nkjp_channel}->[1], 'NKJP-Channel');
135is($meta->{K_nkjp_type}->[0], 'literatura piękna', 'NKJP-Type');
136ok(!$meta->{K_nkjp_type}->[1], 'NKJP-Type');
137
138
Akronafb98562022-06-08 14:45:09 +0200139# Get tokenization
140$tokens = KorAP::XML::Tokenizer->new(
141 path => $doc->path,
142 doc => $doc,
143 foundry => $token_base_foundry,
144 layer => $token_base_layer,
145 name => 'tokens'
146);
147ok($tokens, 'Token Object is fine');
148ok($tokens->parse, 'Token parsing is fine');
149
150$output = decode_json( $tokens->to_json );
151
152is($output->{data}->{stream}->[0]->[0], '-:tokens$<i>117', 't');
153is($output->{data}->{stream}->[0]->[3], 'i:czy', 't');
154is($output->{data}->{stream}->[1]->[2], 's:zdarza', 't');
155
156## Base
157ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'));
Akron527af142022-07-21 15:40:06 +0200158ok($tokens->add('NKJP', 'Morpho'), 'Add Morpho');
159ok($tokens->add('NKJP', 'NamedEntities'), 'Add NamedEntities');
Akronafb98562022-06-08 14:45:09 +0200160
161$output = $tokens->to_data;
162
Akron527af142022-07-21 15:40:06 +0200163is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs nkjp nkjp/morpho nkjp/namedentities', 'Foundries');
Akronafb98562022-06-08 14:45:09 +0200164
Akronddf33192022-08-08 16:44:39 +0200165is($output->{data}->{layerInfos}, 'dereko/s=spans nkjp/l=tokens nkjp/m=tokens nkjp/ne=tokens nkjp/ov=tokens nkjp/p=tokens', 'layerInfos');
Akronafb98562022-06-08 14:45:09 +0200166
167$token = join('||', @{$output->{data}->{stream}->[5]});
168
169like($token, qr!<>:dereko/s:seg\$<b>64<i>23<i>28<i>6<b>4<s>1!);
170like($token, qr!_5\$<i>23<i>28!);
171like($token, qr!i:takie!);
172like($token, qr!nkjp/l:taki!);
173like($token, qr!nkjp/m:sg:nom:n:pos!);
174like($token, qr!nkjp/p:adj!);
175like($token, qr!s:takie!);
Akronddf33192022-08-08 16:44:39 +0200176like($token, qr!nkjp/ov:takie!);
177
178
Akronafb98562022-06-08 14:45:09 +0200179
Akron527af142022-07-21 15:40:06 +0200180$token = join('||', @{$output->{data}->{stream}->[67]});
181
182like($token, qr!<>:dereko/s:seg\$<b>64<i>464<i>475<i>68<b>4<s>1!);
183like($token, qr!\@:dereko\/s:corresp:ann_segmentation\.xml\\#segm_2\.2-seg\$<b>17<s>1<i>68!);
184like($token, qr!\@:dereko\/s:id:morph_2\.2-seg\$<b>17<s>1<i>68!);
185like($token, qr!_67\$<i>464<i>475!);
186like($token, qr!i:kierkegaard!);
187like($token, qr!nkjp/l:Kierkegaard!);
188like($token, qr!nkjp/m:sg:nom:m1!);
189like($token, qr!nkjp/ne:persName:surname!);
190like($token, qr!nkjp/p:subst!);
191like($token, qr!s:Kierkegaard!);
Akronddf33192022-08-08 16:44:39 +0200192like($token, qr!nkjp/ov:Kierkegaard!);
Akron527af142022-07-21 15:40:06 +0200193
Akron88d063a2022-03-21 15:10:01 +0100194done_testing;
195__END__
196