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 | |
| 10 | use utf8; |
| 11 | use lib 'lib', '../lib'; |
| 12 | |
| 13 | use File::Basename 'dirname'; |
| 14 | use File::Spec::Functions 'catdir'; |
| 15 | |
| 16 | use_ok('KorAP::Document'); |
| 17 | |
| 18 | # GOE/AGA/03828 |
| 19 | my $path = catdir(dirname(__FILE__), 'GOE/AGA/03828'); |
| 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, 'GOE_AGA.03828', 'Correct text sigle'); |
| 25 | is($doc->doc_sigle, 'GOE_AGA', 'Correct document sigle'); |
| 26 | is($doc->corpus_sigle, 'GOE', 'Correct corpus sigle'); |
| 27 | |
| 28 | is($doc->corpus_title, 'Goethes Werke', 'Correct Corpus title'); |
| 29 | is($doc->text_type, 'Autobiographie', 'Correct Text Type'); |
| 30 | is($doc->author->[0], 'Goethe, Johann Wolfgang von', 'Author'); |
| 31 | is($doc->reference . "\n", <<'REF', 'Author'); |
| 32 | 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 |
| 33 | REF |
| 34 | is($doc->pub_place, 'München', 'PubPlace'); |
| 35 | is($doc->publisher, 'Verlag C. H. Beck', 'Publisher'); |
| 36 | is($doc->coll_editor, 'Trunz, Erich', 'Editor'); |
| 37 | is($doc->language, 'de', 'Language'); |
| 38 | is($doc->license, 'QAO-NC', 'License'); |
| 39 | is($doc->creation_date, '18200000', 'Creation Date'); |
| 40 | is($doc->pub_date, '19820000', 'Creation Date'); |
| 41 | is($doc->title, 'Autobiographische Einzelheiten', 'Title'); |
| 42 | is($doc->pages, '529-547', 'Pages'); |
| 43 | |
| 44 | # Tokenization |
| 45 | use_ok('KorAP::Tokenizer'); |
| 46 | |
| 47 | my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/); |
| 48 | |
| 49 | # Get tokenization |
| 50 | my $tokens = KorAP::Tokenizer->new( |
| 51 | path => $doc->path, |
| 52 | doc => $doc, |
| 53 | foundry => $token_base_foundry, |
| 54 | layer => $token_base_layer, |
| 55 | name => 'tokens' |
| 56 | ); |
| 57 | ok($tokens, 'Token Object is fine'); |
| 58 | ok($tokens->parse, 'Token parsing is fine'); |
| 59 | |
| 60 | my $output = decode_json( $tokens->to_json ); |
| 61 | |
| 62 | |
| 63 | is(substr($output->{primaryData}, 0, 100), 'Autobiographische einzelheiten Selbstschilderung (1) immer tätiger, nach innen und außen fortwirkend', 'Primary Data'); |
| 64 | is($output->{tokenName}, 'tokens', 'tokenName'); |
| 65 | is($output->{tokenSource}, 'opennlp#tokens', 'tokenSource'); |
| 66 | is($output->{version}, '0.02', 'version'); |
| 67 | |
| 68 | is($output->{foundries}, '', 'Foundries'); |
| 69 | is($output->{layerInfos}, '', 'layerInfos'); |
| 70 | is($output->{data}->[0]->[0], 's:Autobiographische', 'data'); |
| 71 | |
| 72 | is($output->{textSigle}, 'GOE_AGA.03828', 'Correct text sigle'); |
| 73 | is($output->{docSigle}, 'GOE_AGA', 'Correct document sigle'); |
| 74 | is($output->{corpusSigle}, 'GOE', 'Correct corpus sigle'); |
| 75 | |
| 76 | is($output->{corpusTitle}, 'Goethes Werke', 'Correct Corpus title'); |
| 77 | is($output->{textType}, 'Autobiographie', 'Correct Text Type'); |
| 78 | is($output->{author}, 'Goethe, Johann Wolfgang von', 'Author'); |
| 79 | is($output->{reference} . "\n", <<'REF', 'Author'); |
| 80 | 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 |
| 81 | REF |
| 82 | is($output->{pubPlace}, 'München', 'PubPlace'); |
| 83 | is($output->{publisher}, 'Verlag C. H. Beck', 'Publisher'); |
| 84 | is($output->{collEditor}, 'Trunz, Erich', 'Editor'); |
| 85 | is($output->{language}, 'de', 'Language'); |
| 86 | is($output->{license}, 'QAO-NC', 'License'); |
| 87 | is($output->{creationDate}, '18200000', 'Creation Date'); |
| 88 | is($output->{pubDate}, '19820000', 'Creation Date'); |
| 89 | is($output->{title}, 'Autobiographische Einzelheiten', 'Title'); |
| 90 | is($output->{pages}, '529-547', 'Pages'); |
| 91 | |
| 92 | |
| 93 | ## Base |
| 94 | $tokens->add('Base', 'Sentences'); |
| 95 | $tokens->add('Base', 'Paragraphs'); |
| 96 | |
| 97 | $output = decode_json( $tokens->to_json ); |
| 98 | |
| 99 | is($output->{foundries}, 'base base/paragraphs base/sentences', 'Foundries'); |
| 100 | is($output->{layerInfos}, 'base/s=spans', 'layerInfos'); |
| 101 | my $first_token = join('||', @{$output->{data}->[0]}); |
| 102 | like($first_token, qr/s:Autobiographische/, 'data'); |
| 103 | like($first_token, qr/_0#0-17/, 'data'); |
| 104 | like($first_token, qr!<>:base/s:s#0-30\$<i>2!, 'data'); |
| 105 | like($first_token, qr!<>:base\/s:t#0-35199\$<i>5226!, 'data'); |
| 106 | |
| 107 | ## OpenNLP |
| 108 | $tokens->add('OpenNLP', 'Sentences'); |
| 109 | |
| 110 | $output = decode_json( $tokens->to_json ); |
| 111 | is($output->{foundries}, |
| 112 | 'base base/paragraphs base/sentences opennlp opennlp/sentences', |
| 113 | 'Foundries'); |
| 114 | is($output->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos'); |
| 115 | $first_token = join('||', @{$output->{data}->[0]}); |
| 116 | like($first_token, qr!<>:opennlp/s:s#0-254\$<i>32!, 'data'); |
| 117 | |
| 118 | $tokens->add('OpenNLP', 'Morpho'); |
| 119 | $output = decode_json( $tokens->to_json ); |
| 120 | is($output->{foundries}, |
| 121 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences', |
| 122 | 'Foundries'); |
| 123 | is($output->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos'); |
| 124 | $first_token = join('||', @{$output->{data}->[0]}); |
| 125 | like($first_token, qr!opennlp/p:ADJA!, 'data'); |
| 126 | |
| 127 | ## Treetagger |
| 128 | $tokens->add('TreeTagger', 'Sentences'); |
| 129 | $output = decode_json( $tokens->to_json ); |
| 130 | is($output->{foundries}, |
| 131 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences', |
| 132 | 'Foundries'); |
| 133 | is($output->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos'); |
| 134 | $first_token = join('||', @{$output->{data}->[0]}); |
| 135 | like($first_token, qr!<>:tt/s:s#0-179\$<i>21!, 'data'); |
| 136 | |
| 137 | |
| 138 | $tokens->add('TreeTagger', 'Morpho'); |
| 139 | $output = decode_json( $tokens->to_json ); |
| 140 | is($output->{foundries}, |
| 141 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 142 | 'Foundries'); |
| 143 | is($output->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 144 | $first_token = join('||', @{$output->{data}->[0]}); |
| 145 | like($first_token, qr!tt/l:autobiographisch\$<b>165!, 'data'); |
| 146 | like($first_token, qr!tt/p:ADJA\$<b>165!, 'data'); |
| 147 | like($first_token, qr!tt/l:Autobiographische\$<b>89!, 'data'); |
| 148 | like($first_token, qr!tt/p:NN\$<b>89!, 'data'); |
| 149 | |
| 150 | |
| 151 | ## CoreNLP |
| 152 | $tokens->add('CoreNLP', 'NamedEntities'); |
| 153 | $output = decode_json( $tokens->to_json ); |
| 154 | is($output->{foundries}, |
| 155 | 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 156 | 'Foundries'); |
| 157 | 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'); |
| 158 | |
| 159 | diag "Missing test for NamedEntities"; |
| 160 | |
| 161 | # Problematic: |
| 162 | # diag Dumper $output->{data}->[180]; |
| 163 | # diag Dumper $output->{data}->[341]; |
| 164 | |
| 165 | $tokens->add('CoreNLP', 'Sentences'); |
| 166 | $output = decode_json( $tokens->to_json ); |
| 167 | is($output->{foundries}, |
| 168 | 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 169 | 'Foundries'); |
| 170 | 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'); |
| 171 | $first_token = join('||', @{$output->{data}->[0]}); |
| 172 | like($first_token, qr!<>:corenlp/s:s#0-254\$<i>32!, 'data'); |
| 173 | |
| 174 | |
| 175 | $tokens->add('CoreNLP', 'Morpho'); |
| 176 | $output = decode_json( $tokens->to_json ); |
| 177 | like($output->{foundries}, qr!corenlp/morpho!, 'Foundries'); |
| 178 | like($output->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos'); |
| 179 | $first_token = join('||', @{$output->{data}->[0]}); |
| 180 | like($first_token, qr!corenlp/p:ADJA!, 'data'); |
| 181 | |
| 182 | fail('Check for Constiuency!'); |
| 183 | |
| 184 | ## Glemm |
| 185 | $tokens->add('Glemm', 'Morpho'); |
| 186 | $output = decode_json( $tokens->to_json ); |
| 187 | like($output->{foundries}, qr!glemm/morpho!, 'Foundries'); |
| 188 | like($output->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos'); |
| 189 | $first_token = join('||', @{$output->{data}->[0]}); |
| 190 | like($first_token, qr!glemm/l:__autobiographisch!, 'data'); |
| 191 | like($first_token, qr!glemm/l:\+_Auto!, 'data'); |
| 192 | like($first_token, qr!glemm/l:\+_biographisch!, 'data'); |
| 193 | like($first_token, qr!glemm/l:\+\+Biograph!, 'data'); |
| 194 | like($first_token, qr!glemm/l:\+\+-isch!, 'data'); |
| 195 | |
| 196 | |
| 197 | ## Connexor |
| 198 | $tokens->add('Connexor', 'Sentences'); |
| 199 | $output = decode_json( $tokens->to_json ); |
| 200 | like($output->{foundries}, qr!connexor/sentences!, 'Foundries'); |
| 201 | like($output->{layerInfos}, qr!cnx/s=spans!, 'layerInfos'); |
| 202 | $first_token = join('||', @{$output->{data}->[0]}); |
| 203 | like($first_token, qr!<>:cnx/s:s#0-179\$<i>21!, 'data'); |
| 204 | |
| 205 | |
| 206 | $tokens->add('Connexor', 'Morpho'); |
| 207 | $output = decode_json( $tokens->to_json ); |
| 208 | like($output->{foundries}, qr!connexor/morpho!, 'Foundries'); |
| 209 | like($output->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos'); |
| 210 | like($output->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos'); |
| 211 | like($output->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos'); |
| 212 | $first_token = join('||', @{$output->{data}->[0]}); |
| 213 | like($first_token, qr!cnx/l:autobiografisch!, 'data'); |
| 214 | like($first_token, qr!cnx/p:A!, 'data'); |
| 215 | |
| 216 | $tokens->add('Connexor', 'Phrase'); |
| 217 | $output = decode_json( $tokens->to_json ); |
| 218 | like($output->{foundries}, qr!connexor/phrase!, 'Foundries'); |
| 219 | like($output->{layerInfos}, qr!cnx/c=spans!, 'layerInfos'); |
| 220 | $first_token = join('||', @{$output->{data}->[0]}); |
| 221 | like($first_token, qr!<>:cnx/c:np#0-30\$<i>2!, 'data'); |
| 222 | |
| 223 | |
| 224 | $tokens->add('Connexor', 'Syntax'); |
| 225 | $output = decode_json( $tokens->to_json ); |
| 226 | like($output->{foundries}, qr!connexor/syntax!, 'Foundries'); |
| 227 | like($output->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos'); |
| 228 | $first_token = join('||', @{$output->{data}->[0]}); |
| 229 | like($first_token, qr!cnx/syn:\@PREMOD!, 'data'); |
| 230 | |
| 231 | ## Mate |
| 232 | $tokens->add('Mate', 'Morpho'); |
| 233 | $output = decode_json( $tokens->to_json ); |
| 234 | like($output->{foundries}, qr!mate/morpho!, 'Foundries'); |
| 235 | like($output->{layerInfos}, qr!mate/p=tokens!, 'layerInfos'); |
| 236 | like($output->{layerInfos}, qr!mate/l=tokens!, 'layerInfos'); |
| 237 | like($output->{layerInfos}, qr!mate/m=tokens!, 'layerInfos'); |
| 238 | $first_token = join('||', @{$output->{data}->[0]}); |
| 239 | like($first_token, qr!---!, 'data'); |
| 240 | |
| 241 | diag Dumper $output->{data}->[0]; |
| 242 | |
| 243 | |
| 244 | diag "Use token-ids in tokens!"; |
| 245 | diag "Sort tokens based on positions!"; |
| 246 | |
| 247 | done_testing; |
| 248 | __END__ |