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