Akron | 1924bbe | 2016-06-22 16:05:41 +0200 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use Data::Dumper; |
| 5 | use JSON::XS; |
Akron | a5920b1 | 2016-06-29 18:51:21 +0200 | [diff] [blame] | 6 | use Log::Log4perl; |
Akron | 1924bbe | 2016-06-22 16:05:41 +0200 | [diff] [blame] | 7 | |
| 8 | use utf8; |
| 9 | use lib 'lib', '../lib'; |
| 10 | |
| 11 | use File::Basename 'dirname'; |
| 12 | use File::Spec::Functions 'catdir'; |
| 13 | |
Akron | a5920b1 | 2016-06-29 18:51:21 +0200 | [diff] [blame] | 14 | # Initialize log4perl object |
| 15 | Log::Log4perl->init({ |
| 16 | 'log4perl.rootLogger' => 'ERROR, 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 | 1924bbe | 2016-06-22 16:05:41 +0200 | [diff] [blame] | 22 | use_ok('KorAP::XML::Krill'); |
| 23 | |
| 24 | my $path = catdir(dirname(__FILE__), '../corpus/REI/BNG/00128'); |
| 25 | |
| 26 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 27 | ok($doc->parse, 'Parse document'); |
| 28 | |
| 29 | is($doc->text_sigle, 'REI/BNG/00128', 'Correct text sigle'); |
| 30 | is($doc->doc_sigle, 'REI/BNG', 'Correct document sigle'); |
| 31 | is($doc->corpus_sigle, 'REI', 'Correct corpus sigle'); |
| 32 | |
| 33 | my $meta = $doc->meta; |
| 34 | is($meta->{title}, 'Friedensgutachten der führenden Friedensforschungsinstitute', 'Title'); |
| 35 | is($meta->{sub_title}, 'Rede im Deutschen Bundestag am 14.06.2002', 'SubTitle'); |
| 36 | is($meta->{author}, 'Nachtwei, Winfried', 'Author'); |
| 37 | ok(!$meta->{editor}, 'Editor'); |
| 38 | is($meta->{pub_place}, 'Berlin', 'PubPlace'); |
| 39 | ok(!$meta->{publisher}, 'Publisher'); |
| 40 | |
| 41 | ok(!$meta->{text_type}, 'No Text Type'); |
| 42 | ok(!$meta->{text_type_art}, 'No Text Type Art'); |
| 43 | ok(!$meta->{text_type_ref}, 'No Text Type Ref'); |
| 44 | ok(!$meta->{text_domain}, 'No Text Domain'); |
| 45 | ok(!$meta->{text_column}, 'No Text Column'); |
| 46 | |
| 47 | is($meta->{text_class}->[0], 'politik', 'Correct Text Class'); |
| 48 | is($meta->{text_class}->[1], 'inland', 'Correct Text Class'); |
| 49 | ok(!$meta->{text_class}->[2], 'Correct Text Class'); |
| 50 | |
| 51 | is($meta->{pub_date}, '20020614', 'Creation date'); |
| 52 | is($meta->{creation_date}, '20020614', 'Creation date'); |
| 53 | is($meta->{availability}, 'CC-BY-SA', 'License'); |
| 54 | ok(!$meta->{pages}, 'Pages'); |
| 55 | |
| 56 | ok(!$meta->{file_edition_statement}, 'File Statement'); |
| 57 | ok(!$meta->{bibl_edition_statement}, 'Bibl Statement'); |
| 58 | |
| 59 | is($meta->{reference} . "\n", <<'REF', 'Reference'); |
| 60 | Nachtwei, Winfried: Friedensgutachten der führenden Friedensforschungsinstitute. Rede im Deutschen Bundestag am 14.06.2002, Hrsg: Bundestagsfraktion Bündnis 90/DIE GRÜNEN [Ausführliche Zitierung nicht verfügbar] |
| 61 | REF |
| 62 | is($meta->{language}, 'de', 'Language'); |
| 63 | |
| 64 | is($meta->{corpus_title}, 'Reden und Interviews', 'Correct Corpus title'); |
| 65 | ok(!$meta->{corpus_sub_title}, 'Correct Corpus sub title'); |
| 66 | ok(!$meta->{corpus_author}, 'Correct Corpus author'); |
| 67 | ok(!$meta->{corpus_editor}, 'Correct Corpus editor'); |
| 68 | |
| 69 | is($meta->{doc_title}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Correct Doc title'); |
| 70 | ok(!$meta->{doc_sub_title}, 'Correct Doc sub title'); |
| 71 | ok(!$meta->{doc_author}, 'Correct Doc author'); |
| 72 | ok(!$meta->{doc_editor}, 'Correct doc editor'); |
| 73 | |
| 74 | # Tokenization |
| 75 | use_ok('KorAP::XML::Tokenizer'); |
| 76 | |
| 77 | my ($token_base_foundry, $token_base_layer) = (qw/Base tokens_conservative/); |
| 78 | |
| 79 | # Get tokenization |
| 80 | my $tokens = KorAP::XML::Tokenizer->new( |
| 81 | path => $doc->path, |
| 82 | doc => $doc, |
| 83 | foundry => $token_base_foundry, |
| 84 | layer => $token_base_layer, |
| 85 | name => 'tokens' |
| 86 | ); |
| 87 | |
| 88 | ok($tokens, 'Token Object is fine'); |
| 89 | ok($tokens->parse, 'Token parsing is fine'); |
| 90 | |
| 91 | my $output = decode_json( $tokens->to_json ); |
| 92 | |
| 93 | is(substr($output->{data}->{text}, 0, 100), 'Winfried Nachtwei, Friedensgutachten der führenden Friedensforschungsinstitute 14. Juni 2002 Vizeprä', 'Primary Data'); |
| 94 | |
| 95 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 96 | is($output->{data}->{tokenSource}, 'base#tokens_conservative', 'tokenSource'); |
| 97 | is($output->{version}, '0.03', 'version'); |
| 98 | |
| 99 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 100 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
| 101 | is($output->{data}->{stream}->[0]->[4], 's:Winfried', 'data'); |
| 102 | |
| 103 | is($output->{textSigle}, 'REI/BNG/00128', 'Correct text sigle'); |
| 104 | is($output->{docSigle}, 'REI/BNG', 'Correct document sigle'); |
| 105 | is($output->{corpusSigle}, 'REI', 'Correct corpus sigle'); |
| 106 | |
| 107 | is($output->{title}, 'Friedensgutachten der führenden Friedensforschungsinstitute', 'Title'); |
| 108 | is($output->{subTitle}, 'Rede im Deutschen Bundestag am 14.06.2002', 'Correct SubTitle'); |
| 109 | is($output->{author}, 'Nachtwei, Winfried', 'Author'); |
| 110 | ok(!exists $output->{editor}, 'Publisher'); |
| 111 | |
| 112 | is($output->{pubPlace}, 'Berlin', 'PubPlace'); |
| 113 | ok(!exists $output->{publisher}, 'Publisher'); |
| 114 | |
| 115 | ok(!exists $output->{textType}, 'Correct Text Type'); |
| 116 | ok(!exists $output->{textTypeArt}, 'Correct Text Type Art'); |
| 117 | ok(!exists $output->{textTypeRef}, 'Correct Text Type Ref'); |
| 118 | ok(!exists $output->{textDomain}, 'Correct Text Domain'); |
| 119 | |
| 120 | is($output->{creationDate}, '20020614', 'Creation date'); |
| 121 | is($output->{availability}, 'CC-BY-SA', 'License'); |
| 122 | |
| 123 | ok(!exists $output->{pages}, 'Pages'); |
| 124 | ok(!exists $output->{fileEditionStatement}, 'File Statement'); |
| 125 | ok(!exists $output->{biblEditionStatement}, 'Bibl Statement'); |
| 126 | |
| 127 | is($output->{reference} . "\n", <<'REF', 'Reference'); |
| 128 | Nachtwei, Winfried: Friedensgutachten der führenden Friedensforschungsinstitute. Rede im Deutschen Bundestag am 14.06.2002, Hrsg: Bundestagsfraktion Bündnis 90/DIE GRÜNEN [Ausführliche Zitierung nicht verfügbar] |
| 129 | REF |
| 130 | is($output->{language}, 'de', 'Language'); |
| 131 | |
| 132 | is($output->{corpusTitle}, 'Reden und Interviews', 'Correct Corpus title'); |
| 133 | ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title'); |
| 134 | ok(!exists $output->{corpusAuthor}, 'Correct Corpus author'); |
| 135 | ok(!exists $output->{corpusEditor}, 'Correct Corpus editor'); |
| 136 | |
| 137 | is($output->{docTitle}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Correct Doc title'); |
| 138 | ok(!exists $output->{docSubTitle}, 'Correct Doc sub title'); |
| 139 | ok(!exists $output->{docAuthor}, 'Correct Doc author'); |
| 140 | ok(!exists $output->{docEditor}, 'Correct doc editor'); |
| 141 | |
| 142 | ## Base |
| 143 | $tokens->add('Base', 'Sentences'); |
| 144 | $tokens->add('Base', 'Paragraphs'); |
| 145 | |
| 146 | $output = decode_json( $tokens->to_json ); |
| 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:Winfried/, 'data'); |
| 152 | like($first_token, qr/_0\$<i>0<i>8/, 'data'); |
| 153 | |
| 154 | |
Akron | a5920b1 | 2016-06-29 18:51:21 +0200 | [diff] [blame] | 155 | # REI/RBR/00610 |
| 156 | $path = catdir(dirname(__FILE__), '../corpus/REI/RBR/00610'); |
| 157 | |
| 158 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 159 | ok($doc->parse, 'Parse document'); |
| 160 | |
| 161 | # Get tokenization |
| 162 | $tokens = KorAP::XML::Tokenizer->new( |
| 163 | path => $doc->path, |
| 164 | doc => $doc, |
| 165 | foundry => $token_base_foundry, |
| 166 | layer => $token_base_layer, |
| 167 | name => 'tokens' |
| 168 | ); |
| 169 | |
| 170 | ok($tokens, 'Token Object is fine'); |
| 171 | ok($tokens->parse, 'Token parsing is fine'); |
| 172 | |
| 173 | # Add annotations |
| 174 | $tokens->add('Base', 'Sentences'); |
| 175 | $tokens->add('Base', 'Paragraphs'); |
| 176 | |
| 177 | $tokens->add('CoreNLP', 'Constituency'); |
| 178 | $tokens->add('CoreNLP', 'Morpho'); |
| 179 | $tokens->add('CoreNLP', 'Sentences'); |
| 180 | |
| 181 | $tokens->add('Malt', 'Dependency'); |
| 182 | |
| 183 | $tokens->add('OpenNLP', 'Morpho'); |
| 184 | $tokens->add('OpenNLP', 'Sentences'); |
| 185 | |
| 186 | $tokens->add('DeReKo', 'Structure'); |
| 187 | |
| 188 | $tokens->add('TreeTagger', 'Morpho'); |
| 189 | $tokens->add('TreeTagger', 'Sentences'); |
| 190 | |
| 191 | $output = decode_json( $tokens->to_json ); |
| 192 | |
| 193 | my $first = $output->{data}->{stream}->[0]; |
| 194 | is('-:base/paragraphs$<i>31', $first->[0]); |
| 195 | is('-:base/sentences$<i>168', $first->[1]); |
| 196 | is('-:corenlp/sentences$<i>175', $first->[2]); |
| 197 | is('-:opennlp/sentences$<i>169', $first->[3]); |
| 198 | is('-:tokens$<i>2641', $first->[4]); |
| 199 | is('-:tt/sentences$<i>196', $first->[5]); |
| 200 | is('<:malt/d:PP$<b>32<i>4', $first->[6]); |
| 201 | is('<>:corenlp/c:ROOT$<b>64<i>0<i>48<i>7<b>0', $first->[7]); |
| 202 | is('<>:corenlp/s:s$<b>64<i>0<i>48<i>7<b>0', $first->[8]); |
| 203 | is('<>:opennlp/s:s$<b>64<i>0<i>48<i>7<b>0', $first->[9]); |
| 204 | is('<>:tt/s:s$<b>64<i>0<i>48<i>7<b>0', $first->[10]); |
| 205 | is('<>:corenlp/c:S$<b>64<i>0<i>48<i>7<b>1', $first->[11]); |
| 206 | is('<>:dereko/s:front$<b>64<i>0<i>91<i>11<b>1', $first->[12]); |
| 207 | is('<>:base/s:s$<b>64<i>0<i>91<i>11<b>2', $first->[13]); |
| 208 | is('<>:dereko/s:titlePage$<b>64<i>0<i>91<i>11<b>2<s>1', $first->[14]); |
| 209 | is('<>:dereko/s:docTitle$<b>64<i>0<i>91<i>11<b>3', $first->[15]); |
| 210 | is('<>:dereko/s:titlePart$<b>64<i>0<i>91<i>11<b>4<s>2', $first->[16]); |
| 211 | is('<>:dereko/s:s$<b>64<i>0<i>91<i>11<b>5', $first->[17]); |
| 212 | is('<>:base/s:t$<b>64<i>0<i>17859<i>2640<b>0', $first->[18]); |
| 213 | is('>:malt/d:ROOT$<b>33<i>0<i>48<i>0<i>7', $first->[19]); |
| 214 | is('<:malt/d:PP$<b>32<i>1', $first->[20]); |
| 215 | is('<:malt/d:ROOT$<b>34<i>0<i>48<i>7<i>0', $first->[21]); |
| 216 | is('@:dereko/s:id:rbr.00610-0-titlepage$<b>17<s>1<i>11', $first->[22]); |
| 217 | is('@:dereko/s:type:unspecified$<b>17<s>2<i>11', $first->[23]); |
| 218 | is('_0$<i>0<i>4', $first->[24]); |
| 219 | is('corenlp/p:NN', $first->[25]); |
| 220 | is('i:rede', $first->[26]); |
| 221 | is('opennlp/p:NN', $first->[27]); |
| 222 | is('s:Rede', $first->[28]); |
Akron | 0426176 | 2018-01-29 20:16:39 +0100 | [diff] [blame^] | 223 | is('tt/l:Rede', $first->[29]); |
Akron | a5920b1 | 2016-06-29 18:51:21 +0200 | [diff] [blame] | 224 | is('tt/p:NN$<b>129<b>253', $first->[30]); |
| 225 | |
| 226 | my $last = $output->{data}->{stream}->[-1]; |
| 227 | |
| 228 | is('<>:dereko/s:text$<b>65<i>17859<i>17859<i>2640<b>0', $last->[0]); |
| 229 | is('<>:dereko/s:back$<b>65<i>17859<i>17859<i>2640<b>1', $last->[1]); |
| 230 | is('>:malt/d:APP$<b>32<i>2639', $last->[2]); |
| 231 | is('_2640$<i>17851<i>17859', $last->[3]); |
| 232 | is('corenlp/p:NE', $last->[4]); |
| 233 | is("i:schr\x{f6}der", $last->[5]); |
| 234 | is('opennlp/p:NE', $last->[6]); |
| 235 | is("s:Schr\x{f6}der", $last->[7]); |
Akron | 0426176 | 2018-01-29 20:16:39 +0100 | [diff] [blame^] | 236 | is("tt/l:Schr\x{f6}der", $last->[8]); |
Akron | a5920b1 | 2016-06-29 18:51:21 +0200 | [diff] [blame] | 237 | is('tt/p:NE$<b>129<b>255', $last->[9]); |
| 238 | |
| 239 | |
| 240 | # REI/BNG/00071 |
| 241 | $path = catdir(dirname(__FILE__), '../corpus/REI/BNG/00071'); |
| 242 | |
| 243 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 244 | ok($doc->parse, 'Parse document'); |
| 245 | |
| 246 | # Get tokenization |
| 247 | $tokens = KorAP::XML::Tokenizer->new( |
| 248 | path => $doc->path, |
| 249 | doc => $doc, |
| 250 | foundry => $token_base_foundry, |
| 251 | layer => $token_base_layer, |
| 252 | name => 'tokens' |
| 253 | ); |
| 254 | |
| 255 | ok($tokens, 'Token Object is fine'); |
| 256 | ok($tokens->parse, 'Token parsing is fine'); |
| 257 | |
| 258 | # Add annotations |
| 259 | $tokens->add('Base', 'Sentences'); |
| 260 | $tokens->add('Base', 'Paragraphs'); |
| 261 | |
| 262 | $tokens->add('CoreNLP', 'Constituency'); |
| 263 | $tokens->add('CoreNLP', 'Morpho'); |
| 264 | $tokens->add('CoreNLP', 'Sentences'); |
| 265 | |
| 266 | $tokens->add('Malt', 'Dependency'); |
| 267 | |
| 268 | $tokens->add('OpenNLP', 'Morpho'); |
| 269 | $tokens->add('OpenNLP', 'Sentences'); |
| 270 | |
| 271 | $tokens->add('DeReKo', 'Structure'); |
| 272 | |
| 273 | $tokens->add('TreeTagger', 'Morpho'); |
| 274 | $tokens->add('TreeTagger', 'Sentences'); |
| 275 | |
| 276 | $output = decode_json( $tokens->to_json ); |
| 277 | |
| 278 | $first = $output->{data}->{stream}->[0]; |
| 279 | |
| 280 | is('-:base/paragraphs$<i>41', $first->[0]); |
| 281 | is('-:base/sentences$<i>73', $first->[1]); |
| 282 | is('-:corenlp/sentences$<i>69', $first->[2]); |
| 283 | is('-:opennlp/sentences$<i>65', $first->[3]); |
| 284 | is('-:tokens$<i>1009', $first->[4]); |
| 285 | is('-:tt/sentences$<i>95', $first->[5]); |
| 286 | is('<:malt/d:APP$<b>32<i>1', $first->[6]); |
| 287 | is('<>:corenlp/c:MPN$<b>64<i>0<i>16<i>2<b>3', $first->[7]); |
| 288 | is('<>:base/s:s$<b>64<i>0<i>48<i>5<b>2', $first->[8]); |
| 289 | is('<>:dereko/s:titlePart$<b>64<i>0<i>48<i>5<b>4<s>2', $first->[9]); |
| 290 | is('<>:dereko/s:s$<b>64<i>0<i>48<i>5<b>5', $first->[10]); |
| 291 | is('<>:corenlp/c:ROOT$<b>64<i>0<i>51<i>6<b>0', $first->[11]); |
| 292 | is('<>:corenlp/s:s$<b>64<i>0<i>51<i>6<b>0', $first->[12]); |
| 293 | is('<>:tt/s:s$<b>64<i>0<i>51<i>6<b>0', $first->[13]); |
| 294 | is('<>:corenlp/c:NUR$<b>64<i>0<i>51<i>6<b>1', $first->[14]); |
| 295 | is('<>:corenlp/c:NP$<b>64<i>0<i>50<i>6<b>2', $first->[15]); |
| 296 | is('<>:dereko/s:front$<b>64<i>0<i>61<i>8<b>1', $first->[16]); |
| 297 | is('<>:dereko/s:titlePage$<b>64<i>0<i>61<i>8<b>2<s>1', $first->[17]); |
| 298 | is('<>:dereko/s:docTitle$<b>64<i>0<i>61<i>8<b>3', $first->[18]); |
| 299 | is('<>:opennlp/s:s$<b>64<i>0<i>173<i>24<b>0', $first->[19]); |
| 300 | is('<>:base/s:t$<b>64<i>0<i>7008<i>1008<b>0', $first->[20]); |
| 301 | is('<>:dereko/s:text$<b>64<i>0<i>7008<i>1008<b>0', $first->[21]); |
| 302 | is('>:malt/d:GMOD$<b>32<i>3', $first->[22]); |
| 303 | is('<:malt/d:ROOT$<b>34<i>0<i>51<i>6<i>3', $first->[23]); |
| 304 | is('@:dereko/s:id:bng.00071-0-titlepage$<b>17<s>1<i>8', $first->[24]); |
| 305 | is('@:dereko/s:type:unspecified$<b>17<s>2<i>5', $first->[25]); |
| 306 | is('_0$<i>0<i>9', $first->[26]); |
| 307 | is('corenlp/p:NE', $first->[27]); |
| 308 | is('i:christine', $first->[28]); |
| 309 | is('opennlp/p:NE', $first->[29]); |
| 310 | is('s:Christine', $first->[30]); |
Akron | 0426176 | 2018-01-29 20:16:39 +0100 | [diff] [blame^] | 311 | is('tt/l:Christine', $first->[31]); |
Akron | a5920b1 | 2016-06-29 18:51:21 +0200 | [diff] [blame] | 312 | is('tt/p:NE$<b>129<b>255', $first->[32]); |
| 313 | |
| 314 | $last = $output->{data}->{stream}->[-1]; |
| 315 | is('<>:dereko/s:back$<b>65<i>7008<i>7008<i>1008<b>1', $last->[0]); |
| 316 | is('<>:dereko/s:div$<b>65<i>7008<i>7008<i>1008<b>2<s>1', $last->[1]); |
| 317 | is('@:dereko/s:n:1$<b>17<s>1', $last->[2]); |
| 318 | is('@:dereko/s:type:footnotes$<b>17<s>1', $last->[3]); |
| 319 | is('@:dereko/s:complete:y$<b>17<s>1', $last->[4]); |
| 320 | is('_1008$<i>6990<i>7006', $last->[5]); |
| 321 | is('corenlp/p:NN', $last->[6]); |
| 322 | is('i:befreiungsschlag', $last->[7]); |
| 323 | is('opennlp/p:NN', $last->[8]); |
| 324 | is('s:Befreiungsschlag', $last->[9]); |
| 325 | |
Akron | 1924bbe | 2016-06-22 16:05:41 +0200 | [diff] [blame] | 326 | done_testing; |
| 327 | __END__ |