Akron | d3a0bad | 2016-02-26 14:07:58 +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 | |
| 17 | use_ok('KorAP::XML::Krill'); |
| 18 | |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 19 | my $path = catdir(dirname(__FILE__), '../corpus/WPD/00001'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 20 | |
| 21 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 22 | ok($doc->parse, 'Parse document'); |
| 23 | |
Akron | 1cd5b87 | 2016-03-22 00:23:46 +0100 | [diff] [blame] | 24 | is($doc->text_sigle, 'WPD/AAA/00001', 'Correct text sigle'); |
| 25 | is($doc->doc_sigle, 'WPD/AAA', 'Correct document sigle'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 26 | is($doc->corpus_sigle, 'WPD', 'Correct corpus sigle'); |
| 27 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 28 | my $meta = $doc->meta; |
| 29 | is($meta->{title}, 'A', 'Title'); |
| 30 | is($meta->{pub_place}, 'URL:http://de.wikipedia.org', 'PubPlace'); |
| 31 | is($meta->{pub_date}, '20050328', 'Creation Date'); |
| 32 | ok(!$meta->{sub_title}, 'SubTitle'); |
| 33 | is($meta->{author}, 'Ruru; Jens.Ol; Aglarech; u.a.', 'Author'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 34 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 35 | ok(!$meta->{doc_title}, 'Correct Doc title'); |
| 36 | ok(!$meta->{doc_sub_title}, 'Correct Doc Sub title'); |
| 37 | ok(!$meta->{doc_author}, 'Correct Doc author'); |
| 38 | ok(!$meta->{doc_editor}, 'Correct Doc editor'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 39 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 40 | ok(!$meta->{corpus_title}, 'Correct Corpus title'); |
| 41 | ok(!$meta->{corpus_sub_title}, 'Correct Corpus Sub title'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 42 | |
| 43 | # Tokenization |
| 44 | use_ok('KorAP::XML::Tokenizer'); |
| 45 | |
| 46 | my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/); |
| 47 | |
| 48 | # Get tokenization |
| 49 | my $tokens = KorAP::XML::Tokenizer->new( |
| 50 | path => $doc->path, |
| 51 | doc => $doc, |
| 52 | foundry => $token_base_foundry, |
| 53 | layer => $token_base_layer, |
| 54 | name => 'tokens' |
| 55 | ); |
| 56 | ok($tokens, 'Token Object is fine'); |
| 57 | ok($tokens->parse, 'Token parsing is fine'); |
| 58 | |
| 59 | my $output = $tokens->to_data; |
| 60 | |
| 61 | is(substr($output->{data}->{text}, 0, 100), 'A bzw. a ist der erste Buchstabe des lateinischen Alphabets und ein Vokal. Der Buchstabe A hat in de', 'Primary Data'); |
| 62 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 63 | is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource'); |
| 64 | |
| 65 | is($output->{version}, '0.03', 'version'); |
| 66 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 67 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
| 68 | is($output->{data}->{stream}->[0]->[4], 's:A', 'data'); |
| 69 | |
| 70 | $tokens->add('Mate', 'Dependency'); |
| 71 | |
| 72 | my $stream = $tokens->to_data->{data}->{stream}; |
| 73 | |
Akron | 75ba57d | 2016-03-07 23:36:27 +0100 | [diff] [blame] | 74 | # This is not a goot relation example |
| 75 | is($stream->[77]->[0], |
| 76 | '<:mate/d:--$<b>34<i>498<i>499<i>78<i>78', |
| 77 | 'element to term'); |
Akron | 75ba57d | 2016-03-07 23:36:27 +0100 | [diff] [blame] | 78 | is($stream->[78]->[0], '>:mate/d:--$<b>33<i>498<i>499<i>77<i>78', 'term to element'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 79 | |
Akron | af0ae3f | 2016-07-14 16:21:50 +0200 | [diff] [blame] | 80 | $tokens->add('Base', 'Sentences'); |
| 81 | |
| 82 | $stream = $tokens->to_data->{data}->{stream}; |
| 83 | |
| 84 | is($stream->[0]->[2], '<>:base/s:s$<b>64<i>0<i>74<i>13<b>2', 'Text starts with sentence'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 85 | |
Akron | 6f9fef5 | 2016-11-03 17:06:40 +0100 | [diff] [blame] | 86 | |
| 87 | # Problematic document |
| 88 | $path = catdir(dirname(__FILE__), '../corpus/WPD15/W28/65631'); |
| 89 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 90 | ok($doc->parse, 'Parse document'); |
| 91 | |
| 92 | is($doc->text_sigle, 'WPD15/W28/65631', 'Correct text sigle'); |
| 93 | is($doc->doc_sigle, 'WPD15/W28', 'Correct document sigle'); |
| 94 | is($doc->corpus_sigle, 'WPD15', 'Correct corpus sigle'); |
| 95 | |
| 96 | # Get tokenization |
| 97 | $tokens = KorAP::XML::Tokenizer->new( |
| 98 | path => $doc->path, |
| 99 | doc => $doc, |
| 100 | foundry => 'Base', |
| 101 | layer => 'tokens_aggr', |
| 102 | name => 'tokens' |
| 103 | ); |
| 104 | ok($tokens, 'Token Object is fine'); |
| 105 | ok($tokens->parse, 'Token parsing is fine'); |
| 106 | |
| 107 | is($tokens->foundry, 'Base', 'Foundry'); |
| 108 | is($tokens->layer, 'tokens_aggr', 'Layer'); |
| 109 | |
Akron | 6f9fef5 | 2016-11-03 17:06:40 +0100 | [diff] [blame] | 110 | ok($tokens->add('CoreNLP', 'Constituency'), 'Add Structure'); |
| 111 | |
| 112 | $output = $tokens->to_data; |
| 113 | |
| 114 | is($output->{data}->{foundries}, 'corenlp corenlp/constituency', 'Foundries'); |
| 115 | is($output->{data}->{layerInfos}, 'corenlp/c=spans', 'layerInfos'); |
| 116 | |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 117 | done_testing; |
| 118 | __END__ |
| 119 | |
| 120 | |
| 121 | |
| 122 | |