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