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