Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use Data::Dumper; |
| 5 | use JSON::XS; |
| 6 | |
| 7 | if ($ENV{SKIP_REAL}) { |
| 8 | plan skip_all => 'Skip real tests'; |
| 9 | }; |
| 10 | |
| 11 | use utf8; |
| 12 | use lib 'lib', '../lib'; |
| 13 | |
| 14 | use File::Basename 'dirname'; |
| 15 | use File::Spec::Functions 'catdir'; |
| 16 | |
| 17 | use_ok('KorAP::XML::Krill'); |
Akron | 64f7fae | 2022-07-27 12:45:33 +0200 | [diff] [blame] | 18 | use_ok('KorAP::XML::Meta::I5'); |
Akron | 1a2535d | 2022-07-28 16:31:43 +0200 | [diff] [blame] | 19 | use_ok('KorAP::XML::Meta::NKJP'); |
Akron | 527af14 | 2022-07-21 15:40:06 +0200 | [diff] [blame] | 20 | use_ok('KorAP::XML::Annotation::NKJP::NamedEntities'); |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 21 | |
| 22 | my $path = catdir(dirname(__FILE__), 'corpus','NKJP','NKJP','KOT'); |
| 23 | |
Akron | 1a2535d | 2022-07-28 16:31:43 +0200 | [diff] [blame] | 24 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/', meta_type => 'NKJP' ), 'Load Korap::Document'); |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 25 | ok($doc->parse, 'Parse document'); |
| 26 | |
| 27 | is($doc->text_sigle, 'NKJP/NKJP/KOT', 'Correct text sigle'); |
| 28 | is($doc->doc_sigle, 'NKJP/NKJP', 'Correct document sigle'); |
| 29 | is($doc->corpus_sigle, 'NKJP', 'Correct corpus sigle'); |
| 30 | |
| 31 | my $meta = $doc->meta; |
| 32 | |
| 33 | is($meta->{T_title}, 'TEI P5 encoded version of sample(s) of "Kot"', 'Title'); |
Akron | 64f7fae | 2022-07-27 12:45:33 +0200 | [diff] [blame] | 34 | is($meta->{T_corpus_title}, 'Narodowy Korpus Języka Polskiego -- podkorpus zawierający 1 milion słów', 'Title'); |
| 35 | |
Akron | 1a2535d | 2022-07-28 16:31:43 +0200 | [diff] [blame] | 36 | is($meta->{K_nkjp_channel}->[0], 'miesiecznik', 'NKJP-Channel'); |
| 37 | ok(!$meta->{K_nkjp_channel}->[1], 'NKJP-Channel'); |
| 38 | is($meta->{K_nkjp_type}->[0], 'publicystyka i wiadomości prasowe', 'NKJP-Type'); |
| 39 | ok(!$meta->{K_nkjp_type}->[1], 'NKJP-Type'); |
| 40 | |
| 41 | ok($doc = KorAP::XML::Krill->new( path => $path . '/', meta_type => 'NKJP', lang => 'en' ), 'Load Korap::Document'); |
Akron | 64f7fae | 2022-07-27 12:45:33 +0200 | [diff] [blame] | 42 | ok($doc->parse, 'Parse document'); |
| 43 | $meta = $doc->meta; |
| 44 | |
| 45 | is($meta->{T_title}, 'TEI P5 encoded version of sample(s) of "Kot"', 'Title'); |
| 46 | is($meta->{T_corpus_title}, 'National Corpus of Polish -- the 1 million word subcorpus', 'Language sensitive Title'); |
| 47 | |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 48 | ok(!$meta->{T_sub_title}, 'SubTitle'); |
| 49 | ok(!$meta->{T_author}, 'Author'); |
| 50 | ok(!$meta->{A_editor}, 'Editor'); |
| 51 | ok(!$meta->{S_pub_place}, 'PubPlace'); |
| 52 | ok(!$meta->{A_publisher}, 'Publisher'); |
| 53 | |
| 54 | ok(!$meta->{S_text_type}, 'No Text Type'); |
| 55 | ok(!$meta->{S_text_type_art}, 'No Text Type Art'); |
| 56 | ok(!$meta->{S_text_type_ref}, 'No Text Type Ref'); |
| 57 | ok(!$meta->{S_text_domain}, 'No Text Domain'); |
| 58 | ok(!$meta->{S_text_column}, 'No Text Column'); |
| 59 | |
Akron | 1a2535d | 2022-07-28 16:31:43 +0200 | [diff] [blame] | 60 | is($meta->{K_nkjp_channel}->[0], 'monthly', 'NKJP-Channel'); |
| 61 | ok(!$meta->{K_nkjp_channel}->[1], 'NKJP-Channel'); |
| 62 | is($meta->{K_nkjp_type}->[0], 'journalism', 'NKJP-Type'); |
| 63 | ok(!$meta->{K_nkjp_type}->[1], 'NKJP-Type'); |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 64 | |
| 65 | # Tokenization |
| 66 | use_ok('KorAP::XML::Tokenizer'); |
| 67 | |
| 68 | my ($token_base_foundry, $token_base_layer) = (qw/nkjp Morpho/); |
| 69 | |
| 70 | # Get tokenization |
| 71 | my $tokens = KorAP::XML::Tokenizer->new( |
| 72 | path => $doc->path, |
| 73 | doc => $doc, |
| 74 | foundry => $token_base_foundry, |
| 75 | layer => $token_base_layer, |
Akron | 527af14 | 2022-07-21 15:40:06 +0200 | [diff] [blame] | 76 | name => 'tokens', |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 77 | ); |
| 78 | ok($tokens, 'Token Object is fine'); |
| 79 | ok($tokens->parse, 'Token parsing is fine'); |
| 80 | |
| 81 | my $output = decode_json( $tokens->to_json ); |
| 82 | |
| 83 | is($output->{data}->{stream}->[0]->[0], '-:tokens$<i>43', 't'); |
| 84 | is($output->{data}->{stream}->[0]->[3], 'i:nie', 't'); |
| 85 | is($output->{data}->{stream}->[1]->[2], 's:zdążyła', 't'); |
| 86 | |
| 87 | ## Base |
| 88 | ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs')); |
Akron | 527af14 | 2022-07-21 15:40:06 +0200 | [diff] [blame] | 89 | ok($tokens->add('NKJP', 'Morpho'), 'Add Morpho'); |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 90 | |
| 91 | $output = $tokens->to_data; |
| 92 | |
| 93 | is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs nkjp nkjp/morpho', 'Foundries'); |
| 94 | |
Akron | ddf3319 | 2022-08-08 16:44:39 +0200 | [diff] [blame^] | 95 | is($output->{data}->{layerInfos}, 'dereko/s=spans nkjp/l=tokens nkjp/m=tokens nkjp/ov=tokens nkjp/p=tokens', 'layerInfos'); |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 96 | |
| 97 | my $token = join('||', @{$output->{data}->{stream}->[7]}); |
| 98 | |
| 99 | like($token, qr!<>:dereko\/s:seg\$<b>64!); |
| 100 | like($token, qr!<>:dereko\/s:seg\$<b>64!); |
| 101 | like($token, qr!i:ładu!); |
| 102 | like($token, qr!nkjp\/l:ład!); |
| 103 | like($token, qr!nkjp\/m:sg:gen:m3!); |
| 104 | like($token, qr!nkjp\/p:subst!); |
| 105 | like($token, qr!s:ładu!); |
| 106 | |
Akron | afb9856 | 2022-06-08 14:45:09 +0200 | [diff] [blame] | 107 | |
| 108 | # KolakowskiOco |
| 109 | $path = catdir(dirname(__FILE__), 'corpus','NKJP','NKJP','KolakowskiOco'); |
| 110 | |
Akron | 1a2535d | 2022-07-28 16:31:43 +0200 | [diff] [blame] | 111 | ok($doc = KorAP::XML::Krill->new( path => $path . '/', meta_type => 'NKJP', lang => 'pl'), 'Load Korap::Document'); |
Akron | afb9856 | 2022-06-08 14:45:09 +0200 | [diff] [blame] | 112 | ok($doc->parse, 'Parse document'); |
| 113 | |
| 114 | is($doc->text_sigle, 'NKJP/NKJP/KolakowskiOco', 'Correct text sigle'); |
| 115 | is($doc->doc_sigle, 'NKJP/NKJP', 'Correct document sigle'); |
| 116 | is($doc->corpus_sigle, 'NKJP', 'Correct corpus sigle'); |
| 117 | |
| 118 | $meta = $doc->meta; |
| 119 | |
| 120 | is($meta->{T_title}, 'TEI P5 encoded version of sample(s) of "O co nas pytają wielcy filozofowie. Seria 3 "', 'Title'); |
| 121 | ok(!$meta->{T_sub_title}, 'SubTitle'); |
| 122 | ok(!$meta->{T_author}, 'Author'); |
| 123 | ok(!$meta->{A_editor}, 'Editor'); |
| 124 | ok(!$meta->{S_pub_place}, 'PubPlace'); |
| 125 | ok(!$meta->{A_publisher}, 'Publisher'); |
| 126 | |
| 127 | ok(!$meta->{S_text_type}, 'No Text Type'); |
| 128 | ok(!$meta->{S_text_type_art}, 'No Text Type Art'); |
| 129 | ok(!$meta->{S_text_type_ref}, 'No Text Type Ref'); |
| 130 | ok(!$meta->{S_text_domain}, 'No Text Domain'); |
| 131 | ok(!$meta->{S_text_column}, 'No Text Column'); |
| 132 | |
Akron | 1a2535d | 2022-07-28 16:31:43 +0200 | [diff] [blame] | 133 | is($meta->{K_nkjp_channel}->[0], 'książka', 'NKJP-Channel'); |
| 134 | ok(!$meta->{K_nkjp_channel}->[1], 'NKJP-Channel'); |
| 135 | is($meta->{K_nkjp_type}->[0], 'literatura piękna', 'NKJP-Type'); |
| 136 | ok(!$meta->{K_nkjp_type}->[1], 'NKJP-Type'); |
| 137 | |
| 138 | |
Akron | afb9856 | 2022-06-08 14:45:09 +0200 | [diff] [blame] | 139 | # 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 | ); |
| 147 | ok($tokens, 'Token Object is fine'); |
| 148 | ok($tokens->parse, 'Token parsing is fine'); |
| 149 | |
| 150 | $output = decode_json( $tokens->to_json ); |
| 151 | |
| 152 | is($output->{data}->{stream}->[0]->[0], '-:tokens$<i>117', 't'); |
| 153 | is($output->{data}->{stream}->[0]->[3], 'i:czy', 't'); |
| 154 | is($output->{data}->{stream}->[1]->[2], 's:zdarza', 't'); |
| 155 | |
| 156 | ## Base |
| 157 | ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs')); |
Akron | 527af14 | 2022-07-21 15:40:06 +0200 | [diff] [blame] | 158 | ok($tokens->add('NKJP', 'Morpho'), 'Add Morpho'); |
| 159 | ok($tokens->add('NKJP', 'NamedEntities'), 'Add NamedEntities'); |
Akron | afb9856 | 2022-06-08 14:45:09 +0200 | [diff] [blame] | 160 | |
| 161 | $output = $tokens->to_data; |
| 162 | |
Akron | 527af14 | 2022-07-21 15:40:06 +0200 | [diff] [blame] | 163 | is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs nkjp nkjp/morpho nkjp/namedentities', 'Foundries'); |
Akron | afb9856 | 2022-06-08 14:45:09 +0200 | [diff] [blame] | 164 | |
Akron | ddf3319 | 2022-08-08 16:44:39 +0200 | [diff] [blame^] | 165 | is($output->{data}->{layerInfos}, 'dereko/s=spans nkjp/l=tokens nkjp/m=tokens nkjp/ne=tokens nkjp/ov=tokens nkjp/p=tokens', 'layerInfos'); |
Akron | afb9856 | 2022-06-08 14:45:09 +0200 | [diff] [blame] | 166 | |
| 167 | $token = join('||', @{$output->{data}->{stream}->[5]}); |
| 168 | |
| 169 | like($token, qr!<>:dereko/s:seg\$<b>64<i>23<i>28<i>6<b>4<s>1!); |
| 170 | like($token, qr!_5\$<i>23<i>28!); |
| 171 | like($token, qr!i:takie!); |
| 172 | like($token, qr!nkjp/l:taki!); |
| 173 | like($token, qr!nkjp/m:sg:nom:n:pos!); |
| 174 | like($token, qr!nkjp/p:adj!); |
| 175 | like($token, qr!s:takie!); |
Akron | ddf3319 | 2022-08-08 16:44:39 +0200 | [diff] [blame^] | 176 | like($token, qr!nkjp/ov:takie!); |
| 177 | |
| 178 | |
Akron | afb9856 | 2022-06-08 14:45:09 +0200 | [diff] [blame] | 179 | |
Akron | 527af14 | 2022-07-21 15:40:06 +0200 | [diff] [blame] | 180 | $token = join('||', @{$output->{data}->{stream}->[67]}); |
| 181 | |
| 182 | like($token, qr!<>:dereko/s:seg\$<b>64<i>464<i>475<i>68<b>4<s>1!); |
| 183 | like($token, qr!\@:dereko\/s:corresp:ann_segmentation\.xml\\#segm_2\.2-seg\$<b>17<s>1<i>68!); |
| 184 | like($token, qr!\@:dereko\/s:id:morph_2\.2-seg\$<b>17<s>1<i>68!); |
| 185 | like($token, qr!_67\$<i>464<i>475!); |
| 186 | like($token, qr!i:kierkegaard!); |
| 187 | like($token, qr!nkjp/l:Kierkegaard!); |
| 188 | like($token, qr!nkjp/m:sg:nom:m1!); |
| 189 | like($token, qr!nkjp/ne:persName:surname!); |
| 190 | like($token, qr!nkjp/p:subst!); |
| 191 | like($token, qr!s:Kierkegaard!); |
Akron | ddf3319 | 2022-08-08 16:44:39 +0200 | [diff] [blame^] | 192 | like($token, qr!nkjp/ov:Kierkegaard!); |
Akron | 527af14 | 2022-07-21 15:40:06 +0200 | [diff] [blame] | 193 | |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 194 | done_testing; |
| 195 | __END__ |
| 196 | |