Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use Data::Dumper; |
| 5 | use JSON::XS; |
| 6 | use Log::Log4perl; |
| 7 | use utf8; |
| 8 | |
Akron | fab17d3 | 2020-07-31 14:38:29 +0200 | [diff] [blame^] | 9 | if ($ENV{SKIP_REAL}) { |
| 10 | plan skip_all => 'Skip real tests'; |
| 11 | }; |
| 12 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 13 | use Benchmark qw/:hireswallclock/; |
| 14 | |
| 15 | my $t = Benchmark->new; |
| 16 | |
| 17 | # Initialize log4perl object |
| 18 | #Log::Log4perl->init({ |
| 19 | # 'log4perl.rootLogger' => 'TRACE, STDERR', |
| 20 | # 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels', |
| 21 | # 'log4perl.appender.STDERR.layout' => 'PatternLayout', |
| 22 | # 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n' |
| 23 | #}); |
| 24 | |
| 25 | |
| 26 | use File::Basename 'dirname'; |
| 27 | use File::Spec::Functions 'catdir'; |
| 28 | |
| 29 | use_ok('KorAP::XML::Krill'); |
| 30 | |
| 31 | my $path = catdir(dirname(__FILE__), '..', 'corpus', 'AGD-scrambled', 'DOC', '00001'); |
| 32 | |
| 33 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 34 | ok($doc->parse, 'Parse document'); |
| 35 | |
| 36 | is($doc->text_sigle, 'AGD/DOC/00001', 'Correct text sigle'); |
| 37 | is($doc->doc_sigle, 'AGD/DOC', 'Correct document sigle'); |
| 38 | is($doc->corpus_sigle, 'AGD', 'Correct corpus sigle'); |
| 39 | |
| 40 | my $meta = $doc->meta; |
| 41 | is($meta->{T_title}, 'FOLK_E_00321_SE_01_T_01_DF_01', 'Title'); |
| 42 | is($meta->{D_creation_date}, '20181112', 'Title'); |
| 43 | |
Akron | 2029455 | 2019-11-29 16:15:35 +0100 | [diff] [blame] | 44 | is($meta->{A_externalLink}, 'data:application/x.korap-link;title=DGD,'. |
| 45 | 'https://dgd.ids-mannheim.de/DGD2Web/ExternalAccessServlet?command=displayData'. |
| 46 | '&id=FOLK_E_00321_SE_01_T_01', 'External link'); |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 47 | |
| 48 | # Tokenization |
| 49 | use_ok('KorAP::XML::Tokenizer'); |
| 50 | |
| 51 | my ($token_base_foundry, $token_base_layer) = (qw/DGD Annot/); |
| 52 | |
| 53 | # Get tokenization |
| 54 | my $tokens = KorAP::XML::Tokenizer->new( |
| 55 | path => $doc->path, |
| 56 | doc => $doc, |
| 57 | foundry => $token_base_foundry, |
| 58 | layer => $token_base_layer, |
| 59 | name => 'tokens', |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 60 | non_verbal_tokens => 1 |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 61 | ); |
| 62 | |
| 63 | ok($tokens, 'Token Object is fine'); |
| 64 | ok($tokens->parse, 'Token parsing is fine'); |
| 65 | |
| 66 | my $output = decode_json( $tokens->to_json ); |
| 67 | |
| 68 | is(substr($output->{data}->{text}, 0, 100), |
| 69 | '+++++++++ ku sqn alxv a pwm ▮ xnj nq qtl ohmdgjqp ▮ ▮ ▮ ▮ ▮ fi ▮ sna ▮ alxv hn ▮ zjc ahyx ftwbramn l', |
| 70 | 'Primary Data'); |
| 71 | |
| 72 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 73 | is($output->{data}->{tokenSource}, 'dgd#annot', 'tokenSource'); |
| 74 | |
| 75 | is($output->{version}, '0.03', 'version'); |
| 76 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 77 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 78 | is($output->{data}->{stream}->[0]->[4], 's:ku', 'data'); |
| 79 | is($output->{data}->{stream}->[1]->[2], 's:sqn', 'data'); |
| 80 | is($output->{data}->{stream}->[2]->[2], 's:alxv', 'data'); |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 81 | is($output->{textSigle}, 'AGD/DOC/00001', 'Correct text sigle'); |
| 82 | is($output->{docSigle}, 'AGD/DOC', 'Correct document sigle'); |
| 83 | is($output->{corpusSigle}, 'AGD', 'Correct corpus sigle'); |
| 84 | |
| 85 | is($output->{title}, 'FOLK_E_00321_SE_01_T_01_DF_01', 'Title'); |
| 86 | |
| 87 | ## DeReKo |
| 88 | $tokens->add('DeReKo', 'Structure'); |
| 89 | |
| 90 | $output = decode_json( $tokens->to_json ); |
| 91 | |
| 92 | is($output->{data}->{foundries}, |
| 93 | 'dereko dereko/structure', |
| 94 | 'Foundries'); |
| 95 | is($output->{data}->{layerInfos}, 'dereko/s=spans', 'layerInfos'); |
| 96 | |
| 97 | my $first_token = join('||', @{$output->{data}->{stream}->[0]}); |
| 98 | like($first_token, qr!<>:dereko/s:text!); |
| 99 | |
| 100 | ## DGD |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 101 | ok($tokens->add('DGD', 'Morpho'), 'Add Morpho'); |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 102 | |
| 103 | $output = decode_json( $tokens->to_json ); |
| 104 | is($output->{data}->{foundries}, |
| 105 | 'dereko dereko/structure dgd dgd/morpho', |
| 106 | 'Foundries'); |
| 107 | is($output->{data}->{layerInfos}, 'dereko/s=spans dgd/l=tokens dgd/p=tokens dgd/para=tokens', |
| 108 | 'layerInfos'); |
| 109 | |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 110 | my $third_token = join('||', @{$output->{data}->{stream}->[2]}); |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 111 | like($third_token, qr!dgd/l:alui!); |
| 112 | like($third_token, qr!dgd/p:VMGWY!); |
| 113 | like($third_token, qr!i:alxv!); |
| 114 | like($third_token, qr!s:alxv!); |
| 115 | |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 116 | ## DGD base sentences |
| 117 | ok($tokens->add('DGD', 'Structure'), 'Add sentences'); |
| 118 | $output = decode_json( $tokens->to_json ); |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 119 | |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 120 | # Offsets are suboptimal set, but good enough |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 121 | |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 122 | $first_token = join('||', @{$output->{data}->{stream}->[0]}); |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 123 | like($first_token, qr!<>:base/s:s\$<b>64<i>0<i>16<i>2<b>1!); |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 124 | |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 125 | my $token = join('||', @{$output->{data}->{stream}->[2]}); |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 126 | like($token, qr!<>:base/s:s\$<b>64<i>16<i>23<i>4<b>1!); |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 127 | $token = join('||', @{$output->{data}->{stream}->[3]}); |
Akron | c29b8e1 | 2019-12-16 14:28:09 +0100 | [diff] [blame] | 128 | unlike($token, qr!<>:base/s:s!); |
| 129 | |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 130 | $token = join('||', @{$output->{data}->{stream}->[4]}); |
Akron | f1849aa | 2019-12-16 23:35:33 +0100 | [diff] [blame] | 131 | like($token, qr!<>:base/s:s\$<b>64<i>23<i>27<i>5<b>1!); |
| 132 | |
| 133 | $token = join('||', @{$output->{data}->{stream}->[5]}); |
| 134 | like($token, qr!dgd/para:pause!); |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 135 | |
Akron | 1cdbc9d | 2020-05-07 15:28:54 +0200 | [diff] [blame] | 136 | |
| 137 | # New revision |
| 138 | $path = catdir(dirname(__FILE__), '..', 'corpus', 'FOLK-scrambled', '00068-SE-01', 'T-05'); |
| 139 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 140 | ok($doc->parse, 'Parse document'); |
| 141 | |
| 142 | is($doc->text_sigle, 'FOLK/00068-SE-01/T-05', 'Correct text sigle'); |
| 143 | is($doc->doc_sigle, 'FOLK/00068-SE-01', 'Correct document sigle'); |
| 144 | is($doc->corpus_sigle, 'FOLK', 'Correct corpus sigle'); |
| 145 | |
| 146 | $meta = $doc->meta; |
| 147 | is($meta->{T_title}, 'FOLK_E_00068_SE_01_T_05_DF_01', 'Title'); |
| 148 | |
| 149 | is($meta->{A_externalLink}, 'data:application/x.korap-link;title=DGD,https://dgd.ids-mannheim.de/DGD2Web/ExternalAccessServlet?command=displayData&id=FOLK_E_00068_SE_01_T_05'); |
| 150 | |
| 151 | # Tokenization |
| 152 | use_ok('KorAP::XML::Tokenizer'); |
| 153 | |
| 154 | ($token_base_foundry, $token_base_layer) = (qw/DGD Annot/); |
| 155 | |
| 156 | # Get tokenization |
| 157 | $tokens = KorAP::XML::Tokenizer->new( |
| 158 | path => $doc->path, |
| 159 | doc => $doc, |
| 160 | foundry => $token_base_foundry, |
| 161 | layer => $token_base_layer, |
| 162 | name => 'tokens', |
| 163 | non_verbal_tokens => 1 |
| 164 | ); |
| 165 | |
| 166 | ok($tokens, 'Token Object is fine'); |
| 167 | ok($tokens->parse, 'Token parsing is fine'); |
| 168 | |
| 169 | ## DeReKo |
| 170 | # $tokens->add('DeReKo', 'Structure'); |
| 171 | |
| 172 | ## DGD |
| 173 | ok($tokens->add('DGD', 'Morpho'), 'Add Morpho'); |
| 174 | |
| 175 | $output = decode_json( $tokens->to_json ); |
| 176 | |
| 177 | is(substr($output->{data}->{text}, 11, 30), |
| 178 | 'ogeuy Nva wvho zhl usblyuug Kt', |
| 179 | 'Primary Data'); |
| 180 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 181 | is($output->{data}->{tokenSource}, 'dgd#annot', 'tokenSource'); |
| 182 | |
| 183 | is($output->{data}->{stream}->[0]->[1], |
| 184 | '<>:base/s:t$<b>64<i>0<i>39384<i>7190<b>0', |
| 185 | 'data' |
| 186 | ); |
| 187 | |
| 188 | is($output->{data}->{stream}->[0]->[2], |
| 189 | '@:dgd/para:type:micro$<b>16<s>1', |
| 190 | 'data' |
| 191 | ); |
| 192 | |
| 193 | is($output->{data}->{stream}->[0]->[3], |
| 194 | '@:dgd/para:rend:(.)$<b>16<s>1', |
| 195 | 'data' |
| 196 | ); |
| 197 | |
| 198 | is($output->{data}->{stream}->[0]->[5], |
| 199 | 'dgd/para:pause$<b>128<s>1', |
| 200 | 'data' |
| 201 | ); |
| 202 | |
| 203 | is($output->{data}->{stream}->[1]->[0], |
| 204 | '@:dgd/para:desc:short breathe in$<b>16<s>1', |
| 205 | 'data' |
| 206 | ); |
| 207 | |
| 208 | is($output->{data}->{stream}->[1]->[1], |
| 209 | "\@:dgd/para:rend:\x{b0}h\$<b>16<s>1", |
| 210 | 'data' |
| 211 | ); |
| 212 | |
| 213 | is($output->{data}->{stream}->[1]->[3], |
| 214 | 'dgd/para:vocal$<b>128<s>1', |
| 215 | 'data' |
| 216 | ); |
| 217 | |
| 218 | is($output->{data}->{stream}->[97]->[1], |
| 219 | 'dgd/l:ui', |
| 220 | 'data' |
| 221 | ); |
| 222 | |
| 223 | is($output->{data}->{stream}->[97]->[2], |
| 224 | 'dgd/p:AUUK', |
| 225 | 'data' |
| 226 | ); |
| 227 | |
| 228 | is($output->{data}->{stream}->[97]->[3], |
| 229 | 'dgd/trans:rh', |
| 230 | 'data' |
| 231 | ); |
| 232 | |
| 233 | is($output->{data}->{stream}->[97]->[4], |
| 234 | 'dgd/type:assimilated', |
| 235 | 'data' |
| 236 | ); |
| 237 | |
| 238 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 239 | done_testing; |
| 240 | __END__ |