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 | eed4cb1 | 2021-02-17 19:39:32 +0100 | [diff] [blame] | 201 | subtest 'Check KorAP tokenizer for infinite loop bug' => sub { |
| 202 | |
| 203 | my $file = catfile($f, 'data', 'korap_tokenizer_challenge.xml'); |
| 204 | |
| 205 | eval { |
| 206 | require KorAP::XML::TEI::Tokenizer::KorAP; |
| 207 | 1; |
| 208 | } or do { |
| 209 | plan skip_all => "KorAP::XML::TEI::Tokenizer::KorAP cannot be used"; |
| 210 | }; |
| 211 | |
| 212 | test_tei2korapxml( |
| 213 | file => $file, |
| 214 | param => "-tk -s", |
| 215 | tmp => 'script_bug_check' |
| 216 | ) |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 217 | ->stderr_like(qr!tei2korapxml:.*? text_id=WDD19_H0039\.87242!) |
Marc Kupietz | eed4cb1 | 2021-02-17 19:39:32 +0100 | [diff] [blame] | 218 | ->file_readable('WDD19/H0039/87242/struct/structure.xml'); |
| 219 | }; |
| 220 | |
Marc Kupietz | 985da0c | 2021-02-15 19:29:50 +0100 | [diff] [blame] | 221 | subtest 'Sentence split with KorAP tokenizer' => sub { |
| 222 | |
| 223 | eval { |
| 224 | require KorAP::XML::TEI::Tokenizer::KorAP; |
| 225 | 1; |
| 226 | } or do { |
| 227 | plan skip_all => "KorAP::XML::TEI::Tokenizer::KorAP cannot be used"; |
| 228 | }; |
| 229 | |
| 230 | test_tei2korapxml( |
| 231 | file => $file, |
| 232 | param => "-tk -s", |
| 233 | tmp => 'script_sentence_split' |
| 234 | ) |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 235 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
Marc Kupietz | 985da0c | 2021-02-15 19:29:50 +0100 | [diff] [blame] | 236 | ->file_readable('GOE/AGA/00000/struct/structure.xml') |
| 237 | ->unzip_xml('GOE/AGA/00000/struct/structure.xml') |
| 238 | ->text_is('span#s25 fs f', 's') |
| 239 | ->attr_is('span#s25', 'l', -1) |
| 240 | ->attr_is('span#s25', 'to', 54) |
| 241 | ->text_is('span#s30 fs f', 's') |
| 242 | ->attr_is('span#s30', 'l', -1) |
| 243 | ->attr_is('span#s30', 'from', 1099) |
| 244 | ->attr_is('span#s30', 'to', 1266); |
| 245 | }; |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 246 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 247 | subtest 'Test Tokenizations' => sub { |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 248 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 249 | my $t = test_tei2korapxml( |
| 250 | file => catfile($f, 'data', 'text_with_blanks.i5.xml'), |
| 251 | tmp => 'script_out3', |
| 252 | param => '-ti' |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 253 | )->stderr_like(qr!tei2korapxml:.*? text_id=CORP_DOC.00001!); |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 254 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 255 | # ~ test conservative tokenization ~ |
| 256 | $t->unzip_xml('CORP/DOC/00001/base/tokens_conservative.xml') |
| 257 | ->attr_is('spanList span:nth-child(1)', 'to', 6) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 258 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 259 | ->attr_is('spanList span#t_1', 'from', 7) |
| 260 | ->attr_is('spanList span#t_1', 'to', 9) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 261 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 262 | ->attr_is('spanList span#t_3', 'from', 12) |
| 263 | ->attr_is('spanList span#t_3', 'to', 16) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 264 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 265 | ->attr_is('spanList span#t_9', 'from', 36) |
| 266 | ->attr_is('spanList span#t_9', 'to', 37) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 267 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 268 | ->attr_is('spanList span#t_13', 'from', 44) |
| 269 | ->attr_is('spanList span#t_13', 'to', 45) # " |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 270 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 271 | ->attr_is('spanList span#t_14', 'from', 45) # twenty-two |
| 272 | ->attr_is('spanList span#t_14', 'to', 55) |
Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 273 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 274 | ->attr_is('spanList span#t_15', 'from', 55) # " |
| 275 | ->attr_is('spanList span#t_15', 'to', 56) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 276 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 277 | ->attr_is('spanList span#t_19', 'from', 66) |
| 278 | ->attr_is('spanList span#t_19', 'to', 67) |
Peter Harders | b122717 | 2020-07-21 02:12:10 +0200 | [diff] [blame] | 279 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 280 | ->element_count_is('spanList span', 20); |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 281 | |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 282 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 283 | # ~ test aggressive tokenization ~ |
| 284 | $t->unzip_xml('CORP/DOC/00001/base/tokens_aggressive.xml') |
| 285 | ->attr_is('spanList span:nth-child(1)', 'to', 6) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 286 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 287 | ->attr_is('spanList span#t_1', 'from', 7) |
| 288 | ->attr_is('spanList span#t_1', 'to', 9) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 289 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 290 | ->attr_is('spanList span#t_3', 'from', 12) |
| 291 | ->attr_is('spanList span#t_3', 'to', 16) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 292 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 293 | ->attr_is('spanList span#t_9', 'from', 36) |
| 294 | ->attr_is('spanList span#t_9', 'to', 37) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 295 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 296 | ->attr_is('spanList span#t_13', 'from', 44) |
| 297 | ->attr_is('spanList span#t_13', 'to', 45) # " |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 298 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 299 | ->attr_is('spanList span#t_14', 'from', 45) # twenty |
| 300 | ->attr_is('spanList span#t_14', 'to', 51) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 301 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 302 | ->attr_is('spanList span#t_15', 'from', 51) # - |
| 303 | ->attr_is('spanList span#t_15', 'to', 52) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 304 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 305 | ->attr_is('spanList span#t_16', 'from', 52) # two |
| 306 | ->attr_is('spanList span#t_16', 'to', 55) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 307 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 308 | ->attr_is('spanList span#t_17', 'from', 55) # " |
| 309 | ->attr_is('spanList span#t_17', 'to', 56) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 310 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 311 | ->attr_is('spanList span#t_21', 'from', 66) |
| 312 | ->attr_is('spanList span#t_21', 'to', 67) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 313 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 314 | ->element_count_is('spanList span', 22); |
| 315 | }; |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 316 | |
| 317 | |
Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 318 | subtest 'Check Tokenization Flags' => sub { |
| 319 | |
| 320 | # Get external tokenizer |
| 321 | my $f = dirname(__FILE__); |
| 322 | my $cmd = catfile($f, 'cmd', 'tokenizer.pl'); |
| 323 | |
| 324 | # Load example file |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 325 | test_tei2korapxml( |
| 326 | file => catfile($f, 'data', 'goe_sample.i5.xml'), |
| 327 | param => "-ti -tc 'perl $cmd'", |
| 328 | tmp => 'script_tokflags' |
| 329 | ) |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 330 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 331 | ->file_exists('GOE/AGA/00000/base/tokens_aggressive.xml') |
| 332 | ->file_exists('GOE/AGA/00000/base/tokens_conservative.xml') |
| 333 | ->file_exists('GOE/AGA/00000/base/tokens.xml') |
| 334 | ; |
Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 335 | }; |
| 336 | |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 337 | |
| 338 | subtest 'Test utf-8 handling' => sub { |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 339 | # Introduce invalid utf-8 characters |
| 340 | my $text_sigle; |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 341 | { |
| 342 | no warnings; |
| 343 | # $text_sigle printed to file, without encoding: Aþ¿¿¿¿¿A_Bþ¿¿¿¿¿B.Cþ¿¿¿¿¿C |
| 344 | # the utf8-sequence 'þ¿¿¿¿¿' encodes 32 bit of data (see 0x7FFF_FFFF in perlunicode) |
| 345 | $text_sigle = "A\x{FFFF_FFFF}A_B\x{FFFF_FFFF}B.C\x{FFFF_FFFF}C" |
| 346 | } |
| 347 | # If CHECK is 0, encoding and decoding replace any malformed character |
| 348 | # with a substitution character. |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 349 | # � = substitution character |
| 350 | my $text_sigle_lax = encode_utf8($text_sigle); |
| 351 | my $text_sigle_esc = encode('UTF-8', $text_sigle); |
| 352 | |
| 353 | is(length($text_sigle), 11); # A�A_B�B.C�C (char string => length(�) = 1) |
| 354 | is(length($text_sigle_lax), 29); # Aþ¿¿¿¿¿A_Bþ¿¿¿¿¿B.Cþ¿¿¿¿¿C (byte string) |
| 355 | is(length($text_sigle_esc), 17); # A�A_B�B.C�C (byte string => length(�) = 3) |
| 356 | |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 357 | |
| 358 | my $tpl; |
| 359 | { |
| 360 | no warnings; |
| 361 | $tpl = i5_template( |
| 362 | korpusSigle => "A\x{FFFF_FFFF}A", |
| 363 | dokumentSigle => "A\x{FFFF_FFFF}A_B\x{FFFF_FFFF}B", |
| 364 | text => "<p>d\x{FFFF_FFFF}d e\x{FFFF_FFFF}e f\x{FFFF_FFFF}f</p>", |
| 365 | textSigle => $text_sigle |
| 366 | ); |
| 367 | }; |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 368 | |
| 369 | my ($fh, $tplfile) = korap_tempfile('script_out4'); |
| 370 | binmode($fh); |
| 371 | print $fh encode_utf8($tpl); # => text_id=Aþ¿¿¿¿¿A_Bþ¿¿¿¿¿B.Cþ¿¿¿¿¿C |
| 372 | close($fh); |
| 373 | |
| 374 | my (undef, $outzip) = korap_tempfile('script_out5'); |
| 375 | |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 376 | # because output 'textid=...' goes to STDERR (see script/tei2korapxml) |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 377 | binmode STDERR; |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 378 | |
| 379 | stderr_like( |
Akron | a2cb281 | 2021-10-30 10:29:08 +0200 | [diff] [blame^] | 380 | sub { `cat '$tplfile' | perl '$script' -ti - > '$outzip'` }, |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 381 | 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] | 382 | ); |
| 383 | }; |
| 384 | |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 385 | |
Akron | dd0be8f | 2021-02-18 19:29:41 +0100 | [diff] [blame] | 386 | subtest 'Check structure parsing with defined foundry and folder' => sub { |
| 387 | # Load example file |
| 388 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 389 | |
| 390 | my $t = test_tei2korapxml( |
| 391 | tmp => 'script_out', |
| 392 | file => $file, |
| 393 | param => '-ti --inline-structures=myfoundry#mystr' |
Akron | 91705d7 | 2021-02-19 10:59:45 +0100 | [diff] [blame] | 394 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
Akron | dd0be8f | 2021-02-18 19:29:41 +0100 | [diff] [blame] | 395 | ->file_exists_not('GOE/AGA/00000/struct/structure.xml', 'Structure not generated') |
| 396 | ->unzip_xml('GOE/AGA/00000/myfoundry/mystr.xml') |
| 397 | ->text_is('span[id=s3] *[name=type]', 'Autobiographie', 'text content') |
| 398 | ->text_is('#s3 *[name=type]', 'Autobiographie', 'text content') |
| 399 | ->attr_is('#s0','to','1266') |
| 400 | ->attr_is('#s0','l','1') |
| 401 | ->attr_is('#s18','from','925') |
| 402 | ->attr_is('#s18','to','1266') |
| 403 | ->attr_is('#s18','l','5') |
| 404 | ; |
| 405 | |
| 406 | $t = test_tei2korapxml( |
| 407 | tmp => 'script_out', |
| 408 | file => $file, |
| 409 | param => '-ti --inline-structures=myfoundry' |
Akron | 91705d7 | 2021-02-19 10:59:45 +0100 | [diff] [blame] | 410 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
Akron | dd0be8f | 2021-02-18 19:29:41 +0100 | [diff] [blame] | 411 | ->file_exists_not('GOE/AGA/00000/struct/structure.xml', 'Structure not generated') |
| 412 | ->unzip_xml('GOE/AGA/00000/myfoundry/structure.xml') |
| 413 | ->text_is('span[id=s3] *[name=type]', 'Autobiographie', 'text content') |
| 414 | ->text_is('#s3 *[name=type]', 'Autobiographie', 'text content') |
| 415 | ->attr_is('#s0','to','1266') |
| 416 | ->attr_is('#s0','l','1') |
| 417 | ->attr_is('#s18','from','925') |
| 418 | ->attr_is('#s18','to','1266') |
| 419 | ->attr_is('#s18','l','5') |
| 420 | ; |
| 421 | }; |
| 422 | |
Akron | 54c3ff1 | 2021-02-25 11:33:37 +0100 | [diff] [blame] | 423 | subtest 'Check structure parsing with skipped tags' => sub { |
| 424 | # Load example file |
| 425 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 426 | |
| 427 | my $t = test_tei2korapxml( |
| 428 | tmp => 'script_out', |
| 429 | file => $file, |
| 430 | param => '-ti' |
| 431 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| 432 | ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated') |
| 433 | ->unzip_xml('GOE/AGA/00000/struct/structure.xml') |
| 434 | ->text_is('layer spanList span fs f', 'text') |
| 435 | ->text_is('#s5 fs f[name=name]','head') |
| 436 | ->text_is('#s6 fs f[name=name]','s') |
| 437 | ->text_is('#s7 fs f[name=name]','head') |
| 438 | ->text_is('#s8 fs f[name=name]','s') |
| 439 | ->text_is('#s9 fs f[name=name]','quote') |
| 440 | ->text_is('#s10 fs f[name=name]','s') |
| 441 | ; |
| 442 | |
| 443 | $t = test_tei2korapxml( |
| 444 | tmp => 'script_out', |
| 445 | file => $file, |
| 446 | param => '-ti --skip-inline-tags=head' |
| 447 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| 448 | ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated') |
| 449 | ->unzip_xml('GOE/AGA/00000/struct/structure.xml') |
| 450 | ->text_is('layer spanList span fs f', 'text') |
| 451 | ->text_is('#s5 fs f[name=name]','s') |
| 452 | ->text_is('#s6 fs f[name=name]','s') |
| 453 | ->text_is('#s7 fs f[name=name]','quote') |
| 454 | ->text_is('#s8 fs f[name=name]','s') |
| 455 | ; |
| 456 | |
| 457 | $t = test_tei2korapxml( |
| 458 | tmp => 'script_out', |
| 459 | file => $file, |
| 460 | param => '-ti --skip-inline-tags=head,quote' |
| 461 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| 462 | ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated') |
| 463 | ->unzip_xml('GOE/AGA/00000/struct/structure.xml') |
| 464 | ->text_is('layer spanList span fs f', 'text') |
| 465 | ->text_is('#s5 fs f[name=name]','s') |
| 466 | ->text_is('#s6 fs f[name=name]','s') |
| 467 | ->text_is('#s7 fs f[name=name]','s') |
| 468 | ; |
| 469 | }; |
| 470 | |
Akron | dd0be8f | 2021-02-18 19:29:41 +0100 | [diff] [blame] | 471 | |
Akron | 75d6314 | 2021-02-23 18:40:56 +0100 | [diff] [blame] | 472 | subtest 'Check parsing but skip inline tokens' => sub { |
| 473 | # Load example file |
| 474 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 475 | |
| 476 | my $t = test_tei2korapxml( |
| 477 | tmp => 'script_skip_inline_tokens_1', |
| 478 | file => $file, |
| 479 | param => '-ti --skip-inline-tokens' |
| 480 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| 481 | ->file_exists('GOE/AGA/00000/data.xml', 'Data exists') |
| 482 | ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated') |
| 483 | ->file_exists_not('GOE/AGA/00000/tokens/morpho.xml', 'Morpho not generated') |
| 484 | ; |
| 485 | |
| 486 | $t = test_tei2korapxml( |
| 487 | tmp => 'script_skip_inline_tokens_2', |
| 488 | file => $file, |
| 489 | param => '-ti --skip-inline-tokens --inline-tokens=myfoundry#myfile' |
| 490 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
| 491 | ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated') |
| 492 | ->file_exists_not('GOE/AGA/00000/tokens/morpho.xml', 'Morpho not generated') |
| 493 | ->file_exists_not('GOE/AGA/00000/myfoundry/myfile.xml', 'Morpho not generated') |
| 494 | ; |
| 495 | }; |
| 496 | |
| 497 | |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 498 | subtest 'Check Inline annotations' => sub { |
| 499 | |
| 500 | # Load example file |
| 501 | my $file = catfile($f, 'data', 'goe_sample_tagged.i5.xml'); |
| 502 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 503 | my $t = test_tei2korapxml( |
| 504 | file => $file, |
| 505 | env => 'KORAPXMLTEI_INLINE=1', |
| 506 | tmp => 'script_tagged' |
| 507 | ) |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 508 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
Akron | 692d17d | 2021-03-05 13:21:03 +0100 | [diff] [blame] | 509 | ->stderr_like(qr!KORAPXMLTEI_INLINE is deprecated!) |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 510 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 511 | # Check zip using xml loy |
| 512 | ->unzip_xml('GOE/AGA/00000/tokens/morpho.xml') |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 513 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 514 | ->attr_is('layer', 'docid', 'GOE_AGA.00000') |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 515 | ->attr_is('spanList span:nth-child(1)', 'id', 's0') |
| 516 | ->attr_is('spanList span:nth-child(1)', 'from', '75') |
| 517 | ->attr_is('spanList span:nth-child(1)', 'to', '81') |
| 518 | ->attr_is('spanList span:nth-child(1)', 'l', '7') |
| 519 | |
| 520 | ->attr_is('span#s0 > fs', 'type', 'lex') |
| 521 | ->attr_is('span#s0 > fs', 'xmlns', 'http://www.tei-c.org/ns/1.0') |
| 522 | ->attr_is('span#s0 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 523 | ->text_is('span#s0 > fs > f > fs > f:nth-child(1)', 'A') |
| 524 | ->attr_is('span#s0 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 525 | ->text_is('span#s0 > fs > f > fs > f:nth-child(2)', '@NH') |
| 526 | |
| 527 | ->attr_is('span#s25', 'from', '259') |
| 528 | ->attr_is('span#s25', 'to', '263') |
| 529 | ->attr_is('span#s25', 'l', '7') |
| 530 | ->attr_is('span#s25 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 531 | ->text_is('span#s25 > fs > f > fs > f:nth-child(1)', 'PRON') |
| 532 | ->attr_is('span#s25 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 533 | ->text_is('span#s25 > fs > f > fs > f:nth-child(2)', '@NH') |
| 534 | |
| 535 | ->attr_is('span#s58', 'from', '495') |
| 536 | ->attr_is('span#s58', 'to', '500') |
| 537 | ->attr_is('span#s58', 'l', '7') |
| 538 | ->attr_is('span#s58 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 539 | ->text_is('span#s58 > fs > f > fs > f:nth-child(1)', 'N') |
| 540 | ->attr_is('span#s58 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 541 | ->text_is('span#s58 > fs > f > fs > f:nth-child(2)', '@NH') |
| 542 | |
| 543 | ->attr_is('span#s119', 'from', '914') |
| 544 | ->attr_is('span#s119', 'to', '925') |
| 545 | ->attr_is('span#s119', 'l', '7') |
| 546 | ->attr_is('span#s119 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 547 | ->text_is('span#s119 > fs > f > fs > f:nth-child(1)', 'A') |
| 548 | ->attr_is('span#s119 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 549 | ->text_is('span#s119 > fs > f > fs > f:nth-child(2)', '@NH') |
| 550 | ->element_exists_not('span#s120') |
| 551 | ; |
| 552 | }; |
| 553 | |
Akron | 26a7152 | 2021-02-19 10:27:37 +0100 | [diff] [blame] | 554 | |
| 555 | subtest 'Check file structure with defined folder and filenames' => sub { |
| 556 | # Load example file |
| 557 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 558 | my $t = test_tei2korapxml( |
| 559 | tmp => 'script_out', |
| 560 | file => $file, |
| 561 | param => '-ti --base-foundry=root --data-file=primary --header-file=meta' |
Akron | 91705d7 | 2021-02-19 10:59:45 +0100 | [diff] [blame] | 562 | )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
Akron | 26a7152 | 2021-02-19 10:27:37 +0100 | [diff] [blame] | 563 | ->file_exists_not('GOE/AGA/00000/header.xml', 'Header not there') |
| 564 | ->file_exists_not('GOE/AGA/header.xml', 'Header not there') |
| 565 | ->file_exists_not('GOE/header.xml', 'Header not there') |
| 566 | ->file_exists_not('GOE/AGA/00000/data.xml', 'Data not there') |
| 567 | ->file_exists_not('GOE/AGA/00000/base/tokens_conservative.xml', 'Tokens not there') |
| 568 | ->file_exists_not('GOE/AGA/00000/base/tokens_aggressive.xml', 'Tokens not there') |
| 569 | ->file_exists('GOE/AGA/00000/meta.xml', 'Header there') |
| 570 | ->file_exists('GOE/AGA/meta.xml', 'Header there') |
| 571 | ->file_exists('GOE/meta.xml', 'Header there') |
| 572 | ->file_exists('GOE/AGA/00000/primary.xml', 'Data there') |
| 573 | ->file_exists('GOE/AGA/00000/root/tokens_conservative.xml', 'Tokens there') |
| 574 | ->file_exists('GOE/AGA/00000/root/tokens_aggressive.xml', 'Tokens there') |
| 575 | ; |
| 576 | |
| 577 | $t->unzip_xml('GOE/AGA/00000/primary.xml') |
| 578 | ->content_like(qr/\Q"Kriegstheater"\E/) |
| 579 | ; |
| 580 | }; |
| 581 | |
Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 582 | subtest 'Check Inline annotations with defined foundry and folder' => sub { |
| 583 | # Load example file |
| 584 | my $file = catfile($f, 'data', 'goe_sample_tagged.i5.xml'); |
| 585 | |
| 586 | my $t = test_tei2korapxml( |
| 587 | file => $file, |
Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 588 | tmp => 'script_tagged', |
Akron | 692d17d | 2021-03-05 13:21:03 +0100 | [diff] [blame] | 589 | param => '--inline-tokens=myfoundry#myfile --skip-inline-token-annotations=0' |
Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 590 | ) |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 591 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
Akron | 692d17d | 2021-03-05 13:21:03 +0100 | [diff] [blame] | 592 | ->stderr_unlike(qr!KORAPXMLTEI_INLINE is deprecated!) |
Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 593 | |
| 594 | ->file_exists_not('GOE/AGA/00000/tokens/morpho.xml', 'Morpho not generated') |
| 595 | |
| 596 | # Check zip using xml loy |
| 597 | ->unzip_xml('GOE/AGA/00000/myfoundry/myfile.xml') |
| 598 | |
| 599 | ->attr_is('layer', 'docid', 'GOE_AGA.00000') |
| 600 | ->attr_is('spanList span:nth-child(1)', 'id', 's0') |
| 601 | ->attr_is('spanList span:nth-child(1)', 'from', '75') |
| 602 | ->attr_is('spanList span:nth-child(1)', 'to', '81') |
| 603 | ->attr_is('spanList span:nth-child(1)', 'l', '7') |
| 604 | ; |
| 605 | |
| 606 | $t = test_tei2korapxml( |
| 607 | file => $file, |
Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 608 | tmp => 'script_tagged', |
Akron | 692d17d | 2021-03-05 13:21:03 +0100 | [diff] [blame] | 609 | param => '--inline-tokens=myfoundry --skip-inline-token-annotations=0' |
Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 610 | ) |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 611 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
Akron | 1a5271a | 2021-02-18 13:18:15 +0100 | [diff] [blame] | 612 | |
| 613 | ->file_exists_not('GOE/AGA/00000/tokens/morpho.xml', 'Morpho not generated') |
| 614 | |
| 615 | # Check zip using xml loy |
| 616 | ->unzip_xml('GOE/AGA/00000/myfoundry/morpho.xml') |
| 617 | |
| 618 | ->attr_is('layer', 'docid', 'GOE_AGA.00000') |
| 619 | ->attr_is('spanList span:nth-child(1)', 'id', 's0') |
| 620 | ->attr_is('spanList span:nth-child(1)', 'from', '75') |
| 621 | ->attr_is('spanList span:nth-child(1)', 'to', '81') |
| 622 | ->attr_is('spanList span:nth-child(1)', 'l', '7') |
| 623 | ; |
| 624 | }; |
| 625 | |
Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 626 | subtest 'Check Inline annotations with untagged file' => sub { |
| 627 | |
| 628 | # Load example file |
| 629 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 630 | |
| 631 | my ($fh, $outzip) = korap_tempfile('script_untagged'); |
| 632 | |
| 633 | # Generate zip file (unportable!) |
| 634 | stderr_like( |
Akron | a2cb281 | 2021-10-30 10:29:08 +0200 | [diff] [blame^] | 635 | sub { `cat '$file' | perl '$script' --skip-token-inline-annotations=0 - > '$outzip'` }, |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 636 | qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!, |
Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 637 | 'Processing 1' |
| 638 | ); |
| 639 | |
| 640 | # TODO: there should be a better way to test this |
| 641 | stderr_unlike( |
Akron | a2cb281 | 2021-10-30 10:29:08 +0200 | [diff] [blame^] | 642 | sub { `cat '$file' | perl '$script' --skip-token-inline-annotations=0 - > '$outzip'` }, |
Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 643 | qr!.*undefined value.*!, |
| 644 | 'Processing 2' |
| 645 | ); |
| 646 | # |
| 647 | |
| 648 | ok(-e $outzip, "File $outzip exists"); |
| 649 | |
| 650 | my $zip = IO::Uncompress::Unzip->new( |
| 651 | $outzip, |
| 652 | Name => 'GOE/AGA/00000/tokens/morpho.xml' |
| 653 | ); |
| 654 | ok((not $zip), 'missing morpho.xml'); |
| 655 | |
| 656 | $zip = IO::Uncompress::Unzip->new( |
| 657 | $outzip, |
| 658 | Name => 'GOE/AGA/00000/struct/structure.xml' |
| 659 | ); |
| 660 | ok($zip, 'found structure.xml'); |
| 661 | }; |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 662 | |
Akron | 3378dfd | 2020-08-01 15:01:36 +0200 | [diff] [blame] | 663 | |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 664 | subtest 'Check input encoding' => sub { |
| 665 | |
| 666 | # Load example file |
| 667 | test_tei2korapxml( |
| 668 | file => catfile($f, 'data', 'goe_sample.i5.xml'), |
Akron | 692d17d | 2021-03-05 13:21:03 +0100 | [diff] [blame] | 669 | tmp => 'script_utf8_enc', |
| 670 | param => '--skip-inline-token-annotations=0', |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 671 | ) |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 672 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 673 | ->unzip_xml('GOE/AGA/00000/data.xml') |
| 674 | ->content_like(qr/\Q"Kriegstheater"\E/) |
| 675 | ->content_like(qr/\QTür'\E/) |
| 676 | ; |
| 677 | |
| 678 | test_tei2korapxml( |
| 679 | file => catfile($f, 'data', 'goe_sample.i5.iso.xml'), |
Akron | 692d17d | 2021-03-05 13:21:03 +0100 | [diff] [blame] | 680 | param => '--skip-inline-token-annotations=0', |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 681 | tmp => 'script_iso_enc' |
| 682 | ) |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 683 | ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!) |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 684 | ->unzip_xml('GOE/AGA/00000/data.xml') |
| 685 | ->content_like(qr/\Q"Kriegstheater"\E/) |
| 686 | ->content_like(qr/\QTür'\E/) |
| 687 | ; |
| 688 | }; |
| 689 | |
Marc Kupietz | 44b1f25 | 2020-11-26 16:31:40 +0100 | [diff] [blame] | 690 | subtest 'Check encoding with utf-8 sigle' => sub { |
| 691 | |
| 692 | # Load example file |
| 693 | my $file = catfile($f, 'data', 'wdd_sample.i5.xml'); |
| 694 | |
| 695 | my $t = test_tei2korapxml( |
| 696 | tmp => 'script_sigle', |
| 697 | file => $file, |
| 698 | param => "-ti" |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 699 | )->stderr_like(qr!tei2korapxml:.*? text_id=WDD19_ß0000\.10317!) |
Marc Kupietz | 44b1f25 | 2020-11-26 16:31:40 +0100 | [diff] [blame] | 700 | ->stderr_unlike(qr!Debugging is activated!); |
| 701 | |
| 702 | $t->unzip_xml('WDD19/ß0000/10317/header.xml') |
| 703 | ->text_is('idsHeader fileDesc titleStmt textSigle', 'WDD19/ß0000.10317'); |
| 704 | |
| 705 | $t->unzip_xml('WDD19/ß0000/10317/data.xml') |
| 706 | ->attr_is('raw_text', 'docid', 'WDD19_ß0000.10317'); |
| 707 | |
| 708 | $t->unzip_xml('WDD19/ß0000/10317/struct/structure.xml') |
| 709 | ->attr_is('layer', 'docid', 'WDD19_ß0000.10317'); |
| 710 | |
| 711 | $t->unzip_xml('WDD19/ß0000/10317/base/tokens_conservative.xml') |
| 712 | ->attr_is('layer', 'docid', 'WDD19_ß0000.10317'); |
| 713 | }; |
| 714 | |
Marc Kupietz | 8a954e5 | 2021-02-16 22:03:07 +0100 | [diff] [blame] | 715 | subtest 'Check entity replacement' => sub { |
| 716 | my $t = test_tei2korapxml( |
| 717 | file => catfile($f, 'data', 'text_with_entities.i5.xml'), |
| 718 | tmp => 'script_entity_replacement', |
| 719 | param => '-ti' |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame] | 720 | )->stderr_like(qr!tei2korapxml:.*? text_id=CORP_DOC.00003!); |
Marc Kupietz | 8a954e5 | 2021-02-16 22:03:07 +0100 | [diff] [blame] | 721 | |
| 722 | $t->unzip_xml('CORP/DOC/00003/data.xml') |
| 723 | ->content_like(qr!üüü Aα≈„▒░▓█╗┐┌╔═─┬╦┴╩╝┘└╚│║┼╬┤╣╠├•ˇčˆ†‡ě€ƒ…‗ıι“„▄‹‘‚—–νœŒωΩ‰φπϖř”ρ›’‘šŠσ□■▪⊂˜™▀ŸžŽ!); |
| 724 | |
| 725 | $t->unzip_xml('CORP/DOC/00003/header.xml') |
| 726 | ->content_like(qr!üüü x α•α y!); |
| 727 | }; |
| 728 | |
Akron | 3378dfd | 2020-08-01 15:01:36 +0200 | [diff] [blame] | 729 | subtest 'Test Log' => sub { |
| 730 | test_tei2korapxml( |
| 731 | tmp => 'script_out', |
| 732 | file => $file, |
| 733 | param => '-l=warn' |
| 734 | )->stderr_is(''); |
| 735 | }; |
| 736 | |
| 737 | |
Akron | 5986da3 | 2021-10-01 12:53:55 +0200 | [diff] [blame] | 738 | subtest 'Broken data testing' => sub { |
| 739 | my $file = catfile($f, 'data', 'wikipedia.txt'); |
| 740 | |
| 741 | my $t = test_tei2korapxml( |
| 742 | tmp => 'script_ginkgo', |
| 743 | file => $file, |
| 744 | param => '-ti', |
| 745 | env => 'KORAPXMLTEI_DEBUG=1' |
| 746 | )->stderr_like(qr!No opened zip file to close!) |
| 747 | ->stderr_like(qr!Debugging is activated!); |
| 748 | }; |
| 749 | |
| 750 | |
Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 751 | done_testing; |