Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [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 | 7d5e638 | 2019-08-08 16:36:27 +0200 | [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','WPF19','P00','0042242'); |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 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, 'WPF19/P00/0042242', 'Correct text sigle'); |
| 29 | is($doc->doc_sigle, 'WPF19/P00', 'Correct document sigle'); |
| 30 | is($doc->corpus_sigle, 'WPF19', 'Correct corpus sigle'); |
| 31 | |
| 32 | my $meta = $doc->meta; |
| 33 | |
| 34 | is($meta->{T_title}, 'Psychanalyse', 'Title'); |
| 35 | is($meta->{S_pub_place}, 'URL:http://fr.wikipedia.org', 'PubPlace'); |
| 36 | is($meta->{D_pub_date}, '20190220', 'Creation Date'); |
| 37 | is($meta->{S_text_type}, 'Enzyklopädie', 'Text type'); |
| 38 | is($meta->{T_author}, 'Pierrette13, u.a.', 'Author'); |
| 39 | is($meta->{S_language}, 'fr', 'Author'); |
| 40 | |
| 41 | is($meta->{T_doc_title}, 'Wikipedia, Artikel mit Anfangsbuchstabe P, Teil 00', 'Correct Doc title'); |
| 42 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title'); |
| 43 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
| 44 | ok(!$meta->{A_doc_editor}, 'Correct Doc editor'); |
| 45 | |
| 46 | is($meta->{T_corpus_title}, 'Wikipedia', 'Correct Corpus title'); |
| 47 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title'); |
| 48 | |
| 49 | # This link is broken, but that's due to the data |
Akron | 8ad06c4 | 2022-01-11 17:07:49 +0100 | [diff] [blame] | 50 | is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http%3A%2F%2Ffr.wikipedia.org%2Fwiki%2FPsychanalyse', 'No link'); |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 51 | |
| 52 | # Tokenization |
| 53 | use_ok('KorAP::XML::Tokenizer'); |
| 54 | |
| 55 | my ($token_base_foundry, $token_base_layer) = (qw/Base Tokens/); |
| 56 | |
| 57 | # Get tokenization |
| 58 | my $tokens = KorAP::XML::Tokenizer->new( |
| 59 | path => $doc->path, |
| 60 | doc => $doc, |
| 61 | foundry => $token_base_foundry, |
| 62 | layer => $token_base_layer, |
| 63 | name => 'tokens' |
| 64 | ); |
| 65 | ok($tokens, 'Token Object is fine'); |
| 66 | ok($tokens->parse, 'Token parsing is fine'); |
| 67 | |
| 68 | my $output = $tokens->to_data; |
| 69 | |
| 70 | is(substr($output->{data}->{text}, 0, 100), 'Fichier:Sigmund Freud LIFE.jpg La psychanalyse est, selon la définition classique qu\'en a donnée Sig', 'Primary Data'); |
| 71 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 72 | is($output->{data}->{tokenSource}, 'base#tokens', 'tokenSource'); |
| 73 | |
| 74 | is($output->{version}, '0.03', 'version'); |
| 75 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 76 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
| 77 | is($output->{data}->{stream}->[0]->[4], 's:Fichier', 'data'); |
| 78 | |
| 79 | $tokens->add('Malt', 'Dependency'); |
| 80 | |
| 81 | my $stream = $tokens->to_data->{data}->{stream}; |
| 82 | |
| 83 | # This is not a goot relation example |
| 84 | is($stream->[77]->[0], |
| 85 | '>:malt/d:nsubj$<b>32<i>78', |
| 86 | 'element to term'); |
| 87 | is($stream->[78]->[0], '>:malt/d:null$<b>32<i>76', 'term to element'); |
| 88 | |
| 89 | # Add structure |
| 90 | $tokens->add('DeReKo', 'Structure'); |
| 91 | |
| 92 | $stream = $tokens->to_data->{data}->{stream}; |
| 93 | |
| 94 | is($stream->[71]->[1], '<>:dereko/s:s$<b>64<i>530<i>856<i>124<b>4', 'Text starts with sentence'); |
| 95 | |
| 96 | # Add Talismane Dependency |
| 97 | $tokens->add('Talismane', 'Dependency'); |
| 98 | |
| 99 | $stream = $tokens->to_data->{data}->{stream}; |
| 100 | is($stream->[1]->[0], '>:talismane/d:mod$<b>32<i>0', 'Talismane dependency annotation'); |
| 101 | is($stream->[300]->[0], '>:talismane/d:det$<b>32<i>301', 'Talismane dep annotation'); |
| 102 | |
| 103 | |
| 104 | # Add Talismane Morpho |
| 105 | $tokens->add('Talismane', 'Morpho'); |
| 106 | |
| 107 | $stream = $tokens->to_data->{data}->{stream}; |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 108 | |
| 109 | is($stream->[1]->[9], 'talismane/l:Sigmund', 'Talismane morpho annotation'); |
| 110 | is($stream->[1]->[10], 'talismane/m:g:m', 'Talismane morpho annotation'); |
| 111 | is($stream->[1]->[11], 'talismane/m:n:s', 'Talismane morpho annotation'); |
| 112 | is($stream->[1]->[12], 'talismane/p:NPP', 'Talismane morpho annotation'); |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 113 | |
| 114 | is($stream->[300]->[5], 'talismane/l:son', 'Talismane lemma annotation'); |
| 115 | is($stream->[300]->[6], 'talismane/m:g:m', 'Talismane morph annotation'); |
| 116 | is($stream->[300]->[7], 'talismane/m:n:s', 'Talismane morph annotation'); |
| 117 | is($stream->[300]->[8], 'talismane/m:p:3', 'Talismane morph annotation'); |
| 118 | is($stream->[300]->[9], 'talismane/m:poss:s', 'Talismane morph annotation'); |
| 119 | is($stream->[300]->[10], 'talismane/p:DET', 'Talismane pos annotation'); |
| 120 | |
| 121 | # Add Malt dependency |
| 122 | $tokens->add('Malt', 'Dependency'); |
| 123 | $stream = $tokens->to_data->{data}->{stream}; |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 124 | |
| 125 | # This is no longer indexed |
| 126 | # is($stream->[1]->[1], '>:malt/d:dep$<b>33<i>7<i>8<i>0<i>1', 'Malt dep annotation'); |
| 127 | |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 128 | is($stream->[1]->[2], '<:malt/d:dep$<b>32<i>2', 'Malt dep annotation'); |
| 129 | is($stream->[300]->[1], '>:malt/d:punct$<b>32<i>302', 'Malt dep annotation'); |
| 130 | |
| 131 | |
| 132 | # Add TreeTagger morpho |
| 133 | $tokens->add('TreeTagger', 'Morpho'); |
| 134 | $stream = $tokens->to_data->{data}->{stream}; |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame] | 135 | |
| 136 | is($stream->[1]->[13], 'tt/p:ADJ$<b>129<b>26', 'TreeTagger morph annotation'); |
| 137 | is($stream->[1]->[14], 'tt/p:NAM$<b>129<b>200', 'TreeTagger morph annotation'); |
| 138 | is($stream->[1]->[15], 'tt/p:NOM$<b>129<b>27', 'TreeTagger morph annotation'); |
Akron | 7d5e638 | 2019-08-08 16:36:27 +0200 | [diff] [blame] | 139 | |
| 140 | |
| 141 | done_testing; |
| 142 | __END__ |
| 143 | |
| 144 | |
| 145 | |
| 146 | |