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