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