Akron | 9c0488f | 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 | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 17 | use_ok('KorAP::XML::Krill'); |
Akron | 9c0488f | 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 | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 22 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 23 | ok($doc->parse, 'Parse document'); |
| 24 | |
Akron | 1cd5b87 | 2016-03-22 00:23:46 +0100 | [diff] [blame] | 25 | is($doc->text_sigle, 'WDD11/G27/38989', 'Correct text sigle'); |
| 26 | is($doc->doc_sigle, 'WDD11/G27', 'Correct document sigle'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 27 | is($doc->corpus_sigle, 'WDD11', 'Correct corpus sigle'); |
| 28 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 29 | my $meta = $doc->meta; |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 30 | is($meta->{T_title}, 'Diskussion:Gunter A. Pilz', 'Title'); |
| 31 | ok(!$meta->{T_sub_title}, 'No SubTitle'); |
| 32 | is($meta->{T_author}, '€pa, u.a.', 'Author'); |
| 33 | is($meta->{A_editor}, 'wikipedia.org', 'Editor'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 34 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 35 | is($meta->{S_pub_place}, 'URL:http://de.wikipedia.org', 'PubPlace'); |
| 36 | is($meta->{A_publisher}, 'Wikipedia', 'Publisher'); |
| 37 | is($meta->{S_text_type}, 'Diskussionen zu Enzyklopädie-Artikeln', 'Correct Text Type'); |
| 38 | ok(!$meta->{S_text_type_art}, 'Correct Text Type Art'); |
| 39 | ok(!$meta->{S_text_type_ref}, 'Correct Text Type Ref'); |
| 40 | ok(!$meta->{S_text_domain}, 'Correct Text Domain'); |
| 41 | is($meta->{D_creation_date}, '20070707', 'Creation date'); |
| 42 | is($meta->{S_availability}, 'CC-BY-SA', 'License'); |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 43 | ok(!$meta->{pages}, 'Pages'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 44 | ok(!$meta->{A_file_edition_statement}, 'File Statement'); |
| 45 | ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement'); |
| 46 | is($meta->{A_reference} . "\n", <<'REF', 'Reference'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 47 | Diskussion:Gunter A. Pilz, In: Wikipedia - URL:http://de.wikipedia.org/wiki/Diskussion:Gunter_A._Pilz: Wikipedia, 2007 |
| 48 | REF |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 49 | is($meta->{S_language}, 'de', 'Language'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 50 | |
Akron | 6bf3cc9 | 2019-02-07 12:11:20 +0100 | [diff] [blame] | 51 | is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http://de.wikipedia.org/wiki/Diskussion:Gunter_A._Pilz', 'link'); |
| 52 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 53 | is($meta->{T_corpus_title}, 'Wikipedia', 'Correct Corpus title'); |
| 54 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title'); |
| 55 | ok(!$meta->{T_corpus_author}, 'Correct Corpus author'); |
| 56 | is($meta->{A_corpus_editor}, 'wikipedia.org', 'Correct Corpus editor'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 57 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 58 | is($meta->{T_doc_title}, 'Wikipedia, Diskussionen zu Artikeln mit Anfangsbuchstabe G, Teil 27', 'Correct Doc title'); |
| 59 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc sub title'); |
| 60 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
| 61 | ok(!$meta->{A_doc_editor}, 'Correct doc editor'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 62 | |
| 63 | # Tokenization |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 64 | use_ok('KorAP::XML::Tokenizer'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 65 | |
| 66 | my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/); |
| 67 | |
| 68 | # Get tokenization |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 69 | my $tokens = KorAP::XML::Tokenizer->new( |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 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.03', 'version'); |
| 85 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 86 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
Akron | 2d83a5a | 2016-02-26 00:21:16 +0100 | [diff] [blame] | 87 | is($output->{data}->{stream}->[0]->[4], 's:{War', 'data'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 88 | |
Akron | 1cd5b87 | 2016-03-22 00:23:46 +0100 | [diff] [blame] | 89 | is($output->{textSigle}, 'WDD11/G27/38989', 'Correct text sigle'); |
| 90 | is($output->{docSigle}, 'WDD11/G27', 'Correct document sigle'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 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'); |
Akron | 7e2eb88 | 2017-01-18 17:28:07 +0100 | [diff] [blame] | 96 | is($output->{editor}, 'wikipedia.org', 'Editor'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 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'); |
Akron | 6396c30 | 2016-03-18 16:05:39 +0100 | [diff] [blame] | 105 | is($output->{availability}, 'CC-BY-SA', 'License'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 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]}); |
Akron | a9455ec | 2016-02-14 01:42:20 +0100 | [diff] [blame] | 134 | like($first_token, qr/s:\{War/, 'data'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 135 | like($first_token, qr/_0\$<i>1<i>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 | |
| 156 | ## Treetagger |
| 157 | $tokens->add('TreeTagger', 'Sentences'); |
| 158 | $output = decode_json( $tokens->to_json ); |
| 159 | is($output->{data}->{foundries}, |
| 160 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences', |
| 161 | 'Foundries'); |
| 162 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos'); |
| 163 | |
| 164 | $tokens->add('TreeTagger', 'Morpho'); |
| 165 | $output = decode_json( $tokens->to_json ); |
| 166 | is($output->{data}->{foundries}, |
| 167 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 168 | 'Foundries'); |
| 169 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 170 | |
| 171 | ## CoreNLP |
| 172 | { |
| 173 | local $SIG{__WARN__} = sub {}; |
| 174 | $tokens->add('CoreNLP', 'NamedEntities'); |
| 175 | }; |
| 176 | $output = decode_json( $tokens->to_json ); |
| 177 | is($output->{data}->{foundries}, |
| 178 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 179 | 'Foundries'); |
| 180 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 181 | |
| 182 | |
| 183 | { |
| 184 | local $SIG{__WARN__} = sub {}; |
| 185 | $tokens->add('CoreNLP', 'Sentences'); |
| 186 | }; |
| 187 | $output = decode_json( $tokens->to_json ); |
| 188 | is($output->{data}->{foundries}, |
| 189 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 190 | 'Foundries'); |
| 191 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 192 | |
| 193 | { |
| 194 | local $SIG{__WARN__} = sub {}; |
| 195 | $tokens->add('CoreNLP', 'Morpho'); |
| 196 | }; |
| 197 | $output = decode_json( $tokens->to_json ); |
| 198 | unlike($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries'); |
| 199 | unlike($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos'); |
| 200 | |
| 201 | { |
| 202 | local $SIG{__WARN__} = sub {}; |
| 203 | $tokens->add('CoreNLP', 'Constituency'); |
| 204 | }; |
| 205 | $output = decode_json( $tokens->to_json ); |
| 206 | unlike($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries'); |
| 207 | unlike($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos'); |
| 208 | |
| 209 | ## Glemm |
| 210 | { |
| 211 | local $SIG{__WARN__} = sub {}; |
| 212 | $tokens->add('Glemm', 'Morpho'); |
| 213 | }; |
| 214 | $output = decode_json( $tokens->to_json ); |
| 215 | unlike($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries'); |
| 216 | unlike($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos'); |
| 217 | |
| 218 | ## Connexor |
| 219 | $tokens->add('Connexor', 'Sentences'); |
| 220 | $output = decode_json( $tokens->to_json ); |
| 221 | like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries'); |
| 222 | like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos'); |
| 223 | |
| 224 | $tokens->add('Connexor', 'Morpho'); |
| 225 | $output = decode_json( $tokens->to_json ); |
| 226 | like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries'); |
| 227 | like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos'); |
| 228 | like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos'); |
| 229 | like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos'); |
| 230 | |
| 231 | $tokens->add('Connexor', 'Phrase'); |
| 232 | $output = decode_json( $tokens->to_json ); |
| 233 | like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries'); |
| 234 | like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos'); |
| 235 | |
| 236 | $tokens->add('Connexor', 'Syntax'); |
| 237 | $output = decode_json( $tokens->to_json ); |
| 238 | like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries'); |
| 239 | like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos'); |
| 240 | |
| 241 | ## Mate |
| 242 | $tokens->add('Mate', 'Morpho'); |
| 243 | $output = decode_json( $tokens->to_json ); |
| 244 | like($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries'); |
| 245 | like($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos'); |
| 246 | like($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos'); |
| 247 | like($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos'); |
| 248 | |
| 249 | # diag "No test for mate dependency"; |
| 250 | |
| 251 | ## XIP |
| 252 | $tokens->add('XIP', 'Sentences'); |
| 253 | $output = decode_json( $tokens->to_json ); |
| 254 | like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries'); |
| 255 | like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos'); |
| 256 | |
| 257 | $tokens->add('XIP', 'Morpho'); |
| 258 | $output = decode_json( $tokens->to_json ); |
| 259 | like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries'); |
| 260 | like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos'); |
| 261 | like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos'); |
| 262 | |
| 263 | $tokens->add('XIP', 'Constituency'); |
| 264 | $output = decode_json( $tokens->to_json ); |
| 265 | like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries'); |
| 266 | like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos'); |
| 267 | |
| 268 | # diag "No test for xip dependency"; |
| 269 | |
Akron | 89df4fa | 2016-11-04 14:35:37 +0100 | [diff] [blame] | 270 | $path = catdir(dirname(__FILE__), '../corpus/WDD15/A79/83946'); |
| 271 | |
| 272 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 273 | ok($doc->parse, 'Parse document'); |
| 274 | |
| 275 | is($doc->text_sigle, 'WDD15/A79/83946', 'Correct text sigle'); |
| 276 | is($doc->doc_sigle, 'WDD15/A79', 'Correct document sigle'); |
| 277 | is($doc->corpus_sigle, 'WDD15', 'Correct corpus sigle'); |
| 278 | |
Akron | 6bf3cc9 | 2019-02-07 12:11:20 +0100 | [diff] [blame] | 279 | $meta = $doc->meta; |
| 280 | is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http://de.wikipedia.org/wiki/Diskussion:Arteria_interossea_communis', 'link'); |
| 281 | |
Akron | 89df4fa | 2016-11-04 14:35:37 +0100 | [diff] [blame] | 282 | # Get tokenization |
| 283 | $tokens = KorAP::XML::Tokenizer->new( |
| 284 | path => $doc->path, |
| 285 | doc => $doc, |
| 286 | foundry => $token_base_foundry, |
| 287 | layer => $token_base_layer, |
| 288 | name => 'tokens' |
| 289 | ); |
| 290 | ok($tokens, 'Token Object is fine'); |
| 291 | |
| 292 | # Initialize log4perl object |
| 293 | Log::Log4perl->init({ |
| 294 | 'log4perl.rootLogger' => 'DEBUG, STDERR', |
| 295 | 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels', |
| 296 | 'log4perl.appender.STDERR.layout' => 'PatternLayout', |
| 297 | 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n' |
| 298 | }); |
| 299 | |
| 300 | ok(!$tokens->parse, 'Token parsing is fine'); |
| 301 | |
| 302 | |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 303 | done_testing; |
| 304 | __END__ |