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 | my $path = catdir(dirname(__FILE__), '../corpus/BZK/D59/00001'); |
| 20 | |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame^] | 21 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 22 | ok($doc->parse, 'Parse document'); |
| 23 | |
| 24 | is($doc->text_sigle, 'BZK_D59.00001', 'Correct text sigle'); |
| 25 | is($doc->doc_sigle, 'BZK_D59', 'Correct document sigle'); |
| 26 | is($doc->corpus_sigle, 'BZK', 'Correct corpus sigle'); |
| 27 | |
| 28 | is($doc->title, 'Unser gemeinsames Werk wird siegreich sein', 'Title'); |
| 29 | ok(!$doc->sub_title, 'No SubTitle'); |
| 30 | ok(!$doc->author, 'Author'); |
| 31 | ok(!$doc->editor, 'Editor'); |
| 32 | is($doc->pub_place, 'Berlin', 'PubPlace'); |
| 33 | ok(!$doc->publisher, 'Publisher'); |
| 34 | |
| 35 | is($doc->text_type, 'Zeitung: Tageszeitung', 'Correct Text Type'); |
| 36 | |
| 37 | ok(!$doc->text_type_art, 'Correct Text Type Art'); |
| 38 | is($doc->text_type_ref, 'Tageszeitung', 'Correct Text Type Ref'); |
| 39 | is($doc->text_domain, 'Politik', 'Correct Text Domain'); |
| 40 | is($doc->text_column, 'POLITIK', 'Correct Text Column'); |
| 41 | is($doc->text_class->[0], 'politik', 'Correct Text Class'); |
| 42 | is($doc->text_class->[1], 'ausland', 'Correct Text Class'); |
| 43 | ok(!$doc->text_class->[2], 'Correct Text Class'); |
| 44 | |
| 45 | is($doc->pub_date, '19590101', 'Creation date'); |
| 46 | is($doc->creation_date, '19590101', 'Creation date'); |
| 47 | is($doc->license, 'ACA-NC-LC', 'License'); |
| 48 | ok(!$doc->pages, 'Pages'); |
| 49 | |
| 50 | ok(!$doc->file_edition_statement, 'File Statement'); |
| 51 | ok(!$doc->bibl_edition_statement, 'Bibl Statement'); |
| 52 | |
| 53 | is($doc->reference . "\n", <<'REF', 'Reference'); |
| 54 | Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein |
| 55 | REF |
| 56 | is($doc->language, 'de', 'Language'); |
| 57 | |
| 58 | is($doc->corpus_title, 'Bonner Zeitungskorpus', 'Correct Corpus title'); |
| 59 | ok(!$doc->corpus_sub_title, 'Correct Corpus sub title'); |
| 60 | ok(!$doc->corpus_author, 'Correct Corpus author'); |
| 61 | ok(!$doc->corpus_editor, 'Correct Corpus editor'); |
| 62 | |
| 63 | is($doc->doc_title, 'Neues Deutschland', 'Correct Doc title'); |
| 64 | is($doc->doc_sub_title, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title'); |
| 65 | ok(!$doc->doc_author, 'Correct Doc author'); |
| 66 | ok(!$doc->doc_editor, 'Correct doc editor'); |
| 67 | |
| 68 | # Tokenization |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame^] | 69 | use_ok('KorAP::XML::Tokenizer'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 70 | |
| 71 | my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/); |
| 72 | |
| 73 | # Get tokenization |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame^] | 74 | my $tokens = KorAP::XML::Tokenizer->new( |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 75 | path => $doc->path, |
| 76 | doc => $doc, |
| 77 | foundry => $token_base_foundry, |
| 78 | layer => $token_base_layer, |
| 79 | name => 'tokens' |
| 80 | ); |
| 81 | ok($tokens, 'Token Object is fine'); |
| 82 | ok($tokens->parse, 'Token parsing is fine'); |
| 83 | |
| 84 | my $output = decode_json( $tokens->to_json ); |
| 85 | |
| 86 | is(substr($output->{data}->{text}, 0, 100), 'unser gemeinsames Werk wird siegreich sein Neujahrsbotschaft des Präsidenten der DeutschenDemokratis', 'Primary Data'); |
| 87 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 88 | is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource'); |
| 89 | is($output->{version}, '0.03', 'version'); |
| 90 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 91 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
| 92 | is($output->{data}->{stream}->[0]->[3], 's:unser', 'data'); |
| 93 | |
| 94 | is($output->{textSigle}, 'BZK_D59.00001', 'Correct text sigle'); |
| 95 | is($output->{docSigle}, 'BZK_D59', 'Correct document sigle'); |
| 96 | is($output->{corpusSigle}, 'BZK', 'Correct corpus sigle'); |
| 97 | |
| 98 | is($output->{title}, 'Unser gemeinsames Werk wird siegreich sein', 'Title'); |
| 99 | ok(!exists $output->{subTitle}, 'No SubTitle'); |
| 100 | ok(!exists $output->{author}, 'Author'); |
| 101 | ok(!exists $output->{editor}, 'Publisher'); |
| 102 | |
| 103 | is($output->{pubPlace}, 'Berlin', 'PubPlace'); |
| 104 | ok(!exists $output->{publisher}, 'Publisher'); |
| 105 | |
| 106 | is($output->{textType}, 'Zeitung: Tageszeitung', 'Correct Text Type'); |
| 107 | ok(!exists $output->{textTypeArt}, 'Correct Text Type Art'); |
| 108 | is($output->{textTypeRef}, 'Tageszeitung', 'Correct Text Type Ref'); |
| 109 | is($output->{textDomain}, 'Politik', 'Correct Text Domain'); |
| 110 | |
| 111 | is($output->{creationDate}, '19590101', 'Creation date'); |
| 112 | is($output->{license}, 'ACA-NC-LC', 'License'); |
| 113 | ok(!exists $output->{pages}, 'Pages'); |
| 114 | ok(!exists $output->{fileEditionStatement}, 'File Statement'); |
| 115 | ok(!exists $output->{biblEditionStatement}, 'Bibl Statement'); |
| 116 | |
| 117 | is($output->{reference} . "\n", <<'REF', 'Reference'); |
| 118 | Neues Deutschland, [Tageszeitung], 01.01.1959, Jg. 14, Berliner Ausgabe, S. 1. - Sachgebiet: Politik, Originalressort: POLITIK; Unser gemeinsames Werk wird siegreich sein |
| 119 | REF |
| 120 | is($output->{language}, 'de', 'Language'); |
| 121 | |
| 122 | is($output->{corpusTitle}, 'Bonner Zeitungskorpus', 'Correct Corpus title'); |
| 123 | ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title'); |
| 124 | ok(!exists $output->{corpusAuthor}, 'Correct Corpus author'); |
| 125 | ok(!exists $output->{corpusEditor}, 'Correct Corpus editor'); |
| 126 | |
| 127 | is($output->{docTitle}, 'Neues Deutschland', 'Correct Doc title'); |
| 128 | is($output->{docSubTitle}, 'Organ des Zentralkomitees der Sozialistischen Einheitspartei Deutschlands', 'Correct Doc sub title'); |
| 129 | ok(!exists $output->{docAuthor}, 'Correct Doc author'); |
| 130 | ok(!exists $output->{docEditor}, 'Correct doc editor'); |
| 131 | |
| 132 | ## Base |
| 133 | $tokens->add('Base', 'Sentences'); |
| 134 | $tokens->add('Base', 'Paragraphs'); |
| 135 | |
| 136 | $output = decode_json( $tokens->to_json ); |
| 137 | |
| 138 | |
| 139 | is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries'); |
| 140 | is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos'); |
| 141 | my $first_token = join('||', @{$output->{data}->{stream}->[0]}); |
| 142 | like($first_token, qr/s:unser/, 'data'); |
| 143 | like($first_token, qr/_0\$<i>0<i>5/, 'data'); |
| 144 | |
| 145 | ## OpenNLP |
| 146 | $tokens->add('OpenNLP', 'Sentences'); |
| 147 | |
| 148 | $output = decode_json( $tokens->to_json ); |
| 149 | is($output->{data}->{foundries}, |
| 150 | 'base base/paragraphs base/sentences opennlp opennlp/sentences', |
| 151 | 'Foundries'); |
| 152 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/s=spans', 'layerInfos'); |
| 153 | |
| 154 | |
| 155 | $tokens->add('OpenNLP', 'Morpho'); |
| 156 | $output = decode_json( $tokens->to_json ); |
| 157 | is($output->{data}->{foundries}, |
| 158 | 'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences', |
| 159 | 'Foundries'); |
| 160 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans', 'layerInfos'); |
| 161 | |
| 162 | |
| 163 | ## Treetagger |
| 164 | $tokens->add('TreeTagger', 'Sentences'); |
| 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/sentences', |
| 168 | 'Foundries'); |
| 169 | is($output->{data}->{layerInfos}, 'base/s=spans opennlp/p=tokens opennlp/s=spans tt/s=spans', 'layerInfos'); |
| 170 | |
| 171 | $tokens->add('TreeTagger', 'Morpho'); |
| 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 | ## CoreNLP |
| 179 | $tokens->add('CoreNLP', 'NamedEntities'); |
| 180 | $output = decode_json( $tokens->to_json ); |
| 181 | is($output->{data}->{foundries}, |
| 182 | 'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 183 | 'Foundries'); |
| 184 | is($output->{data}->{layerInfos}, 'base/s=spans corenlp/ne=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans', 'layerInfos'); |
| 185 | |
| 186 | $tokens->add('CoreNLP', 'Sentences'); |
| 187 | $output = decode_json( $tokens->to_json ); |
| 188 | is($output->{data}->{foundries}, |
| 189 | 'base base/paragraphs base/sentences corenlp corenlp/namedentities corenlp/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences', |
| 190 | 'Foundries'); |
| 191 | is($output->{data}->{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'); |
| 192 | |
| 193 | $tokens->add('CoreNLP', 'Morpho'); |
| 194 | $output = decode_json( $tokens->to_json ); |
| 195 | like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries'); |
| 196 | like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos'); |
| 197 | |
| 198 | $tokens->add('CoreNLP', 'Constituency'); |
| 199 | $output = decode_json( $tokens->to_json ); |
| 200 | like($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries'); |
| 201 | like($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos'); |
| 202 | |
| 203 | ## Glemm |
| 204 | $tokens->add('Glemm', 'Morpho'); |
| 205 | $output = decode_json( $tokens->to_json ); |
| 206 | like($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries'); |
| 207 | like($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos'); |
| 208 | |
| 209 | ## Connexor |
| 210 | $tokens->add('Connexor', 'Sentences'); |
| 211 | $output = decode_json( $tokens->to_json ); |
| 212 | like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries'); |
| 213 | like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos'); |
| 214 | |
| 215 | $tokens->add('Connexor', 'Morpho'); |
| 216 | $output = decode_json( $tokens->to_json ); |
| 217 | like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries'); |
| 218 | like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos'); |
| 219 | like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos'); |
| 220 | like($output->{data}->{layerInfos}, qr!cnx/m=tokens!, 'layerInfos'); |
| 221 | |
| 222 | $tokens->add('Connexor', 'Phrase'); |
| 223 | $output = decode_json( $tokens->to_json ); |
| 224 | like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries'); |
| 225 | like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos'); |
| 226 | |
| 227 | $tokens->add('Connexor', 'Syntax'); |
| 228 | $output = decode_json( $tokens->to_json ); |
| 229 | like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries'); |
| 230 | like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos'); |
| 231 | |
| 232 | ## Mate - not in existence |
| 233 | { |
| 234 | local $SIG{__WARN__} = sub {}; |
| 235 | $tokens->add('Mate', 'Morpho'); |
| 236 | $output = decode_json( $tokens->to_json ); |
| 237 | unlike($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries'); |
| 238 | unlike($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos'); |
| 239 | unlike($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos'); |
| 240 | unlike($output->{data}->{layerInfos}, qr!mate/m=tokens!, 'layerInfos'); |
| 241 | }; |
| 242 | |
| 243 | # diag "No test for mate dependency"; |
| 244 | |
| 245 | ## XIP |
| 246 | $tokens->add('XIP', 'Sentences'); |
| 247 | $output = decode_json( $tokens->to_json ); |
| 248 | like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries'); |
| 249 | like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos'); |
| 250 | |
| 251 | $tokens->add('XIP', 'Morpho'); |
| 252 | $output = decode_json( $tokens->to_json ); |
| 253 | like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries'); |
| 254 | like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos'); |
| 255 | like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos'); |
| 256 | |
| 257 | |
| 258 | $tokens->add('XIP', 'Constituency'); |
| 259 | $output = decode_json( $tokens->to_json ); |
| 260 | like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries'); |
| 261 | like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos'); |
| 262 | |
| 263 | # diag "No test for xip dependency"; |
| 264 | |
| 265 | |
| 266 | done_testing; |
| 267 | __END__ |