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