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; |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 29 | is($meta->{T_title}, 'A', 'Title'); |
| 30 | is($meta->{S_pub_place}, 'URL:http://de.wikipedia.org', 'PubPlace'); |
| 31 | is($meta->{D_pub_date}, '20050328', 'Creation Date'); |
Akron | 7e2eb88 | 2017-01-18 17:28:07 +0100 | [diff] [blame] | 32 | SKIP: { |
| 33 | skip 'Failure because corpus is no longer supported', 1; |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 34 | ok(!$meta->{T_sub_title}, 'SubTitle'); |
Akron | 7e2eb88 | 2017-01-18 17:28:07 +0100 | [diff] [blame] | 35 | }; |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 36 | is($meta->{T_author}, 'Ruru; Jens.Ol; Aglarech; u.a.', 'Author'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 37 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 38 | ok(!$meta->{T_doc_title}, 'Correct Doc title'); |
| 39 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title'); |
| 40 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
| 41 | ok(!$meta->{A_doc_editor}, 'Correct Doc editor'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 42 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 43 | ok(!$meta->{T_corpus_title}, 'Correct Corpus title'); |
| 44 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 45 | |
Akron | 6bf3cc9 | 2019-02-07 12:11:20 +0100 | [diff] [blame] | 46 | # This link is broken, but that's due to the data |
| 47 | is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http://de.wikipedia.org', 'No link'); |
| 48 | |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 49 | # Tokenization |
| 50 | use_ok('KorAP::XML::Tokenizer'); |
| 51 | |
| 52 | my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/); |
| 53 | |
| 54 | # Get tokenization |
| 55 | my $tokens = KorAP::XML::Tokenizer->new( |
| 56 | path => $doc->path, |
| 57 | doc => $doc, |
| 58 | foundry => $token_base_foundry, |
| 59 | layer => $token_base_layer, |
| 60 | name => 'tokens' |
| 61 | ); |
| 62 | ok($tokens, 'Token Object is fine'); |
| 63 | ok($tokens->parse, 'Token parsing is fine'); |
| 64 | |
| 65 | my $output = $tokens->to_data; |
| 66 | |
| 67 | 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'); |
| 68 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 69 | is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource'); |
| 70 | |
| 71 | is($output->{version}, '0.03', 'version'); |
| 72 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 73 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
| 74 | is($output->{data}->{stream}->[0]->[4], 's:A', 'data'); |
| 75 | |
| 76 | $tokens->add('Mate', 'Dependency'); |
| 77 | |
| 78 | my $stream = $tokens->to_data->{data}->{stream}; |
| 79 | |
Akron | 75ba57d | 2016-03-07 23:36:27 +0100 | [diff] [blame] | 80 | # This is not a goot relation example |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame^] | 81 | is($stream->[79]->[0], |
| 82 | '>:mate/d:CJ$<b>32<i>68', |
| 83 | 'term to term'); |
| 84 | is($stream->[79]->[1], '<:mate/d:PD$<b>32<i>81', 'term to term'); |
| 85 | |
| 86 | |
| 87 | # These are no longer aligned |
| 88 | # is($stream->[77]->[0], |
| 89 | # '<:mate/d:--$<b>34<i>498<i>499<i>78<i>78', |
| 90 | # 'element to term'); |
| 91 | # 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] | 92 | |
Akron | af0ae3f | 2016-07-14 16:21:50 +0200 | [diff] [blame] | 93 | $tokens->add('Base', 'Sentences'); |
| 94 | |
| 95 | $stream = $tokens->to_data->{data}->{stream}; |
| 96 | |
| 97 | 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] | 98 | |
Akron | 6f9fef5 | 2016-11-03 17:06:40 +0100 | [diff] [blame] | 99 | |
| 100 | # Problematic document |
| 101 | $path = catdir(dirname(__FILE__), '../corpus/WPD15/W28/65631'); |
| 102 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 103 | ok($doc->parse, 'Parse document'); |
| 104 | |
| 105 | is($doc->text_sigle, 'WPD15/W28/65631', 'Correct text sigle'); |
| 106 | is($doc->doc_sigle, 'WPD15/W28', 'Correct document sigle'); |
| 107 | is($doc->corpus_sigle, 'WPD15', 'Correct corpus sigle'); |
| 108 | |
Akron | 6bf3cc9 | 2019-02-07 12:11:20 +0100 | [diff] [blame] | 109 | $meta = $doc->meta; |
| 110 | is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http://de.wikipedia.org/wiki/Wolfgang_Krebs_(Schauspieler)', 'link'); |
| 111 | |
Akron | 6f9fef5 | 2016-11-03 17:06:40 +0100 | [diff] [blame] | 112 | # Get tokenization |
| 113 | $tokens = KorAP::XML::Tokenizer->new( |
| 114 | path => $doc->path, |
| 115 | doc => $doc, |
| 116 | foundry => 'Base', |
| 117 | layer => 'tokens_aggr', |
| 118 | name => 'tokens' |
| 119 | ); |
| 120 | ok($tokens, 'Token Object is fine'); |
| 121 | ok($tokens->parse, 'Token parsing is fine'); |
| 122 | |
| 123 | is($tokens->foundry, 'Base', 'Foundry'); |
| 124 | is($tokens->layer, 'tokens_aggr', 'Layer'); |
| 125 | |
Akron | 6f9fef5 | 2016-11-03 17:06:40 +0100 | [diff] [blame] | 126 | ok($tokens->add('CoreNLP', 'Constituency'), 'Add Structure'); |
| 127 | |
| 128 | $output = $tokens->to_data; |
| 129 | |
| 130 | is($output->{data}->{foundries}, 'corenlp corenlp/constituency', 'Foundries'); |
| 131 | is($output->{data}->{layerInfos}, 'corenlp/c=spans', 'layerInfos'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 132 | is($doc->meta->{A_editor}, 'wikipedia.org', 'Editor'); |
Akron | 6f9fef5 | 2016-11-03 17:06:40 +0100 | [diff] [blame] | 133 | |
Akron | 56dfb31 | 2017-11-23 18:37:35 +0100 | [diff] [blame] | 134 | |
| 135 | # Check offset problem |
| 136 | $path = catdir(dirname(__FILE__), '../corpus/WPD15/U43/34816'); |
| 137 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 138 | ok($doc->parse, 'Parse document'); |
| 139 | |
| 140 | is($doc->text_sigle, 'WPD15/U43/34816', 'Correct text sigle'); |
| 141 | |
Akron | 6bf3cc9 | 2019-02-07 12:11:20 +0100 | [diff] [blame] | 142 | $meta = $doc->meta; |
| 143 | is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http://de.wikipedia.org/wiki/Universitätsbibliothek_Augsburg', 'link'); |
| 144 | |
Akron | 56dfb31 | 2017-11-23 18:37:35 +0100 | [diff] [blame] | 145 | # Tokenization |
| 146 | use_ok('KorAP::XML::Tokenizer'); |
| 147 | |
| 148 | $token_base_foundry = 'Base'; |
| 149 | |
| 150 | # Get tokenization |
| 151 | $tokens = KorAP::XML::Tokenizer->new( |
| 152 | path => $doc->path, |
| 153 | doc => $doc, |
| 154 | foundry => $token_base_foundry, |
| 155 | layer => $token_base_layer, |
| 156 | name => 'tokens' |
| 157 | ); |
| 158 | ok($tokens, 'Token Object is fine'); |
| 159 | ok($tokens->parse, 'Token parsing is fine'); |
| 160 | |
| 161 | $output = $tokens->to_data; |
| 162 | $stream = $tokens->to_data->{data}->{stream}; |
| 163 | |
| 164 | is($stream->[420]->[-1], 's:online', 'online'); |
| 165 | is($stream->[421]->[-1], 's:verfügbar', 'verfügbar'); |
| 166 | |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 167 | done_testing; |
| 168 | __END__ |
| 169 | |
| 170 | |
| 171 | |
| 172 | |