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