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