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!); |
Akron | 2dd0e5d | 2022-11-15 09:44:43 +0100 | [diff] [blame] | 103 | like($token, qr!nkjp\/m:number:sg!); |
| 104 | like($token, qr!nkjp\/m:case:gen!); |
| 105 | like($token, qr!nkjp\/m:gender:m3!); |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 106 | like($token, qr!nkjp\/p:subst!); |
| 107 | like($token, qr!s:ładu!); |
| 108 | |
Akron | afb9856 | 2022-06-08 14:45:09 +0200 | [diff] [blame] | 109 | |
| 110 | # KolakowskiOco |
| 111 | $path = catdir(dirname(__FILE__), 'corpus','NKJP','NKJP','KolakowskiOco'); |
| 112 | |
Akron | 1a2535d | 2022-07-28 16:31:43 +0200 | [diff] [blame] | 113 | 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] | 114 | ok($doc->parse, 'Parse document'); |
| 115 | |
| 116 | is($doc->text_sigle, 'NKJP/NKJP/KolakowskiOco', 'Correct text sigle'); |
| 117 | is($doc->doc_sigle, 'NKJP/NKJP', 'Correct document sigle'); |
| 118 | is($doc->corpus_sigle, 'NKJP', 'Correct corpus sigle'); |
| 119 | |
| 120 | $meta = $doc->meta; |
| 121 | |
| 122 | is($meta->{T_title}, 'TEI P5 encoded version of sample(s) of "O co nas pytają wielcy filozofowie. Seria 3 "', 'Title'); |
| 123 | ok(!$meta->{T_sub_title}, 'SubTitle'); |
| 124 | ok(!$meta->{T_author}, 'Author'); |
| 125 | ok(!$meta->{A_editor}, 'Editor'); |
| 126 | ok(!$meta->{S_pub_place}, 'PubPlace'); |
| 127 | ok(!$meta->{A_publisher}, 'Publisher'); |
| 128 | |
| 129 | ok(!$meta->{S_text_type}, 'No Text Type'); |
| 130 | ok(!$meta->{S_text_type_art}, 'No Text Type Art'); |
| 131 | ok(!$meta->{S_text_type_ref}, 'No Text Type Ref'); |
| 132 | ok(!$meta->{S_text_domain}, 'No Text Domain'); |
| 133 | ok(!$meta->{S_text_column}, 'No Text Column'); |
| 134 | |
Akron | 1a2535d | 2022-07-28 16:31:43 +0200 | [diff] [blame] | 135 | is($meta->{K_nkjp_channel}->[0], 'książka', 'NKJP-Channel'); |
| 136 | ok(!$meta->{K_nkjp_channel}->[1], 'NKJP-Channel'); |
| 137 | is($meta->{K_nkjp_type}->[0], 'literatura piękna', 'NKJP-Type'); |
| 138 | ok(!$meta->{K_nkjp_type}->[1], 'NKJP-Type'); |
| 139 | |
| 140 | |
Akron | afb9856 | 2022-06-08 14:45:09 +0200 | [diff] [blame] | 141 | # Get tokenization |
| 142 | $tokens = KorAP::XML::Tokenizer->new( |
| 143 | path => $doc->path, |
| 144 | doc => $doc, |
| 145 | foundry => $token_base_foundry, |
| 146 | layer => $token_base_layer, |
| 147 | name => 'tokens' |
| 148 | ); |
| 149 | ok($tokens, 'Token Object is fine'); |
| 150 | ok($tokens->parse, 'Token parsing is fine'); |
| 151 | |
| 152 | $output = decode_json( $tokens->to_json ); |
| 153 | |
| 154 | is($output->{data}->{stream}->[0]->[0], '-:tokens$<i>117', 't'); |
| 155 | is($output->{data}->{stream}->[0]->[3], 'i:czy', 't'); |
| 156 | is($output->{data}->{stream}->[1]->[2], 's:zdarza', 't'); |
| 157 | |
| 158 | ## Base |
| 159 | ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs')); |
Akron | 527af14 | 2022-07-21 15:40:06 +0200 | [diff] [blame] | 160 | ok($tokens->add('NKJP', 'Morpho'), 'Add Morpho'); |
| 161 | ok($tokens->add('NKJP', 'NamedEntities'), 'Add NamedEntities'); |
Akron | afb9856 | 2022-06-08 14:45:09 +0200 | [diff] [blame] | 162 | |
| 163 | $output = $tokens->to_data; |
| 164 | |
Akron | 527af14 | 2022-07-21 15:40:06 +0200 | [diff] [blame] | 165 | 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] | 166 | |
Akron | ddf3319 | 2022-08-08 16:44:39 +0200 | [diff] [blame] | 167 | 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] | 168 | |
| 169 | $token = join('||', @{$output->{data}->{stream}->[5]}); |
| 170 | |
| 171 | like($token, qr!<>:dereko/s:seg\$<b>64<i>23<i>28<i>6<b>4<s>1!); |
| 172 | like($token, qr!_5\$<i>23<i>28!); |
| 173 | like($token, qr!i:takie!); |
| 174 | like($token, qr!nkjp/l:taki!); |
Akron | 2dd0e5d | 2022-11-15 09:44:43 +0100 | [diff] [blame] | 175 | like($token, qr!nkjp/m:number:sg!); |
| 176 | like($token, qr!nkjp/m:case:nom!); |
| 177 | like($token, qr!nkjp/m:gender:n!); |
| 178 | like($token, qr!nkjp/m:degree:pos!); |
Akron | afb9856 | 2022-06-08 14:45:09 +0200 | [diff] [blame] | 179 | like($token, qr!nkjp/p:adj!); |
| 180 | like($token, qr!s:takie!); |
Akron | ddf3319 | 2022-08-08 16:44:39 +0200 | [diff] [blame] | 181 | like($token, qr!nkjp/ov:takie!); |
| 182 | |
| 183 | |
Akron | afb9856 | 2022-06-08 14:45:09 +0200 | [diff] [blame] | 184 | |
Akron | 527af14 | 2022-07-21 15:40:06 +0200 | [diff] [blame] | 185 | $token = join('||', @{$output->{data}->{stream}->[67]}); |
| 186 | |
| 187 | like($token, qr!<>:dereko/s:seg\$<b>64<i>464<i>475<i>68<b>4<s>1!); |
| 188 | like($token, qr!\@:dereko\/s:corresp:ann_segmentation\.xml\\#segm_2\.2-seg\$<b>17<s>1<i>68!); |
| 189 | like($token, qr!\@:dereko\/s:id:morph_2\.2-seg\$<b>17<s>1<i>68!); |
| 190 | like($token, qr!_67\$<i>464<i>475!); |
| 191 | like($token, qr!i:kierkegaard!); |
| 192 | like($token, qr!nkjp/l:Kierkegaard!); |
Akron | 2dd0e5d | 2022-11-15 09:44:43 +0100 | [diff] [blame] | 193 | like($token, qr!nkjp/m:number:sg!); |
| 194 | like($token, qr!nkjp/m:case:nom!); |
| 195 | like($token, qr!nkjp/m:gender:m1!); |
Akron | 527af14 | 2022-07-21 15:40:06 +0200 | [diff] [blame] | 196 | like($token, qr!nkjp/ne:persName:surname!); |
| 197 | like($token, qr!nkjp/p:subst!); |
| 198 | like($token, qr!s:Kierkegaard!); |
Akron | ddf3319 | 2022-08-08 16:44:39 +0200 | [diff] [blame] | 199 | like($token, qr!nkjp/ov:Kierkegaard!); |
Akron | 527af14 | 2022-07-21 15:40:06 +0200 | [diff] [blame] | 200 | |
Akron | 88d063a | 2022-03-21 15:10:01 +0100 | [diff] [blame] | 201 | done_testing; |
| 202 | __END__ |
| 203 | |