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 | |
| 17 | use_ok('KorAP::Document'); |
| 18 | |
| 19 | my $path = catdir(dirname(__FILE__), '../corpus/BZK/D59/00089'); |
| 20 | |
| 21 | ok(my $doc = KorAP::Document->new( path => $path . '/' ), 'Load Korap::Document'); |
| 22 | ok($doc->parse, 'Parse document'); |
| 23 | |
| 24 | is($doc->text_sigle, 'BZK_D59.00089', 'Correct text sigle'); |
| 25 | is($doc->doc_sigle, 'BZK_D59', 'Correct document sigle'); |
| 26 | is($doc->corpus_sigle, 'BZK', 'Correct corpus sigle'); |
| 27 | |
| 28 | is($doc->title, 'Saragat-Partei zerfällt', 'Title'); |
| 29 | ok(!$doc->sub_title, 'No SubTitle'); |
| 30 | ok(!$doc->author, 'Author'); |
| 31 | ok(!$doc->editor, 'Editor'); |
| 32 | is($doc->pub_place, 'Berlin', 'PubPlace'); |
| 33 | is($doc->pub_date, '19590219', 'PubDate'); |
| 34 | ok(!$doc->publisher, 'Publisher'); |
| 35 | |
| 36 | is($doc->text_type, 'Zeitung: Tageszeitung', 'Correct Text Type'); |
| 37 | |
| 38 | ok(!$doc->text_type_art, 'Correct Text Type Art'); |
| 39 | is($doc->text_type_ref, 'Tageszeitung', 'Correct Text Type Ref'); |
| 40 | is($doc->text_domain, 'Politik', 'Correct Text Domain'); |
| 41 | is($doc->text_column, 'POLITIK', 'Correct Text Column'); |
| 42 | is($doc->text_class->[0], 'politik', 'Correct Text Class'); |
| 43 | is($doc->text_class->[1], 'ausland', 'Correct Text Class'); |
| 44 | ok(!$doc->text_class->[2], 'Correct Text Class'); |
| 45 | |
| 46 | |
| 47 | is($doc->creation_date, '19590219', 'Creation date'); |
| 48 | is($doc->license, 'ACA-NC-LC', 'License'); |
| 49 | ok(!$doc->pages, 'Pages'); |
| 50 | |
| 51 | ok(!$doc->file_edition_statement, 'File Statement'); |
| 52 | ok(!$doc->bibl_edition_statement, 'Bibl Statement'); |
| 53 | |
| 54 | is($doc->reference . "\n", <<'REF', 'Reference'); |
| 55 | Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt |
| 56 | REF |
| 57 | is($doc->language, 'de', 'Language'); |
| 58 | |
| 59 | is($doc->corpus_title, 'Bonner Zeitungskorpus', 'Correct Corpus title'); |
| 60 | ok(!$doc->corpus_sub_title, 'Correct Corpus sub title'); |
| 61 | ok(!$doc->corpus_author, 'Correct Corpus author'); |
| 62 | ok(!$doc->corpus_editor, 'Correct Corpus editor'); |
| 63 | |
| 64 | is($doc->doc_title, 'Neues Deutschland', 'Correct Doc title'); |
| 65 | is($doc->doc_sub_title, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title'); |
| 66 | ok(!$doc->doc_author, 'Correct Doc author'); |
| 67 | ok(!$doc->doc_editor, 'Correct doc editor'); |
| 68 | |
| 69 | # Tokenization |
| 70 | use_ok('KorAP::Tokenizer'); |
| 71 | |
| 72 | my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/); |
| 73 | |
| 74 | # Get tokenization |
| 75 | my $tokens = KorAP::Tokenizer->new( |
| 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), 'Saragat-Partei zerfällt Rom (ADN) die von dem Rechtssozialisten Saragat geführte Sozialdemokratische', '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'); |
| 93 | is($output->{data}->{stream}->[0]->[3], 's:Saragat-Partei', 'data'); |
| 94 | |
| 95 | is($output->{textSigle}, 'BZK_D59.00089', 'Correct text sigle'); |
| 96 | is($output->{docSigle}, 'BZK_D59', 'Correct document sigle'); |
| 97 | is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle'); |
| 98 | |
| 99 | is($output->{title}, 'Saragat-Partei zerfällt', '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 | is($output->{textClass}, 'politik ausland', 'Correct Text Domain'); |
| 112 | |
| 113 | is($output->{creationDate}, '19590219', 'Creation date'); |
| 114 | is($output->{license}, 'ACA-NC-LC', 'License'); |
| 115 | ok(!exists $output->{pages}, 'Pages'); |
| 116 | ok(!exists $output->{fileEditionStatement}, 'File Statement'); |
| 117 | ok(!exists $output->{biblEditionStatement}, 'Bibl Statement'); |
| 118 | |
| 119 | is($output->{reference} . "\n", <<'REF', 'Reference'); |
| 120 | Neues Deutschland, [Tageszeitung], 19.02.1959, Jg. 14, Berliner Ausgabe, S. 7. - Sachgebiet: Politik, Originalressort: POLITIK; Saragat-Partei zerfällt |
| 121 | REF |
| 122 | is($output->{language}, 'de', 'Language'); |
| 123 | |
| 124 | is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title'); |
| 125 | ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title'); |
| 126 | ok(!exists $output->{corpusAuthor}, 'Correct Corpus author'); |
| 127 | ok(!exists $output->{corpusEditor}, 'Correct Corpus editor'); |
| 128 | |
| 129 | is($output->{docTitle}, 'Neues Deutschland', 'Correct Doc title'); |
| 130 | is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title'); |
| 131 | ok(!exists $output->{docAuthor}, 'Correct Doc author'); |
| 132 | ok(!exists $output->{docEditor}, 'Correct doc editor'); |
| 133 | |
| 134 | ## Base |
| 135 | $tokens->add('Base', 'Sentences'); |
| 136 | $tokens->add('Base', 'Paragraphs'); |
| 137 | |
| 138 | $output = decode_json( $tokens->to_json ); |
| 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:Saragat-Partei/, 'data'); |
| 144 | like($first_token, qr/_0\$<i>0<i>14/, '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 | $tokens->add('OpenNLP', 'Morpho'); |
| 156 | $output = decode_json( $tokens->to_json ); |
| 157 | is($output->{data}->{foundries}, |
| 158 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences', |
| 159 | 'Foundries'); |
| 160 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos'); |
| 161 | |
| 162 | ## Treetagger |
| 163 | $tokens->add('TreeTagger', 'Sentences'); |
| 164 | $output = decode_json( $tokens->to_json ); |
| 165 | is($output->{data}->{foundries}, |
| 166 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences', |
| 167 | 'Foundries'); |
| 168 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos'); |
| 169 | |
| 170 | $tokens->add('TreeTagger', 'Morpho'); |
| 171 | $output = decode_json( $tokens->to_json ); |
| 172 | is($output->{data}->{foundries}, |
| 173 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 174 | 'Foundries'); |
| 175 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 176 | |
| 177 | ## CoreNLP |
| 178 | $tokens->add('CoreNLP', 'NamedEntities'); |
| 179 | $output = decode_json( $tokens->to_json ); |
| 180 | is($output->{data}->{foundries}, |
| 181 | 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 182 | 'Foundries'); |
| 183 | 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'); |
| 184 | |
| 185 | $tokens->add('CoreNLP', 'Sentences'); |
| 186 | $output = decode_json( $tokens->to_json ); |
| 187 | is($output->{data}->{foundries}, |
| 188 | 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 189 | 'Foundries'); |
| 190 | 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'); |
| 191 | |
| 192 | $tokens->add('CoreNLP', 'Morpho'); |
| 193 | $output = decode_json( $tokens->to_json ); |
| 194 | like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries'); |
| 195 | like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos'); |
| 196 | |
| 197 | $tokens->add('CoreNLP', 'Constituency'); |
| 198 | $output = decode_json( $tokens->to_json ); |
| 199 | like($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries'); |
| 200 | like($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos'); |
| 201 | |
| 202 | ## Glemm |
| 203 | $tokens->add('Glemm', 'Morpho'); |
| 204 | $output = decode_json( $tokens->to_json ); |
| 205 | like($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries'); |
| 206 | like($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos'); |
| 207 | |
| 208 | ## Connexor |
| 209 | $tokens->add('Connexor', 'Sentences'); |
| 210 | $output = decode_json( $tokens->to_json ); |
| 211 | like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries'); |
| 212 | like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos'); |
| 213 | |
| 214 | $tokens->add('Connexor', 'Morpho'); |
| 215 | $output = decode_json( $tokens->to_json ); |
| 216 | like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries'); |
| 217 | like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos'); |
| 218 | like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos'); |
| 219 | like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos'); |
| 220 | |
| 221 | $tokens->add('Connexor', 'Phrase'); |
| 222 | $output = decode_json( $tokens->to_json ); |
| 223 | like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries'); |
| 224 | like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos'); |
| 225 | |
| 226 | $tokens->add('Connexor', 'Syntax'); |
| 227 | $output = decode_json( $tokens->to_json ); |
| 228 | like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries'); |
| 229 | like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos'); |
| 230 | |
| 231 | ## Mate |
| 232 | $tokens->add('Mate', 'Morpho'); |
| 233 | $output = decode_json( $tokens->to_json ); |
| 234 | like($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries'); |
| 235 | like($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos'); |
| 236 | like($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos'); |
| 237 | like($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos'); |
| 238 | |
| 239 | # diag "No test for mate dependency"; |
| 240 | |
| 241 | ## XIP |
| 242 | $tokens->add('XIP', 'Sentences'); |
| 243 | $output = decode_json( $tokens->to_json ); |
| 244 | like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries'); |
| 245 | like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos'); |
| 246 | |
| 247 | $tokens->add('XIP', 'Morpho'); |
| 248 | $output = decode_json( $tokens->to_json ); |
| 249 | like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries'); |
| 250 | like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos'); |
| 251 | like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos'); |
| 252 | |
| 253 | $tokens->add('XIP', 'Constituency'); |
| 254 | $output = decode_json( $tokens->to_json ); |
| 255 | like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries'); |
| 256 | like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos'); |
| 257 | |
| 258 | # diag "No test for xip dependency"; |
| 259 | |
| 260 | done_testing; |
| 261 | __END__ |