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