| Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use File::Basename 'dirname'; |
| 4 | use File::Spec::Functions qw/catfile/; |
| Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 5 | use Encode qw!encode_utf8 decode_utf8 encode!; |
| Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 6 | |
| 7 | use Test::More; |
| 8 | use Test::Output; |
| Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 9 | |
| 10 | use FindBin; |
| 11 | BEGIN { |
| 12 | unshift @INC, "$FindBin::Bin/../lib"; |
| 13 | }; |
| Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 14 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 15 | use Test::KorAP::XML::TEI qw!korap_tempfile i5_template test_tei2korapxml!; |
| Peter Harders | 57c884e | 2020-07-16 01:28:52 +0200 | [diff] [blame] | 16 | |
| Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 17 | my $f = dirname(__FILE__); |
| 18 | my $script = catfile($f, '..', 'script', 'tei2korapxml'); |
| 19 | ok(-f $script, 'Script found'); |
| 20 | |
| Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 21 | stdout_like( |
| Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 22 | sub { system('perl', $script, '--help') }, |
| Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 23 | qr!This\s*program\s*is\s*usually\s*called\s*from\s*inside\s*another\s*script\.!, |
| Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 24 | 'Help' |
| 25 | ); |
| 26 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 27 | |
| Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 28 | stdout_like( |
| 29 | sub { system('perl', $script, '--version') }, |
| 30 | qr!tei2korapxml - v\d+?\.\d+?!, |
| 31 | 'Version' |
| 32 | ); |
| 33 | |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 34 | # Load example file |
| 35 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| Peter Harders | 57c884e | 2020-07-16 01:28:52 +0200 | [diff] [blame] | 36 | |
| Akron | b364947 | 2020-09-29 08:24:46 +0200 | [diff] [blame] | 37 | subtest 'Debugging' => sub { |
| 38 | |
| 39 | my $t = test_tei2korapxml( |
| 40 | tmp => 'script_out', |
| 41 | file => $file, |
| 42 | param => '-ti', |
| 43 | env => 'KORAPXMLTEI_DEBUG=1' |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 44 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| Akron | b364947 | 2020-09-29 08:24:46 +0200 | [diff] [blame] | 45 | ->stderr_like(qr!Debugging is activated!); |
| 46 | }; |
| 47 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 48 | subtest 'Basic processing' => sub { |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 49 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 50 | my $t = test_tei2korapxml( |
| 51 | tmp => 'script_out', |
| 52 | file => $file, |
| 53 | param => '-ti' |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 54 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| Akron | b364947 | 2020-09-29 08:24:46 +0200 | [diff] [blame] | 55 | ->stderr_unlike(qr!Debugging is activated!); |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 56 | |
| Akron | 6896608 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 57 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 58 | # Uncompress GOE/header.xml from zip file |
| 59 | $t->unzip_xml('GOE/header.xml') |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 60 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 61 | # TODO: check wrong encoding in header-files (compare with input document)! |
| 62 | ->text_is('korpusSigle', 'GOE', 'korpusSigle') |
| 63 | ->text_is('h\.title[type=main]', 'Goethes Werke', 'h.title') |
| 64 | ->text_is('h\.author', 'Goethe, Johann Wolfgang von', 'h.author') |
| 65 | ->text_is('pubDate[type=year]', '1982', 'pubDate'); |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 66 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 67 | # Uncompress GOE/AGA/header.xml from zip file |
| 68 | $t->unzip_xml('GOE/AGA/header.xml') |
| 69 | ->text_is('dokumentSigle', 'GOE/AGA', 'dokumentSigle') |
| 70 | ->text_is('d\.title', 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)', 'd.title') |
| 71 | ->text_is('creatDate', '1820-1822', 'creatDate'); |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 72 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 73 | # Uncompress GOE/AGA/00000/header.xml from zip file |
| 74 | $t->unzip_xml('GOE/AGA/00000/header.xml') |
| 75 | ->text_is('textSigle', 'GOE/AGA.00000', 'textSigle') |
| 76 | ->text_is('analytic > h\.title[type=main]', 'Campagne in Frankreich', 'h.title'); |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 77 | |
| 78 | # Uncompress GOE/AGA/00000/data.xml from zip file |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 79 | $t->unzip_xml('GOE/AGA/00000/data.xml') |
| 80 | ->attr_is('raw_text', 'docid', 'GOE_AGA.00000', 'text id') |
| Marc Kupietz | fd0e6a9 | 2020-09-09 18:07:29 +0200 | [diff] [blame] | 81 | ->text_like('raw_text > text', qr!^Campagne in Frankreich 1792.*?uns allein begl.*cke\.$!, 'text content') |
| 82 | ->text_like('raw_text > text', qr!unter dem Titel "Kriegstheater"!, 'text content'); |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 83 | |
| Akron | 417ed2f | 2020-09-28 12:43:17 +0200 | [diff] [blame] | 84 | my $content = $t->get_content_of('GOE/AGA/00000/data.xml'); |
| 85 | like($content, qr!unter dem Titel "Kriegstheater"!, 'raw text content'); |
| 86 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 87 | $t->unzip_xml('GOE/AGA/00000/struct/structure.xml') |
| Akron | c57625b | 2020-07-30 11:46:06 +0200 | [diff] [blame] | 88 | ->text_is('span[id=s3] *[name=type]', 'Autobiographie', 'text content') |
| 89 | ->text_is('#s3 *[name=type]', 'Autobiographie', 'text content') |
| 90 | ->attr_is('#s0','to','1266') |
| 91 | ->attr_is('#s0','l','1') |
| 92 | |
| 93 | ->attr_is('#s18','from','925') |
| 94 | ->attr_is('#s18','to','1266') |
| 95 | ->attr_is('#s18','l','5') |
| 96 | ->attr_is('#s18 > fs','type', 'struct') |
| 97 | ->attr_is('#s18 > fs > f','name','name') |
| 98 | ->text_is('#s18 > fs > f','poem') |
| 99 | |
| 100 | ->attr_is('#s19','from','925') |
| 101 | ->attr_is('#s19','to','1098') |
| 102 | ->attr_is('#s19','l','6') |
| 103 | ->attr_is('#s19 > fs','type','struct') |
| 104 | ->text_is('#s19 > fs > f[name=name]','lg') |
| 105 | ->text_is('#s19 > fs > f[name=attr] > fs[type=attr] >f[name=part]','u') |
| 106 | |
| 107 | ->attr_is('#s37','from','1229') |
| 108 | ->attr_is('#s37','to','1266') |
| 109 | ->attr_is('#s37','l','8') |
| 110 | ->attr_is('#s37 > fs','type','struct') |
| 111 | ->text_is('#s37 > fs > f[name=name]','s') |
| 112 | ->text_is('#s37 > fs > f[name=attr] > fs[type=attr] > f[name=type]','manual') |
| 113 | |
| 114 | ->attr_is('#s38','from','1266') |
| 115 | ->attr_is('#s38','to','1266') |
| 116 | ->attr_is('#s38','l','2') |
| 117 | ->attr_is('#s38 > fs','type','struct') |
| 118 | ->text_is('#s38 > fs > f[name=name]','back') |
| Akron | f7084c4 | 2021-01-07 10:25:22 +0100 | [diff] [blame] | 119 | ->element_count_is('*', 196); |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 120 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 121 | $t->file_exists_not('GOE/AGA/00000/base/tokens.xml', 'External not generated'); |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 122 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 123 | # Uncompress GOE/AGA/00000/base/tokens_aggressive.xml from zip file |
| 124 | $t->unzip_xml('GOE/AGA/00000/base/tokens_aggressive.xml') |
| 125 | ->attr_is('spanList span:nth-child(1)', 'to', 8) |
| 126 | ->attr_is('spanList span#t_1', 'from', 9) |
| 127 | ->attr_is('spanList span#t_1', 'to', 11) |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 128 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 129 | ->attr_is('spanList span#t_67', 'from', 427) |
| 130 | ->attr_is('spanList span#t_67', 'to', 430) |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 131 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 132 | ->attr_is('spanList span#t_214', 'from', 1209) |
| 133 | ->attr_is('spanList span#t_214', 'to', 1212) |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 134 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 135 | ->element_count_is('spanList span', 227); |
| Peter Harders | 57c884e | 2020-07-16 01:28:52 +0200 | [diff] [blame] | 136 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 137 | # Uncompress GOE/AGA/00000/base/tokens_conservative.xml from zip file |
| 138 | $t->unzip_xml('GOE/AGA/00000/base/tokens_conservative.xml') |
| 139 | ->attr_is('spanList span:nth-child(1)', 'to', 8) |
| Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 140 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 141 | ->attr_is('spanList span#t_1', 'from', 9) |
| 142 | ->attr_is('spanList span#t_1', 'to', 11) |
| Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 143 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 144 | ->attr_is('spanList span#t_67', 'from', 427) |
| 145 | ->attr_is('spanList span#t_67', 'to', 430) |
| Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 146 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 147 | ->attr_is('spanList span#t_214', 'from', 1209) |
| 148 | ->attr_is('spanList span#t_214', 'to', 1212) |
| Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 149 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 150 | ->element_count_is('spanList span', 227); |
| 151 | }; |
| Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 152 | |
| Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 153 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 154 | subtest 'Tokenize with external tokenizer' => sub { |
| Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 155 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 156 | my $cmd = catfile($f, 'cmd', 'tokenizer.pl'); |
| Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 157 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 158 | test_tei2korapxml( |
| 159 | file => $file, |
| 160 | param => "-tc='perl $cmd'", |
| 161 | tmp => 'script_out2' |
| 162 | ) |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 163 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 164 | ->file_readable('GOE/AGA/00000/base/tokens.xml') |
| Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 165 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 166 | # Uncompress GOE/AGA/00000/base/tokens.xml from zip file |
| 167 | ->unzip_xml('GOE/AGA/00000/base/tokens.xml') |
| 168 | ->attr_is('spanList span:nth-child(1)', 'to', 8) |
| 169 | ->attr_is('spanList span#t_1', 'from', 9) |
| 170 | ->attr_is('spanList span#t_1', 'to', 11) |
| 171 | ->attr_is('spanList span#t_67', 'from', 427) |
| 172 | ->attr_is('spanList span#t_67', 'to', 430) |
| 173 | ->attr_is('spanList span#t_214', 'from', 1209) |
| 174 | ->attr_is('spanList span#t_214', 'to', 1212) |
| 175 | ->element_count_is('spanList span', 227); |
| 176 | }; |
| Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 177 | |
| Akron | 91705d7 | 2021-02-19 10:59:45 +0100 | [diff] [blame] | 178 | subtest 'Tokenize with external tokenizer and defined folder' => sub { |
| 179 | |
| 180 | my $cmd = catfile($f, 'cmd', 'tokenizer.pl'); |
| 181 | |
| 182 | test_tei2korapxml( |
| 183 | file => $file, |
| 184 | param => "-tc='perl $cmd' --tokens-file=yadda", |
| 185 | tmp => 'script_out2' |
| 186 | ) |
| 187 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| 188 | ->file_exists_not('GOE/AGA/00000/base/tokens.xml') |
| 189 | ->file_readable('GOE/AGA/00000/base/yadda.xml') |
| 190 | ->unzip_xml('GOE/AGA/00000/base/yadda.xml') |
| 191 | ->attr_is('spanList span:nth-child(1)', 'to', 8) |
| 192 | ->attr_is('spanList span#t_1', 'from', 9) |
| 193 | ->attr_is('spanList span#t_1', 'to', 11) |
| 194 | ->attr_is('spanList span#t_67', 'from', 427) |
| 195 | ->attr_is('spanList span#t_67', 'to', 430) |
| 196 | ->attr_is('spanList span#t_214', 'from', 1209) |
| 197 | ->attr_is('spanList span#t_214', 'to', 1212) |
| 198 | ->element_count_is('spanList span', 227); |
| 199 | }; |
| 200 | |
| Marc Kupietz | 8ab6832 | 2026-03-18 18:04:14 +0100 | [diff] [blame^] | 201 | subtest 'Skip text after repeated external tokenizer crash' => sub { |
| 202 | |
| 203 | my $cmd = catfile($f, 'cmd', 'tokenizer_faulty.pl'); |
| 204 | my ($fh, $testfile) = korap_tempfile('script_exttok_skip'); |
| 205 | |
| 206 | print {$fh} <<'XML'; |
| 207 | <?xml version="1.0" encoding="UTF-8"?> |
| 208 | <idsCorpus> |
| 209 | <idsHeader type="corpus"> |
| 210 | <fileDesc> |
| 211 | <titleStmt> |
| 212 | <korpusSigle>CORP</korpusSigle> |
| 213 | </titleStmt> |
| 214 | </fileDesc> |
| 215 | </idsHeader> |
| 216 | <idsDoc version="1.0"> |
| 217 | <idsHeader type="document"> |
| 218 | <fileDesc> |
| 219 | <titleStmt> |
| 220 | <dokumentSigle>CORP/DOC</dokumentSigle> |
| 221 | </titleStmt> |
| 222 | </fileDesc> |
| 223 | </idsHeader> |
| 224 | <idsText version="1.0"> |
| 225 | <idsHeader type="text"> |
| 226 | <fileDesc> |
| 227 | <titleStmt> |
| 228 | <textSigle>CORP/DOC.00001</textSigle> |
| 229 | </titleStmt> |
| 230 | </fileDesc> |
| 231 | </idsHeader> |
| 232 | <text> |
| 233 | stable text |
| 234 | </text> |
| 235 | </idsText> |
| 236 | <idsText version="1.0"> |
| 237 | <idsHeader type="text"> |
| 238 | <fileDesc> |
| 239 | <titleStmt> |
| 240 | <textSigle>CORP/DOC.00002</textSigle> |
| 241 | </titleStmt> |
| 242 | </fileDesc> |
| 243 | </idsHeader> |
| 244 | <text> |
| 245 | __ALWAYS_CRASH__ text |
| 246 | </text> |
| 247 | </idsText> |
| 248 | </idsDoc> |
| 249 | </idsCorpus> |
| 250 | XML |
| 251 | close($fh); |
| 252 | |
| 253 | test_tei2korapxml( |
| 254 | file => $testfile, |
| 255 | param => "-tc='perl $cmd'", |
| 256 | tmp => 'script_exttok_skip' |
| 257 | ) |
| 258 | ->stderr_like(qr!tei2korapxml:.*? text_id=CORP_DOC\.00001!) |
| 259 | ->stderr_like(qr!tei2korapxml:.*? text_id=CORP_DOC\.00002!) |
| 260 | ->stderr_like(qr!External tokenizer failed for 'CORP_DOC\.00002' on attempt 1/2!) |
| 261 | ->stderr_like(qr!Skipping tokenization for 'CORP_DOC\.00002' after 2/2 attempts!) |
| 262 | ->file_readable('CORP/DOC/00001/base/tokens.xml') |
| 263 | ->file_exists_not('CORP/DOC/00002/base/tokens.xml') |
| 264 | ->file_readable('CORP/DOC/00002/data.xml'); |
| 265 | }; |
| 266 | |
| Marc Kupietz | eed4cb1 | 2021-02-17 19:39:32 +0100 | [diff] [blame] | 267 | subtest 'Check KorAP tokenizer for infinite loop bug' => sub { |
| 268 | |
| 269 | my $file = catfile($f, 'data', 'korap_tokenizer_challenge.xml'); |
| 270 | |
| 271 | eval { |
| 272 | require KorAP::XML::TEI::Tokenizer::KorAP; |
| 273 | 1; |
| 274 | } or do { |
| 275 | plan skip_all => "KorAP::XML::TEI::Tokenizer::KorAP cannot be used"; |
| 276 | }; |
| 277 | |
| 278 | test_tei2korapxml( |
| 279 | file => $file, |
| 280 | param => "-tk -s", |
| 281 | tmp => 'script_bug_check' |
| 282 | ) |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 283 | ->stderr_like(qr!tei2korapxml:.*? text_id=WDD19_H0039\.87242!) |
| Marc Kupietz | eed4cb1 | 2021-02-17 19:39:32 +0100 | [diff] [blame] | 284 | ->file_readable('WDD19/H0039/87242/struct/structure.xml'); |
| 285 | }; |
| 286 | |
| Marc Kupietz | 985da0c | 2021-02-15 19:29:50 +0100 | [diff] [blame] | 287 | subtest 'Sentence split with KorAP tokenizer' => sub { |
| 288 | |
| 289 | eval { |
| 290 | require KorAP::XML::TEI::Tokenizer::KorAP; |
| 291 | 1; |
| 292 | } or do { |
| 293 | plan skip_all => "KorAP::XML::TEI::Tokenizer::KorAP cannot be used"; |
| 294 | }; |
| 295 | |
| 296 | test_tei2korapxml( |
| 297 | file => $file, |
| 298 | param => "-tk -s", |
| 299 | tmp => 'script_sentence_split' |
| 300 | ) |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 301 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| Marc Kupietz | 985da0c | 2021-02-15 19:29:50 +0100 | [diff] [blame] | 302 | ->file_readable('GOE/AGA/00000/struct/structure.xml') |
| 303 | ->unzip_xml('GOE/AGA/00000/struct/structure.xml') |
| 304 | ->text_is('span#s25 fs f', 's') |
| 305 | ->attr_is('span#s25', 'l', -1) |
| 306 | ->attr_is('span#s25', 'to', 54) |
| 307 | ->text_is('span#s30 fs f', 's') |
| 308 | ->attr_is('span#s30', 'l', -1) |
| 309 | ->attr_is('span#s30', 'from', 1099) |
| 310 | ->attr_is('span#s30', 'to', 1266); |
| 311 | }; |
| Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 312 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 313 | subtest 'Test Tokenizations' => sub { |
| Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 314 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 315 | my $t = test_tei2korapxml( |
| 316 | file => catfile($f, 'data', 'text_with_blanks.i5.xml'), |
| 317 | tmp => 'script_out3', |
| 318 | param => '-ti' |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 319 | )->stderr_like(qr!tei2korapxml:.*? text_id=CORP_DOC.00001!); |
| Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 320 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 321 | # ~ test conservative tokenization ~ |
| 322 | $t->unzip_xml('CORP/DOC/00001/base/tokens_conservative.xml') |
| 323 | ->attr_is('spanList span:nth-child(1)', 'to', 6) |
| Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 324 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 325 | ->attr_is('spanList span#t_1', 'from', 7) |
| 326 | ->attr_is('spanList span#t_1', 'to', 9) |
| Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 327 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 328 | ->attr_is('spanList span#t_3', 'from', 12) |
| 329 | ->attr_is('spanList span#t_3', 'to', 16) |
| Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 330 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 331 | ->attr_is('spanList span#t_9', 'from', 36) |
| 332 | ->attr_is('spanList span#t_9', 'to', 37) |
| Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 333 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 334 | ->attr_is('spanList span#t_13', 'from', 44) |
| 335 | ->attr_is('spanList span#t_13', 'to', 45) # " |
| Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 336 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 337 | ->attr_is('spanList span#t_14', 'from', 45) # twenty-two |
| 338 | ->attr_is('spanList span#t_14', 'to', 55) |
| Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 339 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 340 | ->attr_is('spanList span#t_15', 'from', 55) # " |
| 341 | ->attr_is('spanList span#t_15', 'to', 56) |
| Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 342 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 343 | ->attr_is('spanList span#t_19', 'from', 66) |
| 344 | ->attr_is('spanList span#t_19', 'to', 67) |
| Peter Harders | b122717 | 2020-07-21 02:12:10 +0200 | [diff] [blame] | 345 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 346 | ->element_count_is('spanList span', 20); |
| Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 347 | |
| Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 348 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 349 | # ~ test aggressive tokenization ~ |
| 350 | $t->unzip_xml('CORP/DOC/00001/base/tokens_aggressive.xml') |
| 351 | ->attr_is('spanList span:nth-child(1)', 'to', 6) |
| Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 352 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 353 | ->attr_is('spanList span#t_1', 'from', 7) |
| 354 | ->attr_is('spanList span#t_1', 'to', 9) |
| Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 355 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 356 | ->attr_is('spanList span#t_3', 'from', 12) |
| 357 | ->attr_is('spanList span#t_3', 'to', 16) |
| Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 358 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 359 | ->attr_is('spanList span#t_9', 'from', 36) |
| 360 | ->attr_is('spanList span#t_9', 'to', 37) |
| Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 361 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 362 | ->attr_is('spanList span#t_13', 'from', 44) |
| 363 | ->attr_is('spanList span#t_13', 'to', 45) # " |
| Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 364 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 365 | ->attr_is('spanList span#t_14', 'from', 45) # twenty |
| 366 | ->attr_is('spanList span#t_14', 'to', 51) |
| Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 367 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 368 | ->attr_is('spanList span#t_15', 'from', 51) # - |
| 369 | ->attr_is('spanList span#t_15', 'to', 52) |
| Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 370 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 371 | ->attr_is('spanList span#t_16', 'from', 52) # two |
| 372 | ->attr_is('spanList span#t_16', 'to', 55) |
| Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 373 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 374 | ->attr_is('spanList span#t_17', 'from', 55) # " |
| 375 | ->attr_is('spanList span#t_17', 'to', 56) |
| Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 376 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 377 | ->attr_is('spanList span#t_21', 'from', 66) |
| 378 | ->attr_is('spanList span#t_21', 'to', 67) |
| Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 379 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 380 | ->element_count_is('spanList span', 22); |
| 381 | }; |
| Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 382 | |
| 383 | |
| Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 384 | subtest 'Check Tokenization Flags' => sub { |
| 385 | |
| 386 | # Get external tokenizer |
| 387 | my $f = dirname(__FILE__); |
| 388 | my $cmd = catfile($f, 'cmd', 'tokenizer.pl'); |
| 389 | |
| 390 | # Load example file |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 391 | test_tei2korapxml( |
| 392 | file => catfile($f, 'data', 'goe_sample.i5.xml'), |
| 393 | param => "-ti -tc 'perl $cmd'", |
| 394 | tmp => 'script_tokflags' |
| 395 | ) |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 396 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 397 | ->file_exists('GOE/AGA/00000/base/tokens_aggressive.xml') |
| 398 | ->file_exists('GOE/AGA/00000/base/tokens_conservative.xml') |
| 399 | ->file_exists('GOE/AGA/00000/base/tokens.xml') |
| 400 | ; |
| Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 401 | }; |
| 402 | |
| Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 403 | |
| 404 | subtest 'Test utf-8 handling' => sub { |
| Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 405 | # Introduce invalid utf-8 characters |
| 406 | my $text_sigle; |
| Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 407 | { |
| 408 | no warnings; |
| 409 | # $text_sigle printed to file, without encoding: Aþ¿¿¿¿¿A_Bþ¿¿¿¿¿B.Cþ¿¿¿¿¿C |
| 410 | # the utf8-sequence 'þ¿¿¿¿¿' encodes 32 bit of data (see 0x7FFF_FFFF in perlunicode) |
| 411 | $text_sigle = "A\x{FFFF_FFFF}A_B\x{FFFF_FFFF}B.C\x{FFFF_FFFF}C" |
| 412 | } |
| 413 | # If CHECK is 0, encoding and decoding replace any malformed character |
| 414 | # with a substitution character. |
| Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 415 | # � = substitution character |
| 416 | my $text_sigle_lax = encode_utf8($text_sigle); |
| 417 | my $text_sigle_esc = encode('UTF-8', $text_sigle); |
| 418 | |
| 419 | is(length($text_sigle), 11); # A�A_B�B.C�C (char string => length(�) = 1) |
| 420 | is(length($text_sigle_lax), 29); # Aþ¿¿¿¿¿A_Bþ¿¿¿¿¿B.Cþ¿¿¿¿¿C (byte string) |
| 421 | is(length($text_sigle_esc), 17); # A�A_B�B.C�C (byte string => length(�) = 3) |
| 422 | |
| Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 423 | |
| 424 | my $tpl; |
| 425 | { |
| 426 | no warnings; |
| 427 | $tpl = i5_template( |
| 428 | korpusSigle => "A\x{FFFF_FFFF}A", |
| 429 | dokumentSigle => "A\x{FFFF_FFFF}A_B\x{FFFF_FFFF}B", |
| 430 | text => "<p>d\x{FFFF_FFFF}d e\x{FFFF_FFFF}e f\x{FFFF_FFFF}f</p>", |
| 431 | textSigle => $text_sigle |
| 432 | ); |
| 433 | }; |
| Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 434 | |
| 435 | my ($fh, $tplfile) = korap_tempfile('script_out4'); |
| 436 | binmode($fh); |
| 437 | print $fh encode_utf8($tpl); # => text_id=Aþ¿¿¿¿¿A_Bþ¿¿¿¿¿B.Cþ¿¿¿¿¿C |
| 438 | close($fh); |
| 439 | |
| 440 | my (undef, $outzip) = korap_tempfile('script_out5'); |
| 441 | |
| Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 442 | # because output 'textid=...' goes to STDERR (see script/tei2korapxml) |
| Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 443 | binmode STDERR; |
| Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 444 | |
| 445 | stderr_like( |
| Akron | a2cb281 | 2021-10-30 10:29:08 +0200 | [diff] [blame] | 446 | sub { `cat '$tplfile' | perl '$script' -ti - > '$outzip'` }, |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 447 | qr!tei2korapxml:.*? text_id=$text_sigle_esc!, # see above: print $fh encode_utf8($tpl); |
| Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 448 | ); |
| 449 | }; |
| 450 | |
| Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 451 | |
| Akron | dd0be8f | 2021-02-18 19:29:41 +0100 | [diff] [blame] | 452 | subtest 'Check structure parsing with defined foundry and folder' => sub { |
| 453 | # Load example file |
| 454 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 455 | |
| 456 | my $t = test_tei2korapxml( |
| 457 | tmp => 'script_out', |
| 458 | file => $file, |
| 459 | param => '-ti --inline-structures=myfoundry#mystr' |
| Akron | 91705d7 | 2021-02-19 10:59:45 +0100 | [diff] [blame] | 460 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| Akron | dd0be8f | 2021-02-18 19:29:41 +0100 | [diff] [blame] | 461 | ->file_exists_not('GOE/AGA/00000/struct/structure.xml', 'Structure not generated') |
| 462 | ->unzip_xml('GOE/AGA/00000/myfoundry/mystr.xml') |
| 463 | ->text_is('span[id=s3] *[name=type]', 'Autobiographie', 'text content') |
| 464 | ->text_is('#s3 *[name=type]', 'Autobiographie', 'text content') |
| 465 | ->attr_is('#s0','to','1266') |
| 466 | ->attr_is('#s0','l','1') |
| 467 | ->attr_is('#s18','from','925') |
| 468 | ->attr_is('#s18','to','1266') |
| 469 | ->attr_is('#s18','l','5') |
| 470 | ; |
| 471 | |
| 472 | $t = test_tei2korapxml( |
| 473 | tmp => 'script_out', |
| 474 | file => $file, |
| 475 | param => '-ti --inline-structures=myfoundry' |
| Akron | 91705d7 | 2021-02-19 10:59:45 +0100 | [diff] [blame] | 476 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| Akron | dd0be8f | 2021-02-18 19:29:41 +0100 | [diff] [blame] | 477 | ->file_exists_not('GOE/AGA/00000/struct/structure.xml', 'Structure not generated') |
| 478 | ->unzip_xml('GOE/AGA/00000/myfoundry/structure.xml') |
| 479 | ->text_is('span[id=s3] *[name=type]', 'Autobiographie', 'text content') |
| 480 | ->text_is('#s3 *[name=type]', 'Autobiographie', 'text content') |
| 481 | ->attr_is('#s0','to','1266') |
| 482 | ->attr_is('#s0','l','1') |
| 483 | ->attr_is('#s18','from','925') |
| 484 | ->attr_is('#s18','to','1266') |
| 485 | ->attr_is('#s18','l','5') |
| 486 | ; |
| 487 | }; |
| 488 | |
| Akron | 54c3ff1 | 2021-02-25 11:33:37 +0100 | [diff] [blame] | 489 | subtest 'Check structure parsing with skipped tags' => sub { |
| 490 | # Load example file |
| 491 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 492 | |
| 493 | my $t = test_tei2korapxml( |
| 494 | tmp => 'script_out', |
| 495 | file => $file, |
| 496 | param => '-ti' |
| 497 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| 498 | ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated') |
| 499 | ->unzip_xml('GOE/AGA/00000/struct/structure.xml') |
| 500 | ->text_is('layer spanList span fs f', 'text') |
| 501 | ->text_is('#s5 fs f[name=name]','head') |
| 502 | ->text_is('#s6 fs f[name=name]','s') |
| 503 | ->text_is('#s7 fs f[name=name]','head') |
| 504 | ->text_is('#s8 fs f[name=name]','s') |
| 505 | ->text_is('#s9 fs f[name=name]','quote') |
| 506 | ->text_is('#s10 fs f[name=name]','s') |
| 507 | ; |
| 508 | |
| 509 | $t = test_tei2korapxml( |
| 510 | tmp => 'script_out', |
| 511 | file => $file, |
| 512 | param => '-ti --skip-inline-tags=head' |
| 513 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| 514 | ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated') |
| 515 | ->unzip_xml('GOE/AGA/00000/struct/structure.xml') |
| 516 | ->text_is('layer spanList span fs f', 'text') |
| 517 | ->text_is('#s5 fs f[name=name]','s') |
| 518 | ->text_is('#s6 fs f[name=name]','s') |
| 519 | ->text_is('#s7 fs f[name=name]','quote') |
| 520 | ->text_is('#s8 fs f[name=name]','s') |
| 521 | ; |
| 522 | |
| 523 | $t = test_tei2korapxml( |
| 524 | tmp => 'script_out', |
| 525 | file => $file, |
| 526 | param => '-ti --skip-inline-tags=head,quote' |
| 527 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| 528 | ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated') |
| 529 | ->unzip_xml('GOE/AGA/00000/struct/structure.xml') |
| 530 | ->text_is('layer spanList span fs f', 'text') |
| 531 | ->text_is('#s5 fs f[name=name]','s') |
| 532 | ->text_is('#s6 fs f[name=name]','s') |
| 533 | ->text_is('#s7 fs f[name=name]','s') |
| 534 | ; |
| 535 | }; |
| 536 | |
| Akron | dd0be8f | 2021-02-18 19:29:41 +0100 | [diff] [blame] | 537 | |
| Akron | 75d6314 | 2021-02-23 18:40:56 +0100 | [diff] [blame] | 538 | subtest 'Check parsing but skip inline tokens' => sub { |
| 539 | # Load example file |
| 540 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 541 | |
| 542 | my $t = test_tei2korapxml( |
| 543 | tmp => 'script_skip_inline_tokens_1', |
| 544 | file => $file, |
| 545 | param => '-ti --skip-inline-tokens' |
| 546 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| 547 | ->file_exists('GOE/AGA/00000/data.xml', 'Data exists') |
| 548 | ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated') |
| 549 | ->file_exists_not('GOE/AGA/00000/tokens/morpho.xml', 'Morpho not generated') |
| 550 | ; |
| 551 | |
| 552 | $t = test_tei2korapxml( |
| 553 | tmp => 'script_skip_inline_tokens_2', |
| 554 | file => $file, |
| 555 | param => '-ti --skip-inline-tokens --inline-tokens=myfoundry#myfile' |
| 556 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| 557 | ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated') |
| 558 | ->file_exists_not('GOE/AGA/00000/tokens/morpho.xml', 'Morpho not generated') |
| 559 | ->file_exists_not('GOE/AGA/00000/myfoundry/myfile.xml', 'Morpho not generated') |
| 560 | ; |
| 561 | }; |
| 562 | |
| 563 | |
| Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 564 | subtest 'Check Inline annotations' => sub { |
| 565 | |
| 566 | # Load example file |
| 567 | my $file = catfile($f, 'data', 'goe_sample_tagged.i5.xml'); |
| 568 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 569 | my $t = test_tei2korapxml( |
| 570 | file => $file, |
| 571 | env => 'KORAPXMLTEI_INLINE=1', |
| Akron | b93fabb | 2023-01-13 12:05:44 +0100 | [diff] [blame] | 572 | tmp => 'script_tagged', |
| 573 | param => '--no-tokenizer' |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 574 | ) |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 575 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| Akron | 692d17d | 2021-03-05 13:21:03 +0100 | [diff] [blame] | 576 | ->stderr_like(qr!KORAPXMLTEI_INLINE is deprecated!) |
| Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 577 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 578 | # Check zip using xml loy |
| 579 | ->unzip_xml('GOE/AGA/00000/tokens/morpho.xml') |
| Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 580 | |
| Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 581 | ->attr_is('layer', 'docid', 'GOE_AGA.00000') |
| Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 582 | ->attr_is('spanList span:nth-child(1)', 'id', 's0') |
| 583 | ->attr_is('spanList span:nth-child(1)', 'from', '75') |
| 584 | ->attr_is('spanList span:nth-child(1)', 'to', '81') |
| 585 | ->attr_is('spanList span:nth-child(1)', 'l', '7') |
| 586 | |
| 587 | ->attr_is('span#s0 > fs', 'type', 'lex') |
| 588 | ->attr_is('span#s0 > fs', 'xmlns', 'http://www.tei-c.org/ns/1.0') |
| 589 | ->attr_is('span#s0 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 590 | ->text_is('span#s0 > fs > f > fs > f:nth-child(1)', 'A') |
| 591 | ->attr_is('span#s0 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 592 | ->text_is('span#s0 > fs > f > fs > f:nth-child(2)', '@NH') |
| 593 | |
| 594 | ->attr_is('span#s25', 'from', '259') |
| 595 | ->attr_is('span#s25', 'to', '263') |
| 596 | ->attr_is('span#s25', 'l', '7') |
| 597 | ->attr_is('span#s25 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 598 | ->text_is('span#s25 > fs > f > fs > f:nth-child(1)', 'PRON') |
| 599 | ->attr_is('span#s25 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 600 | ->text_is('span#s25 > fs > f > fs > f:nth-child(2)', '@NH') |
| 601 | |
| 602 | ->attr_is('span#s58', 'from', '495') |
| 603 | ->attr_is('span#s58', 'to', '500') |
| 604 | ->attr_is('span#s58', 'l', '7') |
| 605 | ->attr_is('span#s58 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 606 | ->text_is('span#s58 > fs > f > fs > f:nth-child(1)', 'N') |
| 607 | ->attr_is('span#s58 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 608 | ->text_is('span#s58 > fs > f > fs > f:nth-child(2)', '@NH') |
| 609 | |
| 610 | ->attr_is('span#s119', 'from', '914') |
| 611 | ->attr_is('span#s119', 'to', '925') |
| 612 | ->attr_is('span#s119', 'l', '7') |
| 613 | ->attr_is('span#s119 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 614 | ->text_is('span#s119 > fs > f > fs > f:nth-child(1)', 'A') |
| 615 | ->attr_is('span#s119 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 616 | ->text_is('span#s119 > fs > f > fs > f:nth-child(2)', '@NH') |
| 617 | ->element_exists_not('span#s120') |
| 618 | ; |
| 619 | }; |
| 620 | |
| Akron | 26a7152 | 2021-02-19 10:27:37 +0100 | [diff] [blame] | 621 | |
| 622 | subtest 'Check file structure with defined folder and filenames' => sub { |
| 623 | # Load example file |
| 624 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 625 | my $t = test_tei2korapxml( |
| 626 | tmp => 'script_out', |
| 627 | file => $file, |
| 628 | param => '-ti --base-foundry=root --data-file=primary --header-file=meta' |
| Akron | 91705d7 | 2021-02-19 10:59:45 +0100 | [diff] [blame] | 629 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| Akron | 26a7152 | 2021-02-19 10:27:37 +0100 | [diff] [blame] | 630 | ->file_exists_not('GOE/AGA/00000/header.xml', 'Header not there') |
| 631 | ->file_exists_not('GOE/AGA/header.xml', 'Header not there') |
| 632 | ->file_exists_not('GOE/header.xml', 'Header not there') |
| 633 | ->file_exists_not('GOE/AGA/00000/data.xml', 'Data not there') |
| 634 | ->file_exists_not('GOE/AGA/00000/base/tokens_conservative.xml', 'Tokens not there') |
| 635 | ->file_exists_not('GOE/AGA/00000/base/tokens_aggressive.xml', 'Tokens not there') |
| 636 | ->file_exists('GOE/AGA/00000/meta.xml', 'Header there') |
| 637 | ->file_exists('GOE/AGA/meta.xml', 'Header there') |
| 638 | ->file_exists('GOE/meta.xml', 'Header there') |
| 639 | ->file_exists('GOE/AGA/00000/primary.xml', 'Data there') |
| 640 | ->file_exists('GOE/AGA/00000/root/tokens_conservative.xml', 'Tokens there') |
| 641 | ->file_exists('GOE/AGA/00000/root/tokens_aggressive.xml', 'Tokens there') |
| 642 | ; |
| 643 | |
| 644 | $t->unzip_xml('GOE/AGA/00000/primary.xml') |
| 645 | ->content_like(qr/\Q"Kriegstheater"\E/) |
| 646 | ; |
| 647 | }; |
| 648 | |
| Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 649 | subtest 'Check Inline annotations with defined foundry and folder' => sub { |
| 650 | # Load example file |
| 651 | my $file = catfile($f, 'data', 'goe_sample_tagged.i5.xml'); |
| 652 | |
| 653 | my $t = test_tei2korapxml( |
| 654 | file => $file, |
| Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 655 | tmp => 'script_tagged', |
| Akron | b93fabb | 2023-01-13 12:05:44 +0100 | [diff] [blame] | 656 | param => '--inline-tokens=myfoundry#myfile --skip-inline-token-annotations=0 --no-tokenizer' |
| Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 657 | ) |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 658 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| Akron | 692d17d | 2021-03-05 13:21:03 +0100 | [diff] [blame] | 659 | ->stderr_unlike(qr!KORAPXMLTEI_INLINE is deprecated!) |
| Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 660 | |
| 661 | ->file_exists_not('GOE/AGA/00000/tokens/morpho.xml', 'Morpho not generated') |
| 662 | |
| 663 | # Check zip using xml loy |
| 664 | ->unzip_xml('GOE/AGA/00000/myfoundry/myfile.xml') |
| 665 | |
| 666 | ->attr_is('layer', 'docid', 'GOE_AGA.00000') |
| 667 | ->attr_is('spanList span:nth-child(1)', 'id', 's0') |
| 668 | ->attr_is('spanList span:nth-child(1)', 'from', '75') |
| 669 | ->attr_is('spanList span:nth-child(1)', 'to', '81') |
| 670 | ->attr_is('spanList span:nth-child(1)', 'l', '7') |
| 671 | ; |
| 672 | |
| 673 | $t = test_tei2korapxml( |
| 674 | file => $file, |
| Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 675 | tmp => 'script_tagged', |
| Akron | b93fabb | 2023-01-13 12:05:44 +0100 | [diff] [blame] | 676 | param => '--inline-tokens=myfoundry --skip-inline-token-annotations=0 --no-tokenizer' |
| Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 677 | ) |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 678 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 679 | |
| 680 | ->file_exists_not('GOE/AGA/00000/tokens/morpho.xml', 'Morpho not generated') |
| 681 | |
| 682 | # Check zip using xml loy |
| 683 | ->unzip_xml('GOE/AGA/00000/myfoundry/morpho.xml') |
| 684 | |
| 685 | ->attr_is('layer', 'docid', 'GOE_AGA.00000') |
| 686 | ->attr_is('spanList span:nth-child(1)', 'id', 's0') |
| 687 | ->attr_is('spanList span:nth-child(1)', 'from', '75') |
| 688 | ->attr_is('spanList span:nth-child(1)', 'to', '81') |
| 689 | ->attr_is('spanList span:nth-child(1)', 'l', '7') |
| 690 | ; |
| 691 | }; |
| 692 | |
| Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 693 | subtest 'Check Inline annotations with untagged file' => sub { |
| 694 | |
| 695 | # Load example file |
| 696 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 697 | |
| 698 | my ($fh, $outzip) = korap_tempfile('script_untagged'); |
| 699 | |
| 700 | # Generate zip file (unportable!) |
| 701 | stderr_like( |
| Akron | b93fabb | 2023-01-13 12:05:44 +0100 | [diff] [blame] | 702 | sub { `cat '$file' | perl '$script' --skip-token-inline-annotations=0 --no-tokenizer - > '$outzip'` }, |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 703 | qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!, |
| Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 704 | 'Processing 1' |
| 705 | ); |
| 706 | |
| 707 | # TODO: there should be a better way to test this |
| 708 | stderr_unlike( |
| Akron | b93fabb | 2023-01-13 12:05:44 +0100 | [diff] [blame] | 709 | sub { `cat '$file' | perl '$script' --skip-token-inline-annotations=0 --no-tokenizer - > '$outzip'` }, |
| Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 710 | qr!.*undefined value.*!, |
| 711 | 'Processing 2' |
| 712 | ); |
| 713 | # |
| 714 | |
| 715 | ok(-e $outzip, "File $outzip exists"); |
| 716 | |
| 717 | my $zip = IO::Uncompress::Unzip->new( |
| 718 | $outzip, |
| 719 | Name => 'GOE/AGA/00000/tokens/morpho.xml' |
| 720 | ); |
| 721 | ok((not $zip), 'missing morpho.xml'); |
| 722 | |
| 723 | $zip = IO::Uncompress::Unzip->new( |
| 724 | $outzip, |
| 725 | Name => 'GOE/AGA/00000/struct/structure.xml' |
| 726 | ); |
| 727 | ok($zip, 'found structure.xml'); |
| 728 | }; |
| Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 729 | |
| Akron | 3378dfd | 2020-08-01 15:01:36 +0200 | [diff] [blame] | 730 | |
| Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 731 | subtest 'Check input encoding' => sub { |
| 732 | |
| 733 | # Load example file |
| 734 | test_tei2korapxml( |
| 735 | file => catfile($f, 'data', 'goe_sample.i5.xml'), |
| Akron | 692d17d | 2021-03-05 13:21:03 +0100 | [diff] [blame] | 736 | tmp => 'script_utf8_enc', |
| Akron | b93fabb | 2023-01-13 12:05:44 +0100 | [diff] [blame] | 737 | param => '--skip-inline-token-annotations=0 --no-tokenizer', |
| Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 738 | ) |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 739 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 740 | ->unzip_xml('GOE/AGA/00000/data.xml') |
| 741 | ->content_like(qr/\Q"Kriegstheater"\E/) |
| 742 | ->content_like(qr/\QTür'\E/) |
| 743 | ; |
| 744 | |
| 745 | test_tei2korapxml( |
| 746 | file => catfile($f, 'data', 'goe_sample.i5.iso.xml'), |
| Akron | b93fabb | 2023-01-13 12:05:44 +0100 | [diff] [blame] | 747 | param => '--skip-inline-token-annotations=0 --no-tokenizer', |
| Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 748 | tmp => 'script_iso_enc' |
| 749 | ) |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 750 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 751 | ->unzip_xml('GOE/AGA/00000/data.xml') |
| 752 | ->content_like(qr/\Q"Kriegstheater"\E/) |
| 753 | ->content_like(qr/\QTür'\E/) |
| 754 | ; |
| 755 | }; |
| 756 | |
| Marc Kupietz | 44b1f25 | 2020-11-26 16:31:40 +0100 | [diff] [blame] | 757 | subtest 'Check encoding with utf-8 sigle' => sub { |
| 758 | |
| 759 | # Load example file |
| 760 | my $file = catfile($f, 'data', 'wdd_sample.i5.xml'); |
| 761 | |
| 762 | my $t = test_tei2korapxml( |
| 763 | tmp => 'script_sigle', |
| 764 | file => $file, |
| 765 | param => "-ti" |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 766 | )->stderr_like(qr!tei2korapxml:.*? text_id=WDD19_ß0000\.10317!) |
| Marc Kupietz | 44b1f25 | 2020-11-26 16:31:40 +0100 | [diff] [blame] | 767 | ->stderr_unlike(qr!Debugging is activated!); |
| 768 | |
| 769 | $t->unzip_xml('WDD19/ß0000/10317/header.xml') |
| 770 | ->text_is('idsHeader fileDesc titleStmt textSigle', 'WDD19/ß0000.10317'); |
| 771 | |
| 772 | $t->unzip_xml('WDD19/ß0000/10317/data.xml') |
| 773 | ->attr_is('raw_text', 'docid', 'WDD19_ß0000.10317'); |
| 774 | |
| 775 | $t->unzip_xml('WDD19/ß0000/10317/struct/structure.xml') |
| 776 | ->attr_is('layer', 'docid', 'WDD19_ß0000.10317'); |
| 777 | |
| 778 | $t->unzip_xml('WDD19/ß0000/10317/base/tokens_conservative.xml') |
| 779 | ->attr_is('layer', 'docid', 'WDD19_ß0000.10317'); |
| 780 | }; |
| 781 | |
| Marc Kupietz | 8a954e5 | 2021-02-16 22:03:07 +0100 | [diff] [blame] | 782 | subtest 'Check entity replacement' => sub { |
| 783 | my $t = test_tei2korapxml( |
| 784 | file => catfile($f, 'data', 'text_with_entities.i5.xml'), |
| 785 | tmp => 'script_entity_replacement', |
| 786 | param => '-ti' |
| Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 787 | )->stderr_like(qr!tei2korapxml:.*? text_id=CORP_DOC.00003!); |
| Marc Kupietz | 8a954e5 | 2021-02-16 22:03:07 +0100 | [diff] [blame] | 788 | |
| 789 | $t->unzip_xml('CORP/DOC/00003/data.xml') |
| 790 | ->content_like(qr!üüü Aα≈„▒░▓█╗┐┌╔═─┬╦┴╩╝┘└╚│║┼╬┤╣╠├•ˇčˆ†‡ě€ƒ…‗ıι“„▄‹‘‚—–νœŒωΩ‰φπϖř”ρ›’‘šŠσ□■▪⊂˜™▀ŸžŽ!); |
| 791 | |
| 792 | $t->unzip_xml('CORP/DOC/00003/header.xml') |
| 793 | ->content_like(qr!üüü x α•α y!); |
| 794 | }; |
| 795 | |
| Akron | 3378dfd | 2020-08-01 15:01:36 +0200 | [diff] [blame] | 796 | subtest 'Test Log' => sub { |
| 797 | test_tei2korapxml( |
| 798 | tmp => 'script_out', |
| 799 | file => $file, |
| Akron | b93fabb | 2023-01-13 12:05:44 +0100 | [diff] [blame] | 800 | param => '-l=warn --no-tokenizer' |
| Akron | 3378dfd | 2020-08-01 15:01:36 +0200 | [diff] [blame] | 801 | )->stderr_is(''); |
| 802 | }; |
| 803 | |
| 804 | |
| Akron | 5986da3 | 2021-10-01 12:53:55 +0200 | [diff] [blame] | 805 | subtest 'Broken data testing' => sub { |
| 806 | my $file = catfile($f, 'data', 'wikipedia.txt'); |
| 807 | |
| 808 | my $t = test_tei2korapxml( |
| 809 | tmp => 'script_ginkgo', |
| 810 | file => $file, |
| 811 | param => '-ti', |
| 812 | env => 'KORAPXMLTEI_DEBUG=1' |
| 813 | )->stderr_like(qr!No opened zip file to close!) |
| 814 | ->stderr_like(qr!Debugging is activated!); |
| 815 | }; |
| 816 | |
| Akron | 2520a34 | 2022-03-29 18:18:05 +0200 | [diff] [blame] | 817 | subtest 'Required version testing' => sub { |
| 818 | test_tei2korapxml( |
| 819 | tmp => 'script_out', |
| 820 | file => $file, |
| 821 | param => '-rv=2.2.2' |
| 822 | )->stderr_like(qr!^Required version 2\.2\.2 mismatches version!); |
| 823 | |
| 824 | test_tei2korapxml( |
| 825 | tmp => 'script_out', |
| 826 | file => $file, |
| 827 | param => '--required-version=2.2' |
| 828 | )->stderr_like(qr!^Required version 2\.2 mismatches version!); |
| 829 | |
| 830 | test_tei2korapxml( |
| 831 | tmp => 'script_out', |
| 832 | file => $file, |
| Akron | b93fabb | 2023-01-13 12:05:44 +0100 | [diff] [blame] | 833 | param => '-rv=' . $KorAP::XML::TEI::Tokenizer::KorAP::VERSION . ' --no-tokenizer' |
| Akron | 2520a34 | 2022-03-29 18:18:05 +0200 | [diff] [blame] | 834 | )->stderr_like(qr!GOE_AGA\.00000!); |
| 835 | |
| 836 | test_tei2korapxml( |
| 837 | tmp => 'script_out', |
| 838 | file => $file, |
| Akron | b93fabb | 2023-01-13 12:05:44 +0100 | [diff] [blame] | 839 | param => '-rv= " ' . $KorAP::XML::TEI::Tokenizer::KorAP::VERSION . ' " --no-tokenizer' |
| Akron | 2520a34 | 2022-03-29 18:18:05 +0200 | [diff] [blame] | 840 | )->stderr_like(qr!GOE_AGA\.00000!); |
| 841 | }; |
| 842 | |
| Marc Kupietz | a671ae5 | 2022-12-22 16:28:14 +0100 | [diff] [blame] | 843 | subtest 'Standard TEI P5 testing' => sub { |
| 844 | |
| 845 | my $t = test_tei2korapxml( |
| 846 | file => catfile($f, 'data', 'icc_german_sample.p5.xml'), |
| Akron | fcff734 | 2023-02-07 14:05:15 +0100 | [diff] [blame] | 847 | param => '--xmlid-to-textsigle \'ICC.German\.([^.]+\.[^.]+)\.(.+)@ICCGER/$1/$2\' -s -ti', |
| Marc Kupietz | a671ae5 | 2022-12-22 16:28:14 +0100 | [diff] [blame] | 848 | tmp => 'script_utf8_enc' |
| 849 | )->stderr_like(qr!tei2korapxml:.*? text_id=ICCGER/DeReKo-WPD17\.S00-18619!); |
| 850 | |
| 851 | $t->unzip_xml('ICCGER/DeReKo-WPD17/E51-96136/data.xml') |
| 852 | ->content_like(qr/Recht auf persönliches Hab und Gut/); |
| 853 | |
| 854 | $t->unzip_xml('ICCGER/CCBY-LTE/MJB-00001/header.xml') |
| 855 | ->text_is('textClass > classCode[scheme=ICC]', 'Learned_Technology', 'classCode is correctly extracted'); |
| 856 | |
| 857 | }; |
| Akron | 5986da3 | 2021-10-01 12:53:55 +0200 | [diff] [blame] | 858 | |
| Akron | b93fabb | 2023-01-13 12:05:44 +0100 | [diff] [blame] | 859 | subtest 'Require tokenizer' => sub { |
| 860 | |
| 861 | my $t = test_tei2korapxml( |
| 862 | file => catfile($f, 'data', 'icc_german_sample.p5.xml'), |
| 863 | tmp => 'script_utf8_enc' |
| 864 | )->stderr_like(qr!No tokenizer chosen!); |
| 865 | }; |
| 866 | |
| Akron | 72f4a88 | 2023-03-02 09:48:14 +0100 | [diff] [blame] | 867 | subtest 'Test handling of textSigle in text' => sub { |
| 868 | |
| 869 | my $t = test_tei2korapxml( |
| 870 | file => catfile($f, 'data', 'text_with_textsigle_in_text.i5.xml'), |
| 871 | tmp => 'script_out', |
| 872 | param => '-ti' |
| 873 | ) |
| 874 | ->stderr_like(qr!tei2korapxml:.*? text_id=CORP_DOC.00001!) |
| 875 | ->stderr_unlike(qr!line with closing text-body tag 'text' contains additional information!); |
| 876 | }; |
| 877 | |
| Marc Kupietz | ff061ef | 2026-03-05 09:59:35 +0100 | [diff] [blame] | 878 | subtest 'Handling of closing body and text tags on same line' => sub { |
| 879 | |
| 880 | # Create a custom test file where </body> and </text> are on the same line |
| 881 | my ($fh, $testfile) = korap_tempfile('script_closing_tags'); |
| 882 | print $fh <<'XML'; |
| 883 | <?xml version="1.0" encoding="UTF-8"?> |
| 884 | <idsCorpus> |
| 885 | <idsHeader type="corpus"> |
| 886 | <fileDesc> |
| 887 | <titleStmt> |
| 888 | <korpusSigle>AAA</korpusSigle> |
| 889 | </titleStmt> |
| 890 | </fileDesc> |
| 891 | </idsHeader> |
| 892 | <idsDoc version="1.0"> |
| 893 | <idsHeader type="document"> |
| 894 | <fileDesc> |
| 895 | <titleStmt> |
| 896 | <dokumentSigle>AAA/BBB</dokumentSigle> |
| 897 | </titleStmt> |
| 898 | </fileDesc> |
| 899 | </idsHeader> |
| 900 | <idsText version="1.0"> |
| 901 | <idsHeader type="text"> |
| 902 | <fileDesc> |
| 903 | <titleStmt> |
| 904 | <textSigle>AAA/BBB.00000</textSigle> |
| 905 | </titleStmt> |
| 906 | </fileDesc> |
| 907 | </idsHeader> |
| 908 | <text> |
| 909 | <body><p>some text</p> |
| 910 | </body> </text> |
| 911 | </idsText> |
| 912 | </idsDoc> |
| 913 | </idsCorpus> |
| 914 | XML |
| 915 | close($fh); |
| 916 | |
| 917 | test_tei2korapxml( |
| 918 | file => $testfile, |
| 919 | tmp => 'script_closing_tags_out', |
| 920 | param => '-ti' |
| 921 | ) |
| 922 | ->stderr_like(qr!tei2korapxml:.*? text_id=AAA_BBB\.00000!) |
| 923 | ->stderr_unlike(qr!line with closing text-body tag 'text' contains additional information!); |
| 924 | }; |
| 925 | |
| Akron | ec50325 | 2023-04-24 18:03:17 +0200 | [diff] [blame] | 926 | subtest 'Handling of whitespace at linebreaks' => sub { |
| 927 | my $t = test_tei2korapxml( |
| 928 | file => catfile($f, 'data', 'stadigmer.p5.xml'), |
| 929 | tmp => 'script_out', |
| 930 | param => '-s -ti', |
| 931 | ) |
| 932 | ->stderr_like(qr!tei2korapxml:.*? text_id=NO_000\.00000!); |
| 933 | $t->unzip_xml('NO/000/00000/data.xml') |
| 934 | ->content_like(qr/har lurt/) |
| 935 | ->content_like(qr/etter at/) |
| 936 | ->content_like(qr/en stund/) |
| 937 | ->content_like(qr/skjønner med/) |
| 938 | ->content_like(qr/og det/) |
| 939 | ->content_like(qr/stadig mer/) |
| 940 | ->content_like(qr/sitt, og/) |
| 941 | ->content_like(qr/tenkt å bli/) |
| 942 | ->content_like(qr/er både/) |
| 943 | ; |
| 944 | }; |
| 945 | |
| Akron | 132bdeb | 2024-06-06 14:28:56 +0200 | [diff] [blame] | 946 | subtest 'Write to output' => sub { |
| 947 | |
| 948 | my $temp_out = korap_tempfile('out'); |
| 949 | |
| 950 | my $t = test_tei2korapxml( |
| 951 | file => catfile($f, 'data', 'stadigmer.p5.xml'), |
| 952 | tmp => 'script_out', |
| 953 | param => '-s -ti -o "' . $temp_out . '"', |
| 954 | )->stderr_like(qr!tei2korapxml:.*? text_id=NO_000\.00000!) |
| 955 | ->stdout_is(''); |
| 956 | |
| 957 | my $content; |
| 958 | open(X, '<' . $temp_out); |
| 959 | binmode(X); |
| 960 | $content .= <X> while !eof(X); |
| 961 | close(X); |
| 962 | $t->{stdout} = $content; |
| 963 | |
| 964 | $t->unzip_xml('NO/000/00000/data.xml') |
| 965 | ->content_like(qr/har lurt/) |
| 966 | ->content_like(qr/etter at/) |
| 967 | ->content_like(qr/en stund/) |
| 968 | ->content_like(qr/skjønner med/) |
| 969 | ->content_like(qr/og det/) |
| 970 | ->content_like(qr/stadig mer/) |
| 971 | ->content_like(qr/sitt, og/) |
| 972 | ->content_like(qr/tenkt å bli/) |
| 973 | ->content_like(qr/er både/) |
| 974 | ; |
| 975 | |
| 976 | unlink $temp_out; |
| 977 | }; |
| 978 | |
| Akron | 6b1f26b | 2024-09-19 11:35:32 +0200 | [diff] [blame] | 979 | subtest 'Handling of dependency data (1)' => sub { |
| 980 | my $t = test_tei2korapxml( |
| 981 | file => catfile($f, 'data', 'SKU21.head.i5.xml'), |
| 982 | tmp => 'script_out', |
| 983 | param => '-s --no-tokenizer --inline-tokens=csc#morpho', |
| 984 | ) |
| 985 | ->stderr_like(qr!tei2korapxml:.*? text_id=SKU21_JAN\.00001!); |
| 986 | $t->unzip_xml('SKU21/JAN/00001/data.xml') |
| 987 | ->content_like(qr/cgICpWb AQNFU/) |
| 988 | ->content_like(qr/LhyS OLHV/) |
| 989 | ->content_like(qr/kdQVs hunIRQIN/) |
| 990 | ; |
| 991 | |
| 992 | $t->unzip_xml('SKU21/JAN/00001/csc/morpho.xml') |
| 993 | ->attr_is('spanList span:nth-child(2)', 'id', 's1') |
| 994 | ->attr_is('#s1', 'from', '5') |
| 995 | ->attr_is('#s1', 'to', '9') |
| 996 | ->text_is('#s1 fs f fs f[name="deprel"]', 'name') |
| 997 | ->text_is('#s1 fs f fs f[name="head"]', '3') |
| 998 | ->text_is('#s1 fs f fs f[name="lemma"]', 'kCXD') |
| 999 | ->text_is('#s1 fs f fs f[name="msd"]', 'SUBCAT_Prop|CASECHANGE_Up|OTHER_UNK') |
| 1000 | ->text_is('#s1 fs f fs f[name="n"]', '2') |
| 1001 | ->text_is('#s1 fs f fs f[name="pos"]', 'N') |
| 1002 | ; |
| 1003 | }; |
| 1004 | |
| 1005 | subtest 'Handling of dependency data (2)' => sub { |
| 1006 | my $t = test_tei2korapxml( |
| 1007 | file => catfile($f, 'data', 'SKU21.head.i5.xml'), |
| 1008 | tmp => 'script_out', |
| 1009 | param => '-s --no-tokenizer ' . |
| 1010 | '--inline-tokens=csc#morpho ' . |
| 1011 | '--inline-dependencies=!csc ' . |
| 1012 | '--no-skip-inline-token-annotations', |
| 1013 | ) |
| 1014 | ->stderr_like(qr!tei2korapxml:.*? text_id=SKU21_JAN\.00001!) |
| 1015 | ->stderr_like(qr!tei2korapxml:.*? text_id=SKU21_JAN\.00002!) |
| 1016 | ->stderr_like(qr!tei2korapxml:.*? text_id=SKU21_JAN\.00003!) |
| 1017 | ; |
| 1018 | |
| 1019 | $t->unzip_xml('SKU21/JAN/00001/data.xml') |
| 1020 | ->content_like(qr/cgICpWb AQNFU/) |
| 1021 | ->content_like(qr/LhyS OLHV/) |
| 1022 | ->content_like(qr/kdQVs hunIRQIN/) |
| 1023 | ; |
| 1024 | |
| 1025 | $t->unzip_xml('SKU21/JAN/00001/csc/morpho.xml') |
| 1026 | ->attr_is('spanList span:nth-child(2)', 'id', 's1') |
| 1027 | ->attr_is('#s1', 'from', '5') |
| 1028 | ->attr_is('#s1', 'to', '9') |
| 1029 | ->text_is('#s1 fs f fs f[name="lemma"]', 'kCXD') |
| 1030 | ->text_is('#s1 fs f fs f[name="msd"]', 'SUBCAT_Prop|CASECHANGE_Up|OTHER_UNK') |
| 1031 | ->text_is('#s1 fs f fs f[name="pos"]', 'N') |
| 1032 | ->element_exists_not('#s1 fs f fs f[name="n"]') |
| 1033 | ->element_exists_not('#s1 fs f fs f[name="deprel"]') |
| 1034 | ->element_exists_not('#s1 fs f fs f[name="head"]') |
| 1035 | ; |
| 1036 | |
| 1037 | $t->unzip_xml('SKU21/JAN/00001/csc/dependency.xml') |
| 1038 | ->attr_is('spanList span:nth-child(2)', 'id', 's1_n2') |
| 1039 | ->attr_is('#s1_n2', "from", "5") |
| 1040 | ->attr_is('#s1_n2', "to", "9") |
| 1041 | ->attr_is('#s1_n2 rel', "label", "name") |
| 1042 | ->attr_is('#s1_n2 rel span', "from", '10') |
| 1043 | ->attr_is('#s1_n2 rel span', "to", '15') |
| 1044 | ; |
| 1045 | |
| 1046 | $t->unzip_xml('SKU21/JAN/00002/csc/dependency.xml') |
| 1047 | ->attr_is('spanList span:nth-child(2)', 'id', 's1_n2') |
| 1048 | ->attr_is('#s1_n2', "from", "4") |
| 1049 | ->attr_is('#s1_n2', "to", "5") |
| 1050 | ->attr_is('#s1_n2 rel', "label", "poss") |
| 1051 | ->attr_is('#s1_n2 rel span', "from", '6') |
| 1052 | ->attr_is('#s1_n2 rel span', "to", '12') |
| 1053 | ; |
| 1054 | }; |
| 1055 | |
| 1056 | |
| Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 1057 | done_testing; |