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,'. |
| 35 | 'https://dgd.ids-mannheim.de/DGD2Web/ExternalAccessServlet?command=displayData'. |
| 36 | '&id=FOLK_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 | |
| 139 | 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'); |
| 140 | |
| 141 | # Tokenization |
| 142 | use_ok('KorAP::XML::Tokenizer'); |
| 143 | |
| 144 | ($token_base_foundry, $token_base_layer) = (qw/DGD Annot/); |
| 145 | |
| 146 | # Get tokenization |
| 147 | $tokens = KorAP::XML::Tokenizer->new( |
| 148 | path => $doc->path, |
| 149 | doc => $doc, |
| 150 | foundry => $token_base_foundry, |
| 151 | layer => $token_base_layer, |
| 152 | name => 'tokens', |
| 153 | non_verbal_tokens => 1 |
| 154 | ); |
| 155 | |
| 156 | ok($tokens, 'Token Object is fine'); |
| 157 | ok($tokens->parse, 'Token parsing is fine'); |
| 158 | |
| 159 | ## DeReKo |
| 160 | # $tokens->add('DeReKo', 'Structure'); |
| 161 | |
| 162 | ## DGD |
| 163 | ok($tokens->add('DGD', 'Morpho'), 'Add Morpho'); |
| 164 | |
| 165 | $output = decode_json( $tokens->to_json ); |
| 166 | |
| 167 | is(substr($output->{data}->{text}, 11, 30), |
| 168 | 'ogeuy Nva wvho zhl usblyuug Kt', |
| 169 | 'Primary Data'); |
| 170 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 171 | is($output->{data}->{tokenSource}, 'dgd#annot', 'tokenSource'); |
| 172 | |
| 173 | is($output->{data}->{stream}->[0]->[1], |
| 174 | '<>:base/s:t$<b>64<i>0<i>39384<i>7190<b>0', |
| 175 | 'data' |
| 176 | ); |
| 177 | |
| 178 | is($output->{data}->{stream}->[0]->[2], |
| 179 | '@:dgd/para:type:micro$<b>16<s>1', |
| 180 | 'data' |
| 181 | ); |
| 182 | |
| 183 | is($output->{data}->{stream}->[0]->[3], |
| 184 | '@:dgd/para:rend:(.)$<b>16<s>1', |
| 185 | 'data' |
| 186 | ); |
| 187 | |
| 188 | is($output->{data}->{stream}->[0]->[5], |
| 189 | 'dgd/para:pause$<b>128<s>1', |
| 190 | 'data' |
| 191 | ); |
| 192 | |
| 193 | is($output->{data}->{stream}->[1]->[0], |
| 194 | '@:dgd/para:desc:short breathe in$<b>16<s>1', |
| 195 | 'data' |
| 196 | ); |
| 197 | |
| 198 | is($output->{data}->{stream}->[1]->[1], |
| 199 | "\@:dgd/para:rend:\x{b0}h\$<b>16<s>1", |
| 200 | 'data' |
| 201 | ); |
| 202 | |
| 203 | is($output->{data}->{stream}->[1]->[3], |
| 204 | 'dgd/para:vocal$<b>128<s>1', |
| 205 | 'data' |
| 206 | ); |
| 207 | |
| 208 | is($output->{data}->{stream}->[97]->[1], |
| 209 | 'dgd/l:ui', |
| 210 | 'data' |
| 211 | ); |
| 212 | |
| 213 | is($output->{data}->{stream}->[97]->[2], |
| 214 | 'dgd/p:AUUK', |
| 215 | 'data' |
| 216 | ); |
| 217 | |
| 218 | is($output->{data}->{stream}->[97]->[3], |
| 219 | 'dgd/trans:rh', |
| 220 | 'data' |
| 221 | ); |
| 222 | |
| 223 | is($output->{data}->{stream}->[97]->[4], |
| 224 | 'dgd/type:assimilated', |
| 225 | 'data' |
| 226 | ); |
| 227 | |
| 228 | |
Akron | 57510c1 | 2019-01-04 14:58:53 +0100 | [diff] [blame] | 229 | done_testing; |
| 230 | __END__ |