Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use Data::Dumper; |
| 5 | use JSON::XS; |
| 6 | use Log::Log4perl; |
| 7 | |
| 8 | use utf8; |
| 9 | use lib 'lib', '../lib'; |
| 10 | |
| 11 | use File::Basename 'dirname'; |
| 12 | use File::Spec::Functions 'catdir'; |
| 13 | |
| 14 | # Initialize log4perl object |
| 15 | Log::Log4perl->init({ |
| 16 | 'log4perl.rootLogger' => 'ERROR, STDERR', |
| 17 | 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels', |
| 18 | 'log4perl.appender.STDERR.layout' => 'PatternLayout', |
| 19 | 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n' |
| 20 | }); |
| 21 | |
| 22 | use_ok('KorAP::XML::Krill'); |
| 23 | |
| 24 | my $path = catdir(dirname(__FILE__), '../corpus/REDEW/DOC1/00000'); |
| 25 | |
| 26 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 27 | ok($doc->parse, 'Parse document'); |
| 28 | |
| 29 | is($doc->text_sigle, 'REDEW/DOC1/00000', 'Correct text sigle'); |
| 30 | is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle'); |
| 31 | is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle'); |
| 32 | |
| 33 | my $meta = $doc->meta; |
| 34 | ok(!$meta->{T_title}, 'Title'); # ??? |
| 35 | ok(!$meta->{T_sub_title}, 'SubTitle'); |
| 36 | ok(!$meta->{T_author}, 'Author'); |
| 37 | ok(!$meta->{A_editor}, 'Editor'); |
| 38 | ok(!$meta->{S_pub_place}, 'PubPlace'); |
Akron | 8ff5879 | 2020-04-17 16:51:55 +0200 | [diff] [blame] | 39 | ok(!$meta->{A_publisher}, 'Publisher'); |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 40 | |
| 41 | is($meta->{S_text_type}, '?', 'Text Type'); # ??? |
| 42 | ok(!$meta->{S_text_type_art}, 'No Text Type Art'); |
| 43 | ok(!$meta->{S_text_type_ref}, 'No Text Type Ref'); |
| 44 | ok(!$meta->{S_text_domain}, 'No Text Domain'); |
| 45 | ok(!$meta->{S_text_column}, 'No Text Column'); |
| 46 | |
| 47 | ok(!$meta->{K_text_class}->[0], 'Correct Text Class'); |
| 48 | |
Akron | 8ff5879 | 2020-04-17 16:51:55 +0200 | [diff] [blame] | 49 | is($meta->{D_pub_date}, '00000000', 'Creation date'); # ??? |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 50 | is($meta->{D_creation_date}, '20200000', 'Creation date'); |
| 51 | is($meta->{S_availability}, 'QAO-NC', 'License'); # ??? |
| 52 | ok(!$meta->{A_pages}, 'Pages'); |
| 53 | |
| 54 | ok(!$meta->{A_file_edition_statement}, 'File Statement'); |
| 55 | ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement'); |
| 56 | |
| 57 | ok(!$meta->{A_reference}, 'Reference'); |
| 58 | ok(!$meta->{S_language}, 'Language'); # ??? |
| 59 | |
| 60 | is($meta->{T_corpus_title}, 'Redewiedergabe', 'Correct Corpus title'); |
| 61 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title'); |
Akron | 8ff5879 | 2020-04-17 16:51:55 +0200 | [diff] [blame] | 62 | ok(!$meta->{T_corpus_author}, 'Correct Corpus author'); |
| 63 | ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor'); |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 64 | |
| 65 | is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Correct Doc title'); |
| 66 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc sub title'); |
| 67 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
| 68 | ok(!$meta->{A_doc_editor}, 'Correct doc editor'); |
| 69 | |
| 70 | # Tokenization |
| 71 | use_ok('KorAP::XML::Tokenizer'); |
| 72 | |
| 73 | my ($token_base_foundry, $token_base_layer) = (qw/drukola Morpho/); |
| 74 | |
| 75 | # Get tokenization |
| 76 | my $tokens = KorAP::XML::Tokenizer->new( |
| 77 | path => $doc->path, |
| 78 | doc => $doc, |
| 79 | foundry => $token_base_foundry, |
| 80 | layer => $token_base_layer, |
| 81 | name => 'tokens' |
| 82 | ); |
| 83 | |
| 84 | ok($tokens, 'Token Object is fine'); |
| 85 | ok($tokens->parse, 'Token parsing is fine'); |
| 86 | |
| 87 | my $output = decode_json( $tokens->to_json ); |
| 88 | |
| 89 | is(substr($output->{data}->{text}, 0, 100), 'Cechov,_Anton_Pavlovic_Gram.tg4_1.xml 1886 1880 Gram Čechov, Anton Pavlovič yes yes Erzähltext digbi', 'Primary Data'); |
| 90 | |
| 91 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 92 | is($output->{data}->{tokenSource}, 'drukola#morpho', 'tokenSource'); |
| 93 | is($output->{version}, '0.03', 'version'); |
| 94 | |
| 95 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 96 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
| 97 | is($output->{data}->{stream}->[0]->[4], 's:Hörst', 'data'); |
| 98 | |
| 99 | is($output->{textSigle}, 'REDEW/DOC1/00000', 'Correct text sigle'); |
| 100 | is($output->{docSigle}, 'REDEW/DOC1', 'Correct document sigle'); |
| 101 | is($output->{corpusSigle}, 'REDEW', 'Correct corpus sigle'); |
| 102 | |
| 103 | ok(!$output->{title}, 'Title'); |
| 104 | ok(!$output->{subTitle}, 'Correct SubTitle'); |
| 105 | ok(!$output->{author}, 'Author'); |
| 106 | ok(!exists $output->{editor}, 'Publisher'); |
| 107 | |
| 108 | # Add annotations |
| 109 | $tokens->add('DRuKoLa', 'Morpho'); |
| 110 | $tokens->add('DeReKo', 'Structure'); |
| 111 | |
| 112 | $output = decode_json( $tokens->to_json ); |
| 113 | |
| 114 | my $first = $output->{data}->{stream}->[0]; |
| 115 | |
| 116 | is('-:tokens$<i>13',$first->[0]); |
Akron | dec4312 | 2020-03-03 11:22:25 +0100 | [diff] [blame] | 117 | is('<>:base/s:t$<b>64<i>0<i>197<i>13<b>0',$first->[1]); |
| 118 | is('<>:dereko/s:text$<b>64<i>0<i>197<i>13<b>0',$first->[2]); |
| 119 | is('<>:dereko/s:body$<b>64<i>118<i>197<i>13<b>1',$first->[3]); |
| 120 | is('<>:dereko/s:p$<b>64<i>118<i>197<i>13<b>2',$first->[4]); |
| 121 | is('<>:dereko/s:said$<b>64<i>118<i>197<i>13<b>3<s>1',$first->[5]); |
| 122 | is('@:dereko/s:level:1$<b>17<s>1<i>13',$first->[6]); |
| 123 | is('@:dereko/s:content:speech$<b>17<s>1<i>13',$first->[7]); |
| 124 | is('@:dereko/s:mode:direct$<b>17<s>1<i>13',$first->[8]); |
| 125 | is('@:dereko/s:id:1$<b>17<s>1<i>13',$first->[9]); |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 126 | is('_0$<i>123<i>128',$first->[10]); |
| 127 | is("drukola/l:H\x{f6}rst",$first->[11]); |
| 128 | is('drukola/m:msd:rfpos',$first->[12]); |
| 129 | is('drukola/m:sentstart:no',$first->[13]); |
| 130 | is('drukola/m:stwr:direct.speech.1',$first->[14]); |
| 131 | is('drukola/p:VVFIN',$first->[15]); |
| 132 | is("i:h\x{f6}rst",$first->[16]); |
| 133 | is("s:H\x{f6}rst",$first->[17]); |
| 134 | |
| 135 | my $nine = join(',', @{$output->{data}->{stream}->[9]}); |
| 136 | like($nine, qr{drukola\/l:nichts}, 'Nichts'); |
| 137 | like($nine, qr{_9\$<i>170<i>176}, 'Term boundaries'); |
Akron | dec4312 | 2020-03-03 11:22:25 +0100 | [diff] [blame] | 138 | unlike($nine, qr{<>:dereko/s:said\$<b>64<i>176<i>196<i>13<b>4<s>1}, 'Term boundaries'); |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 139 | |
| 140 | my $ten = join(',', @{$output->{data}->{stream}->[10]}); |
| 141 | like($ten, qr{_10\$<i>177<i>180}, 'Term boundaries'); |
Akron | dec4312 | 2020-03-03 11:22:25 +0100 | [diff] [blame] | 142 | like($ten, qr{<>:dereko/s:said\$<b>64<i>176<i>196<i>13<b>4<s>1}, 'Term boundaries'); |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 143 | |
| 144 | my $eleven = join(',', @{$output->{data}->{stream}->[11]}); |
| 145 | like($eleven, qr{_11\$<i>181<i>188}, 'Term boundaries'); |
| 146 | like($eleven, qr{<>:dereko/s:seg\$<b>64<i>180<i>188<i>12<b>5<s>1}, 'Segment'); |
| 147 | |
| 148 | |
| 149 | my $twelve = join(',', @{$output->{data}->{stream}->[12]}); |
| 150 | like($twelve, qr{_12\$<i>189<i>195}, 'Term boundaries'); |
| 151 | like($twelve, qr{drukola/l:Wort}, 'Lemma'); |
| 152 | like($twelve, qr{<>:dereko/s:seg\$<b>64<i>188<i>195<i>13<b>5<s>1}, 'Segment'); |
| 153 | |
Akron | 8ff5879 | 2020-04-17 16:51:55 +0200 | [diff] [blame] | 154 | |
| 155 | # Updated format: |
| 156 | $path = catdir(dirname(__FILE__), '../corpus/REDEW/DOC1b/00011'); |
| 157 | |
| 158 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 159 | ok($doc->parse, 'Parse document'); |
| 160 | |
| 161 | is($doc->text_sigle, 'REDEW/DOC1/00011', 'Correct text sigle'); |
| 162 | is($doc->doc_sigle, 'REDEW/DOC1', 'Correct document sigle'); |
| 163 | is($doc->corpus_sigle, 'REDEW', 'Correct corpus sigle'); |
| 164 | |
| 165 | $meta = $doc->meta; |
| 166 | |
| 167 | is($meta->{A_distributor}, 'Institut für Deutsche Sprache', 'Distributor'); |
| 168 | is($meta->{D_pub_date}, '18730000', 'Publication date'); |
| 169 | is($meta->{D_creation_date}, '18730000', 'Publication date'); |
| 170 | is($meta->{S_pub_place_key}, 'DE', 'Publication place key'); |
| 171 | is($meta->{T_corpus_title}, 'Redewiedergabe', 'Title'); |
| 172 | is($meta->{T_doc_title}, 'Redewiedergabe Dokument 1', 'Title'); |
| 173 | is($meta->{T_author}, 'Christen, Ada', 'Author'); |
| 174 | is($meta->{T_title}, 'Rahel', 'Author'); |
| 175 | is($meta->{S_availability}, 'QAO-NC-LOC:ids', 'Availability'); |
| 176 | is($meta->{S_text_type_art}, 'Erzähltext', 'Availability'); |
| 177 | |
| 178 | # Tokenization |
| 179 | use_ok('KorAP::XML::Tokenizer'); |
| 180 | |
| 181 | ($token_base_foundry, $token_base_layer) = (qw/rwk Morpho/); |
| 182 | |
| 183 | # Get tokenization |
| 184 | $tokens = KorAP::XML::Tokenizer->new( |
| 185 | path => $doc->path, |
| 186 | doc => $doc, |
| 187 | foundry => $token_base_foundry, |
| 188 | layer => $token_base_layer, |
| 189 | name => 'tokens' |
| 190 | ); |
| 191 | |
| 192 | ok($tokens, 'Token Object is fine'); |
| 193 | ok($tokens->parse, 'Token parsing is fine'); |
| 194 | |
| 195 | $output = decode_json( $tokens->to_json ); |
| 196 | |
| 197 | is(substr($output->{data}->{text}, 0, 100), 'Er hatte den Kopf weit nach rückwärts gebeugt, seine langen schwarzen Haare lockten sich über den li', 'Primary Data'); |
| 198 | |
Akron | 28299f4 | 2020-04-17 17:54:33 +0200 | [diff] [blame] | 199 | use Log::Log4perl; |
| 200 | |
| 201 | Log::Log4perl->init({ |
| 202 | 'log4perl.rootLogger' => 'WARN, STDERR', |
| 203 | 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels', |
| 204 | 'log4perl.appender.STDERR.layout' => 'PatternLayout', |
| 205 | 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n' |
| 206 | }); |
| 207 | |
| 208 | |
Akron | 8ff5879 | 2020-04-17 16:51:55 +0200 | [diff] [blame] | 209 | # Add annotations |
Akron | 28299f4 | 2020-04-17 17:54:33 +0200 | [diff] [blame] | 210 | ok($tokens->add('RWK', 'Morpho')); |
| 211 | ok($tokens->add('RWK', 'Structure')); |
Akron | 8ff5879 | 2020-04-17 16:51:55 +0200 | [diff] [blame] | 212 | |
| 213 | $output = decode_json( $tokens->to_json ); |
| 214 | |
| 215 | $first = $output->{data}->{stream}->[0]; |
| 216 | |
Akron | 28299f4 | 2020-04-17 17:54:33 +0200 | [diff] [blame] | 217 | is('-:base/paragraphs$<i>2',$first->[0]); |
| 218 | is('-:base/sentences$<i>21',$first->[1]); |
| 219 | is('-:tokens$<i>522',$first->[2]); |
| 220 | is('<>:base/s:s$<b>64<i>0<i>139<i>23<b>1',$first->[3]); |
| 221 | is('<>:base/s:p$<b>64<i>0<i>2631<i>449<b>1',$first->[4]); |
| 222 | is('<>:base/s:t$<b>64<i>0<i>3062<i>522<b>0',$first->[5]); |
| 223 | is('_0$<i>0<i>2',$first->[6]); |
| 224 | is('i:er',$first->[7]); |
| 225 | is('rwk/l:er',$first->[8]); |
| 226 | is('rwk/m:PRO.Pers.Subst.3.Nom.Sg.Masc',$first->[9]); |
| 227 | is('rwk/norm:Er',$first->[10]); |
| 228 | is('rwk/p:PPER',$first->[11]); |
| 229 | is('s:Er',$first->[12]); |
Akron | 8ff5879 | 2020-04-17 16:51:55 +0200 | [diff] [blame] | 230 | |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 231 | done_testing; |
Akron | 28299f4 | 2020-04-17 17:54:33 +0200 | [diff] [blame] | 232 | |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 233 | __END__ |
Akron | 8ff5879 | 2020-04-17 16:51:55 +0200 | [diff] [blame] | 234 | |