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