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