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/; |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 5 | use File::Temp ':POSIX'; |
| 6 | use IO::Uncompress::Unzip qw(unzip $UnzipError); |
Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 7 | |
| 8 | use Test::More; |
| 9 | use Test::Output; |
| 10 | |
Akron | d89ef82 | 2020-02-17 12:42:09 +0100 | [diff] [blame] | 11 | use Test::XML::Loy; |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 12 | |
Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 13 | my $f = dirname(__FILE__); |
| 14 | my $script = catfile($f, '..', 'script', 'tei2korapxml'); |
| 15 | ok(-f $script, 'Script found'); |
| 16 | |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 17 | stdout_like( |
Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 18 | sub { system('perl', $script, '--help') }, |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 19 | 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] | 20 | 'Help' |
| 21 | ); |
| 22 | |
Akron | d949e18 | 2020-02-14 12:23:57 +0100 | [diff] [blame] | 23 | stdout_like( |
| 24 | sub { system('perl', $script, '--version') }, |
| 25 | qr!tei2korapxml - v\d+?\.\d+?!, |
| 26 | 'Version' |
| 27 | ); |
| 28 | |
| 29 | |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 30 | # Load example file |
| 31 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 32 | my $outzip = tmpnam(); |
| 33 | |
| 34 | # Generate zip file (unportable!) |
| 35 | stderr_like( |
| 36 | sub { `cat '$file' | perl '$script' > '$outzip'` }, |
| 37 | qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!, |
| 38 | 'Processing' |
| 39 | ); |
| 40 | |
Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame^] | 41 | ok(-e $outzip, "File $outzip exists"); |
| 42 | |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 43 | # Uncompress GOE/header.xml from zip file |
| 44 | my $zip = IO::Uncompress::Unzip->new($outzip, Name => 'GOE/header.xml'); |
| 45 | |
| 46 | ok($zip, 'Zip-File is created'); |
| 47 | |
| 48 | # Read GOE/header.xml |
| 49 | my $header_xml = ''; |
| 50 | $header_xml .= $zip->getline while !$zip->eof; |
| 51 | ok($zip->close, 'Closed'); |
| 52 | |
Akron | d89ef82 | 2020-02-17 12:42:09 +0100 | [diff] [blame] | 53 | my $t = Test::XML::Loy->new($header_xml); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 54 | |
Akron | d89ef82 | 2020-02-17 12:42:09 +0100 | [diff] [blame] | 55 | $t->text_is('korpusSigle', 'GOE', 'korpusSigle') |
| 56 | ->text_is('h\.title[type=main]', 'Goethes Werke', 'h.title') |
| 57 | ->text_is('h\.author', 'Goethe, Johann Wolfgang von', 'h.author') |
| 58 | ->text_is('pubDate[type=year]', '1982', 'pubDate'); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 59 | |
Akron | 6896608 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 60 | |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 61 | # Uncompress GOE/AGA/header.xml from zip file |
| 62 | $zip = IO::Uncompress::Unzip->new($outzip, Name => 'GOE/AGA/header.xml'); |
| 63 | |
| 64 | ok($zip, 'Zip-File is found'); |
| 65 | |
| 66 | # Read GOE/AGA/header.xml |
| 67 | $header_xml = ''; |
| 68 | $header_xml .= $zip->getline while !$zip->eof; |
| 69 | ok($zip->close, 'Closed'); |
| 70 | |
Akron | d89ef82 | 2020-02-17 12:42:09 +0100 | [diff] [blame] | 71 | $t = Test::XML::Loy->new($header_xml); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 72 | |
Akron | d89ef82 | 2020-02-17 12:42:09 +0100 | [diff] [blame] | 73 | $t->text_is('dokumentSigle', 'GOE/AGA', 'dokumentSigle') |
| 74 | ->text_is('d\.title', 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)', 'd.title') |
| 75 | ->text_is('creatDate', '1820-1822', 'creatDate'); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 76 | |
| 77 | # Uncompress GOE/AGA/00000/header.xml from zip file |
| 78 | $zip = IO::Uncompress::Unzip->new($outzip, Name => 'GOE/AGA/00000/header.xml'); |
| 79 | |
| 80 | ok($zip, 'Zip-File is found'); |
| 81 | |
| 82 | # Read GOE/AGA/00000/header.xml |
| 83 | $header_xml = ''; |
| 84 | $header_xml .= $zip->getline while !$zip->eof; |
| 85 | ok($zip->close, 'Closed'); |
| 86 | |
Akron | d89ef82 | 2020-02-17 12:42:09 +0100 | [diff] [blame] | 87 | $t = Test::XML::Loy->new($header_xml); |
| 88 | $t->text_is('textSigle', 'GOE/AGA.00000', 'textSigle') |
| 89 | ->text_is('analytic > h\.title[type=main]', 'Campagne in Frankreich', 'h.title'); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 90 | |
| 91 | # Uncompress GOE/AGA/00000/data.xml from zip file |
| 92 | $zip = IO::Uncompress::Unzip->new($outzip, Name => 'GOE/AGA/00000/data.xml'); |
| 93 | |
| 94 | ok($zip, 'Zip-File is found'); |
| 95 | |
| 96 | # Read GOE/AGA/00000/data.xml |
| 97 | my $data_xml = ''; |
| 98 | $data_xml .= $zip->getline while !$zip->eof; |
| 99 | ok($zip->close, 'Closed'); |
| 100 | |
Akron | d89ef82 | 2020-02-17 12:42:09 +0100 | [diff] [blame] | 101 | $t = Test::XML::Loy->new($data_xml); |
| 102 | $t->attr_is('raw_text', 'docid', 'GOE_AGA.00000', 'text id') |
| 103 | ->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] | 104 | |
| 105 | # Uncompress GOE/AGA/00000/struct/structure.xml from zip file |
| 106 | $zip = IO::Uncompress::Unzip->new($outzip, Name => 'GOE/AGA/00000/struct/structure.xml'); |
| 107 | |
| 108 | ok($zip, 'Zip-File is found'); |
| 109 | |
| 110 | # Read GOE/AGA/00000/struct/structure.xml |
| 111 | my $struct_xml = ''; |
| 112 | $struct_xml .= $zip->getline while !$zip->eof; |
| 113 | ok($zip->close, 'Closed'); |
| 114 | |
Akron | d89ef82 | 2020-02-17 12:42:09 +0100 | [diff] [blame] | 115 | $t = Test::XML::Loy->new($struct_xml); |
| 116 | $t->text_is('span[id=s3] *[name=type]', 'Autobiographie', 'text content'); |
Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 117 | |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 118 | |
| 119 | # Uncompress GOE/AGA/00000/base/tokens_aggressive.xml from zip file |
| 120 | $zip = IO::Uncompress::Unzip->new($outzip, Name => 'GOE/AGA/00000/base/tokens_aggressive.xml'); |
| 121 | |
| 122 | # Read GOE/AGA/00000/base/tok.xml |
| 123 | my $tokens_xml = ''; |
| 124 | $tokens_xml .= $zip->getline while !$zip->eof; |
| 125 | ok($zip->close, 'Closed'); |
| 126 | |
| 127 | $t = Test::XML::Loy->new($tokens_xml); |
| 128 | $t->attr_is('spanList span:nth-child(1)', 'to', 8); |
| 129 | |
| 130 | $t->attr_is('spanList span#t_1', 'from', 9); |
| 131 | $t->attr_is('spanList span#t_1', 'to', 11); |
| 132 | |
| 133 | $t->attr_is('spanList span#t_67', 'from', 427); |
| 134 | $t->attr_is('spanList span#t_67', 'to', 430); |
| 135 | |
| 136 | $t->attr_is('spanList span#t_214', 'from', 1209); |
| 137 | $t->attr_is('spanList span#t_214', 'to', 1212); |
| 138 | |
| 139 | $t->element_count_is('spanList span', 227); |
| 140 | |
| 141 | |
| 142 | # Uncompress GOE/AGA/00000/base/tokens_conservative.xml from zip file |
| 143 | $zip = IO::Uncompress::Unzip->new($outzip, Name => 'GOE/AGA/00000/base/tokens_conservative.xml'); |
| 144 | |
| 145 | # Read GOE/AGA/00000/base/tok.xml |
| 146 | $tokens_xml = ''; |
| 147 | $tokens_xml .= $zip->getline while !$zip->eof; |
| 148 | ok($zip->close, 'Closed'); |
| 149 | |
| 150 | $t = Test::XML::Loy->new($tokens_xml); |
| 151 | $t->attr_is('spanList span:nth-child(1)', 'to', 8); |
| 152 | |
| 153 | $t->attr_is('spanList span#t_1', 'from', 9); |
| 154 | $t->attr_is('spanList span#t_1', 'to', 11); |
| 155 | |
| 156 | $t->attr_is('spanList span#t_67', 'from', 427); |
| 157 | $t->attr_is('spanList span#t_67', 'to', 430); |
| 158 | |
| 159 | $t->attr_is('spanList span#t_214', 'from', 1209); |
| 160 | $t->attr_is('spanList span#t_214', 'to', 1212); |
| 161 | |
| 162 | $t->element_count_is('spanList span', 227); |
| 163 | |
Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 164 | done_testing; |