Nils Diewald | 79a355c | 2014-10-30 00:52:36 +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 | |
Nils Diewald | a5565f6 | 2014-10-30 23:20:58 +0000 | [diff] [blame] | 10 | use Benchmark qw/:hireswallclock/; |
| 11 | |
| 12 | my $t = Benchmark->new; |
| 13 | |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 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 | # GOE/AGA/03828 |
| 23 | my $path = catdir(dirname(__FILE__), 'GOE/AGA/03828'); |
Nils Diewald | a0e8d72 | 2014-11-01 01:18:25 +0000 | [diff] [blame^] | 24 | # my $path = '/home/ndiewald/Repositories/korap/KorAP-sandbox/KorAP-lucene-indexer/t/GOE/AGA/03828'; |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 25 | |
| 26 | ok(my $doc = KorAP::Document->new( path => $path . '/' ), 'Load Korap::Document'); |
| 27 | ok($doc->parse, 'Parse document'); |
| 28 | |
| 29 | is($doc->text_sigle, 'GOE_AGA.03828', 'Correct text sigle'); |
| 30 | is($doc->doc_sigle, 'GOE_AGA', 'Correct document sigle'); |
| 31 | is($doc->corpus_sigle, 'GOE', 'Correct corpus sigle'); |
| 32 | |
| 33 | is($doc->corpus_title, 'Goethes Werke', 'Correct Corpus title'); |
| 34 | is($doc->text_type, 'Autobiographie', 'Correct Text Type'); |
Nils Diewald | ebdc52d | 2014-10-31 17:29:23 +0000 | [diff] [blame] | 35 | is($doc->author, 'Goethe, Johann Wolfgang von', 'Author'); |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 36 | is($doc->reference . "\n", <<'REF', 'Author'); |
| 37 | Goethe, Johann Wolfgang von: Autobiographische Einzelheiten, (Geschrieben bis 1832), In: Goethe, Johann Wolfgang von: Goethes Werke, Bd. 10, Autobiographische Schriften II, Hrsg.: Trunz, Erich. München: Verlag C. H. Beck, 1982, S. 529-547 |
| 38 | REF |
| 39 | is($doc->pub_place, 'München', 'PubPlace'); |
| 40 | is($doc->publisher, 'Verlag C. H. Beck', 'Publisher'); |
| 41 | is($doc->coll_editor, 'Trunz, Erich', 'Editor'); |
| 42 | is($doc->language, 'de', 'Language'); |
| 43 | is($doc->license, 'QAO-NC', 'License'); |
| 44 | is($doc->creation_date, '18200000', 'Creation Date'); |
| 45 | is($doc->pub_date, '19820000', 'Creation Date'); |
| 46 | is($doc->title, 'Autobiographische Einzelheiten', 'Title'); |
| 47 | is($doc->pages, '529-547', 'Pages'); |
| 48 | |
| 49 | # Tokenization |
| 50 | use_ok('KorAP::Tokenizer'); |
| 51 | |
| 52 | my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/); |
| 53 | |
| 54 | # Get tokenization |
| 55 | my $tokens = KorAP::Tokenizer->new( |
| 56 | path => $doc->path, |
| 57 | doc => $doc, |
| 58 | foundry => $token_base_foundry, |
| 59 | layer => $token_base_layer, |
| 60 | name => 'tokens' |
| 61 | ); |
| 62 | ok($tokens, 'Token Object is fine'); |
| 63 | ok($tokens->parse, 'Token parsing is fine'); |
| 64 | |
| 65 | my $output = decode_json( $tokens->to_json ); |
| 66 | |
| 67 | |
| 68 | is(substr($output->{primaryData}, 0, 100), 'Autobiographische einzelheiten Selbstschilderung (1) immer tätiger, nach innen und außen fortwirkend', 'Primary Data'); |
| 69 | is($output->{tokenName}, 'tokens', 'tokenName'); |
| 70 | is($output->{tokenSource}, 'opennlp#tokens', 'tokenSource'); |
| 71 | is($output->{version}, '0.02', 'version'); |
| 72 | |
| 73 | is($output->{foundries}, '', 'Foundries'); |
| 74 | is($output->{layerInfos}, '', 'layerInfos'); |
Nils Diewald | a5565f6 | 2014-10-30 23:20:58 +0000 | [diff] [blame] | 75 | is($output->{data}->[0]->[3], 's:Autobiographische', 'data'); |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 76 | |
| 77 | is($output->{textSigle}, 'GOE_AGA.03828', 'Correct text sigle'); |
| 78 | is($output->{docSigle}, 'GOE_AGA', 'Correct document sigle'); |
| 79 | is($output->{corpusSigle}, 'GOE', 'Correct corpus sigle'); |
| 80 | |
| 81 | is($output->{corpusTitle}, 'Goethes Werke', 'Correct Corpus title'); |
| 82 | is($output->{textType}, 'Autobiographie', 'Correct Text Type'); |
| 83 | is($output->{author}, 'Goethe, Johann Wolfgang von', 'Author'); |
| 84 | is($output->{reference} . "\n", <<'REF', 'Author'); |
| 85 | Goethe, Johann Wolfgang von: Autobiographische Einzelheiten, (Geschrieben bis 1832), In: Goethe, Johann Wolfgang von: Goethes Werke, Bd. 10, Autobiographische Schriften II, Hrsg.: Trunz, Erich. München: Verlag C. H. Beck, 1982, S. 529-547 |
| 86 | REF |
| 87 | is($output->{pubPlace}, 'München', 'PubPlace'); |
| 88 | is($output->{publisher}, 'Verlag C. H. Beck', 'Publisher'); |
| 89 | is($output->{collEditor}, 'Trunz, Erich', 'Editor'); |
| 90 | is($output->{language}, 'de', 'Language'); |
| 91 | is($output->{license}, 'QAO-NC', 'License'); |
| 92 | is($output->{creationDate}, '18200000', 'Creation Date'); |
| 93 | is($output->{pubDate}, '19820000', 'Creation Date'); |
| 94 | is($output->{title}, 'Autobiographische Einzelheiten', 'Title'); |
| 95 | is($output->{pages}, '529-547', 'Pages'); |
| 96 | |
| 97 | |
| 98 | ## Base |
| 99 | $tokens->add('Base', 'Sentences'); |
| 100 | $tokens->add('Base', 'Paragraphs'); |
| 101 | |
| 102 | $output = decode_json( $tokens->to_json ); |
| 103 | |
| 104 | is($output->{foundries}, 'base base/paragraphs base/sentences', 'Foundries'); |
| 105 | is($output->{layerInfos}, 'base/s=spans', 'layerInfos'); |
| 106 | my $first_token = join('||', @{$output->{data}->[0]}); |
| 107 | like($first_token, qr/s:Autobiographische/, 'data'); |
| 108 | like($first_token, qr/_0#0-17/, 'data'); |
Nils Diewald | a5565f6 | 2014-10-30 23:20:58 +0000 | [diff] [blame] | 109 | like($first_token, qr!<>:base/s:s#0-30\$<i>2<b>2!, 'data'); |
| 110 | like($first_token, qr!<>:base\/s:t#0-35199\$<i>5226<b>0!, 'data'); |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 111 | |
| 112 | ## OpenNLP |
| 113 | $tokens->add('OpenNLP', 'Sentences'); |
| 114 | |
| 115 | $output = decode_json( $tokens->to_json ); |
| 116 | is($output->{foundries}, |
| 117 | 'base base/paragraphs base/sentences opennlp opennlp/sentences', |
| 118 | 'Foundries'); |
| 119 | is($output->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos'); |
| 120 | $first_token = join('||', @{$output->{data}->[0]}); |
| 121 | like($first_token, qr!<>:opennlp/s:s#0-254\$<i>32!, 'data'); |
| 122 | |
| 123 | $tokens->add('OpenNLP', 'Morpho'); |
| 124 | $output = decode_json( $tokens->to_json ); |
| 125 | is($output->{foundries}, |
| 126 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences', |
| 127 | 'Foundries'); |
| 128 | is($output->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos'); |
| 129 | $first_token = join('||', @{$output->{data}->[0]}); |
| 130 | like($first_token, qr!opennlp/p:ADJA!, 'data'); |
| 131 | |
| 132 | ## Treetagger |
| 133 | $tokens->add('TreeTagger', 'Sentences'); |
| 134 | $output = decode_json( $tokens->to_json ); |
| 135 | is($output->{foundries}, |
| 136 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences', |
| 137 | 'Foundries'); |
| 138 | is($output->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos'); |
| 139 | $first_token = join('||', @{$output->{data}->[0]}); |
Nils Diewald | a5565f6 | 2014-10-30 23:20:58 +0000 | [diff] [blame] | 140 | like($first_token, qr!<>:tt/s:s#0-179\$<i>21<b>2!, 'data'); |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 141 | |
| 142 | $tokens->add('TreeTagger', 'Morpho'); |
| 143 | $output = decode_json( $tokens->to_json ); |
| 144 | is($output->{foundries}, |
| 145 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 146 | 'Foundries'); |
| 147 | is($output->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 148 | $first_token = join('||', @{$output->{data}->[0]}); |
| 149 | like($first_token, qr!tt/l:autobiographisch\$<b>165!, 'data'); |
| 150 | like($first_token, qr!tt/p:ADJA\$<b>165!, 'data'); |
| 151 | like($first_token, qr!tt/l:Autobiographische\$<b>89!, 'data'); |
| 152 | like($first_token, qr!tt/p:NN\$<b>89!, 'data'); |
| 153 | |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 154 | ## CoreNLP |
| 155 | $tokens->add('CoreNLP', 'NamedEntities'); |
| 156 | $output = decode_json( $tokens->to_json ); |
| 157 | is($output->{foundries}, |
| 158 | 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 159 | 'Foundries'); |
| 160 | is($output->{layerInfos}, 'base/s=spans corenlp/ne=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 161 | |
| 162 | diag "Missing test for NamedEntities"; |
| 163 | |
| 164 | # Problematic: |
| 165 | # diag Dumper $output->{data}->[180]; |
| 166 | # diag Dumper $output->{data}->[341]; |
| 167 | |
| 168 | $tokens->add('CoreNLP', 'Sentences'); |
| 169 | $output = decode_json( $tokens->to_json ); |
| 170 | is($output->{foundries}, |
| 171 | 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 172 | 'Foundries'); |
| 173 | is($output->{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'); |
| 174 | $first_token = join('||', @{$output->{data}->[0]}); |
| 175 | like($first_token, qr!<>:corenlp/s:s#0-254\$<i>32!, 'data'); |
| 176 | |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 177 | $tokens->add('CoreNLP', 'Morpho'); |
| 178 | $output = decode_json( $tokens->to_json ); |
| 179 | like($output->{foundries}, qr!corenlp/morpho!, 'Foundries'); |
| 180 | like($output->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos'); |
| 181 | $first_token = join('||', @{$output->{data}->[0]}); |
| 182 | like($first_token, qr!corenlp/p:ADJA!, 'data'); |
| 183 | |
Nils Diewald | a5565f6 | 2014-10-30 23:20:58 +0000 | [diff] [blame] | 184 | $tokens->add('CoreNLP', 'Constituency'); |
| 185 | $output = decode_json( $tokens->to_json ); |
| 186 | like($output->{foundries}, qr!corenlp/constituency!, 'Foundries'); |
| 187 | like($output->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos'); |
| 188 | $first_token = join('||', @{$output->{data}->[0]}); |
Nils Diewald | 90a23f2 | 2014-10-31 02:16:14 +0000 | [diff] [blame] | 189 | like($first_token, qr!<>:corenlp/c:NP#0-17\$<i>1<b>6!, 'data'); |
| 190 | like($first_token, qr!<>:corenlp/c:CNP#0-17\$<i>1<b>7!, 'data'); |
| 191 | like($first_token, qr!<>:corenlp/c:NP#0-17\$<i>1<b>8!, 'data'); |
| 192 | like($first_token, qr!<>:corenlp/c:AP#0-17\$<i>1<b>9!, 'data'); |
| 193 | like($first_token, qr!<>:corenlp/c:PP#0-50\$<i>3<b>4!, 'data'); |
| 194 | like($first_token, qr!<>:corenlp/c:S#0-50\$<i>3<b>5!, 'data'); |
| 195 | like($first_token, qr!<>:corenlp/c:PP#0-58\$<i>5<b>2!, 'data'); |
| 196 | like($first_token, qr!<>:corenlp/c:S#0-58\$<i>5<b>3!, 'data'); |
| 197 | like($first_token, qr!<>:corenlp/c:ROOT#0-254\$<i>32<b>0!, 'data'); |
| 198 | like($first_token, qr!<>:corenlp/c:S#0-254\$<i>32<b>1!, 'data'); |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 199 | |
| 200 | ## Glemm |
| 201 | $tokens->add('Glemm', 'Morpho'); |
| 202 | $output = decode_json( $tokens->to_json ); |
| 203 | like($output->{foundries}, qr!glemm/morpho!, 'Foundries'); |
| 204 | like($output->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos'); |
| 205 | $first_token = join('||', @{$output->{data}->[0]}); |
| 206 | like($first_token, qr!glemm/l:__autobiographisch!, 'data'); |
| 207 | like($first_token, qr!glemm/l:\+_Auto!, 'data'); |
| 208 | like($first_token, qr!glemm/l:\+_biographisch!, 'data'); |
| 209 | like($first_token, qr!glemm/l:\+\+Biograph!, 'data'); |
| 210 | like($first_token, qr!glemm/l:\+\+-isch!, 'data'); |
| 211 | |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 212 | ## Connexor |
| 213 | $tokens->add('Connexor', 'Sentences'); |
| 214 | $output = decode_json( $tokens->to_json ); |
| 215 | like($output->{foundries}, qr!connexor/sentences!, 'Foundries'); |
| 216 | like($output->{layerInfos}, qr!cnx/s=spans!, 'layerInfos'); |
| 217 | $first_token = join('||', @{$output->{data}->[0]}); |
Nils Diewald | a5565f6 | 2014-10-30 23:20:58 +0000 | [diff] [blame] | 218 | like($first_token, qr!<>:cnx/s:s#0-179\$<i>21<b>2!, 'data'); |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 219 | |
| 220 | $tokens->add('Connexor', 'Morpho'); |
| 221 | $output = decode_json( $tokens->to_json ); |
| 222 | like($output->{foundries}, qr!connexor/morpho!, 'Foundries'); |
| 223 | like($output->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos'); |
| 224 | like($output->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos'); |
| 225 | like($output->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos'); |
| 226 | $first_token = join('||', @{$output->{data}->[0]}); |
| 227 | like($first_token, qr!cnx/l:autobiografisch!, 'data'); |
| 228 | like($first_token, qr!cnx/p:A!, 'data'); |
| 229 | |
| 230 | $tokens->add('Connexor', 'Phrase'); |
| 231 | $output = decode_json( $tokens->to_json ); |
| 232 | like($output->{foundries}, qr!connexor/phrase!, 'Foundries'); |
| 233 | like($output->{layerInfos}, qr!cnx/c=spans!, 'layerInfos'); |
| 234 | $first_token = join('||', @{$output->{data}->[0]}); |
| 235 | like($first_token, qr!<>:cnx/c:np#0-30\$<i>2!, 'data'); |
| 236 | |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 237 | $tokens->add('Connexor', 'Syntax'); |
| 238 | $output = decode_json( $tokens->to_json ); |
| 239 | like($output->{foundries}, qr!connexor/syntax!, 'Foundries'); |
| 240 | like($output->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos'); |
| 241 | $first_token = join('||', @{$output->{data}->[0]}); |
| 242 | like($first_token, qr!cnx/syn:\@PREMOD!, 'data'); |
| 243 | |
| 244 | ## Mate |
| 245 | $tokens->add('Mate', 'Morpho'); |
| 246 | $output = decode_json( $tokens->to_json ); |
| 247 | like($output->{foundries}, qr!mate/morpho!, 'Foundries'); |
| 248 | like($output->{layerInfos}, qr!mate/p=tokens!, 'layerInfos'); |
| 249 | like($output->{layerInfos}, qr!mate/l=tokens!, 'layerInfos'); |
| 250 | like($output->{layerInfos}, qr!mate/m=tokens!, 'layerInfos'); |
| 251 | $first_token = join('||', @{$output->{data}->[0]}); |
Nils Diewald | a5565f6 | 2014-10-30 23:20:58 +0000 | [diff] [blame] | 252 | like($first_token, qr!mate/l:autobiographisch!, 'data'); |
| 253 | like($first_token, qr!mate/p:NN!, 'data'); |
| 254 | like($first_token, qr!mate/m:case:nom!, 'data'); |
| 255 | like($first_token, qr!mate/m:number:pl!, 'data'); |
| 256 | like($first_token, qr!mate/m:gender:\*!, 'data'); |
| 257 | |
| 258 | |
Nils Diewald | 90a23f2 | 2014-10-31 02:16:14 +0000 | [diff] [blame] | 259 | diag "No test for mate dependency"; |
Nils Diewald | a5565f6 | 2014-10-30 23:20:58 +0000 | [diff] [blame] | 260 | |
| 261 | ## XIP |
| 262 | $tokens->add('XIP', 'Sentences'); |
| 263 | $output = decode_json( $tokens->to_json ); |
| 264 | like($output->{foundries}, qr!xip/sentences!, 'Foundries'); |
| 265 | like($output->{layerInfos}, qr!xip/s=spans!, 'layerInfos'); |
| 266 | $first_token = join('||', @{$output->{data}->[0]}); |
| 267 | like($first_token, qr!<>:xip/s:s#0-179\$<i>21!, 'data'); |
| 268 | |
| 269 | $tokens->add('XIP', 'Morpho'); |
| 270 | $output = decode_json( $tokens->to_json ); |
| 271 | like($output->{foundries}, qr!xip/morpho!, 'Foundries'); |
| 272 | like($output->{layerInfos}, qr!xip/l=tokens!, 'layerInfos'); |
| 273 | like($output->{layerInfos}, qr!xip/p=tokens!, 'layerInfos'); |
| 274 | $first_token = join('||', @{$output->{data}->[0]}); |
| 275 | like($first_token, qr!<>:xip/s:s#0-179\$<i>21!, 'data'); |
| 276 | |
| 277 | |
Nils Diewald | a5565f6 | 2014-10-30 23:20:58 +0000 | [diff] [blame] | 278 | $tokens->add('XIP', 'Constituency'); |
| 279 | $output = decode_json( $tokens->to_json ); |
| 280 | like($output->{foundries}, qr!xip/constituency!, 'Foundries'); |
| 281 | like($output->{layerInfos}, qr!xip/c=spans!, 'layerInfos'); |
| 282 | $first_token = join('||', @{$output->{data}->[0]}); |
| 283 | like($first_token, qr!<>:xip/c:NP#0-17\$<i>1<b>1!, 'data'); |
| 284 | like($first_token, qr!<>:xip/c:AP#0-17\$<i>1<b>2!, 'data'); |
| 285 | like($first_token, qr!<>:xip/c:ADJ#0-17\$<i>1<b>3!, 'data'); |
| 286 | like($first_token, qr!<>:xip/c:TOP#0-179\$<i>21<b>0!, 'data'); |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 287 | |
Nils Diewald | 90a23f2 | 2014-10-31 02:16:14 +0000 | [diff] [blame] | 288 | diag "No test for xip dependency"; |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 289 | |
Nils Diewald | 90a23f2 | 2014-10-31 02:16:14 +0000 | [diff] [blame] | 290 | # diag Dumper $output->{data}->[0]; |
| 291 | |
| 292 | # print timestr(timediff(Benchmark->new, $t)); |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 293 | |
Nils Diewald | 79a355c | 2014-10-30 00:52:36 +0000 | [diff] [blame] | 294 | done_testing; |
| 295 | __END__ |