Nils Diewald | 90410c2 | 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/00001'); |
| 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.00001', '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, 'Unser gemeinsames Werk wird siegreich sein', '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 | ok(!$doc->publisher, 'Publisher'); |
| 37 | |
| 38 | is($doc->text_type, 'Zeitung: Tageszeitung', 'Correct Text Type'); |
| 39 | |
| 40 | ok(!$doc->text_type_art, 'Correct Text Type Art'); |
| 41 | is($doc->text_type_ref, 'Tageszeitung', 'Correct Text Type Ref'); |
| 42 | is($doc->text_domain, 'Politik', 'Correct Text Domain'); |
| 43 | is($doc->text_column, 'POLITIK', 'Correct Text Column'); |
| 44 | is($doc->text_class->[0], 'politik', 'Correct Text Class'); |
| 45 | is($doc->text_class->[1], 'ausland', 'Correct Text Class'); |
| 46 | ok(!$doc->text_class->[2], 'Correct Text Class'); |
| 47 | |
| 48 | is($doc->pub_date, '19590101', 'Creation date'); |
| 49 | is($doc->creation_date, '19590101', 'Creation date'); |
| 50 | is($doc->license, 'ACA-NC-LC', 'License'); |
| 51 | ok(!$doc->pages, 'Pages'); |
| 52 | |
| 53 | ok(!$doc->file_edition_statement, 'File Statement'); |
| 54 | ok(!$doc->bibl_edition_statement, 'Bibl Statement'); |
| 55 | |
| 56 | is($doc->reference . "\n", <<'REF', 'Reference'); |
| 57 | Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein |
| 58 | REF |
| 59 | is($doc->language, 'de', 'Language'); |
| 60 | |
| 61 | is($doc->corpus_title, 'Bonner Zeitungskorpus', 'Correct Corpus title'); |
| 62 | ok(!$doc->corpus_sub_title, 'Correct Corpus sub title'); |
| 63 | ok(!$doc->corpus_author, 'Correct Corpus author'); |
| 64 | ok(!$doc->corpus_editor, 'Correct Corpus editor'); |
| 65 | |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 66 | is($doc->doc_title, 'Neues Deutschland, Jahrgangsquerschnitt 1959', 'Correct Doc title'); |
Nils Diewald | 90410c2 | 2014-11-03 21:04:05 +0000 | [diff] [blame] | 67 | is($doc->doc_sub_title, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title'); |
| 68 | ok(!$doc->doc_author, 'Correct Doc author'); |
| 69 | ok(!$doc->doc_editor, 'Correct doc editor'); |
| 70 | |
| 71 | # Tokenization |
| 72 | use_ok('KorAP::Tokenizer'); |
| 73 | |
| 74 | my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/); |
| 75 | |
| 76 | # Get tokenization |
| 77 | my $tokens = KorAP::Tokenizer->new( |
| 78 | path => $doc->path, |
| 79 | doc => $doc, |
| 80 | foundry => $token_base_foundry, |
| 81 | layer => $token_base_layer, |
| 82 | name => 'tokens' |
| 83 | ); |
| 84 | ok($tokens, 'Token Object is fine'); |
| 85 | ok($tokens->parse, 'Token parsing is fine'); |
| 86 | |
| 87 | my $output = decode_json( $tokens->to_json ); |
| 88 | |
| 89 | is(substr($output->{data}->{text}, 0, 100), 'unser gemeinsames Werk wird siegreich sein Neujahrsbotschaft des Präsidenten der DeutschenDemokratis', 'Primary Data'); |
| 90 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 91 | is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource'); |
| 92 | is($output->{version}, '0.02', 'version'); |
| 93 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 94 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
| 95 | is($output->{data}->{stream}->[0]->[3], 's:unser', 'data'); |
| 96 | |
| 97 | is($output->{textSigle}, 'BZK_D59.00001', 'Correct text sigle'); |
| 98 | is($output->{docSigle}, 'BZK_D59', 'Correct document sigle'); |
| 99 | is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle'); |
| 100 | |
| 101 | is($output->{title}, 'Unser gemeinsames Werk wird siegreich sein', 'Title'); |
| 102 | ok(!exists $output->{subTitle}, 'No SubTitle'); |
| 103 | ok(!exists $output->{author}, 'Author'); |
| 104 | ok(!exists $output->{editor}, 'Publisher'); |
| 105 | |
| 106 | is($output->{pubPlace}, 'Berlin', 'PubPlace'); |
| 107 | ok(!exists $output->{publisher}, 'Publisher'); |
| 108 | |
| 109 | is($output->{textType}, 'Zeitung: Tageszeitung', 'Correct Text Type'); |
| 110 | ok(!exists $output->{textTypeArt}, 'Correct Text Type Art'); |
| 111 | is($output->{textTypeRef}, 'Tageszeitung', 'Correct Text Type Ref'); |
| 112 | is($output->{textDomain}, 'Politik', 'Correct Text Domain'); |
| 113 | |
| 114 | is($output->{creationDate}, '19590101', 'Creation date'); |
| 115 | is($output->{license}, 'ACA-NC-LC', 'License'); |
| 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], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein |
| 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 | |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 130 | is($output->{docTitle}, 'Neues Deutschland, Jahrgangsquerschnitt 1959', 'Correct Doc title'); |
Nils Diewald | 90410c2 | 2014-11-03 21:04:05 +0000 | [diff] [blame] | 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:unser/, 'data'); |
| 145 | like($first_token, qr/_0#0-5/, '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 | |
| 157 | $tokens->add('OpenNLP', 'Morpho'); |
| 158 | $output = decode_json( $tokens->to_json ); |
| 159 | is($output->{data}->{foundries}, |
| 160 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences', |
| 161 | 'Foundries'); |
| 162 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos'); |
| 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 | |
| 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 | unlike($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries'); |
| 238 | unlike($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos'); |
| 239 | unlike($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos'); |
| 240 | unlike($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__ |