blob: 81067d9348c7732006bd3fb82325a79db41f8b3f [file] [log] [blame]
Akron797e8072020-02-13 07:59:40 +01001use strict;
2use warnings;
3use File::Basename 'dirname';
4use File::Spec::Functions qw/catfile/;
Peter Harders1c5ce152020-07-22 18:02:50 +02005use Encode qw!encode_utf8 decode_utf8 encode!;
Akron797e8072020-02-13 07:59:40 +01006
7use Test::More;
8use Test::Output;
Peter Harders42e18a62020-07-21 02:43:26 +02009
10use FindBin;
11BEGIN {
12 unshift @INC, "$FindBin::Bin/../lib";
13};
Peter Harders1c5ce152020-07-22 18:02:50 +020014
Akron044bd922020-07-30 09:12:28 +020015use Test::KorAP::XML::TEI qw!korap_tempfile i5_template test_tei2korapxml!;
Peter Harders57c884e2020-07-16 01:28:52 +020016
Akron797e8072020-02-13 07:59:40 +010017my $f = dirname(__FILE__);
18my $script = catfile($f, '..', 'script', 'tei2korapxml');
19ok(-f $script, 'Script found');
20
Akrond949e182020-02-14 12:23:57 +010021stdout_like(
Akron797e8072020-02-13 07:59:40 +010022 sub { system('perl', $script, '--help') },
Akrond949e182020-02-14 12:23:57 +010023 qr!This\s*program\s*is\s*usually\s*called\s*from\s*inside\s*another\s*script\.!,
Akron797e8072020-02-13 07:59:40 +010024 'Help'
25);
26
Akron044bd922020-07-30 09:12:28 +020027
Akrond949e182020-02-14 12:23:57 +010028stdout_like(
29 sub { system('perl', $script, '--version') },
30 qr!tei2korapxml - v\d+?\.\d+?!,
31 'Version'
32);
33
Akron2a60c532020-02-13 15:52:18 +010034# Load example file
35my $file = catfile($f, 'data', 'goe_sample.i5.xml');
Peter Harders57c884e2020-07-16 01:28:52 +020036
Akronb3649472020-09-29 08:24:46 +020037subtest '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
Akron044bd922020-07-30 09:12:28 +020048subtest 'Basic processing' => sub {
Akron2a60c532020-02-13 15:52:18 +010049
Akron044bd922020-07-30 09:12:28 +020050 my $t = test_tei2korapxml(
51 tmp => 'script_out',
52 file => $file,
53 param => '-ti'
Akronb3649472020-09-29 08:24:46 +020054 )->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!)
55 ->stderr_unlike(qr!Debugging is activated!);
Akron2a60c532020-02-13 15:52:18 +010056
Akron68966082020-02-13 15:52:18 +010057
Akron044bd922020-07-30 09:12:28 +020058 # Uncompress GOE/header.xml from zip file
59 $t->unzip_xml('GOE/header.xml')
Akron2a60c532020-02-13 15:52:18 +010060
Akron044bd922020-07-30 09:12:28 +020061 # 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');
Akron2a60c532020-02-13 15:52:18 +010066
Akron044bd922020-07-30 09:12:28 +020067 # 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');
Akron2a60c532020-02-13 15:52:18 +010072
Akron044bd922020-07-30 09:12:28 +020073 # 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');
Akron2a60c532020-02-13 15:52:18 +010077
78# Uncompress GOE/AGA/00000/data.xml from zip file
Akron044bd922020-07-30 09:12:28 +020079 $t->unzip_xml('GOE/AGA/00000/data.xml')
80 ->attr_is('raw_text', 'docid', 'GOE_AGA.00000', 'text id')
Marc Kupietzfd0e6a92020-09-09 18:07:29 +020081 ->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');
Akron2a60c532020-02-13 15:52:18 +010083
Akron417ed2f2020-09-28 12:43:17 +020084 my $content = $t->get_content_of('GOE/AGA/00000/data.xml');
85 like($content, qr!unter dem Titel "Kriegstheater"!, 'raw text content');
86
Akron044bd922020-07-30 09:12:28 +020087 $t->unzip_xml('GOE/AGA/00000/struct/structure.xml')
Akronc57625b2020-07-30 11:46:06 +020088 ->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')
Akronf7084c42021-01-07 10:25:22 +0100119 ->element_count_is('*', 196);
Akron2a60c532020-02-13 15:52:18 +0100120
Akron044bd922020-07-30 09:12:28 +0200121 $t->file_exists_not('GOE/AGA/00000/base/tokens.xml', 'External not generated');
Akron2a60c532020-02-13 15:52:18 +0100122
Akron044bd922020-07-30 09:12:28 +0200123 # 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)
Akron2a60c532020-02-13 15:52:18 +0100128
Akron044bd922020-07-30 09:12:28 +0200129 ->attr_is('spanList span#t_67', 'from', 427)
130 ->attr_is('spanList span#t_67', 'to', 430)
Akron2a60c532020-02-13 15:52:18 +0100131
Akron044bd922020-07-30 09:12:28 +0200132 ->attr_is('spanList span#t_214', 'from', 1209)
133 ->attr_is('spanList span#t_214', 'to', 1212)
Akron2a60c532020-02-13 15:52:18 +0100134
Akron044bd922020-07-30 09:12:28 +0200135 ->element_count_is('spanList span', 227);
Peter Harders57c884e2020-07-16 01:28:52 +0200136
Akron044bd922020-07-30 09:12:28 +0200137 # 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)
Akron2a60c532020-02-13 15:52:18 +0100140
Akron044bd922020-07-30 09:12:28 +0200141 ->attr_is('spanList span#t_1', 'from', 9)
142 ->attr_is('spanList span#t_1', 'to', 11)
Akron797e8072020-02-13 07:59:40 +0100143
Akron044bd922020-07-30 09:12:28 +0200144 ->attr_is('spanList span#t_67', 'from', 427)
145 ->attr_is('spanList span#t_67', 'to', 430)
Akroneac374d2020-07-07 09:00:44 +0200146
Akron044bd922020-07-30 09:12:28 +0200147 ->attr_is('spanList span#t_214', 'from', 1209)
148 ->attr_is('spanList span#t_214', 'to', 1212)
Akroneac374d2020-07-07 09:00:44 +0200149
Akron044bd922020-07-30 09:12:28 +0200150 ->element_count_is('spanList span', 227);
151};
Akroneac374d2020-07-07 09:00:44 +0200152
Akroneac374d2020-07-07 09:00:44 +0200153
Akron044bd922020-07-30 09:12:28 +0200154subtest 'Tokenize with external tokenizer' => sub {
Akroneac374d2020-07-07 09:00:44 +0200155
Akron044bd922020-07-30 09:12:28 +0200156 my $cmd = catfile($f, 'cmd', 'tokenizer.pl');
Akroneac374d2020-07-07 09:00:44 +0200157
Akron044bd922020-07-30 09:12:28 +0200158 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')
Akroneac374d2020-07-07 09:00:44 +0200165
Akron044bd922020-07-30 09:12:28 +0200166 # 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};
Akroneac374d2020-07-07 09:00:44 +0200177
Marc Kupietz985da0c2021-02-15 19:29:50 +0100178subtest 'Sentence split with KorAP tokenizer' => sub {
179
180 eval {
181 require KorAP::XML::TEI::Tokenizer::KorAP;
182 1;
183 } or do {
184 plan skip_all => "KorAP::XML::TEI::Tokenizer::KorAP cannot be used";
185 };
186
187 test_tei2korapxml(
188 file => $file,
189 param => "-tk -s",
190 tmp => 'script_sentence_split'
191 )
192 ->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!)
193 ->file_readable('GOE/AGA/00000/struct/structure.xml')
194 ->unzip_xml('GOE/AGA/00000/struct/structure.xml')
195 ->text_is('span#s25 fs f', 's')
196 ->attr_is('span#s25', 'l', -1)
197 ->attr_is('span#s25', 'to', 54)
198 ->text_is('span#s30 fs f', 's')
199 ->attr_is('span#s30', 'l', -1)
200 ->attr_is('span#s30', 'from', 1099)
201 ->attr_is('span#s30', 'to', 1266);
202};
Akroneac374d2020-07-07 09:00:44 +0200203
Akron044bd922020-07-30 09:12:28 +0200204subtest 'Test Tokenizations' => sub {
Akroneac374d2020-07-07 09:00:44 +0200205
Akron044bd922020-07-30 09:12:28 +0200206 my $t = test_tei2korapxml(
207 file => catfile($f, 'data', 'text_with_blanks.i5.xml'),
208 tmp => 'script_out3',
209 param => '-ti'
210 )->stderr_like(qr!tei2korapxml: .*? text_id=CORP_DOC.00001!);
Akron8b511f92020-07-09 17:28:08 +0200211
Akron044bd922020-07-30 09:12:28 +0200212 # ~ test conservative tokenization ~
213 $t->unzip_xml('CORP/DOC/00001/base/tokens_conservative.xml')
214 ->attr_is('spanList span:nth-child(1)', 'to', 6)
Akron8b511f92020-07-09 17:28:08 +0200215
Akron044bd922020-07-30 09:12:28 +0200216 ->attr_is('spanList span#t_1', 'from', 7)
217 ->attr_is('spanList span#t_1', 'to', 9)
Akron8b511f92020-07-09 17:28:08 +0200218
Akron044bd922020-07-30 09:12:28 +0200219 ->attr_is('spanList span#t_3', 'from', 12)
220 ->attr_is('spanList span#t_3', 'to', 16)
Akron8b511f92020-07-09 17:28:08 +0200221
Akron044bd922020-07-30 09:12:28 +0200222 ->attr_is('spanList span#t_9', 'from', 36)
223 ->attr_is('spanList span#t_9', 'to', 37)
Akron8b511f92020-07-09 17:28:08 +0200224
Akron044bd922020-07-30 09:12:28 +0200225 ->attr_is('spanList span#t_13', 'from', 44)
226 ->attr_is('spanList span#t_13', 'to', 45) # "
Akron8b511f92020-07-09 17:28:08 +0200227
Akron044bd922020-07-30 09:12:28 +0200228 ->attr_is('spanList span#t_14', 'from', 45) # twenty-two
229 ->attr_is('spanList span#t_14', 'to', 55)
Peter Harders42e18a62020-07-21 02:43:26 +0200230
Akron044bd922020-07-30 09:12:28 +0200231 ->attr_is('spanList span#t_15', 'from', 55) # "
232 ->attr_is('spanList span#t_15', 'to', 56)
Akron8b511f92020-07-09 17:28:08 +0200233
Akron044bd922020-07-30 09:12:28 +0200234 ->attr_is('spanList span#t_19', 'from', 66)
235 ->attr_is('spanList span#t_19', 'to', 67)
Peter Hardersb1227172020-07-21 02:12:10 +0200236
Akron044bd922020-07-30 09:12:28 +0200237 ->element_count_is('spanList span', 20);
Peter Harders71f072b2020-07-15 14:15:01 +0200238
Peter Harders71f072b2020-07-15 14:15:01 +0200239
Akron044bd922020-07-30 09:12:28 +0200240 # ~ test aggressive tokenization ~
241 $t->unzip_xml('CORP/DOC/00001/base/tokens_aggressive.xml')
242 ->attr_is('spanList span:nth-child(1)', 'to', 6)
Peter Harders71f072b2020-07-15 14:15:01 +0200243
Akron044bd922020-07-30 09:12:28 +0200244 ->attr_is('spanList span#t_1', 'from', 7)
245 ->attr_is('spanList span#t_1', 'to', 9)
Peter Harders71f072b2020-07-15 14:15:01 +0200246
Akron044bd922020-07-30 09:12:28 +0200247 ->attr_is('spanList span#t_3', 'from', 12)
248 ->attr_is('spanList span#t_3', 'to', 16)
Peter Harders71f072b2020-07-15 14:15:01 +0200249
Akron044bd922020-07-30 09:12:28 +0200250 ->attr_is('spanList span#t_9', 'from', 36)
251 ->attr_is('spanList span#t_9', 'to', 37)
Peter Harders71f072b2020-07-15 14:15:01 +0200252
Akron044bd922020-07-30 09:12:28 +0200253 ->attr_is('spanList span#t_13', 'from', 44)
254 ->attr_is('spanList span#t_13', 'to', 45) # "
Peter Harders71f072b2020-07-15 14:15:01 +0200255
Akron044bd922020-07-30 09:12:28 +0200256 ->attr_is('spanList span#t_14', 'from', 45) # twenty
257 ->attr_is('spanList span#t_14', 'to', 51)
Peter Harders71f072b2020-07-15 14:15:01 +0200258
Akron044bd922020-07-30 09:12:28 +0200259 ->attr_is('spanList span#t_15', 'from', 51) # -
260 ->attr_is('spanList span#t_15', 'to', 52)
Peter Harders71f072b2020-07-15 14:15:01 +0200261
Akron044bd922020-07-30 09:12:28 +0200262 ->attr_is('spanList span#t_16', 'from', 52) # two
263 ->attr_is('spanList span#t_16', 'to', 55)
Peter Harders71f072b2020-07-15 14:15:01 +0200264
Akron044bd922020-07-30 09:12:28 +0200265 ->attr_is('spanList span#t_17', 'from', 55) # "
266 ->attr_is('spanList span#t_17', 'to', 56)
Peter Harders71f072b2020-07-15 14:15:01 +0200267
Akron044bd922020-07-30 09:12:28 +0200268 ->attr_is('spanList span#t_21', 'from', 66)
269 ->attr_is('spanList span#t_21', 'to', 67)
Peter Harders71f072b2020-07-15 14:15:01 +0200270
Akron044bd922020-07-30 09:12:28 +0200271 ->element_count_is('spanList span', 22);
272};
Peter Harders71f072b2020-07-15 14:15:01 +0200273
274
Peter Harders42e18a62020-07-21 02:43:26 +0200275subtest 'Check Tokenization Flags' => sub {
276
277 # Get external tokenizer
278 my $f = dirname(__FILE__);
279 my $cmd = catfile($f, 'cmd', 'tokenizer.pl');
280
281 # Load example file
Akron044bd922020-07-30 09:12:28 +0200282 test_tei2korapxml(
283 file => catfile($f, 'data', 'goe_sample.i5.xml'),
284 param => "-ti -tc 'perl $cmd'",
285 tmp => 'script_tokflags'
286 )
287 ->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!)
288 ->file_exists('GOE/AGA/00000/base/tokens_aggressive.xml')
289 ->file_exists('GOE/AGA/00000/base/tokens_conservative.xml')
290 ->file_exists('GOE/AGA/00000/base/tokens.xml')
291 ;
Peter Harders42e18a62020-07-21 02:43:26 +0200292};
293
Peter Harders1c5ce152020-07-22 18:02:50 +0200294
295subtest 'Test utf-8 handling' => sub {
Peter Harders1c5ce152020-07-22 18:02:50 +0200296 # Introduce invalid utf-8 characters
297 my $text_sigle;
Akron54e363c2020-07-29 11:01:03 +0200298 {
299 no warnings;
300 # $text_sigle printed to file, without encoding: Aþƒ¿¿¿¿¿A_Bþƒ¿¿¿¿¿B.Cþƒ¿¿¿¿¿C
301 # the utf8-sequence 'þƒ¿¿¿¿¿' encodes 32 bit of data (see 0x7FFF_FFFF in perlunicode)
302 $text_sigle = "A\x{FFFF_FFFF}A_B\x{FFFF_FFFF}B.C\x{FFFF_FFFF}C"
303 }
304 # If CHECK is 0, encoding and decoding replace any malformed character
305 # with a substitution character.
Peter Harders1c5ce152020-07-22 18:02:50 +0200306 # � = substitution character
307 my $text_sigle_lax = encode_utf8($text_sigle);
308 my $text_sigle_esc = encode('UTF-8', $text_sigle);
309
310 is(length($text_sigle), 11); # A�A_B�B.C�C (char string => length(�) = 1)
311 is(length($text_sigle_lax), 29); # Aþƒ¿¿¿¿¿A_Bþƒ¿¿¿¿¿B.Cþƒ¿¿¿¿¿C (byte string)
312 is(length($text_sigle_esc), 17); # A�A_B�B.C�C (byte string => length(�) = 3)
313
Akron54e363c2020-07-29 11:01:03 +0200314
315 my $tpl;
316 {
317 no warnings;
318 $tpl = i5_template(
319 korpusSigle => "A\x{FFFF_FFFF}A",
320 dokumentSigle => "A\x{FFFF_FFFF}A_B\x{FFFF_FFFF}B",
321 text => "<p>d\x{FFFF_FFFF}d e\x{FFFF_FFFF}e f\x{FFFF_FFFF}f</p>",
322 textSigle => $text_sigle
323 );
324 };
Peter Harders1c5ce152020-07-22 18:02:50 +0200325
326 my ($fh, $tplfile) = korap_tempfile('script_out4');
327 binmode($fh);
328 print $fh encode_utf8($tpl); # => text_id=Aþƒ¿¿¿¿¿A_Bþƒ¿¿¿¿¿B.Cþƒ¿¿¿¿¿C
329 close($fh);
330
331 my (undef, $outzip) = korap_tempfile('script_out5');
332
Akron54e363c2020-07-29 11:01:03 +0200333 # because output 'textid=...' goes to STDERR (see script/tei2korapxml)
Akroneaa96232020-10-15 17:06:15 +0200334 binmode STDERR;
Peter Harders1c5ce152020-07-22 18:02:50 +0200335
336 stderr_like(
337 sub { `cat '$tplfile' | perl '$script' -ti > '$outzip'` },
Akroneaa96232020-10-15 17:06:15 +0200338 qr!tei2korapxml: .*? text_id=$text_sigle_esc!, # see above: print $fh encode_utf8($tpl);
Peter Harders1c5ce152020-07-22 18:02:50 +0200339 );
340};
341
Akrone68ec0c2020-07-28 18:06:19 +0200342
343subtest 'Check Inline annotations' => sub {
344
345 # Load example file
346 my $file = catfile($f, 'data', 'goe_sample_tagged.i5.xml');
347
Akron044bd922020-07-30 09:12:28 +0200348 my $t = test_tei2korapxml(
349 file => $file,
350 env => 'KORAPXMLTEI_INLINE=1',
351 tmp => 'script_tagged'
352 )
353 ->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!)
Akrone68ec0c2020-07-28 18:06:19 +0200354
Akron044bd922020-07-30 09:12:28 +0200355 # Check zip using xml loy
356 ->unzip_xml('GOE/AGA/00000/tokens/morpho.xml')
Akrone68ec0c2020-07-28 18:06:19 +0200357
Akron044bd922020-07-30 09:12:28 +0200358 ->attr_is('layer', 'docid', 'GOE_AGA.00000')
Akrone68ec0c2020-07-28 18:06:19 +0200359 ->attr_is('spanList span:nth-child(1)', 'id', 's0')
360 ->attr_is('spanList span:nth-child(1)', 'from', '75')
361 ->attr_is('spanList span:nth-child(1)', 'to', '81')
362 ->attr_is('spanList span:nth-child(1)', 'l', '7')
363
364 ->attr_is('span#s0 > fs', 'type', 'lex')
365 ->attr_is('span#s0 > fs', 'xmlns', 'http://www.tei-c.org/ns/1.0')
366 ->attr_is('span#s0 > fs > f > fs > f:nth-child(1)', 'name', 'pos')
367 ->text_is('span#s0 > fs > f > fs > f:nth-child(1)', 'A')
368 ->attr_is('span#s0 > fs > f > fs > f:nth-child(2)', 'name', 'msd')
369 ->text_is('span#s0 > fs > f > fs > f:nth-child(2)', '@NH')
370
371 ->attr_is('span#s25', 'from', '259')
372 ->attr_is('span#s25', 'to', '263')
373 ->attr_is('span#s25', 'l', '7')
374 ->attr_is('span#s25 > fs > f > fs > f:nth-child(1)', 'name', 'pos')
375 ->text_is('span#s25 > fs > f > fs > f:nth-child(1)', 'PRON')
376 ->attr_is('span#s25 > fs > f > fs > f:nth-child(2)', 'name', 'msd')
377 ->text_is('span#s25 > fs > f > fs > f:nth-child(2)', '@NH')
378
379 ->attr_is('span#s58', 'from', '495')
380 ->attr_is('span#s58', 'to', '500')
381 ->attr_is('span#s58', 'l', '7')
382 ->attr_is('span#s58 > fs > f > fs > f:nth-child(1)', 'name', 'pos')
383 ->text_is('span#s58 > fs > f > fs > f:nth-child(1)', 'N')
384 ->attr_is('span#s58 > fs > f > fs > f:nth-child(2)', 'name', 'msd')
385 ->text_is('span#s58 > fs > f > fs > f:nth-child(2)', '@NH')
386
387 ->attr_is('span#s119', 'from', '914')
388 ->attr_is('span#s119', 'to', '925')
389 ->attr_is('span#s119', 'l', '7')
390 ->attr_is('span#s119 > fs > f > fs > f:nth-child(1)', 'name', 'pos')
391 ->text_is('span#s119 > fs > f > fs > f:nth-child(1)', 'A')
392 ->attr_is('span#s119 > fs > f > fs > f:nth-child(2)', 'name', 'msd')
393 ->text_is('span#s119 > fs > f > fs > f:nth-child(2)', '@NH')
394 ->element_exists_not('span#s120')
395 ;
396};
397
Akron09e0b2c2020-07-28 15:57:01 +0200398subtest 'Check Inline annotations with untagged file' => sub {
399
400 # Load example file
401 my $file = catfile($f, 'data', 'goe_sample.i5.xml');
402
403 my ($fh, $outzip) = korap_tempfile('script_untagged');
404
405 # Generate zip file (unportable!)
406 stderr_like(
407 sub { `cat '$file' | KORAPXMLTEI_INLINE=1 perl '$script' > '$outzip'` },
408 qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!,
409 'Processing 1'
410 );
411
412 # TODO: there should be a better way to test this
413 stderr_unlike(
414 sub { `cat '$file' | KORAPXMLTEI_INLINE=1 perl '$script' > '$outzip'` },
415 qr!.*undefined value.*!,
416 'Processing 2'
417 );
418 #
419
420 ok(-e $outzip, "File $outzip exists");
421
422 my $zip = IO::Uncompress::Unzip->new(
423 $outzip,
424 Name => 'GOE/AGA/00000/tokens/morpho.xml'
425 );
426 ok((not $zip), 'missing morpho.xml');
427
428 $zip = IO::Uncompress::Unzip->new(
429 $outzip,
430 Name => 'GOE/AGA/00000/struct/structure.xml'
431 );
432 ok($zip, 'found structure.xml');
433};
Akrone68ec0c2020-07-28 18:06:19 +0200434
Akron3378dfd2020-08-01 15:01:36 +0200435
Akroneaa96232020-10-15 17:06:15 +0200436subtest 'Check input encoding' => sub {
437
438 # Load example file
439 test_tei2korapxml(
440 file => catfile($f, 'data', 'goe_sample.i5.xml'),
441 env => 'KORAPXMLTEI_INLINE=1',
442 tmp => 'script_utf8_enc'
443 )
444 ->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!)
445 ->unzip_xml('GOE/AGA/00000/data.xml')
446 ->content_like(qr/\Q&quot;Kriegstheater&quot;\E/)
447 ->content_like(qr/\QTür&#39;\E/)
448 ;
449
450 test_tei2korapxml(
451 file => catfile($f, 'data', 'goe_sample.i5.iso.xml'),
452 env => 'KORAPXMLTEI_INLINE=1',
453 tmp => 'script_iso_enc'
454 )
455 ->stderr_like(qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!)
456 ->unzip_xml('GOE/AGA/00000/data.xml')
457 ->content_like(qr/\Q&quot;Kriegstheater&quot;\E/)
458 ->content_like(qr/\QTür&#39;\E/)
459 ;
460};
461
Marc Kupietz44b1f252020-11-26 16:31:40 +0100462subtest 'Check encoding with utf-8 sigle' => sub {
463
464 # Load example file
465 my $file = catfile($f, 'data', 'wdd_sample.i5.xml');
466
467 my $t = test_tei2korapxml(
468 tmp => 'script_sigle',
469 file => $file,
470 param => "-ti"
471 )->stderr_like(qr!tei2korapxml: .*? text_id=WDD19_ß0000\.10317!)
472 ->stderr_unlike(qr!Debugging is activated!);
473
474 $t->unzip_xml('WDD19/ß0000/10317/header.xml')
475 ->text_is('idsHeader fileDesc titleStmt textSigle', 'WDD19/ß0000.10317');
476
477 $t->unzip_xml('WDD19/ß0000/10317/data.xml')
478 ->attr_is('raw_text', 'docid', 'WDD19_ß0000.10317');
479
480 $t->unzip_xml('WDD19/ß0000/10317/struct/structure.xml')
481 ->attr_is('layer', 'docid', 'WDD19_ß0000.10317');
482
483 $t->unzip_xml('WDD19/ß0000/10317/base/tokens_conservative.xml')
484 ->attr_is('layer', 'docid', 'WDD19_ß0000.10317');
485};
486
Akron3378dfd2020-08-01 15:01:36 +0200487subtest 'Test Log' => sub {
488 test_tei2korapxml(
489 tmp => 'script_out',
490 file => $file,
491 param => '-l=warn'
492 )->stderr_is('');
493};
494
495
Akron797e8072020-02-13 07:59:40 +0100496done_testing;