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' |
| 44 | )->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!) |
| 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 | b364947 | 2020-09-29 08:24:46 +0200 | [diff] [blame] | 54 | )->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!) |
| 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') |
| 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 | ) |
| 163 | ->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!) |
| 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 | |
| 178 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 179 | subtest 'Test Tokenizations' => sub { |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 180 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 181 | my $t = test_tei2korapxml( |
| 182 | file => catfile($f, 'data', 'text_with_blanks.i5.xml'), |
| 183 | tmp => 'script_out3', |
| 184 | param => '-ti' |
| 185 | )->stderr_like(qr!tei2korapxml: .*? text_id=CORP_DOC.00001!); |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 186 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 187 | # ~ test conservative tokenization ~ |
| 188 | $t->unzip_xml('CORP/DOC/00001/base/tokens_conservative.xml') |
| 189 | ->attr_is('spanList span:nth-child(1)', 'to', 6) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 190 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 191 | ->attr_is('spanList span#t_1', 'from', 7) |
| 192 | ->attr_is('spanList span#t_1', 'to', 9) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 193 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 194 | ->attr_is('spanList span#t_3', 'from', 12) |
| 195 | ->attr_is('spanList span#t_3', 'to', 16) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 196 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 197 | ->attr_is('spanList span#t_9', 'from', 36) |
| 198 | ->attr_is('spanList span#t_9', 'to', 37) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 199 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 200 | ->attr_is('spanList span#t_13', 'from', 44) |
| 201 | ->attr_is('spanList span#t_13', 'to', 45) # " |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 202 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 203 | ->attr_is('spanList span#t_14', 'from', 45) # twenty-two |
| 204 | ->attr_is('spanList span#t_14', 'to', 55) |
Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 205 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 206 | ->attr_is('spanList span#t_15', 'from', 55) # " |
| 207 | ->attr_is('spanList span#t_15', 'to', 56) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 208 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 209 | ->attr_is('spanList span#t_19', 'from', 66) |
| 210 | ->attr_is('spanList span#t_19', 'to', 67) |
Peter Harders | b122717 | 2020-07-21 02:12:10 +0200 | [diff] [blame] | 211 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 212 | ->element_count_is('spanList span', 20); |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 213 | |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 214 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 215 | # ~ test aggressive tokenization ~ |
| 216 | $t->unzip_xml('CORP/DOC/00001/base/tokens_aggressive.xml') |
| 217 | ->attr_is('spanList span:nth-child(1)', 'to', 6) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 218 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 219 | ->attr_is('spanList span#t_1', 'from', 7) |
| 220 | ->attr_is('spanList span#t_1', 'to', 9) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 221 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 222 | ->attr_is('spanList span#t_3', 'from', 12) |
| 223 | ->attr_is('spanList span#t_3', 'to', 16) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 224 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 225 | ->attr_is('spanList span#t_9', 'from', 36) |
| 226 | ->attr_is('spanList span#t_9', 'to', 37) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 227 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 228 | ->attr_is('spanList span#t_13', 'from', 44) |
| 229 | ->attr_is('spanList span#t_13', 'to', 45) # " |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 230 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 231 | ->attr_is('spanList span#t_14', 'from', 45) # twenty |
| 232 | ->attr_is('spanList span#t_14', 'to', 51) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 233 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 234 | ->attr_is('spanList span#t_15', 'from', 51) # - |
| 235 | ->attr_is('spanList span#t_15', 'to', 52) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 236 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 237 | ->attr_is('spanList span#t_16', 'from', 52) # two |
| 238 | ->attr_is('spanList span#t_16', 'to', 55) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 239 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 240 | ->attr_is('spanList span#t_17', 'from', 55) # " |
| 241 | ->attr_is('spanList span#t_17', 'to', 56) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 242 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 243 | ->attr_is('spanList span#t_21', 'from', 66) |
| 244 | ->attr_is('spanList span#t_21', 'to', 67) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 245 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 246 | ->element_count_is('spanList span', 22); |
| 247 | }; |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 248 | |
| 249 | |
Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 250 | subtest 'Check Tokenization Flags' => sub { |
| 251 | |
| 252 | # Get external tokenizer |
| 253 | my $f = dirname(__FILE__); |
| 254 | my $cmd = catfile($f, 'cmd', 'tokenizer.pl'); |
| 255 | |
| 256 | # Load example file |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 257 | test_tei2korapxml( |
| 258 | file => catfile($f, 'data', 'goe_sample.i5.xml'), |
| 259 | param => "-ti -tc 'perl $cmd'", |
| 260 | tmp => 'script_tokflags' |
| 261 | ) |
| 262 | ->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!) |
| 263 | ->file_exists('GOE/AGA/00000/base/tokens_aggressive.xml') |
| 264 | ->file_exists('GOE/AGA/00000/base/tokens_conservative.xml') |
| 265 | ->file_exists('GOE/AGA/00000/base/tokens.xml') |
| 266 | ; |
Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 267 | }; |
| 268 | |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 269 | |
| 270 | subtest 'Test utf-8 handling' => sub { |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 271 | # Introduce invalid utf-8 characters |
| 272 | my $text_sigle; |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 273 | { |
| 274 | no warnings; |
| 275 | # $text_sigle printed to file, without encoding: Aþ¿¿¿¿¿A_Bþ¿¿¿¿¿B.Cþ¿¿¿¿¿C |
| 276 | # the utf8-sequence 'þ¿¿¿¿¿' encodes 32 bit of data (see 0x7FFF_FFFF in perlunicode) |
| 277 | $text_sigle = "A\x{FFFF_FFFF}A_B\x{FFFF_FFFF}B.C\x{FFFF_FFFF}C" |
| 278 | } |
| 279 | # If CHECK is 0, encoding and decoding replace any malformed character |
| 280 | # with a substitution character. |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 281 | # � = substitution character |
| 282 | my $text_sigle_lax = encode_utf8($text_sigle); |
| 283 | my $text_sigle_esc = encode('UTF-8', $text_sigle); |
| 284 | |
| 285 | is(length($text_sigle), 11); # A�A_B�B.C�C (char string => length(�) = 1) |
| 286 | is(length($text_sigle_lax), 29); # Aþ¿¿¿¿¿A_Bþ¿¿¿¿¿B.Cþ¿¿¿¿¿C (byte string) |
| 287 | is(length($text_sigle_esc), 17); # A�A_B�B.C�C (byte string => length(�) = 3) |
| 288 | |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 289 | |
| 290 | my $tpl; |
| 291 | { |
| 292 | no warnings; |
| 293 | $tpl = i5_template( |
| 294 | korpusSigle => "A\x{FFFF_FFFF}A", |
| 295 | dokumentSigle => "A\x{FFFF_FFFF}A_B\x{FFFF_FFFF}B", |
| 296 | text => "<p>d\x{FFFF_FFFF}d e\x{FFFF_FFFF}e f\x{FFFF_FFFF}f</p>", |
| 297 | textSigle => $text_sigle |
| 298 | ); |
| 299 | }; |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 300 | |
| 301 | my ($fh, $tplfile) = korap_tempfile('script_out4'); |
| 302 | binmode($fh); |
| 303 | print $fh encode_utf8($tpl); # => text_id=Aþ¿¿¿¿¿A_Bþ¿¿¿¿¿B.Cþ¿¿¿¿¿C |
| 304 | close($fh); |
| 305 | |
| 306 | my (undef, $outzip) = korap_tempfile('script_out5'); |
| 307 | |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 308 | # because output 'textid=...' goes to STDERR (see script/tei2korapxml) |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 309 | binmode STDERR; |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 310 | |
| 311 | stderr_like( |
| 312 | sub { `cat '$tplfile' | perl '$script' -ti > '$outzip'` }, |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 313 | 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] | 314 | ); |
| 315 | }; |
| 316 | |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 317 | |
| 318 | subtest 'Check Inline annotations' => sub { |
| 319 | |
| 320 | # Load example file |
| 321 | my $file = catfile($f, 'data', 'goe_sample_tagged.i5.xml'); |
| 322 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 323 | my $t = test_tei2korapxml( |
| 324 | file => $file, |
| 325 | env => 'KORAPXMLTEI_INLINE=1', |
| 326 | tmp => 'script_tagged' |
| 327 | ) |
| 328 | ->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!) |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 329 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 330 | # Check zip using xml loy |
| 331 | ->unzip_xml('GOE/AGA/00000/tokens/morpho.xml') |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 332 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 333 | ->attr_is('layer', 'docid', 'GOE_AGA.00000') |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 334 | ->attr_is('spanList span:nth-child(1)', 'id', 's0') |
| 335 | ->attr_is('spanList span:nth-child(1)', 'from', '75') |
| 336 | ->attr_is('spanList span:nth-child(1)', 'to', '81') |
| 337 | ->attr_is('spanList span:nth-child(1)', 'l', '7') |
| 338 | |
| 339 | ->attr_is('span#s0 > fs', 'type', 'lex') |
| 340 | ->attr_is('span#s0 > fs', 'xmlns', 'http://www.tei-c.org/ns/1.0') |
| 341 | ->attr_is('span#s0 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 342 | ->text_is('span#s0 > fs > f > fs > f:nth-child(1)', 'A') |
| 343 | ->attr_is('span#s0 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 344 | ->text_is('span#s0 > fs > f > fs > f:nth-child(2)', '@NH') |
| 345 | |
| 346 | ->attr_is('span#s25', 'from', '259') |
| 347 | ->attr_is('span#s25', 'to', '263') |
| 348 | ->attr_is('span#s25', 'l', '7') |
| 349 | ->attr_is('span#s25 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 350 | ->text_is('span#s25 > fs > f > fs > f:nth-child(1)', 'PRON') |
| 351 | ->attr_is('span#s25 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 352 | ->text_is('span#s25 > fs > f > fs > f:nth-child(2)', '@NH') |
| 353 | |
| 354 | ->attr_is('span#s58', 'from', '495') |
| 355 | ->attr_is('span#s58', 'to', '500') |
| 356 | ->attr_is('span#s58', 'l', '7') |
| 357 | ->attr_is('span#s58 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 358 | ->text_is('span#s58 > fs > f > fs > f:nth-child(1)', 'N') |
| 359 | ->attr_is('span#s58 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 360 | ->text_is('span#s58 > fs > f > fs > f:nth-child(2)', '@NH') |
| 361 | |
| 362 | ->attr_is('span#s119', 'from', '914') |
| 363 | ->attr_is('span#s119', 'to', '925') |
| 364 | ->attr_is('span#s119', 'l', '7') |
| 365 | ->attr_is('span#s119 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 366 | ->text_is('span#s119 > fs > f > fs > f:nth-child(1)', 'A') |
| 367 | ->attr_is('span#s119 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 368 | ->text_is('span#s119 > fs > f > fs > f:nth-child(2)', '@NH') |
| 369 | ->element_exists_not('span#s120') |
| 370 | ; |
| 371 | }; |
| 372 | |
Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 373 | subtest 'Check Inline annotations with untagged file' => sub { |
| 374 | |
| 375 | # Load example file |
| 376 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 377 | |
| 378 | my ($fh, $outzip) = korap_tempfile('script_untagged'); |
| 379 | |
| 380 | # Generate zip file (unportable!) |
| 381 | stderr_like( |
| 382 | sub { `cat '$file' | KORAPXMLTEI_INLINE=1 perl '$script' > '$outzip'` }, |
| 383 | qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!, |
| 384 | 'Processing 1' |
| 385 | ); |
| 386 | |
| 387 | # TODO: there should be a better way to test this |
| 388 | stderr_unlike( |
| 389 | sub { `cat '$file' | KORAPXMLTEI_INLINE=1 perl '$script' > '$outzip'` }, |
| 390 | qr!.*undefined value.*!, |
| 391 | 'Processing 2' |
| 392 | ); |
| 393 | # |
| 394 | |
| 395 | ok(-e $outzip, "File $outzip exists"); |
| 396 | |
| 397 | my $zip = IO::Uncompress::Unzip->new( |
| 398 | $outzip, |
| 399 | Name => 'GOE/AGA/00000/tokens/morpho.xml' |
| 400 | ); |
| 401 | ok((not $zip), 'missing morpho.xml'); |
| 402 | |
| 403 | $zip = IO::Uncompress::Unzip->new( |
| 404 | $outzip, |
| 405 | Name => 'GOE/AGA/00000/struct/structure.xml' |
| 406 | ); |
| 407 | ok($zip, 'found structure.xml'); |
| 408 | }; |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 409 | |
Akron | 3378dfd | 2020-08-01 15:01:36 +0200 | [diff] [blame] | 410 | |
Akron | eaa9623 | 2020-10-15 17:06:15 +0200 | [diff] [blame] | 411 | subtest 'Check input encoding' => sub { |
| 412 | |
| 413 | # Load example file |
| 414 | test_tei2korapxml( |
| 415 | file => catfile($f, 'data', 'goe_sample.i5.xml'), |
| 416 | env => 'KORAPXMLTEI_INLINE=1', |
| 417 | tmp => 'script_utf8_enc' |
| 418 | ) |
| 419 | ->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!) |
| 420 | ->unzip_xml('GOE/AGA/00000/data.xml') |
| 421 | ->content_like(qr/\Q"Kriegstheater"\E/) |
| 422 | ->content_like(qr/\QTür'\E/) |
| 423 | ; |
| 424 | |
| 425 | test_tei2korapxml( |
| 426 | file => catfile($f, 'data', 'goe_sample.i5.iso.xml'), |
| 427 | env => 'KORAPXMLTEI_INLINE=1', |
| 428 | tmp => 'script_iso_enc' |
| 429 | ) |
| 430 | ->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!) |
| 431 | ->unzip_xml('GOE/AGA/00000/data.xml') |
| 432 | ->content_like(qr/\Q"Kriegstheater"\E/) |
| 433 | ->content_like(qr/\QTür'\E/) |
| 434 | ; |
| 435 | }; |
| 436 | |
Marc Kupietz | 44b1f25 | 2020-11-26 16:31:40 +0100 | [diff] [blame] | 437 | subtest 'Check encoding with utf-8 sigle' => sub { |
| 438 | |
| 439 | # Load example file |
| 440 | my $file = catfile($f, 'data', 'wdd_sample.i5.xml'); |
| 441 | |
| 442 | my $t = test_tei2korapxml( |
| 443 | tmp => 'script_sigle', |
| 444 | file => $file, |
| 445 | param => "-ti" |
| 446 | )->stderr_like(qr!tei2korapxml: .*? text_id=WDD19_ß0000\.10317!) |
| 447 | ->stderr_unlike(qr!Debugging is activated!); |
| 448 | |
| 449 | $t->unzip_xml('WDD19/ß0000/10317/header.xml') |
| 450 | ->text_is('idsHeader fileDesc titleStmt textSigle', 'WDD19/ß0000.10317'); |
| 451 | |
| 452 | $t->unzip_xml('WDD19/ß0000/10317/data.xml') |
| 453 | ->attr_is('raw_text', 'docid', 'WDD19_ß0000.10317'); |
| 454 | |
| 455 | $t->unzip_xml('WDD19/ß0000/10317/struct/structure.xml') |
| 456 | ->attr_is('layer', 'docid', 'WDD19_ß0000.10317'); |
| 457 | |
| 458 | $t->unzip_xml('WDD19/ß0000/10317/base/tokens_conservative.xml') |
| 459 | ->attr_is('layer', 'docid', 'WDD19_ß0000.10317'); |
| 460 | }; |
| 461 | |
Akron | 3378dfd | 2020-08-01 15:01:36 +0200 | [diff] [blame] | 462 | subtest 'Test Log' => sub { |
| 463 | test_tei2korapxml( |
| 464 | tmp => 'script_out', |
| 465 | file => $file, |
| 466 | param => '-l=warn' |
| 467 | )->stderr_is(''); |
| 468 | }; |
| 469 | |
| 470 | |
Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 471 | done_testing; |