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