Akron | b9c3381 | 2020-10-21 16:19:35 +0200 | [diff] [blame] | 1 | use strict; |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use Data::Dumper; |
| 5 | use JSON::XS; |
| 6 | |
Akron | fab17d3 | 2020-07-31 14:38:29 +0200 | [diff] [blame] | 7 | if ($ENV{SKIP_REAL}) { |
| 8 | plan skip_all => 'Skip real tests'; |
| 9 | }; |
| 10 | |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 11 | use Benchmark qw/:hireswallclock/; |
| 12 | |
| 13 | my $t = Benchmark->new; |
| 14 | |
| 15 | use utf8; |
| 16 | use lib 'lib', '../lib'; |
| 17 | |
| 18 | use File::Basename 'dirname'; |
| 19 | use File::Spec::Functions 'catdir'; |
| 20 | |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 21 | use_ok('KorAP::XML::Krill'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 22 | |
| 23 | # GOE/AGA/03828 |
Akron | 414ec95 | 2020-08-03 15:48:43 +0200 | [diff] [blame] | 24 | my $path = catdir(dirname(__FILE__), 'corpus','WDD','G27','38989'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 25 | |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 26 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 27 | ok($doc->parse, 'Parse document'); |
| 28 | |
Akron | 1cd5b87 | 2016-03-22 00:23:46 +0100 | [diff] [blame] | 29 | is($doc->text_sigle, 'WDD11/G27/38989', 'Correct text sigle'); |
| 30 | is($doc->doc_sigle, 'WDD11/G27', 'Correct document sigle'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 31 | is($doc->corpus_sigle, 'WDD11', 'Correct corpus sigle'); |
| 32 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 33 | my $meta = $doc->meta; |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 34 | is($meta->{T_title}, 'Diskussion:Gunter A. Pilz', 'Title'); |
| 35 | ok(!$meta->{T_sub_title}, 'No SubTitle'); |
| 36 | is($meta->{T_author}, '€pa, u.a.', 'Author'); |
| 37 | is($meta->{A_editor}, 'wikipedia.org', 'Editor'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 38 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 39 | is($meta->{S_pub_place}, 'URL:http://de.wikipedia.org', 'PubPlace'); |
| 40 | is($meta->{A_publisher}, 'Wikipedia', 'Publisher'); |
| 41 | is($meta->{S_text_type}, 'Diskussionen zu Enzyklopädie-Artikeln', 'Correct Text Type'); |
| 42 | ok(!$meta->{S_text_type_art}, 'Correct Text Type Art'); |
| 43 | ok(!$meta->{S_text_type_ref}, 'Correct Text Type Ref'); |
| 44 | ok(!$meta->{S_text_domain}, 'Correct Text Domain'); |
| 45 | is($meta->{D_creation_date}, '20070707', 'Creation date'); |
| 46 | is($meta->{S_availability}, 'CC-BY-SA', 'License'); |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 47 | ok(!$meta->{pages}, 'Pages'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 48 | ok(!$meta->{A_file_edition_statement}, 'File Statement'); |
| 49 | ok(!$meta->{A_bibl_edition_statement}, 'Bibl Statement'); |
| 50 | is($meta->{A_reference} . "\n", <<'REF', 'Reference'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 51 | Diskussion:Gunter A. Pilz, In: Wikipedia - URL:http://de.wikipedia.org/wiki/Diskussion:Gunter_A._Pilz: Wikipedia, 2007 |
| 52 | REF |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 53 | is($meta->{S_language}, 'de', 'Language'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 54 | |
Akron | 8ad06c4 | 2022-01-11 17:07:49 +0100 | [diff] [blame^] | 55 | is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http%3A%2F%2Fde.wikipedia.org%2Fwiki%2FDiskussion%3AGunter_A._Pilz', 'link'); |
Akron | 6bf3cc9 | 2019-02-07 12:11:20 +0100 | [diff] [blame] | 56 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 57 | is($meta->{T_corpus_title}, 'Wikipedia', 'Correct Corpus title'); |
| 58 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus sub title'); |
| 59 | ok(!$meta->{T_corpus_author}, 'Correct Corpus author'); |
| 60 | is($meta->{A_corpus_editor}, 'wikipedia.org', 'Correct Corpus editor'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 61 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 62 | is($meta->{T_doc_title}, 'Wikipedia, Diskussionen zu Artikeln mit Anfangsbuchstabe G, Teil 27', 'Correct Doc title'); |
| 63 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc sub title'); |
| 64 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
| 65 | ok(!$meta->{A_doc_editor}, 'Correct doc editor'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 66 | |
| 67 | # Tokenization |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 68 | use_ok('KorAP::XML::Tokenizer'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 69 | |
| 70 | my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/); |
| 71 | |
| 72 | # Get tokenization |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 73 | my $tokens = KorAP::XML::Tokenizer->new( |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 74 | path => $doc->path, |
| 75 | doc => $doc, |
| 76 | foundry => $token_base_foundry, |
| 77 | layer => $token_base_layer, |
| 78 | name => 'tokens' |
| 79 | ); |
| 80 | ok($tokens, 'Token Object is fine'); |
| 81 | ok($tokens->parse, 'Token parsing is fine'); |
| 82 | |
| 83 | my $output = decode_json( $tokens->to_json ); |
| 84 | |
| 85 | is(substr($output->{data}->{text}, 0, 100), '{{War Löschkandidat|6. Juli 2007|(erl., bleibt)}}', 'Primary Data'); |
| 86 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 87 | is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource'); |
| 88 | is($output->{version}, '0.03', 'version'); |
| 89 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 90 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
Akron | 2d83a5a | 2016-02-26 00:21:16 +0100 | [diff] [blame] | 91 | is($output->{data}->{stream}->[0]->[4], 's:{War', 'data'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 92 | |
Akron | 1cd5b87 | 2016-03-22 00:23:46 +0100 | [diff] [blame] | 93 | is($output->{textSigle}, 'WDD11/G27/38989', 'Correct text sigle'); |
| 94 | is($output->{docSigle}, 'WDD11/G27', 'Correct document sigle'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 95 | is($output->{corpusSigle}, 'WDD11', 'Correct corpus sigle'); |
| 96 | |
| 97 | is($output->{title}, 'Diskussion:Gunter A. Pilz', 'Title'); |
| 98 | ok(!$output->{subTitle}, 'No SubTitle'); |
| 99 | is($output->{author}, '€pa, u.a.', 'Author'); |
Akron | 7e2eb88 | 2017-01-18 17:28:07 +0100 | [diff] [blame] | 100 | is($output->{editor}, 'wikipedia.org', 'Editor'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 101 | |
| 102 | is($output->{pubPlace}, 'URL:http://de.wikipedia.org', 'PubPlace'); |
| 103 | is($output->{publisher}, 'Wikipedia', 'Publisher'); |
| 104 | is($output->{textType}, 'Diskussionen zu Enzyklopädie-Artikeln', 'Correct Text Type'); |
| 105 | ok(!$output->{textTypeArt}, 'Correct Text Type Art'); |
| 106 | ok(!$output->{textTypeRef}, 'Correct Text Type Ref'); |
| 107 | ok(!$output->{textDomain}, 'Correct Text Domain'); |
| 108 | is($output->{creationDate}, '20070707', 'Creation date'); |
Akron | 6396c30 | 2016-03-18 16:05:39 +0100 | [diff] [blame] | 109 | is($output->{availability}, 'CC-BY-SA', 'License'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 110 | ok(!$output->{pages}, 'Pages'); |
| 111 | ok(!$output->{fileEditionStatement}, 'File Statement'); |
| 112 | ok(!$output->{biblEditionStatement}, 'Bibl Statement'); |
| 113 | is($output->{reference} . "\n", <<'REF', 'Reference'); |
| 114 | Diskussion:Gunter A. Pilz, In: Wikipedia - URL:http://de.wikipedia.org/wiki/Diskussion:Gunter_A._Pilz: Wikipedia, 2007 |
| 115 | REF |
| 116 | is($output->{language}, 'de', 'Language'); |
| 117 | |
| 118 | is($output->{corpusTitle}, 'Wikipedia', 'Correct Corpus title'); |
| 119 | ok(!$output->{corpusSubTitle}, 'Correct Corpus sub title'); |
| 120 | ok(!$output->{corpusAuthor}, 'Correct Corpus author'); |
| 121 | is($output->{corpusEditor}, 'wikipedia.org', 'Correct Corpus editor'); |
| 122 | |
| 123 | is($output->{docTitle}, 'Wikipedia, Diskussionen zu Artikeln mit Anfangsbuchstabe G, Teil 27', 'Correct Doc title'); |
| 124 | ok(!$output->{docSubTitle}, 'Correct Doc sub title'); |
| 125 | ok(!$output->{docAuthor}, 'Correct Doc author'); |
| 126 | ok(!$output->{docEditor}, 'Correct doc editor'); |
| 127 | |
| 128 | ## Base |
| 129 | $tokens->add('Base', 'Sentences'); |
| 130 | |
| 131 | $tokens->add('Base', 'Paragraphs'); |
| 132 | |
| 133 | $output = decode_json( $tokens->to_json ); |
| 134 | |
| 135 | is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries'); |
| 136 | is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos'); |
| 137 | my $first_token = join('||', @{$output->{data}->{stream}->[0]}); |
Akron | a9455ec | 2016-02-14 01:42:20 +0100 | [diff] [blame] | 138 | like($first_token, qr/s:\{War/, 'data'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 139 | like($first_token, qr/_0\$<i>1<i>5/, 'data'); |
| 140 | |
| 141 | |
| 142 | ## OpenNLP |
| 143 | $tokens->add('OpenNLP', 'Sentences'); |
| 144 | |
| 145 | $output = decode_json( $tokens->to_json ); |
| 146 | is($output->{data}->{foundries}, |
| 147 | 'base base/paragraphs base/sentences opennlp opennlp/sentences', |
| 148 | 'Foundries'); |
| 149 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos'); |
| 150 | |
| 151 | |
| 152 | $tokens->add('OpenNLP', 'Morpho'); |
| 153 | $output = decode_json( $tokens->to_json ); |
| 154 | is($output->{data}->{foundries}, |
| 155 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences', |
| 156 | 'Foundries'); |
| 157 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos'); |
| 158 | |
| 159 | |
| 160 | ## Treetagger |
| 161 | $tokens->add('TreeTagger', 'Sentences'); |
| 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/sentences', |
| 165 | 'Foundries'); |
| 166 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos'); |
| 167 | |
| 168 | $tokens->add('TreeTagger', 'Morpho'); |
| 169 | $output = decode_json( $tokens->to_json ); |
| 170 | is($output->{data}->{foundries}, |
| 171 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 172 | 'Foundries'); |
| 173 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 174 | |
| 175 | ## CoreNLP |
| 176 | { |
| 177 | local $SIG{__WARN__} = sub {}; |
| 178 | $tokens->add('CoreNLP', 'NamedEntities'); |
| 179 | }; |
| 180 | $output = decode_json( $tokens->to_json ); |
| 181 | is($output->{data}->{foundries}, |
| 182 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 183 | 'Foundries'); |
| 184 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 185 | |
| 186 | |
| 187 | { |
| 188 | local $SIG{__WARN__} = sub {}; |
| 189 | $tokens->add('CoreNLP', 'Sentences'); |
| 190 | }; |
| 191 | $output = decode_json( $tokens->to_json ); |
| 192 | is($output->{data}->{foundries}, |
| 193 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 194 | 'Foundries'); |
| 195 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 196 | |
| 197 | { |
| 198 | local $SIG{__WARN__} = sub {}; |
| 199 | $tokens->add('CoreNLP', 'Morpho'); |
| 200 | }; |
| 201 | $output = decode_json( $tokens->to_json ); |
| 202 | unlike($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries'); |
| 203 | unlike($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos'); |
| 204 | |
| 205 | { |
| 206 | local $SIG{__WARN__} = sub {}; |
| 207 | $tokens->add('CoreNLP', 'Constituency'); |
| 208 | }; |
| 209 | $output = decode_json( $tokens->to_json ); |
| 210 | unlike($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries'); |
| 211 | unlike($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos'); |
| 212 | |
| 213 | ## Glemm |
| 214 | { |
| 215 | local $SIG{__WARN__} = sub {}; |
| 216 | $tokens->add('Glemm', 'Morpho'); |
| 217 | }; |
| 218 | $output = decode_json( $tokens->to_json ); |
| 219 | unlike($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries'); |
| 220 | unlike($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos'); |
| 221 | |
| 222 | ## Connexor |
| 223 | $tokens->add('Connexor', 'Sentences'); |
| 224 | $output = decode_json( $tokens->to_json ); |
| 225 | like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries'); |
| 226 | like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos'); |
| 227 | |
| 228 | $tokens->add('Connexor', 'Morpho'); |
| 229 | $output = decode_json( $tokens->to_json ); |
| 230 | like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries'); |
| 231 | like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos'); |
| 232 | like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos'); |
| 233 | like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos'); |
| 234 | |
| 235 | $tokens->add('Connexor', 'Phrase'); |
| 236 | $output = decode_json( $tokens->to_json ); |
| 237 | like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries'); |
| 238 | like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos'); |
| 239 | |
| 240 | $tokens->add('Connexor', 'Syntax'); |
| 241 | $output = decode_json( $tokens->to_json ); |
| 242 | like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries'); |
| 243 | like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos'); |
| 244 | |
| 245 | ## Mate |
| 246 | $tokens->add('Mate', 'Morpho'); |
| 247 | $output = decode_json( $tokens->to_json ); |
| 248 | like($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries'); |
| 249 | like($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos'); |
| 250 | like($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos'); |
| 251 | like($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos'); |
| 252 | |
| 253 | # diag "No test for mate dependency"; |
| 254 | |
| 255 | ## XIP |
| 256 | $tokens->add('XIP', 'Sentences'); |
| 257 | $output = decode_json( $tokens->to_json ); |
| 258 | like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries'); |
| 259 | like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos'); |
| 260 | |
| 261 | $tokens->add('XIP', 'Morpho'); |
| 262 | $output = decode_json( $tokens->to_json ); |
| 263 | like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries'); |
| 264 | like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos'); |
| 265 | like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos'); |
| 266 | |
| 267 | $tokens->add('XIP', 'Constituency'); |
| 268 | $output = decode_json( $tokens->to_json ); |
| 269 | like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries'); |
| 270 | like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos'); |
| 271 | |
| 272 | # diag "No test for xip dependency"; |
| 273 | |
Akron | 414ec95 | 2020-08-03 15:48:43 +0200 | [diff] [blame] | 274 | $path = catdir(dirname(__FILE__), 'corpus','WDD15','A79','83946'); |
Akron | 89df4fa | 2016-11-04 14:35:37 +0100 | [diff] [blame] | 275 | |
| 276 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 277 | ok($doc->parse, 'Parse document'); |
| 278 | |
| 279 | is($doc->text_sigle, 'WDD15/A79/83946', 'Correct text sigle'); |
| 280 | is($doc->doc_sigle, 'WDD15/A79', 'Correct document sigle'); |
| 281 | is($doc->corpus_sigle, 'WDD15', 'Correct corpus sigle'); |
| 282 | |
Akron | 6bf3cc9 | 2019-02-07 12:11:20 +0100 | [diff] [blame] | 283 | $meta = $doc->meta; |
Akron | 8ad06c4 | 2022-01-11 17:07:49 +0100 | [diff] [blame^] | 284 | is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http%3A%2F%2Fde.wikipedia.org%2Fwiki%2FDiskussion%3AArteria_interossea_communis', 'link'); |
Akron | 6bf3cc9 | 2019-02-07 12:11:20 +0100 | [diff] [blame] | 285 | |
Akron | 89df4fa | 2016-11-04 14:35:37 +0100 | [diff] [blame] | 286 | # Get tokenization |
| 287 | $tokens = KorAP::XML::Tokenizer->new( |
| 288 | path => $doc->path, |
| 289 | doc => $doc, |
| 290 | foundry => $token_base_foundry, |
| 291 | layer => $token_base_layer, |
| 292 | name => 'tokens' |
| 293 | ); |
| 294 | ok($tokens, 'Token Object is fine'); |
| 295 | |
Akron | 89df4fa | 2016-11-04 14:35:37 +0100 | [diff] [blame] | 296 | ok(!$tokens->parse, 'Token parsing is fine'); |
| 297 | |
| 298 | |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 299 | done_testing; |
| 300 | __END__ |