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