Marc Kupietz | 400590b | 2022-12-23 16:02:36 +0100 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use Data::Dumper; |
| 5 | use JSON::XS; |
| 6 | |
| 7 | if ($ENV{SKIP_REAL}) { |
| 8 | plan skip_all => 'Skip real tests'; |
| 9 | }; |
| 10 | |
| 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 | |
| 23 | my $path = catdir(dirname(__FILE__), 'corpus','ICCGER','DeReKo-WPD17','A00-82293'); |
| 24 | |
| 25 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 26 | ok($doc->parse, 'Parse document'); |
| 27 | |
| 28 | is($doc->text_sigle, 'ICCGER/DeReKo-WPD17/A00-82293', 'Correct text sigle'); |
| 29 | is($doc->doc_sigle, 'ICCGER/DeReKo-WPD17', 'Correct document sigle'); |
| 30 | is($doc->corpus_sigle, 'ICCGER', 'Correct corpus sigle'); |
| 31 | |
| 32 | my $meta = $doc->meta; |
| 33 | |
| 34 | is($meta->{T_title}, 'WPD17/A00.82293 Abbildungsfehler, In: Wikipedia - URL:http://de.wikipedia.org/wiki/Abbildungsfehler: Wikipedia, 2017 [Extract]', 'Title'); |
| 35 | is($meta->{S_pub_place}, undef, 'PubPlace'); |
| 36 | is($meta->{D_pub_date}, undef, 'Creation Date'); |
| 37 | is($meta->{S_text_type}, undef, 'Text type'); |
| 38 | is($meta->{T_author}, undef, 'Author'); |
| 39 | is($meta->{S_language}, undef, 'Language'); |
| 40 | is($meta->{T_doc_title}, undef, 'Correct Doc title'); |
| 41 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title'); |
| 42 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
| 43 | ok(!$meta->{A_doc_editor}, 'Correct Doc editor'); |
| 44 | |
| 45 | # Tokenization |
| 46 | use_ok('KorAP::XML::Tokenizer'); |
| 47 | |
| 48 | my ($token_base_foundry, $token_base_layer) = (qw/Base tokens/); |
| 49 | |
| 50 | # Get tokenization |
| 51 | my $tokens = KorAP::XML::Tokenizer->new( |
| 52 | path => $doc->path, |
| 53 | doc => $doc, |
| 54 | foundry => $token_base_foundry, |
| 55 | layer => $token_base_layer, |
| 56 | name => 'tokens' |
| 57 | ); |
| 58 | |
| 59 | ok($tokens, 'Token Object is fine'); |
| 60 | ok($tokens->parse, 'Token parsing is fine'); |
| 61 | |
| 62 | my $output = decode_json( $tokens->to_json ); |
| 63 | |
| 64 | is(substr($output->{data}->{text}, 0, 100), 'Es ist aber möglich, die Abbildungsfehler gegenüber einem einfachen System aus einer einzelnen Linse', 'Primary Data'); |
| 65 | |
| 66 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 67 | is($output->{data}->{tokenSource}, 'base#tokens', 'tokenSource'); |
| 68 | is($output->{version}, '0.03', 'version'); |
| 69 | |
| 70 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 71 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
| 72 | is($output->{data}->{stream}->[0]->[4], 's:Es', 'data'); |
| 73 | |
| 74 | is($output->{textSigle}, 'ICCGER/DeReKo-WPD17/A00-82293', 'Correct text sigle'); |
| 75 | is($output->{docSigle}, 'ICCGER/DeReKo-WPD17', 'Correct document sigle'); |
| 76 | is($output->{corpusSigle}, 'ICCGER', 'Correct corpus sigle'); |
| 77 | |
| 78 | is($output->{title}, 'WPD17/A00.82293 Abbildungsfehler, In: Wikipedia - URL:http://de.wikipedia.org/wiki/Abbildungsfehler: Wikipedia, 2017 [Extract]', 'Title'); |
| 79 | ok(!exists $output->{subTitle}, 'Correct SubTitle'); |
| 80 | ok(!exists $output->{author}, 'Author'); |
| 81 | ok(!exists $output->{editor}, 'Publisher'); |
| 82 | |
| 83 | ok(!exists $output->{pubPlace}, 'PubPlace'); |
| 84 | ok(!exists $output->{publisher}, 'Publisher'); |
| 85 | |
| 86 | ok(!exists $output->{textType}, 'Correct Text Type'); |
| 87 | ok(!exists $output->{textTypeArt}, 'Correct Text Type Art'); |
| 88 | ok(!exists $output->{textTypeRef}, 'Correct Text Type Ref'); |
| 89 | ok(!exists $output->{textDomain}, 'Correct Text Domain'); |
| 90 | |
| 91 | ok(!exists $output->{creationDate}, 'Creation date'); |
| 92 | ok(!exists $output->{availability}, 'License'); |
| 93 | |
| 94 | ok(!exists $output->{pages}, 'Pages'); |
| 95 | ok(!exists $output->{fileEditionStatement}, 'File Statement'); |
| 96 | ok(!exists $output->{biblEditionStatement}, 'Bibl Statement'); |
| 97 | |
| 98 | ok(!exists $output->{reference}, 'Reference'); |
| 99 | ok(!exists $output->{language}, 'Language'); |
| 100 | |
| 101 | ok(!exists $output->{corpusTitle}, 'Correct Corpus title'); |
| 102 | ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title'); |
| 103 | ok(!exists $output->{corpusAuthor}, 'Correct Corpus author'); |
| 104 | ok(!exists $output->{corpusEditor}, 'Correct Corpus editor'); |
| 105 | |
| 106 | ok(!exists $output->{docTitle}, 'Correct Doc title'); |
| 107 | ok(!exists $output->{docSubTitle}, 'Correct Doc sub title'); |
| 108 | ok(!exists $output->{docAuthor}, 'Correct Doc author'); |
| 109 | ok(!exists $output->{docEditor}, 'Correct doc editor'); |
| 110 | |
| 111 | ## Base |
| 112 | $tokens->add('DeReKo', 'Structure'); |
| 113 | |
| 114 | $output = decode_json( $tokens->to_json ); |
| 115 | |
| 116 | is($output->{data}->{foundries}, 'dereko dereko/structure', 'Foundries'); |
| 117 | is($output->{data}->{layerInfos}, 'dereko/s=spans', 'layerInfos'); |
| 118 | my $first_token = join('||', @{$output->{data}->{stream}->[0]}); |
| 119 | like($first_token, qr/<>:dereko\/s:s\$<b>64<i>0<i>145<i>21<b>4/, 'data'); |
| 120 | like($first_token, qr/s:Es/, 'data'); |
| 121 | |
| 122 | # Add annotations |
| 123 | $tokens->add('UDPipe', 'Dependency'); |
| 124 | $tokens->add('UDPipe', 'Morpho'); |
| 125 | |
| 126 | $output = decode_json( $tokens->to_json ); |
| 127 | |
| 128 | my $first = $output->{data}->{stream}->[0]; |
| 129 | |
| 130 | is('-:tokens$<i>1878', $first->[0]); |
| 131 | is('<:ud/d:root$<b>34<i>0<i>145<i>21<i>3', $first->[1]); |
| 132 | is('<>:dereko/s:s$<b>64<i>0<i>145<i>21<b>4', $first->[2]); |
| 133 | is('<>:dereko/s:p$<b>64<i>0<i>484<i>61<b>3', $first->[3]); |
| 134 | is('<>:dereko/s:div$<b>64<i>0<i>782<i>96<b>2<s>1', $first->[4]); |
| 135 | is('<>:base/s:t$<b>64<i>0<i>15402<i>1878<b>0', $first->[5]); |
| 136 | is('<>:dereko/s:text$<b>64<i>0<i>15402<i>1878<b>0', $first->[6]); |
| 137 | is('<>:dereko/s:body$<b>64<i>0<i>15402<i>1878<b>1', $first->[7]); |
| 138 | is('>:ud/d:expl$<b>32<i>3', $first->[8]); |
| 139 | is('@:dereko/s:type:fix2$<b>17<s>1<i>96', $first->[9]); |
| 140 | is('_0$<i>0<i>2', $first->[10]); |
| 141 | is('i:es', $first->[11]); |
| 142 | is('s:Es', $first->[12]); |
| 143 | is('ud/l:Es', $first->[13]); |
| 144 | is('ud/m:case:nom', $first->[14]); |
| 145 | is('ud/m:gender:neut', $first->[15]); |
| 146 | is('ud/m:number:sing', $first->[16]); |
| 147 | is('ud/m:person:3', $first->[17]); |
| 148 | is('ud/m:prontype:prs', $first->[18]); |
| 149 | is('ud/p:PRON', $first->[19]); |
| 150 | ok(!$first->[20]); |
| 151 | |
| 152 | my $last = $output->{data}->{stream}->[-1]; |
| 153 | |
| 154 | is('>:ud/d:advmod$<b>32<i>1876', $last->[0]); |
| 155 | is('_1877$<i>15397<i>15401', $last->[1]); |
| 156 | is('i:auch', $last->[2]); |
| 157 | is('s:auch', $last->[3]); |
| 158 | is('ud/l:auch', $last->[4]); |
| 159 | is('ud/p:ADV', $last->[5]); |
| 160 | ok(!$last->[6]); |
| 161 | |
| 162 | done_testing; |
| 163 | __END__ |