Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use Data::Dumper; |
| 5 | use JSON::XS; |
| 6 | |
Akron | fab17d3 | 2020-07-31 14:38:29 +0200 | [diff] [blame] | 7 | if ($ENV{SKIP_REAL}) { |
| 8 | plan skip_all => 'Skip real tests'; |
| 9 | }; |
| 10 | |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 11 | use Benchmark qw/:hireswallclock/; |
| 12 | |
| 13 | my $t = Benchmark->new; |
| 14 | |
| 15 | use utf8; |
| 16 | use lib 'lib', '../lib'; |
| 17 | |
| 18 | use File::Basename 'dirname'; |
| 19 | use File::Spec::Functions 'catdir'; |
| 20 | |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 21 | use_ok('KorAP::XML::Krill'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 22 | |
Akron | 414ec95 | 2020-08-03 15:48:43 +0200 | [diff] [blame] | 23 | my $path = catdir(dirname(__FILE__), 'corpus','BZK','D59','00089'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 24 | |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 25 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::XML::Krill'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 26 | ok($doc->parse, 'Parse document'); |
| 27 | |
Akron | 1cd5b87 | 2016-03-22 00:23:46 +0100 | [diff] [blame] | 28 | is($doc->text_sigle, 'BZK/D59/00089', 'Correct text sigle'); |
| 29 | is($doc->doc_sigle, 'BZK/D59', 'Correct document sigle'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 30 | is($doc->corpus_sigle, 'BZK', 'Correct corpus sigle'); |
| 31 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 32 | my $meta = $doc->meta; |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 33 | is($meta->{T_title}, 'Saragat-Partei zerfällt', 'Title'); |
| 34 | ok(!$meta->{T_sub_title}, 'No SubTitle'); |
| 35 | ok(!$meta->{T_author}, 'Author'); |
| 36 | ok(!$meta->{A_editor}, 'Editor'); |
| 37 | is($meta->{S_pub_place}, 'Berlin', 'PubPlace'); |
| 38 | is($meta->{D_pub_date}, '19590219', 'PubDate'); |
| 39 | ok(!$meta->{A_publisher}, 'Publisher'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 40 | |
Akron | 9d01c1e | 2024-07-25 18:29:10 +0200 | [diff] [blame^] | 41 | is($meta->{K_award}->[0], 'Deutscher Buchpreis 2023', 'Award'); |
| 42 | is($meta->{K_award}->[1], 'Booker price 2024', 'Award'); |
| 43 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 44 | is($meta->{S_text_type}, 'Zeitung: Tageszeitung', 'Correct Text Type'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 45 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 46 | ok(!$meta->{S_text_type_art}, 'Correct Text Type Art'); |
| 47 | is($meta->{S_text_type_ref}, 'Tageszeitung', 'Correct Text Type Ref'); |
| 48 | is($meta->{S_text_domain}, 'Politik', 'Correct Text Domain'); |
| 49 | is($meta->{S_text_column}, 'POLITIK', 'Correct Text Column'); |
| 50 | is($meta->{K_text_class}->[0], 'politik', 'Correct Text Class'); |
| 51 | is($meta->{K_text_class}->[1], 'ausland', 'Correct Text Class'); |
| 52 | ok(!$meta->{K_text_class}->[2], 'Correct Text Class'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 53 | |
| 54 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 55 | is($meta->{D_creation_date}, '19590219', 'Creation date'); |
| 56 | is($meta->{S_availability}, 'ACA-NC-LC', 'License'); |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 57 | ok(!$meta->{pages}, 'Pages'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 58 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 59 | ok(!$meta->{A_file_edition_statement}, 'File Statement'); |
| 60 | ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 61 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 62 | is($meta->{A_reference} . "\n", <<'REF', 'Reference'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 63 | Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt |
| 64 | REF |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 65 | is($meta->{S_language}, 'de', 'Language'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 66 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 67 | is($meta->{T_corpus_title}, 'Bonner Zeitungskorpus', 'Correct Corpus title'); |
| 68 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title'); |
| 69 | ok(!$meta->{T_corpus_author}, 'Correct Corpus author'); |
| 70 | ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 71 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 72 | is($meta->{T_doc_title}, 'Neues Deutschland', 'Correct Doc title'); |
| 73 | is($meta->{T_doc_sub_title}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title'); |
| 74 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
| 75 | ok(!$meta->{A_doc_editor}, 'Correct doc editor'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 76 | |
| 77 | # Tokenization |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 78 | use_ok('KorAP::XML::Tokenizer'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 79 | |
| 80 | my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/); |
| 81 | |
| 82 | # Get tokenization |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 83 | my $tokens = KorAP::XML::Tokenizer->new( |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 84 | path => $doc->path, |
| 85 | doc => $doc, |
| 86 | foundry => $token_base_foundry, |
| 87 | layer => $token_base_layer, |
| 88 | name => 'tokens' |
| 89 | ); |
| 90 | ok($tokens, 'Token Object is fine'); |
| 91 | ok($tokens->parse, 'Token parsing is fine'); |
| 92 | |
| 93 | my $output = decode_json( $tokens->to_json ); |
| 94 | |
| 95 | is(substr($output->{data}->{text}, 0, 100), 'Saragat-Partei zerfällt Rom (ADN) die von dem Rechtssozialisten Saragat geführte Sozialdemokratische', 'Primary Data'); |
| 96 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 97 | is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource'); |
| 98 | is($output->{version}, '0.03', 'version'); |
| 99 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 100 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
Akron | 2d83a5a | 2016-02-26 00:21:16 +0100 | [diff] [blame] | 101 | is($output->{data}->{stream}->[0]->[4], 's:Saragat-Partei', 'data'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 102 | |
Akron | 1cd5b87 | 2016-03-22 00:23:46 +0100 | [diff] [blame] | 103 | is($output->{textSigle}, 'BZK/D59/00089', 'Correct text sigle'); |
| 104 | is($output->{docSigle}, 'BZK/D59', 'Correct document sigle'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 105 | is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle'); |
| 106 | |
| 107 | is($output->{title}, 'Saragat-Partei zerfällt', 'Title'); |
| 108 | ok(!exists $output->{subTitle}, 'No SubTitle'); |
| 109 | ok(!exists $output->{author}, 'Author'); |
| 110 | ok(!exists $output->{editor}, 'Publisher'); |
| 111 | |
| 112 | is($output->{pubPlace}, 'Berlin', 'PubPlace'); |
| 113 | ok(!exists $output->{publisher}, 'Publisher'); |
| 114 | |
| 115 | is($output->{textType}, 'Zeitung: Tageszeitung', 'Correct Text Type'); |
| 116 | ok(!exists $output->{textTypeArt}, 'Correct Text Type Art'); |
| 117 | is($output->{textTypeRef}, 'Tageszeitung', 'Correct Text Type Ref'); |
| 118 | is($output->{textDomain}, 'Politik', 'Correct Text Domain'); |
| 119 | is($output->{textClass}, 'politik ausland', 'Correct Text Domain'); |
| 120 | |
| 121 | is($output->{creationDate}, '19590219', 'Creation date'); |
Akron | 6396c30 | 2016-03-18 16:05:39 +0100 | [diff] [blame] | 122 | is($output->{availability}, 'ACA-NC-LC', 'License'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 123 | ok(!exists $output->{pages}, 'Pages'); |
| 124 | ok(!exists $output->{fileEditionStatement}, 'File Statement'); |
| 125 | ok(!exists $output->{biblEditionStatement}, 'Bibl Statement'); |
| 126 | |
| 127 | is($output->{reference} . "\n", <<'REF', 'Reference'); |
| 128 | Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt |
| 129 | REF |
| 130 | is($output->{language}, 'de', 'Language'); |
| 131 | |
| 132 | is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title'); |
| 133 | ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title'); |
| 134 | ok(!exists $output->{corpusAuthor}, 'Correct Corpus author'); |
| 135 | ok(!exists $output->{corpusEditor}, 'Correct Corpus editor'); |
| 136 | |
| 137 | is($output->{docTitle}, 'Neues Deutschland', 'Correct Doc title'); |
| 138 | is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title'); |
| 139 | ok(!exists $output->{docAuthor}, 'Correct Doc author'); |
| 140 | ok(!exists $output->{docEditor}, 'Correct doc editor'); |
| 141 | |
| 142 | ## Base |
| 143 | $tokens->add('Base', 'Sentences'); |
| 144 | $tokens->add('Base', 'Paragraphs'); |
| 145 | |
| 146 | $output = decode_json( $tokens->to_json ); |
| 147 | |
| 148 | is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries'); |
| 149 | is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos'); |
| 150 | my $first_token = join('||', @{$output->{data}->{stream}->[0]}); |
| 151 | like($first_token, qr/s:Saragat-Partei/, 'data'); |
| 152 | like($first_token, qr/_0\$<i>0<i>14/, 'data'); |
| 153 | |
| 154 | ## OpenNLP |
| 155 | $tokens->add('OpenNLP', 'Sentences'); |
| 156 | |
| 157 | $output = decode_json( $tokens->to_json ); |
| 158 | is($output->{data}->{foundries}, |
| 159 | 'base base/paragraphs base/sentences opennlp opennlp/sentences', |
| 160 | 'Foundries'); |
| 161 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos'); |
| 162 | |
| 163 | $tokens->add('OpenNLP', 'Morpho'); |
| 164 | $output = decode_json( $tokens->to_json ); |
| 165 | is($output->{data}->{foundries}, |
| 166 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences', |
| 167 | 'Foundries'); |
| 168 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos'); |
| 169 | |
| 170 | ## Treetagger |
| 171 | $tokens->add('TreeTagger', 'Sentences'); |
| 172 | $output = decode_json( $tokens->to_json ); |
| 173 | is($output->{data}->{foundries}, |
| 174 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences', |
| 175 | 'Foundries'); |
| 176 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos'); |
| 177 | |
| 178 | $tokens->add('TreeTagger', 'Morpho'); |
| 179 | $output = decode_json( $tokens->to_json ); |
| 180 | is($output->{data}->{foundries}, |
| 181 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 182 | 'Foundries'); |
| 183 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 184 | |
| 185 | ## CoreNLP |
| 186 | $tokens->add('CoreNLP', 'NamedEntities'); |
| 187 | $output = decode_json( $tokens->to_json ); |
| 188 | is($output->{data}->{foundries}, |
| 189 | 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 190 | 'Foundries'); |
| 191 | is($output->{data}->{layerInfos}, 'base/s=spans corenlp/ne=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 192 | |
| 193 | $tokens->add('CoreNLP', 'Sentences'); |
| 194 | $output = decode_json( $tokens->to_json ); |
| 195 | is($output->{data}->{foundries}, |
| 196 | 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 197 | 'Foundries'); |
| 198 | is($output->{data}->{layerInfos}, 'base/s=spans corenlp/ne=tokens corenlp/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 199 | |
| 200 | $tokens->add('CoreNLP', 'Morpho'); |
| 201 | $output = decode_json( $tokens->to_json ); |
| 202 | like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries'); |
| 203 | like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos'); |
| 204 | |
| 205 | $tokens->add('CoreNLP', 'Constituency'); |
| 206 | $output = decode_json( $tokens->to_json ); |
| 207 | like($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries'); |
| 208 | like($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos'); |
| 209 | |
| 210 | ## Glemm |
| 211 | $tokens->add('Glemm', 'Morpho'); |
| 212 | $output = decode_json( $tokens->to_json ); |
| 213 | like($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries'); |
| 214 | like($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos'); |
| 215 | |
| 216 | ## Connexor |
| 217 | $tokens->add('Connexor', 'Sentences'); |
| 218 | $output = decode_json( $tokens->to_json ); |
| 219 | like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries'); |
| 220 | like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos'); |
| 221 | |
| 222 | $tokens->add('Connexor', 'Morpho'); |
| 223 | $output = decode_json( $tokens->to_json ); |
| 224 | like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries'); |
| 225 | like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos'); |
| 226 | like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos'); |
| 227 | like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos'); |
| 228 | |
| 229 | $tokens->add('Connexor', 'Phrase'); |
| 230 | $output = decode_json( $tokens->to_json ); |
| 231 | like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries'); |
| 232 | like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos'); |
| 233 | |
| 234 | $tokens->add('Connexor', 'Syntax'); |
| 235 | $output = decode_json( $tokens->to_json ); |
| 236 | like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries'); |
| 237 | like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos'); |
| 238 | |
| 239 | ## Mate |
| 240 | $tokens->add('Mate', 'Morpho'); |
| 241 | $output = decode_json( $tokens->to_json ); |
| 242 | like($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries'); |
| 243 | like($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos'); |
| 244 | like($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos'); |
| 245 | like($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos'); |
| 246 | |
| 247 | # diag "No test for mate dependency"; |
| 248 | |
| 249 | ## XIP |
| 250 | $tokens->add('XIP', 'Sentences'); |
| 251 | $output = decode_json( $tokens->to_json ); |
| 252 | like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries'); |
| 253 | like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos'); |
| 254 | |
| 255 | $tokens->add('XIP', 'Morpho'); |
| 256 | $output = decode_json( $tokens->to_json ); |
| 257 | like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries'); |
| 258 | like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos'); |
| 259 | like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos'); |
| 260 | |
| 261 | $tokens->add('XIP', 'Constituency'); |
| 262 | $output = decode_json( $tokens->to_json ); |
| 263 | like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries'); |
| 264 | like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos'); |
| 265 | |
| 266 | # diag "No test for xip dependency"; |
| 267 | |
| 268 | done_testing; |
| 269 | __END__ |