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