Nils Diewald | c95607a | 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 | # GOE/AGA/03828 |
| 23 | my $path = catdir(dirname(__FILE__), 'WDD/G27/38989'); |
| 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, 'WDD11_G27.38989', 'Correct text sigle'); |
| 29 | is($doc->doc_sigle, 'WDD11_G27', 'Correct document sigle'); |
| 30 | is($doc->corpus_sigle, 'WDD11', 'Correct corpus sigle'); |
| 31 | |
| 32 | is($doc->title, 'Diskussion:Gunter A. Pilz', 'Title'); |
| 33 | ok(!$doc->sub_title, 'No SubTitle'); |
| 34 | is($doc->author, '€pa, u.a.', 'Author'); |
| 35 | is($doc->editor, 'wikipedia.org', 'Publisher'); |
| 36 | |
| 37 | is($doc->pub_place, 'URL:http://de.wikipedia.org', 'PubPlace'); |
| 38 | is($doc->publisher, 'Wikipedia', 'Publisher'); |
| 39 | is($doc->text_type, 'Diskussionen zu Enzyklopädie-Artikeln', 'Correct Text Type'); |
| 40 | ok(!$doc->text_type_art, 'Correct Text Type Art'); |
| 41 | ok(!$doc->text_type_ref, 'Correct Text Type Ref'); |
| 42 | ok(!$doc->text_domain, 'Correct Text Domain'); |
| 43 | is($doc->creation_date, '20070707', 'Creation date'); |
| 44 | is($doc->license, 'CC-BY-SA', 'License'); |
| 45 | ok(!$doc->pages, 'Pages'); |
| 46 | ok(!$doc->file_edition_statement, 'File Statement'); |
| 47 | ok(!$doc->bibl_edition_statement, 'Bibl Statement'); |
| 48 | is($doc->reference . "\n", <<'REF', 'Reference'); |
| 49 | Diskussion:Gunter A. Pilz, In: Wikipedia - URL:http://de.wikipedia.org/wiki/Diskussion:Gunter_A._Pilz: Wikipedia, 2007 |
| 50 | REF |
| 51 | is($doc->language, 'de', 'Language'); |
| 52 | |
| 53 | is($doc->corpus_title, 'Wikipedia', 'Correct Corpus title'); |
| 54 | ok(!$doc->corpus_sub_title, 'Correct Corpus sub title'); |
| 55 | ok(!$doc->corpus_author, 'Correct Corpus author'); |
| 56 | is($doc->corpus_editor, 'wikipedia.org', 'Correct Corpus editor'); |
| 57 | |
| 58 | is($doc->doc_title, 'Wikipedia, Diskussionen zu Artikeln mit Anfangsbuchstabe G, Teil 27', 'Correct Doc title'); |
| 59 | ok(!$doc->doc_sub_title, 'Correct Doc sub title'); |
| 60 | ok(!$doc->doc_author, 'Correct Doc author'); |
| 61 | ok(!$doc->doc_editor, 'Correct doc editor'); |
| 62 | |
| 63 | # Tokenization |
| 64 | use_ok('KorAP::Tokenizer'); |
| 65 | |
| 66 | my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/); |
| 67 | |
| 68 | # Get tokenization |
| 69 | my $tokens = KorAP::Tokenizer->new( |
| 70 | path => $doc->path, |
| 71 | doc => $doc, |
| 72 | foundry => $token_base_foundry, |
| 73 | layer => $token_base_layer, |
| 74 | name => 'tokens' |
| 75 | ); |
| 76 | ok($tokens, 'Token Object is fine'); |
| 77 | ok($tokens->parse, 'Token parsing is fine'); |
| 78 | |
| 79 | my $output = decode_json( $tokens->to_json ); |
| 80 | |
| 81 | is(substr($output->{data}->{text}, 0, 100), '{{War Löschkandidat|6. Juli 2007|(erl., bleibt)}}', 'Primary Data'); |
| 82 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 83 | is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource'); |
| 84 | is($output->{version}, '0.02', 'version'); |
| 85 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 86 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
| 87 | is($output->{data}->{stream}->[0]->[3], 's:{War', 'data'); |
| 88 | |
| 89 | is($output->{textSigle}, 'WDD11_G27.38989', 'Correct text sigle'); |
| 90 | is($output->{docSigle}, 'WDD11_G27', 'Correct document sigle'); |
| 91 | is($output->{corpusSigle}, 'WDD11', 'Correct corpus sigle'); |
| 92 | |
| 93 | is($output->{title}, 'Diskussion:Gunter A. Pilz', 'Title'); |
| 94 | ok(!$output->{subTitle}, 'No SubTitle'); |
| 95 | is($output->{author}, '€pa, u.a.', 'Author'); |
| 96 | is($output->{editor}, 'wikipedia.org', 'Publisher'); |
| 97 | |
| 98 | is($output->{pubPlace}, 'URL:http://de.wikipedia.org', 'PubPlace'); |
| 99 | is($output->{publisher}, 'Wikipedia', 'Publisher'); |
| 100 | is($output->{textType}, 'Diskussionen zu Enzyklopädie-Artikeln', 'Correct Text Type'); |
| 101 | ok(!$output->{textTypeArt}, 'Correct Text Type Art'); |
| 102 | ok(!$output->{textTypeRef}, 'Correct Text Type Ref'); |
| 103 | ok(!$output->{textDomain}, 'Correct Text Domain'); |
| 104 | is($output->{creationDate}, '20070707', 'Creation date'); |
| 105 | is($output->{license}, 'CC-BY-SA', 'License'); |
| 106 | ok(!$output->{pages}, 'Pages'); |
| 107 | ok(!$output->{fileEditionStatement}, 'File Statement'); |
| 108 | ok(!$output->{biblEditionStatement}, 'Bibl Statement'); |
| 109 | is($output->{reference} . "\n", <<'REF', 'Reference'); |
| 110 | Diskussion:Gunter A. Pilz, In: Wikipedia - URL:http://de.wikipedia.org/wiki/Diskussion:Gunter_A._Pilz: Wikipedia, 2007 |
| 111 | REF |
| 112 | is($output->{language}, 'de', 'Language'); |
| 113 | |
| 114 | is($output->{corpusTitle}, 'Wikipedia', 'Correct Corpus title'); |
| 115 | ok(!$output->{corpusSubTitle}, 'Correct Corpus sub title'); |
| 116 | ok(!$output->{corpusAuthor}, 'Correct Corpus author'); |
| 117 | is($output->{corpusEditor}, 'wikipedia.org', 'Correct Corpus editor'); |
| 118 | |
| 119 | is($output->{docTitle}, 'Wikipedia, Diskussionen zu Artikeln mit Anfangsbuchstabe G, Teil 27', 'Correct Doc title'); |
| 120 | ok(!$output->{docSubTitle}, 'Correct Doc sub title'); |
| 121 | ok(!$output->{docAuthor}, 'Correct Doc author'); |
| 122 | ok(!$output->{docEditor}, 'Correct doc editor'); |
| 123 | |
| 124 | ## Base |
| 125 | $tokens->add('Base', 'Sentences'); |
| 126 | |
| 127 | $tokens->add('Base', 'Paragraphs'); |
| 128 | |
| 129 | $output = decode_json( $tokens->to_json ); |
| 130 | |
| 131 | is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries'); |
| 132 | is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos'); |
| 133 | my $first_token = join('||', @{$output->{data}->{stream}->[0]}); |
| 134 | like($first_token, qr/s:{War/, 'data'); |
| 135 | like($first_token, qr/_0#1-5/, 'data'); |
| 136 | |
| 137 | |
| 138 | ## OpenNLP |
| 139 | $tokens->add('OpenNLP', 'Sentences'); |
| 140 | |
| 141 | $output = decode_json( $tokens->to_json ); |
| 142 | is($output->{data}->{foundries}, |
| 143 | 'base base/paragraphs base/sentences opennlp opennlp/sentences', |
| 144 | 'Foundries'); |
| 145 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos'); |
| 146 | |
| 147 | |
| 148 | $tokens->add('OpenNLP', 'Morpho'); |
| 149 | $output = decode_json( $tokens->to_json ); |
| 150 | is($output->{data}->{foundries}, |
| 151 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences', |
| 152 | 'Foundries'); |
| 153 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos'); |
| 154 | |
| 155 | ## Treetagger |
| 156 | $tokens->add('TreeTagger', 'Sentences'); |
| 157 | $output = decode_json( $tokens->to_json ); |
| 158 | is($output->{data}->{foundries}, |
| 159 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences', |
| 160 | 'Foundries'); |
| 161 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos'); |
| 162 | |
| 163 | $tokens->add('TreeTagger', 'Morpho'); |
| 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/morpho treetagger/sentences', |
| 167 | 'Foundries'); |
| 168 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 169 | |
| 170 | ## CoreNLP |
| 171 | $tokens->add('CoreNLP', 'NamedEntities'); |
| 172 | $output = decode_json( $tokens->to_json ); |
| 173 | is($output->{data}->{foundries}, |
| 174 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 175 | 'Foundries'); |
| 176 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 177 | |
| 178 | $tokens->add('CoreNLP', 'Sentences'); |
| 179 | $output = decode_json( $tokens->to_json ); |
| 180 | is($output->{data}->{foundries}, |
| 181 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 182 | 'Foundries'); |
| 183 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 184 | |
| 185 | $tokens->add('CoreNLP', 'Morpho'); |
| 186 | $output = decode_json( $tokens->to_json ); |
| 187 | unlike($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries'); |
| 188 | unlike($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos'); |
| 189 | |
| 190 | $tokens->add('CoreNLP', 'Constituency'); |
| 191 | $output = decode_json( $tokens->to_json ); |
| 192 | unlike($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries'); |
| 193 | unlike($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos'); |
| 194 | |
| 195 | ## Glemm |
| 196 | $tokens->add('Glemm', 'Morpho'); |
| 197 | $output = decode_json( $tokens->to_json ); |
| 198 | unlike($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries'); |
| 199 | unlike($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos'); |
| 200 | |
| 201 | ## Connexor |
| 202 | $tokens->add('Connexor', 'Sentences'); |
| 203 | $output = decode_json( $tokens->to_json ); |
| 204 | like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries'); |
| 205 | like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos'); |
| 206 | |
| 207 | $tokens->add('Connexor', 'Morpho'); |
| 208 | $output = decode_json( $tokens->to_json ); |
| 209 | like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries'); |
| 210 | like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos'); |
| 211 | like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos'); |
| 212 | like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos'); |
| 213 | |
| 214 | $tokens->add('Connexor', 'Phrase'); |
| 215 | $output = decode_json( $tokens->to_json ); |
| 216 | like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries'); |
| 217 | like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos'); |
| 218 | |
| 219 | $tokens->add('Connexor', 'Syntax'); |
| 220 | $output = decode_json( $tokens->to_json ); |
| 221 | like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries'); |
| 222 | like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos'); |
| 223 | |
| 224 | ## Mate |
| 225 | $tokens->add('Mate', 'Morpho'); |
| 226 | $output = decode_json( $tokens->to_json ); |
| 227 | like($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries'); |
| 228 | like($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos'); |
| 229 | like($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos'); |
| 230 | like($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos'); |
| 231 | |
| 232 | diag "No test for mate dependency"; |
| 233 | |
| 234 | ## XIP |
| 235 | $tokens->add('XIP', 'Sentences'); |
| 236 | $output = decode_json( $tokens->to_json ); |
| 237 | like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries'); |
| 238 | like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos'); |
| 239 | |
| 240 | $tokens->add('XIP', 'Morpho'); |
| 241 | $output = decode_json( $tokens->to_json ); |
| 242 | like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries'); |
| 243 | like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos'); |
| 244 | like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos'); |
| 245 | |
| 246 | |
| 247 | $tokens->add('XIP', 'Constituency'); |
| 248 | $output = decode_json( $tokens->to_json ); |
| 249 | like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries'); |
| 250 | like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos'); |
| 251 | |
| 252 | diag "No test for xip dependency"; |
| 253 | |
| 254 | |
| 255 | done_testing; |
| 256 | __END__ |