blob: 62b54ade17ec93380db9f824678cdbd162d4e39f [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'
Akron91577922021-02-19 10:32:54 +010044 )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
Akronb3649472020-09-29 08:24:46 +020045 ->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'
Akron91577922021-02-19 10:32:54 +010054 )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
Akronb3649472020-09-29 08:24:46 +020055 ->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 )
Akron91577922021-02-19 10:32:54 +0100163 ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
Akron044bd922020-07-30 09:12:28 +0200164 ->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
Akron91705d72021-02-19 10:59:45 +0100178subtest 'Tokenize with external tokenizer and defined folder' => sub {
179
180 my $cmd = catfile($f, 'cmd', 'tokenizer.pl');
181
182 test_tei2korapxml(
183 file => $file,
184 param => "-tc='perl $cmd' --tokens-file=yadda",
185 tmp => 'script_out2'
186 )
187 ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
188 ->file_exists_not('GOE/AGA/00000/base/tokens.xml')
189 ->file_readable('GOE/AGA/00000/base/yadda.xml')
190 ->unzip_xml('GOE/AGA/00000/base/yadda.xml')
191 ->attr_is('spanList span:nth-child(1)', 'to', 8)
192 ->attr_is('spanList span#t_1', 'from', 9)
193 ->attr_is('spanList span#t_1', 'to', 11)
194 ->attr_is('spanList span#t_67', 'from', 427)
195 ->attr_is('spanList span#t_67', 'to', 430)
196 ->attr_is('spanList span#t_214', 'from', 1209)
197 ->attr_is('spanList span#t_214', 'to', 1212)
198 ->element_count_is('spanList span', 227);
199};
200
Marc Kupietz8ab68322026-03-18 18:04:14 +0100201subtest 'Skip text after repeated external tokenizer crash' => sub {
202
203 my $cmd = catfile($f, 'cmd', 'tokenizer_faulty.pl');
204 my ($fh, $testfile) = korap_tempfile('script_exttok_skip');
205
206 print {$fh} <<'XML';
207<?xml version="1.0" encoding="UTF-8"?>
208<idsCorpus>
209 <idsHeader type="corpus">
210 <fileDesc>
211 <titleStmt>
212 <korpusSigle>CORP</korpusSigle>
213 </titleStmt>
214 </fileDesc>
215 </idsHeader>
216 <idsDoc version="1.0">
217 <idsHeader type="document">
218 <fileDesc>
219 <titleStmt>
220 <dokumentSigle>CORP/DOC</dokumentSigle>
221 </titleStmt>
222 </fileDesc>
223 </idsHeader>
224 <idsText version="1.0">
225 <idsHeader type="text">
226 <fileDesc>
227 <titleStmt>
228 <textSigle>CORP/DOC.00001</textSigle>
229 </titleStmt>
230 </fileDesc>
231 </idsHeader>
232 <text>
233 stable text
234 </text>
235 </idsText>
236 <idsText version="1.0">
237 <idsHeader type="text">
238 <fileDesc>
239 <titleStmt>
240 <textSigle>CORP/DOC.00002</textSigle>
241 </titleStmt>
242 </fileDesc>
243 </idsHeader>
244 <text>
245 __ALWAYS_CRASH__ text
246 </text>
247 </idsText>
248 </idsDoc>
249</idsCorpus>
250XML
251 close($fh);
252
253 test_tei2korapxml(
254 file => $testfile,
255 param => "-tc='perl $cmd'",
256 tmp => 'script_exttok_skip'
257 )
258 ->stderr_like(qr!tei2korapxml:.*? text_id=CORP_DOC\.00001!)
259 ->stderr_like(qr!tei2korapxml:.*? text_id=CORP_DOC\.00002!)
260 ->stderr_like(qr!External tokenizer failed for 'CORP_DOC\.00002' on attempt 1/2!)
261 ->stderr_like(qr!Skipping tokenization for 'CORP_DOC\.00002' after 2/2 attempts!)
262 ->file_readable('CORP/DOC/00001/base/tokens.xml')
263 ->file_exists_not('CORP/DOC/00002/base/tokens.xml')
264 ->file_readable('CORP/DOC/00002/data.xml');
265};
266
Marc Kupietzeed4cb12021-02-17 19:39:32 +0100267subtest 'Check KorAP tokenizer for infinite loop bug' => sub {
268
269 my $file = catfile($f, 'data', 'korap_tokenizer_challenge.xml');
270
271 eval {
272 require KorAP::XML::TEI::Tokenizer::KorAP;
273 1;
274 } or do {
275 plan skip_all => "KorAP::XML::TEI::Tokenizer::KorAP cannot be used";
276 };
277
278 test_tei2korapxml(
279 file => $file,
280 param => "-tk -s",
281 tmp => 'script_bug_check'
282 )
Akron91577922021-02-19 10:32:54 +0100283 ->stderr_like(qr!tei2korapxml:.*? text_id=WDD19_H0039\.87242!)
Marc Kupietzeed4cb12021-02-17 19:39:32 +0100284 ->file_readable('WDD19/H0039/87242/struct/structure.xml');
285};
286
Marc Kupietz985da0c2021-02-15 19:29:50 +0100287subtest 'Sentence split with KorAP tokenizer' => sub {
288
289 eval {
290 require KorAP::XML::TEI::Tokenizer::KorAP;
291 1;
292 } or do {
293 plan skip_all => "KorAP::XML::TEI::Tokenizer::KorAP cannot be used";
294 };
295
296 test_tei2korapxml(
297 file => $file,
298 param => "-tk -s",
299 tmp => 'script_sentence_split'
300 )
Akron91577922021-02-19 10:32:54 +0100301 ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
Marc Kupietz985da0c2021-02-15 19:29:50 +0100302 ->file_readable('GOE/AGA/00000/struct/structure.xml')
303 ->unzip_xml('GOE/AGA/00000/struct/structure.xml')
304 ->text_is('span#s25 fs f', 's')
305 ->attr_is('span#s25', 'l', -1)
306 ->attr_is('span#s25', 'to', 54)
307 ->text_is('span#s30 fs f', 's')
308 ->attr_is('span#s30', 'l', -1)
309 ->attr_is('span#s30', 'from', 1099)
310 ->attr_is('span#s30', 'to', 1266);
311};
Akroneac374d2020-07-07 09:00:44 +0200312
Akron044bd922020-07-30 09:12:28 +0200313subtest 'Test Tokenizations' => sub {
Akroneac374d2020-07-07 09:00:44 +0200314
Akron044bd922020-07-30 09:12:28 +0200315 my $t = test_tei2korapxml(
316 file => catfile($f, 'data', 'text_with_blanks.i5.xml'),
317 tmp => 'script_out3',
318 param => '-ti'
Akron91577922021-02-19 10:32:54 +0100319 )->stderr_like(qr!tei2korapxml:.*? text_id=CORP_DOC.00001!);
Akron8b511f92020-07-09 17:28:08 +0200320
Akron044bd922020-07-30 09:12:28 +0200321 # ~ test conservative tokenization ~
322 $t->unzip_xml('CORP/DOC/00001/base/tokens_conservative.xml')
323 ->attr_is('spanList span:nth-child(1)', 'to', 6)
Akron8b511f92020-07-09 17:28:08 +0200324
Akron044bd922020-07-30 09:12:28 +0200325 ->attr_is('spanList span#t_1', 'from', 7)
326 ->attr_is('spanList span#t_1', 'to', 9)
Akron8b511f92020-07-09 17:28:08 +0200327
Akron044bd922020-07-30 09:12:28 +0200328 ->attr_is('spanList span#t_3', 'from', 12)
329 ->attr_is('spanList span#t_3', 'to', 16)
Akron8b511f92020-07-09 17:28:08 +0200330
Akron044bd922020-07-30 09:12:28 +0200331 ->attr_is('spanList span#t_9', 'from', 36)
332 ->attr_is('spanList span#t_9', 'to', 37)
Akron8b511f92020-07-09 17:28:08 +0200333
Akron044bd922020-07-30 09:12:28 +0200334 ->attr_is('spanList span#t_13', 'from', 44)
335 ->attr_is('spanList span#t_13', 'to', 45) # "
Akron8b511f92020-07-09 17:28:08 +0200336
Akron044bd922020-07-30 09:12:28 +0200337 ->attr_is('spanList span#t_14', 'from', 45) # twenty-two
338 ->attr_is('spanList span#t_14', 'to', 55)
Peter Harders42e18a62020-07-21 02:43:26 +0200339
Akron044bd922020-07-30 09:12:28 +0200340 ->attr_is('spanList span#t_15', 'from', 55) # "
341 ->attr_is('spanList span#t_15', 'to', 56)
Akron8b511f92020-07-09 17:28:08 +0200342
Akron044bd922020-07-30 09:12:28 +0200343 ->attr_is('spanList span#t_19', 'from', 66)
344 ->attr_is('spanList span#t_19', 'to', 67)
Peter Hardersb1227172020-07-21 02:12:10 +0200345
Akron044bd922020-07-30 09:12:28 +0200346 ->element_count_is('spanList span', 20);
Peter Harders71f072b2020-07-15 14:15:01 +0200347
Peter Harders71f072b2020-07-15 14:15:01 +0200348
Akron044bd922020-07-30 09:12:28 +0200349 # ~ test aggressive tokenization ~
350 $t->unzip_xml('CORP/DOC/00001/base/tokens_aggressive.xml')
351 ->attr_is('spanList span:nth-child(1)', 'to', 6)
Peter Harders71f072b2020-07-15 14:15:01 +0200352
Akron044bd922020-07-30 09:12:28 +0200353 ->attr_is('spanList span#t_1', 'from', 7)
354 ->attr_is('spanList span#t_1', 'to', 9)
Peter Harders71f072b2020-07-15 14:15:01 +0200355
Akron044bd922020-07-30 09:12:28 +0200356 ->attr_is('spanList span#t_3', 'from', 12)
357 ->attr_is('spanList span#t_3', 'to', 16)
Peter Harders71f072b2020-07-15 14:15:01 +0200358
Akron044bd922020-07-30 09:12:28 +0200359 ->attr_is('spanList span#t_9', 'from', 36)
360 ->attr_is('spanList span#t_9', 'to', 37)
Peter Harders71f072b2020-07-15 14:15:01 +0200361
Akron044bd922020-07-30 09:12:28 +0200362 ->attr_is('spanList span#t_13', 'from', 44)
363 ->attr_is('spanList span#t_13', 'to', 45) # "
Peter Harders71f072b2020-07-15 14:15:01 +0200364
Akron044bd922020-07-30 09:12:28 +0200365 ->attr_is('spanList span#t_14', 'from', 45) # twenty
366 ->attr_is('spanList span#t_14', 'to', 51)
Peter Harders71f072b2020-07-15 14:15:01 +0200367
Akron044bd922020-07-30 09:12:28 +0200368 ->attr_is('spanList span#t_15', 'from', 51) # -
369 ->attr_is('spanList span#t_15', 'to', 52)
Peter Harders71f072b2020-07-15 14:15:01 +0200370
Akron044bd922020-07-30 09:12:28 +0200371 ->attr_is('spanList span#t_16', 'from', 52) # two
372 ->attr_is('spanList span#t_16', 'to', 55)
Peter Harders71f072b2020-07-15 14:15:01 +0200373
Akron044bd922020-07-30 09:12:28 +0200374 ->attr_is('spanList span#t_17', 'from', 55) # "
375 ->attr_is('spanList span#t_17', 'to', 56)
Peter Harders71f072b2020-07-15 14:15:01 +0200376
Akron044bd922020-07-30 09:12:28 +0200377 ->attr_is('spanList span#t_21', 'from', 66)
378 ->attr_is('spanList span#t_21', 'to', 67)
Peter Harders71f072b2020-07-15 14:15:01 +0200379
Akron044bd922020-07-30 09:12:28 +0200380 ->element_count_is('spanList span', 22);
381};
Peter Harders71f072b2020-07-15 14:15:01 +0200382
383
Peter Harders42e18a62020-07-21 02:43:26 +0200384subtest 'Check Tokenization Flags' => sub {
385
386 # Get external tokenizer
387 my $f = dirname(__FILE__);
388 my $cmd = catfile($f, 'cmd', 'tokenizer.pl');
389
390 # Load example file
Akron044bd922020-07-30 09:12:28 +0200391 test_tei2korapxml(
392 file => catfile($f, 'data', 'goe_sample.i5.xml'),
393 param => "-ti -tc 'perl $cmd'",
394 tmp => 'script_tokflags'
395 )
Akron91577922021-02-19 10:32:54 +0100396 ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
Akron044bd922020-07-30 09:12:28 +0200397 ->file_exists('GOE/AGA/00000/base/tokens_aggressive.xml')
398 ->file_exists('GOE/AGA/00000/base/tokens_conservative.xml')
399 ->file_exists('GOE/AGA/00000/base/tokens.xml')
400 ;
Peter Harders42e18a62020-07-21 02:43:26 +0200401};
402
Peter Harders1c5ce152020-07-22 18:02:50 +0200403
404subtest 'Test utf-8 handling' => sub {
Peter Harders1c5ce152020-07-22 18:02:50 +0200405 # Introduce invalid utf-8 characters
406 my $text_sigle;
Akron54e363c2020-07-29 11:01:03 +0200407 {
408 no warnings;
409 # $text_sigle printed to file, without encoding: Aþƒ¿¿¿¿¿A_Bþƒ¿¿¿¿¿B.Cþƒ¿¿¿¿¿C
410 # the utf8-sequence 'þƒ¿¿¿¿¿' encodes 32 bit of data (see 0x7FFF_FFFF in perlunicode)
411 $text_sigle = "A\x{FFFF_FFFF}A_B\x{FFFF_FFFF}B.C\x{FFFF_FFFF}C"
412 }
413 # If CHECK is 0, encoding and decoding replace any malformed character
414 # with a substitution character.
Peter Harders1c5ce152020-07-22 18:02:50 +0200415 # � = substitution character
416 my $text_sigle_lax = encode_utf8($text_sigle);
417 my $text_sigle_esc = encode('UTF-8', $text_sigle);
418
419 is(length($text_sigle), 11); # A�A_B�B.C�C (char string => length(�) = 1)
420 is(length($text_sigle_lax), 29); # Aþƒ¿¿¿¿¿A_Bþƒ¿¿¿¿¿B.Cþƒ¿¿¿¿¿C (byte string)
421 is(length($text_sigle_esc), 17); # A�A_B�B.C�C (byte string => length(�) = 3)
422
Akron54e363c2020-07-29 11:01:03 +0200423
424 my $tpl;
425 {
426 no warnings;
427 $tpl = i5_template(
428 korpusSigle => "A\x{FFFF_FFFF}A",
429 dokumentSigle => "A\x{FFFF_FFFF}A_B\x{FFFF_FFFF}B",
430 text => "<p>d\x{FFFF_FFFF}d e\x{FFFF_FFFF}e f\x{FFFF_FFFF}f</p>",
431 textSigle => $text_sigle
432 );
433 };
Peter Harders1c5ce152020-07-22 18:02:50 +0200434
435 my ($fh, $tplfile) = korap_tempfile('script_out4');
436 binmode($fh);
437 print $fh encode_utf8($tpl); # => text_id=Aþƒ¿¿¿¿¿A_Bþƒ¿¿¿¿¿B.Cþƒ¿¿¿¿¿C
438 close($fh);
439
440 my (undef, $outzip) = korap_tempfile('script_out5');
441
Akron54e363c2020-07-29 11:01:03 +0200442 # because output 'textid=...' goes to STDERR (see script/tei2korapxml)
Akroneaa96232020-10-15 17:06:15 +0200443 binmode STDERR;
Peter Harders1c5ce152020-07-22 18:02:50 +0200444
445 stderr_like(
Akrona2cb2812021-10-30 10:29:08 +0200446 sub { `cat '$tplfile' | perl '$script' -ti - > '$outzip'` },
Akron91577922021-02-19 10:32:54 +0100447 qr!tei2korapxml:.*? text_id=$text_sigle_esc!, # see above: print $fh encode_utf8($tpl);
Peter Harders1c5ce152020-07-22 18:02:50 +0200448 );
449};
450
Akrone68ec0c2020-07-28 18:06:19 +0200451
Akrondd0be8f2021-02-18 19:29:41 +0100452subtest 'Check structure parsing with defined foundry and folder' => sub {
453 # Load example file
454 my $file = catfile($f, 'data', 'goe_sample.i5.xml');
455
456 my $t = test_tei2korapxml(
457 tmp => 'script_out',
458 file => $file,
459 param => '-ti --inline-structures=myfoundry#mystr'
Akron91705d72021-02-19 10:59:45 +0100460 )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
Akrondd0be8f2021-02-18 19:29:41 +0100461 ->file_exists_not('GOE/AGA/00000/struct/structure.xml', 'Structure not generated')
462 ->unzip_xml('GOE/AGA/00000/myfoundry/mystr.xml')
463 ->text_is('span[id=s3] *[name=type]', 'Autobiographie', 'text content')
464 ->text_is('#s3 *[name=type]', 'Autobiographie', 'text content')
465 ->attr_is('#s0','to','1266')
466 ->attr_is('#s0','l','1')
467 ->attr_is('#s18','from','925')
468 ->attr_is('#s18','to','1266')
469 ->attr_is('#s18','l','5')
470 ;
471
472 $t = test_tei2korapxml(
473 tmp => 'script_out',
474 file => $file,
475 param => '-ti --inline-structures=myfoundry'
Akron91705d72021-02-19 10:59:45 +0100476 )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
Akrondd0be8f2021-02-18 19:29:41 +0100477 ->file_exists_not('GOE/AGA/00000/struct/structure.xml', 'Structure not generated')
478 ->unzip_xml('GOE/AGA/00000/myfoundry/structure.xml')
479 ->text_is('span[id=s3] *[name=type]', 'Autobiographie', 'text content')
480 ->text_is('#s3 *[name=type]', 'Autobiographie', 'text content')
481 ->attr_is('#s0','to','1266')
482 ->attr_is('#s0','l','1')
483 ->attr_is('#s18','from','925')
484 ->attr_is('#s18','to','1266')
485 ->attr_is('#s18','l','5')
486 ;
487};
488
Akron54c3ff12021-02-25 11:33:37 +0100489subtest 'Check structure parsing with skipped tags' => sub {
490 # Load example file
491 my $file = catfile($f, 'data', 'goe_sample.i5.xml');
492
493 my $t = test_tei2korapxml(
494 tmp => 'script_out',
495 file => $file,
496 param => '-ti'
497 )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
498 ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated')
499 ->unzip_xml('GOE/AGA/00000/struct/structure.xml')
500 ->text_is('layer spanList span fs f', 'text')
501 ->text_is('#s5 fs f[name=name]','head')
502 ->text_is('#s6 fs f[name=name]','s')
503 ->text_is('#s7 fs f[name=name]','head')
504 ->text_is('#s8 fs f[name=name]','s')
505 ->text_is('#s9 fs f[name=name]','quote')
506 ->text_is('#s10 fs f[name=name]','s')
507 ;
508
509 $t = test_tei2korapxml(
510 tmp => 'script_out',
511 file => $file,
512 param => '-ti --skip-inline-tags=head'
513 )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
514 ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated')
515 ->unzip_xml('GOE/AGA/00000/struct/structure.xml')
516 ->text_is('layer spanList span fs f', 'text')
517 ->text_is('#s5 fs f[name=name]','s')
518 ->text_is('#s6 fs f[name=name]','s')
519 ->text_is('#s7 fs f[name=name]','quote')
520 ->text_is('#s8 fs f[name=name]','s')
521 ;
522
523 $t = test_tei2korapxml(
524 tmp => 'script_out',
525 file => $file,
526 param => '-ti --skip-inline-tags=head,quote'
527 )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
528 ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated')
529 ->unzip_xml('GOE/AGA/00000/struct/structure.xml')
530 ->text_is('layer spanList span fs f', 'text')
531 ->text_is('#s5 fs f[name=name]','s')
532 ->text_is('#s6 fs f[name=name]','s')
533 ->text_is('#s7 fs f[name=name]','s')
534 ;
535};
536
Akrondd0be8f2021-02-18 19:29:41 +0100537
Akron75d63142021-02-23 18:40:56 +0100538subtest 'Check parsing but skip inline tokens' => sub {
539 # Load example file
540 my $file = catfile($f, 'data', 'goe_sample.i5.xml');
541
542 my $t = test_tei2korapxml(
543 tmp => 'script_skip_inline_tokens_1',
544 file => $file,
545 param => '-ti --skip-inline-tokens'
546 )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
547 ->file_exists('GOE/AGA/00000/data.xml', 'Data exists')
548 ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated')
549 ->file_exists_not('GOE/AGA/00000/tokens/morpho.xml', 'Morpho not generated')
550 ;
551
552 $t = test_tei2korapxml(
553 tmp => 'script_skip_inline_tokens_2',
554 file => $file,
555 param => '-ti --skip-inline-tokens --inline-tokens=myfoundry#myfile'
556 )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
557 ->file_exists('GOE/AGA/00000/struct/structure.xml', 'Structure generated')
558 ->file_exists_not('GOE/AGA/00000/tokens/morpho.xml', 'Morpho not generated')
559 ->file_exists_not('GOE/AGA/00000/myfoundry/myfile.xml', 'Morpho not generated')
560 ;
561};
562
563
Akrone68ec0c2020-07-28 18:06:19 +0200564subtest 'Check Inline annotations' => sub {
565
566 # Load example file
567 my $file = catfile($f, 'data', 'goe_sample_tagged.i5.xml');
568
Akron044bd922020-07-30 09:12:28 +0200569 my $t = test_tei2korapxml(
570 file => $file,
571 env => 'KORAPXMLTEI_INLINE=1',
Akronb93fabb2023-01-13 12:05:44 +0100572 tmp => 'script_tagged',
573 param => '--no-tokenizer'
Akron044bd922020-07-30 09:12:28 +0200574 )
Akron91577922021-02-19 10:32:54 +0100575 ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
Akron692d17d2021-03-05 13:21:03 +0100576 ->stderr_like(qr!KORAPXMLTEI_INLINE is deprecated!)
Akrone68ec0c2020-07-28 18:06:19 +0200577
Akron044bd922020-07-30 09:12:28 +0200578 # Check zip using xml loy
579 ->unzip_xml('GOE/AGA/00000/tokens/morpho.xml')
Akrone68ec0c2020-07-28 18:06:19 +0200580
Akron044bd922020-07-30 09:12:28 +0200581 ->attr_is('layer', 'docid', 'GOE_AGA.00000')
Akrone68ec0c2020-07-28 18:06:19 +0200582 ->attr_is('spanList span:nth-child(1)', 'id', 's0')
583 ->attr_is('spanList span:nth-child(1)', 'from', '75')
584 ->attr_is('spanList span:nth-child(1)', 'to', '81')
585 ->attr_is('spanList span:nth-child(1)', 'l', '7')
586
587 ->attr_is('span#s0 > fs', 'type', 'lex')
588 ->attr_is('span#s0 > fs', 'xmlns', 'http://www.tei-c.org/ns/1.0')
589 ->attr_is('span#s0 > fs > f > fs > f:nth-child(1)', 'name', 'pos')
590 ->text_is('span#s0 > fs > f > fs > f:nth-child(1)', 'A')
591 ->attr_is('span#s0 > fs > f > fs > f:nth-child(2)', 'name', 'msd')
592 ->text_is('span#s0 > fs > f > fs > f:nth-child(2)', '@NH')
593
594 ->attr_is('span#s25', 'from', '259')
595 ->attr_is('span#s25', 'to', '263')
596 ->attr_is('span#s25', 'l', '7')
597 ->attr_is('span#s25 > fs > f > fs > f:nth-child(1)', 'name', 'pos')
598 ->text_is('span#s25 > fs > f > fs > f:nth-child(1)', 'PRON')
599 ->attr_is('span#s25 > fs > f > fs > f:nth-child(2)', 'name', 'msd')
600 ->text_is('span#s25 > fs > f > fs > f:nth-child(2)', '@NH')
601
602 ->attr_is('span#s58', 'from', '495')
603 ->attr_is('span#s58', 'to', '500')
604 ->attr_is('span#s58', 'l', '7')
605 ->attr_is('span#s58 > fs > f > fs > f:nth-child(1)', 'name', 'pos')
606 ->text_is('span#s58 > fs > f > fs > f:nth-child(1)', 'N')
607 ->attr_is('span#s58 > fs > f > fs > f:nth-child(2)', 'name', 'msd')
608 ->text_is('span#s58 > fs > f > fs > f:nth-child(2)', '@NH')
609
610 ->attr_is('span#s119', 'from', '914')
611 ->attr_is('span#s119', 'to', '925')
612 ->attr_is('span#s119', 'l', '7')
613 ->attr_is('span#s119 > fs > f > fs > f:nth-child(1)', 'name', 'pos')
614 ->text_is('span#s119 > fs > f > fs > f:nth-child(1)', 'A')
615 ->attr_is('span#s119 > fs > f > fs > f:nth-child(2)', 'name', 'msd')
616 ->text_is('span#s119 > fs > f > fs > f:nth-child(2)', '@NH')
617 ->element_exists_not('span#s120')
618 ;
619};
620
Akron26a71522021-02-19 10:27:37 +0100621
622subtest 'Check file structure with defined folder and filenames' => sub {
623 # Load example file
624 my $file = catfile($f, 'data', 'goe_sample.i5.xml');
625 my $t = test_tei2korapxml(
626 tmp => 'script_out',
627 file => $file,
628 param => '-ti --base-foundry=root --data-file=primary --header-file=meta'
Akron91705d72021-02-19 10:59:45 +0100629 )->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
Akron26a71522021-02-19 10:27:37 +0100630 ->file_exists_not('GOE/AGA/00000/header.xml', 'Header not there')
631 ->file_exists_not('GOE/AGA/header.xml', 'Header not there')
632 ->file_exists_not('GOE/header.xml', 'Header not there')
633 ->file_exists_not('GOE/AGA/00000/data.xml', 'Data not there')
634 ->file_exists_not('GOE/AGA/00000/base/tokens_conservative.xml', 'Tokens not there')
635 ->file_exists_not('GOE/AGA/00000/base/tokens_aggressive.xml', 'Tokens not there')
636 ->file_exists('GOE/AGA/00000/meta.xml', 'Header there')
637 ->file_exists('GOE/AGA/meta.xml', 'Header there')
638 ->file_exists('GOE/meta.xml', 'Header there')
639 ->file_exists('GOE/AGA/00000/primary.xml', 'Data there')
640 ->file_exists('GOE/AGA/00000/root/tokens_conservative.xml', 'Tokens there')
641 ->file_exists('GOE/AGA/00000/root/tokens_aggressive.xml', 'Tokens there')
642 ;
643
644 $t->unzip_xml('GOE/AGA/00000/primary.xml')
645 ->content_like(qr/\Q&quot;Kriegstheater&quot;\E/)
646 ;
647};
648
Akron1a5271a2021-02-18 13:18:15 +0100649subtest 'Check Inline annotations with defined foundry and folder' => sub {
650 # Load example file
651 my $file = catfile($f, 'data', 'goe_sample_tagged.i5.xml');
652
653 my $t = test_tei2korapxml(
654 file => $file,
Akron1a5271a2021-02-18 13:18:15 +0100655 tmp => 'script_tagged',
Akronb93fabb2023-01-13 12:05:44 +0100656 param => '--inline-tokens=myfoundry#myfile --skip-inline-token-annotations=0 --no-tokenizer'
Akron1a5271a2021-02-18 13:18:15 +0100657 )
Akron91577922021-02-19 10:32:54 +0100658 ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
Akron692d17d2021-03-05 13:21:03 +0100659 ->stderr_unlike(qr!KORAPXMLTEI_INLINE is deprecated!)
Akron1a5271a2021-02-18 13:18:15 +0100660
661 ->file_exists_not('GOE/AGA/00000/tokens/morpho.xml', 'Morpho not generated')
662
663 # Check zip using xml loy
664 ->unzip_xml('GOE/AGA/00000/myfoundry/myfile.xml')
665
666 ->attr_is('layer', 'docid', 'GOE_AGA.00000')
667 ->attr_is('spanList span:nth-child(1)', 'id', 's0')
668 ->attr_is('spanList span:nth-child(1)', 'from', '75')
669 ->attr_is('spanList span:nth-child(1)', 'to', '81')
670 ->attr_is('spanList span:nth-child(1)', 'l', '7')
671 ;
672
673 $t = test_tei2korapxml(
674 file => $file,
Akron1a5271a2021-02-18 13:18:15 +0100675 tmp => 'script_tagged',
Akronb93fabb2023-01-13 12:05:44 +0100676 param => '--inline-tokens=myfoundry --skip-inline-token-annotations=0 --no-tokenizer'
Akron1a5271a2021-02-18 13:18:15 +0100677 )
Akron91577922021-02-19 10:32:54 +0100678 ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
Akron1a5271a2021-02-18 13:18:15 +0100679
680 ->file_exists_not('GOE/AGA/00000/tokens/morpho.xml', 'Morpho not generated')
681
682 # Check zip using xml loy
683 ->unzip_xml('GOE/AGA/00000/myfoundry/morpho.xml')
684
685 ->attr_is('layer', 'docid', 'GOE_AGA.00000')
686 ->attr_is('spanList span:nth-child(1)', 'id', 's0')
687 ->attr_is('spanList span:nth-child(1)', 'from', '75')
688 ->attr_is('spanList span:nth-child(1)', 'to', '81')
689 ->attr_is('spanList span:nth-child(1)', 'l', '7')
690 ;
691};
692
Akron09e0b2c2020-07-28 15:57:01 +0200693subtest 'Check Inline annotations with untagged file' => sub {
694
695 # Load example file
696 my $file = catfile($f, 'data', 'goe_sample.i5.xml');
697
698 my ($fh, $outzip) = korap_tempfile('script_untagged');
699
700 # Generate zip file (unportable!)
701 stderr_like(
Akronb93fabb2023-01-13 12:05:44 +0100702 sub { `cat '$file' | perl '$script' --skip-token-inline-annotations=0 --no-tokenizer - > '$outzip'` },
Akron91577922021-02-19 10:32:54 +0100703 qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!,
Akron09e0b2c2020-07-28 15:57:01 +0200704 'Processing 1'
705 );
706
707 # TODO: there should be a better way to test this
708 stderr_unlike(
Akronb93fabb2023-01-13 12:05:44 +0100709 sub { `cat '$file' | perl '$script' --skip-token-inline-annotations=0 --no-tokenizer - > '$outzip'` },
Akron09e0b2c2020-07-28 15:57:01 +0200710 qr!.*undefined value.*!,
711 'Processing 2'
712 );
713 #
714
715 ok(-e $outzip, "File $outzip exists");
716
717 my $zip = IO::Uncompress::Unzip->new(
718 $outzip,
719 Name => 'GOE/AGA/00000/tokens/morpho.xml'
720 );
721 ok((not $zip), 'missing morpho.xml');
722
723 $zip = IO::Uncompress::Unzip->new(
724 $outzip,
725 Name => 'GOE/AGA/00000/struct/structure.xml'
726 );
727 ok($zip, 'found structure.xml');
728};
Akrone68ec0c2020-07-28 18:06:19 +0200729
Akron3378dfd2020-08-01 15:01:36 +0200730
Akroneaa96232020-10-15 17:06:15 +0200731subtest 'Check input encoding' => sub {
732
733 # Load example file
734 test_tei2korapxml(
735 file => catfile($f, 'data', 'goe_sample.i5.xml'),
Akron692d17d2021-03-05 13:21:03 +0100736 tmp => 'script_utf8_enc',
Akronb93fabb2023-01-13 12:05:44 +0100737 param => '--skip-inline-token-annotations=0 --no-tokenizer',
Akroneaa96232020-10-15 17:06:15 +0200738 )
Akron91577922021-02-19 10:32:54 +0100739 ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
Akroneaa96232020-10-15 17:06:15 +0200740 ->unzip_xml('GOE/AGA/00000/data.xml')
741 ->content_like(qr/\Q&quot;Kriegstheater&quot;\E/)
742 ->content_like(qr/\QTür&#39;\E/)
743 ;
744
745 test_tei2korapxml(
746 file => catfile($f, 'data', 'goe_sample.i5.iso.xml'),
Akronb93fabb2023-01-13 12:05:44 +0100747 param => '--skip-inline-token-annotations=0 --no-tokenizer',
Akroneaa96232020-10-15 17:06:15 +0200748 tmp => 'script_iso_enc'
749 )
Akron91577922021-02-19 10:32:54 +0100750 ->stderr_like(qr!tei2korapxml:.*? text_id=GOE_AGA\.00000!)
Akroneaa96232020-10-15 17:06:15 +0200751 ->unzip_xml('GOE/AGA/00000/data.xml')
752 ->content_like(qr/\Q&quot;Kriegstheater&quot;\E/)
753 ->content_like(qr/\QTür&#39;\E/)
754 ;
755};
756
Marc Kupietz44b1f252020-11-26 16:31:40 +0100757subtest 'Check encoding with utf-8 sigle' => sub {
758
759 # Load example file
760 my $file = catfile($f, 'data', 'wdd_sample.i5.xml');
761
762 my $t = test_tei2korapxml(
763 tmp => 'script_sigle',
764 file => $file,
765 param => "-ti"
Akron91577922021-02-19 10:32:54 +0100766 )->stderr_like(qr!tei2korapxml:.*? text_id=WDD19_ß0000\.10317!)
Marc Kupietz44b1f252020-11-26 16:31:40 +0100767 ->stderr_unlike(qr!Debugging is activated!);
768
769 $t->unzip_xml('WDD19/ß0000/10317/header.xml')
770 ->text_is('idsHeader fileDesc titleStmt textSigle', 'WDD19/ß0000.10317');
771
772 $t->unzip_xml('WDD19/ß0000/10317/data.xml')
773 ->attr_is('raw_text', 'docid', 'WDD19_ß0000.10317');
774
775 $t->unzip_xml('WDD19/ß0000/10317/struct/structure.xml')
776 ->attr_is('layer', 'docid', 'WDD19_ß0000.10317');
777
778 $t->unzip_xml('WDD19/ß0000/10317/base/tokens_conservative.xml')
779 ->attr_is('layer', 'docid', 'WDD19_ß0000.10317');
780};
781
Marc Kupietz8a954e52021-02-16 22:03:07 +0100782subtest 'Check entity replacement' => sub {
783 my $t = test_tei2korapxml(
784 file => catfile($f, 'data', 'text_with_entities.i5.xml'),
785 tmp => 'script_entity_replacement',
786 param => '-ti'
Akron91577922021-02-19 10:32:54 +0100787 )->stderr_like(qr!tei2korapxml:.*? text_id=CORP_DOC.00003!);
Marc Kupietz8a954e52021-02-16 22:03:07 +0100788
789 $t->unzip_xml('CORP/DOC/00003/data.xml')
790 ->content_like(qr!üüü Aα≈„▒░▓█╗┐┌╔═─┬╦┴╩╝┘└╚│║┼╬┤╣╠├•ˇčˆ†‡ě€ƒ…‗ıι“„▄‹‘‚—–νœŒωΩ‰φπϖř”ρ›’‘šŠσ□■▪⊂˜™▀ŸžŽ!);
791
792 $t->unzip_xml('CORP/DOC/00003/header.xml')
793 ->content_like(qr!üüü x α•α y!);
794};
795
Akron3378dfd2020-08-01 15:01:36 +0200796subtest 'Test Log' => sub {
797 test_tei2korapxml(
798 tmp => 'script_out',
799 file => $file,
Akronb93fabb2023-01-13 12:05:44 +0100800 param => '-l=warn --no-tokenizer'
Akron3378dfd2020-08-01 15:01:36 +0200801 )->stderr_is('');
802};
803
804
Akron5986da32021-10-01 12:53:55 +0200805subtest 'Broken data testing' => sub {
806 my $file = catfile($f, 'data', 'wikipedia.txt');
807
808 my $t = test_tei2korapxml(
809 tmp => 'script_ginkgo',
810 file => $file,
811 param => '-ti',
812 env => 'KORAPXMLTEI_DEBUG=1'
813 )->stderr_like(qr!No opened zip file to close!)
814 ->stderr_like(qr!Debugging is activated!);
815};
816
Akron2520a342022-03-29 18:18:05 +0200817subtest 'Required version testing' => sub {
818 test_tei2korapxml(
819 tmp => 'script_out',
820 file => $file,
821 param => '-rv=2.2.2'
822 )->stderr_like(qr!^Required version 2\.2\.2 mismatches version!);
823
824 test_tei2korapxml(
825 tmp => 'script_out',
826 file => $file,
827 param => '--required-version=2.2'
828 )->stderr_like(qr!^Required version 2\.2 mismatches version!);
829
830 test_tei2korapxml(
831 tmp => 'script_out',
832 file => $file,
Akronb93fabb2023-01-13 12:05:44 +0100833 param => '-rv=' . $KorAP::XML::TEI::Tokenizer::KorAP::VERSION . ' --no-tokenizer'
Akron2520a342022-03-29 18:18:05 +0200834 )->stderr_like(qr!GOE_AGA\.00000!);
835
836 test_tei2korapxml(
837 tmp => 'script_out',
838 file => $file,
Akronb93fabb2023-01-13 12:05:44 +0100839 param => '-rv= " ' . $KorAP::XML::TEI::Tokenizer::KorAP::VERSION . ' " --no-tokenizer'
Akron2520a342022-03-29 18:18:05 +0200840 )->stderr_like(qr!GOE_AGA\.00000!);
841};
842
Marc Kupietza671ae52022-12-22 16:28:14 +0100843subtest 'Standard TEI P5 testing' => sub {
844
845 my $t = test_tei2korapxml(
846 file => catfile($f, 'data', 'icc_german_sample.p5.xml'),
Akronfcff7342023-02-07 14:05:15 +0100847 param => '--xmlid-to-textsigle \'ICC.German\.([^.]+\.[^.]+)\.(.+)@ICCGER/$1/$2\' -s -ti',
Marc Kupietza671ae52022-12-22 16:28:14 +0100848 tmp => 'script_utf8_enc'
849 )->stderr_like(qr!tei2korapxml:.*? text_id=ICCGER/DeReKo-WPD17\.S00-18619!);
850
851 $t->unzip_xml('ICCGER/DeReKo-WPD17/E51-96136/data.xml')
852 ->content_like(qr/Recht auf persönliches Hab und Gut/);
853
854 $t->unzip_xml('ICCGER/CCBY-LTE/MJB-00001/header.xml')
855 ->text_is('textClass > classCode[scheme=ICC]', 'Learned_Technology', 'classCode is correctly extracted');
856
857};
Akron5986da32021-10-01 12:53:55 +0200858
Akronb93fabb2023-01-13 12:05:44 +0100859subtest 'Require tokenizer' => sub {
860
861 my $t = test_tei2korapxml(
862 file => catfile($f, 'data', 'icc_german_sample.p5.xml'),
863 tmp => 'script_utf8_enc'
864 )->stderr_like(qr!No tokenizer chosen!);
865};
866
Akron72f4a882023-03-02 09:48:14 +0100867subtest 'Test handling of textSigle in text' => sub {
868
869 my $t = test_tei2korapxml(
870 file => catfile($f, 'data', 'text_with_textsigle_in_text.i5.xml'),
871 tmp => 'script_out',
872 param => '-ti'
873 )
874 ->stderr_like(qr!tei2korapxml:.*? text_id=CORP_DOC.00001!)
875 ->stderr_unlike(qr!line with closing text-body tag 'text' contains additional information!);
876};
877
Marc Kupietzff061ef2026-03-05 09:59:35 +0100878subtest 'Handling of closing body and text tags on same line' => sub {
879
880 # Create a custom test file where </body> and </text> are on the same line
881 my ($fh, $testfile) = korap_tempfile('script_closing_tags');
882 print $fh <<'XML';
883<?xml version="1.0" encoding="UTF-8"?>
884<idsCorpus>
885 <idsHeader type="corpus">
886 <fileDesc>
887 <titleStmt>
888 <korpusSigle>AAA</korpusSigle>
889 </titleStmt>
890 </fileDesc>
891 </idsHeader>
892 <idsDoc version="1.0">
893 <idsHeader type="document">
894 <fileDesc>
895 <titleStmt>
896 <dokumentSigle>AAA/BBB</dokumentSigle>
897 </titleStmt>
898 </fileDesc>
899 </idsHeader>
900 <idsText version="1.0">
901 <idsHeader type="text">
902 <fileDesc>
903 <titleStmt>
904 <textSigle>AAA/BBB.00000</textSigle>
905 </titleStmt>
906 </fileDesc>
907 </idsHeader>
908 <text>
909 <body><p>some text</p>
910 </body> </text>
911 </idsText>
912 </idsDoc>
913</idsCorpus>
914XML
915 close($fh);
916
917 test_tei2korapxml(
918 file => $testfile,
919 tmp => 'script_closing_tags_out',
920 param => '-ti'
921 )
922 ->stderr_like(qr!tei2korapxml:.*? text_id=AAA_BBB\.00000!)
923 ->stderr_unlike(qr!line with closing text-body tag 'text' contains additional information!);
924};
925
Akronec503252023-04-24 18:03:17 +0200926subtest 'Handling of whitespace at linebreaks' => sub {
927 my $t = test_tei2korapxml(
928 file => catfile($f, 'data', 'stadigmer.p5.xml'),
929 tmp => 'script_out',
930 param => '-s -ti',
931 )
932 ->stderr_like(qr!tei2korapxml:.*? text_id=NO_000\.00000!);
933 $t->unzip_xml('NO/000/00000/data.xml')
934 ->content_like(qr/har lurt/)
935 ->content_like(qr/etter at/)
936 ->content_like(qr/en stund/)
937 ->content_like(qr/skjønner med/)
938 ->content_like(qr/og det/)
939 ->content_like(qr/stadig mer/)
940 ->content_like(qr/sitt, og/)
941 ->content_like(qr/tenkt å bli/)
942 ->content_like(qr/er både/)
943 ;
944};
945
Akron132bdeb2024-06-06 14:28:56 +0200946subtest 'Write to output' => sub {
947
948 my $temp_out = korap_tempfile('out');
949
950 my $t = test_tei2korapxml(
951 file => catfile($f, 'data', 'stadigmer.p5.xml'),
952 tmp => 'script_out',
953 param => '-s -ti -o "' . $temp_out . '"',
954 )->stderr_like(qr!tei2korapxml:.*? text_id=NO_000\.00000!)
955 ->stdout_is('');
956
957 my $content;
958 open(X, '<' . $temp_out);
959 binmode(X);
960 $content .= <X> while !eof(X);
961 close(X);
962 $t->{stdout} = $content;
963
964 $t->unzip_xml('NO/000/00000/data.xml')
965 ->content_like(qr/har lurt/)
966 ->content_like(qr/etter at/)
967 ->content_like(qr/en stund/)
968 ->content_like(qr/skjønner med/)
969 ->content_like(qr/og det/)
970 ->content_like(qr/stadig mer/)
971 ->content_like(qr/sitt, og/)
972 ->content_like(qr/tenkt å bli/)
973 ->content_like(qr/er både/)
974 ;
975
976 unlink $temp_out;
977};
978
Akron6b1f26b2024-09-19 11:35:32 +0200979subtest 'Handling of dependency data (1)' => sub {
980 my $t = test_tei2korapxml(
981 file => catfile($f, 'data', 'SKU21.head.i5.xml'),
982 tmp => 'script_out',
983 param => '-s --no-tokenizer --inline-tokens=csc#morpho',
984 )
985 ->stderr_like(qr!tei2korapxml:.*? text_id=SKU21_JAN\.00001!);
986 $t->unzip_xml('SKU21/JAN/00001/data.xml')
987 ->content_like(qr/cgICpWb AQNFU/)
988 ->content_like(qr/LhyS OLHV/)
989 ->content_like(qr/kdQVs hunIRQIN/)
990 ;
991
992 $t->unzip_xml('SKU21/JAN/00001/csc/morpho.xml')
993 ->attr_is('spanList span:nth-child(2)', 'id', 's1')
994 ->attr_is('#s1', 'from', '5')
995 ->attr_is('#s1', 'to', '9')
996 ->text_is('#s1 fs f fs f[name="deprel"]', 'name')
997 ->text_is('#s1 fs f fs f[name="head"]', '3')
998 ->text_is('#s1 fs f fs f[name="lemma"]', 'kCXD')
999 ->text_is('#s1 fs f fs f[name="msd"]', 'SUBCAT_Prop|CASECHANGE_Up|OTHER_UNK')
1000 ->text_is('#s1 fs f fs f[name="n"]', '2')
1001 ->text_is('#s1 fs f fs f[name="pos"]', 'N')
1002 ;
1003};
1004
1005subtest 'Handling of dependency data (2)' => sub {
1006 my $t = test_tei2korapxml(
1007 file => catfile($f, 'data', 'SKU21.head.i5.xml'),
1008 tmp => 'script_out',
1009 param => '-s --no-tokenizer ' .
1010 '--inline-tokens=csc#morpho ' .
1011 '--inline-dependencies=!csc ' .
1012 '--no-skip-inline-token-annotations',
1013 )
1014 ->stderr_like(qr!tei2korapxml:.*? text_id=SKU21_JAN\.00001!)
1015 ->stderr_like(qr!tei2korapxml:.*? text_id=SKU21_JAN\.00002!)
1016 ->stderr_like(qr!tei2korapxml:.*? text_id=SKU21_JAN\.00003!)
1017 ;
1018
1019 $t->unzip_xml('SKU21/JAN/00001/data.xml')
1020 ->content_like(qr/cgICpWb AQNFU/)
1021 ->content_like(qr/LhyS OLHV/)
1022 ->content_like(qr/kdQVs hunIRQIN/)
1023 ;
1024
1025 $t->unzip_xml('SKU21/JAN/00001/csc/morpho.xml')
1026 ->attr_is('spanList span:nth-child(2)', 'id', 's1')
1027 ->attr_is('#s1', 'from', '5')
1028 ->attr_is('#s1', 'to', '9')
1029 ->text_is('#s1 fs f fs f[name="lemma"]', 'kCXD')
1030 ->text_is('#s1 fs f fs f[name="msd"]', 'SUBCAT_Prop|CASECHANGE_Up|OTHER_UNK')
1031 ->text_is('#s1 fs f fs f[name="pos"]', 'N')
1032 ->element_exists_not('#s1 fs f fs f[name="n"]')
1033 ->element_exists_not('#s1 fs f fs f[name="deprel"]')
1034 ->element_exists_not('#s1 fs f fs f[name="head"]')
1035 ;
1036
1037 $t->unzip_xml('SKU21/JAN/00001/csc/dependency.xml')
1038 ->attr_is('spanList span:nth-child(2)', 'id', 's1_n2')
1039 ->attr_is('#s1_n2', "from", "5")
1040 ->attr_is('#s1_n2', "to", "9")
1041 ->attr_is('#s1_n2 rel', "label", "name")
1042 ->attr_is('#s1_n2 rel span', "from", '10')
1043 ->attr_is('#s1_n2 rel span', "to", '15')
1044 ;
1045
1046 $t->unzip_xml('SKU21/JAN/00002/csc/dependency.xml')
1047 ->attr_is('spanList span:nth-child(2)', 'id', 's1_n2')
1048 ->attr_is('#s1_n2', "from", "4")
1049 ->attr_is('#s1_n2', "to", "5")
1050 ->attr_is('#s1_n2 rel', "label", "poss")
1051 ->attr_is('#s1_n2 rel span', "from", '6')
1052 ->attr_is('#s1_n2 rel span', "to", '12')
1053 ;
1054};
1055
1056
Akron797e8072020-02-13 07:59:40 +01001057done_testing;