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 | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 37 | subtest 'Basic processing' => sub { |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 38 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 39 | my $t = test_tei2korapxml( |
| 40 | tmp => 'script_out', |
| 41 | file => $file, |
| 42 | param => '-ti' |
| 43 | )->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 44 | |
Akron | 6896608 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 45 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 46 | # Uncompress GOE/header.xml from zip file |
| 47 | $t->unzip_xml('GOE/header.xml') |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 48 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 49 | # TODO: check wrong encoding in header-files (compare with input document)! |
| 50 | ->text_is('korpusSigle', 'GOE', 'korpusSigle') |
| 51 | ->text_is('h\.title[type=main]', 'Goethes Werke', 'h.title') |
| 52 | ->text_is('h\.author', 'Goethe, Johann Wolfgang von', 'h.author') |
| 53 | ->text_is('pubDate[type=year]', '1982', 'pubDate'); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 54 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 55 | # Uncompress GOE/AGA/header.xml from zip file |
| 56 | $t->unzip_xml('GOE/AGA/header.xml') |
| 57 | ->text_is('dokumentSigle', 'GOE/AGA', 'dokumentSigle') |
| 58 | ->text_is('d\.title', 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)', 'd.title') |
| 59 | ->text_is('creatDate', '1820-1822', 'creatDate'); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 60 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 61 | # Uncompress GOE/AGA/00000/header.xml from zip file |
| 62 | $t->unzip_xml('GOE/AGA/00000/header.xml') |
| 63 | ->text_is('textSigle', 'GOE/AGA.00000', 'textSigle') |
| 64 | ->text_is('analytic > h\.title[type=main]', 'Campagne in Frankreich', 'h.title'); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 65 | |
| 66 | # Uncompress GOE/AGA/00000/data.xml from zip file |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 67 | $t->unzip_xml('GOE/AGA/00000/data.xml') |
| 68 | ->attr_is('raw_text', 'docid', 'GOE_AGA.00000', 'text id') |
Akron | c57625b | 2020-07-30 11:46:06 +0200 | [diff] [blame] | 69 | ->text_like('raw_text > text', qr!^Campagne in Frankreich 1792.*?uns allein begl.*cke\.$!, 'text content'); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 70 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 71 | $t->unzip_xml('GOE/AGA/00000/struct/structure.xml') |
Akron | c57625b | 2020-07-30 11:46:06 +0200 | [diff] [blame] | 72 | ->text_is('span[id=s3] *[name=type]', 'Autobiographie', 'text content') |
| 73 | ->text_is('#s3 *[name=type]', 'Autobiographie', 'text content') |
| 74 | ->attr_is('#s0','to','1266') |
| 75 | ->attr_is('#s0','l','1') |
| 76 | |
| 77 | ->attr_is('#s18','from','925') |
| 78 | ->attr_is('#s18','to','1266') |
| 79 | ->attr_is('#s18','l','5') |
| 80 | ->attr_is('#s18 > fs','type', 'struct') |
| 81 | ->attr_is('#s18 > fs > f','name','name') |
| 82 | ->text_is('#s18 > fs > f','poem') |
| 83 | |
| 84 | ->attr_is('#s19','from','925') |
| 85 | ->attr_is('#s19','to','1098') |
| 86 | ->attr_is('#s19','l','6') |
| 87 | ->attr_is('#s19 > fs','type','struct') |
| 88 | ->text_is('#s19 > fs > f[name=name]','lg') |
| 89 | ->text_is('#s19 > fs > f[name=attr] > fs[type=attr] >f[name=part]','u') |
| 90 | |
| 91 | ->attr_is('#s37','from','1229') |
| 92 | ->attr_is('#s37','to','1266') |
| 93 | ->attr_is('#s37','l','8') |
| 94 | ->attr_is('#s37 > fs','type','struct') |
| 95 | ->text_is('#s37 > fs > f[name=name]','s') |
| 96 | ->text_is('#s37 > fs > f[name=attr] > fs[type=attr] > f[name=type]','manual') |
| 97 | |
| 98 | ->attr_is('#s38','from','1266') |
| 99 | ->attr_is('#s38','to','1266') |
| 100 | ->attr_is('#s38','l','2') |
| 101 | ->attr_is('#s38 > fs','type','struct') |
| 102 | ->text_is('#s38 > fs > f[name=name]','back') |
| 103 | ->element_count_is('', 196); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 104 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 105 | $t->file_exists_not('GOE/AGA/00000/base/tokens.xml', 'External not generated'); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 106 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 107 | # Uncompress GOE/AGA/00000/base/tokens_aggressive.xml from zip file |
| 108 | $t->unzip_xml('GOE/AGA/00000/base/tokens_aggressive.xml') |
| 109 | ->attr_is('spanList span:nth-child(1)', 'to', 8) |
| 110 | ->attr_is('spanList span#t_1', 'from', 9) |
| 111 | ->attr_is('spanList span#t_1', 'to', 11) |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 112 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 113 | ->attr_is('spanList span#t_67', 'from', 427) |
| 114 | ->attr_is('spanList span#t_67', 'to', 430) |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 115 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 116 | ->attr_is('spanList span#t_214', 'from', 1209) |
| 117 | ->attr_is('spanList span#t_214', 'to', 1212) |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 118 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 119 | ->element_count_is('spanList span', 227); |
Peter Harders | 57c884e | 2020-07-16 01:28:52 +0200 | [diff] [blame] | 120 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 121 | # Uncompress GOE/AGA/00000/base/tokens_conservative.xml from zip file |
| 122 | $t->unzip_xml('GOE/AGA/00000/base/tokens_conservative.xml') |
| 123 | ->attr_is('spanList span:nth-child(1)', 'to', 8) |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 124 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 125 | ->attr_is('spanList span#t_1', 'from', 9) |
| 126 | ->attr_is('spanList span#t_1', 'to', 11) |
Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 127 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 128 | ->attr_is('spanList span#t_67', 'from', 427) |
| 129 | ->attr_is('spanList span#t_67', 'to', 430) |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 130 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 131 | ->attr_is('spanList span#t_214', 'from', 1209) |
| 132 | ->attr_is('spanList span#t_214', 'to', 1212) |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 133 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 134 | ->element_count_is('spanList span', 227); |
| 135 | }; |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 136 | |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 137 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 138 | subtest 'Tokenize with external tokenizer' => sub { |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 139 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 140 | my $cmd = catfile($f, 'cmd', 'tokenizer.pl'); |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 141 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 142 | test_tei2korapxml( |
| 143 | file => $file, |
| 144 | param => "-tc='perl $cmd'", |
| 145 | tmp => 'script_out2' |
| 146 | ) |
| 147 | ->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!) |
| 148 | ->file_readable('GOE/AGA/00000/base/tokens.xml') |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 149 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 150 | # Uncompress GOE/AGA/00000/base/tokens.xml from zip file |
| 151 | ->unzip_xml('GOE/AGA/00000/base/tokens.xml') |
| 152 | ->attr_is('spanList span:nth-child(1)', 'to', 8) |
| 153 | ->attr_is('spanList span#t_1', 'from', 9) |
| 154 | ->attr_is('spanList span#t_1', 'to', 11) |
| 155 | ->attr_is('spanList span#t_67', 'from', 427) |
| 156 | ->attr_is('spanList span#t_67', 'to', 430) |
| 157 | ->attr_is('spanList span#t_214', 'from', 1209) |
| 158 | ->attr_is('spanList span#t_214', 'to', 1212) |
| 159 | ->element_count_is('spanList span', 227); |
| 160 | }; |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 161 | |
| 162 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 163 | subtest 'Test Tokenizations' => sub { |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 164 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 165 | my $t = test_tei2korapxml( |
| 166 | file => catfile($f, 'data', 'text_with_blanks.i5.xml'), |
| 167 | tmp => 'script_out3', |
| 168 | param => '-ti' |
| 169 | )->stderr_like(qr!tei2korapxml: .*? text_id=CORP_DOC.00001!); |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 170 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 171 | # ~ test conservative tokenization ~ |
| 172 | $t->unzip_xml('CORP/DOC/00001/base/tokens_conservative.xml') |
| 173 | ->attr_is('spanList span:nth-child(1)', 'to', 6) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 174 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 175 | ->attr_is('spanList span#t_1', 'from', 7) |
| 176 | ->attr_is('spanList span#t_1', 'to', 9) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 177 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 178 | ->attr_is('spanList span#t_3', 'from', 12) |
| 179 | ->attr_is('spanList span#t_3', 'to', 16) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 180 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 181 | ->attr_is('spanList span#t_9', 'from', 36) |
| 182 | ->attr_is('spanList span#t_9', 'to', 37) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 183 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 184 | ->attr_is('spanList span#t_13', 'from', 44) |
| 185 | ->attr_is('spanList span#t_13', 'to', 45) # " |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 186 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 187 | ->attr_is('spanList span#t_14', 'from', 45) # twenty-two |
| 188 | ->attr_is('spanList span#t_14', 'to', 55) |
Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 189 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 190 | ->attr_is('spanList span#t_15', 'from', 55) # " |
| 191 | ->attr_is('spanList span#t_15', 'to', 56) |
Akron | 8b511f9 | 2020-07-09 17:28:08 +0200 | [diff] [blame] | 192 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 193 | ->attr_is('spanList span#t_19', 'from', 66) |
| 194 | ->attr_is('spanList span#t_19', 'to', 67) |
Peter Harders | b122717 | 2020-07-21 02:12:10 +0200 | [diff] [blame] | 195 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 196 | ->element_count_is('spanList span', 20); |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 197 | |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 198 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 199 | # ~ test aggressive tokenization ~ |
| 200 | $t->unzip_xml('CORP/DOC/00001/base/tokens_aggressive.xml') |
| 201 | ->attr_is('spanList span:nth-child(1)', 'to', 6) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 202 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 203 | ->attr_is('spanList span#t_1', 'from', 7) |
| 204 | ->attr_is('spanList span#t_1', 'to', 9) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 205 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 206 | ->attr_is('spanList span#t_3', 'from', 12) |
| 207 | ->attr_is('spanList span#t_3', 'to', 16) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 208 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 209 | ->attr_is('spanList span#t_9', 'from', 36) |
| 210 | ->attr_is('spanList span#t_9', 'to', 37) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 211 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 212 | ->attr_is('spanList span#t_13', 'from', 44) |
| 213 | ->attr_is('spanList span#t_13', 'to', 45) # " |
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 | ->attr_is('spanList span#t_14', 'from', 45) # twenty |
| 216 | ->attr_is('spanList span#t_14', 'to', 51) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 217 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 218 | ->attr_is('spanList span#t_15', 'from', 51) # - |
| 219 | ->attr_is('spanList span#t_15', 'to', 52) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 220 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 221 | ->attr_is('spanList span#t_16', 'from', 52) # two |
| 222 | ->attr_is('spanList span#t_16', 'to', 55) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 223 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 224 | ->attr_is('spanList span#t_17', 'from', 55) # " |
| 225 | ->attr_is('spanList span#t_17', 'to', 56) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 226 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 227 | ->attr_is('spanList span#t_21', 'from', 66) |
| 228 | ->attr_is('spanList span#t_21', 'to', 67) |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 229 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 230 | ->element_count_is('spanList span', 22); |
| 231 | }; |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 232 | |
| 233 | |
Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 234 | subtest 'Check Tokenization Flags' => sub { |
| 235 | |
| 236 | # Get external tokenizer |
| 237 | my $f = dirname(__FILE__); |
| 238 | my $cmd = catfile($f, 'cmd', 'tokenizer.pl'); |
| 239 | |
| 240 | # Load example file |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 241 | test_tei2korapxml( |
| 242 | file => catfile($f, 'data', 'goe_sample.i5.xml'), |
| 243 | param => "-ti -tc 'perl $cmd'", |
| 244 | tmp => 'script_tokflags' |
| 245 | ) |
| 246 | ->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!) |
| 247 | ->file_exists('GOE/AGA/00000/base/tokens_aggressive.xml') |
| 248 | ->file_exists('GOE/AGA/00000/base/tokens_conservative.xml') |
| 249 | ->file_exists('GOE/AGA/00000/base/tokens.xml') |
| 250 | ; |
Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 251 | }; |
| 252 | |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 253 | |
| 254 | subtest 'Test utf-8 handling' => sub { |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 255 | # Introduce invalid utf-8 characters |
| 256 | my $text_sigle; |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 257 | { |
| 258 | no warnings; |
| 259 | # $text_sigle printed to file, without encoding: Aþ¿¿¿¿¿A_Bþ¿¿¿¿¿B.Cþ¿¿¿¿¿C |
| 260 | # the utf8-sequence 'þ¿¿¿¿¿' encodes 32 bit of data (see 0x7FFF_FFFF in perlunicode) |
| 261 | $text_sigle = "A\x{FFFF_FFFF}A_B\x{FFFF_FFFF}B.C\x{FFFF_FFFF}C" |
| 262 | } |
| 263 | # If CHECK is 0, encoding and decoding replace any malformed character |
| 264 | # with a substitution character. |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 265 | # � = substitution character |
| 266 | my $text_sigle_lax = encode_utf8($text_sigle); |
| 267 | my $text_sigle_esc = encode('UTF-8', $text_sigle); |
| 268 | |
| 269 | is(length($text_sigle), 11); # A�A_B�B.C�C (char string => length(�) = 1) |
| 270 | is(length($text_sigle_lax), 29); # Aþ¿¿¿¿¿A_Bþ¿¿¿¿¿B.Cþ¿¿¿¿¿C (byte string) |
| 271 | is(length($text_sigle_esc), 17); # A�A_B�B.C�C (byte string => length(�) = 3) |
| 272 | |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 273 | |
| 274 | my $tpl; |
| 275 | { |
| 276 | no warnings; |
| 277 | $tpl = i5_template( |
| 278 | korpusSigle => "A\x{FFFF_FFFF}A", |
| 279 | dokumentSigle => "A\x{FFFF_FFFF}A_B\x{FFFF_FFFF}B", |
| 280 | text => "<p>d\x{FFFF_FFFF}d e\x{FFFF_FFFF}e f\x{FFFF_FFFF}f</p>", |
| 281 | textSigle => $text_sigle |
| 282 | ); |
| 283 | }; |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 284 | |
| 285 | my ($fh, $tplfile) = korap_tempfile('script_out4'); |
| 286 | binmode($fh); |
| 287 | print $fh encode_utf8($tpl); # => text_id=Aþ¿¿¿¿¿A_Bþ¿¿¿¿¿B.Cþ¿¿¿¿¿C |
| 288 | close($fh); |
| 289 | |
| 290 | my (undef, $outzip) = korap_tempfile('script_out5'); |
| 291 | |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 292 | # because output 'textid=...' goes to STDERR (see script/tei2korapxml) |
| 293 | binmode STDERR, qw{ :encoding(UTF-8) }; |
Peter Harders | 1c5ce15 | 2020-07-22 18:02:50 +0200 | [diff] [blame] | 294 | |
| 295 | stderr_like( |
| 296 | sub { `cat '$tplfile' | perl '$script' -ti > '$outzip'` }, |
| 297 | qr!tei2korapxml: .*? text_id=$text_sigle_lax!, # see above: print $fh encode_utf8($tpl); |
| 298 | ); |
| 299 | }; |
| 300 | |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 301 | |
| 302 | subtest 'Check Inline annotations' => sub { |
| 303 | |
| 304 | # Load example file |
| 305 | my $file = catfile($f, 'data', 'goe_sample_tagged.i5.xml'); |
| 306 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 307 | my $t = test_tei2korapxml( |
| 308 | file => $file, |
| 309 | env => 'KORAPXMLTEI_INLINE=1', |
| 310 | tmp => 'script_tagged' |
| 311 | ) |
| 312 | ->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!) |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 313 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 314 | # Check zip using xml loy |
| 315 | ->unzip_xml('GOE/AGA/00000/tokens/morpho.xml') |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 316 | |
Akron | 044bd92 | 2020-07-30 09:12:28 +0200 | [diff] [blame] | 317 | ->attr_is('layer', 'docid', 'GOE_AGA.00000') |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 318 | ->attr_is('spanList span:nth-child(1)', 'id', 's0') |
| 319 | ->attr_is('spanList span:nth-child(1)', 'from', '75') |
| 320 | ->attr_is('spanList span:nth-child(1)', 'to', '81') |
| 321 | ->attr_is('spanList span:nth-child(1)', 'l', '7') |
| 322 | |
| 323 | ->attr_is('span#s0 > fs', 'type', 'lex') |
| 324 | ->attr_is('span#s0 > fs', 'xmlns', 'http://www.tei-c.org/ns/1.0') |
| 325 | ->attr_is('span#s0 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 326 | ->text_is('span#s0 > fs > f > fs > f:nth-child(1)', 'A') |
| 327 | ->attr_is('span#s0 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 328 | ->text_is('span#s0 > fs > f > fs > f:nth-child(2)', '@NH') |
| 329 | |
| 330 | ->attr_is('span#s25', 'from', '259') |
| 331 | ->attr_is('span#s25', 'to', '263') |
| 332 | ->attr_is('span#s25', 'l', '7') |
| 333 | ->attr_is('span#s25 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 334 | ->text_is('span#s25 > fs > f > fs > f:nth-child(1)', 'PRON') |
| 335 | ->attr_is('span#s25 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 336 | ->text_is('span#s25 > fs > f > fs > f:nth-child(2)', '@NH') |
| 337 | |
| 338 | ->attr_is('span#s58', 'from', '495') |
| 339 | ->attr_is('span#s58', 'to', '500') |
| 340 | ->attr_is('span#s58', 'l', '7') |
| 341 | ->attr_is('span#s58 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 342 | ->text_is('span#s58 > fs > f > fs > f:nth-child(1)', 'N') |
| 343 | ->attr_is('span#s58 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 344 | ->text_is('span#s58 > fs > f > fs > f:nth-child(2)', '@NH') |
| 345 | |
| 346 | ->attr_is('span#s119', 'from', '914') |
| 347 | ->attr_is('span#s119', 'to', '925') |
| 348 | ->attr_is('span#s119', 'l', '7') |
| 349 | ->attr_is('span#s119 > fs > f > fs > f:nth-child(1)', 'name', 'pos') |
| 350 | ->text_is('span#s119 > fs > f > fs > f:nth-child(1)', 'A') |
| 351 | ->attr_is('span#s119 > fs > f > fs > f:nth-child(2)', 'name', 'msd') |
| 352 | ->text_is('span#s119 > fs > f > fs > f:nth-child(2)', '@NH') |
| 353 | ->element_exists_not('span#s120') |
| 354 | ; |
| 355 | }; |
| 356 | |
Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 357 | subtest 'Check Inline annotations with untagged file' => sub { |
| 358 | |
| 359 | # Load example file |
| 360 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 361 | |
| 362 | my ($fh, $outzip) = korap_tempfile('script_untagged'); |
| 363 | |
| 364 | # Generate zip file (unportable!) |
| 365 | stderr_like( |
| 366 | sub { `cat '$file' | KORAPXMLTEI_INLINE=1 perl '$script' > '$outzip'` }, |
| 367 | qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!, |
| 368 | 'Processing 1' |
| 369 | ); |
| 370 | |
| 371 | # TODO: there should be a better way to test this |
| 372 | stderr_unlike( |
| 373 | sub { `cat '$file' | KORAPXMLTEI_INLINE=1 perl '$script' > '$outzip'` }, |
| 374 | qr!.*undefined value.*!, |
| 375 | 'Processing 2' |
| 376 | ); |
| 377 | # |
| 378 | |
| 379 | ok(-e $outzip, "File $outzip exists"); |
| 380 | |
| 381 | my $zip = IO::Uncompress::Unzip->new( |
| 382 | $outzip, |
| 383 | Name => 'GOE/AGA/00000/tokens/morpho.xml' |
| 384 | ); |
| 385 | ok((not $zip), 'missing morpho.xml'); |
| 386 | |
| 387 | $zip = IO::Uncompress::Unzip->new( |
| 388 | $outzip, |
| 389 | Name => 'GOE/AGA/00000/struct/structure.xml' |
| 390 | ); |
| 391 | ok($zip, 'found structure.xml'); |
| 392 | }; |
Akron | e68ec0c | 2020-07-28 18:06:19 +0200 | [diff] [blame] | 393 | |
Akron | 3378dfd | 2020-08-01 15:01:36 +0200 | [diff] [blame^] | 394 | |
| 395 | subtest 'Test Log' => sub { |
| 396 | test_tei2korapxml( |
| 397 | tmp => 'script_out', |
| 398 | file => $file, |
| 399 | param => '-l=warn' |
| 400 | )->stderr_is(''); |
| 401 | }; |
| 402 | |
| 403 | |
Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 404 | done_testing; |