blob: e44e0ba7b0578d861f7c1f3a669d3fc10ee52131 [file] [log] [blame]
Akron7d5e6382019-08-08 16:36:27 +02001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
6
Akronfab17d32020-07-31 14:38:29 +02007if ($ENV{SKIP_REAL}) {
8 plan skip_all => 'Skip real tests';
9};
10
Akron7d5e6382019-08-08 16:36:27 +020011use Benchmark qw/:hireswallclock/;
12
13my $t = Benchmark->new;
14
15use utf8;
16use lib 'lib', '../lib';
17
18use File::Basename 'dirname';
19use File::Spec::Functions 'catdir';
20
21use_ok('KorAP::XML::Krill');
22
Akron414ec952020-08-03 15:48:43 +020023my $path = catdir(dirname(__FILE__), 'corpus','WPF19','P00','0042242');
Akron7d5e6382019-08-08 16:36:27 +020024
25ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
26ok($doc->parse, 'Parse document');
27
28is($doc->text_sigle, 'WPF19/P00/0042242', 'Correct text sigle');
29is($doc->doc_sigle, 'WPF19/P00', 'Correct document sigle');
30is($doc->corpus_sigle, 'WPF19', 'Correct corpus sigle');
31
32my $meta = $doc->meta;
33
34is($meta->{T_title}, 'Psychanalyse', 'Title');
35is($meta->{S_pub_place}, 'URL:http://fr.wikipedia.org', 'PubPlace');
36is($meta->{D_pub_date}, '20190220', 'Creation Date');
37is($meta->{S_text_type}, 'Enzyklopädie', 'Text type');
38is($meta->{T_author}, 'Pierrette13, u.a.', 'Author');
39is($meta->{S_language}, 'fr', 'Author');
40
41is($meta->{T_doc_title}, 'Wikipedia, Artikel mit Anfangsbuchstabe P, Teil 00', 'Correct Doc title');
42ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title');
43ok(!$meta->{T_doc_author}, 'Correct Doc author');
44ok(!$meta->{A_doc_editor}, 'Correct Doc editor');
45
46is($meta->{T_corpus_title}, 'Wikipedia', 'Correct Corpus title');
47ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title');
48
49# This link is broken, but that's due to the data
50is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http://fr.wikipedia.org/wiki/Psychanalyse', 'No link');
51
52# Tokenization
53use_ok('KorAP::XML::Tokenizer');
54
55my ($token_base_foundry, $token_base_layer) = (qw/Base Tokens/);
56
57# Get tokenization
58my $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);
65ok($tokens, 'Token Object is fine');
66ok($tokens->parse, 'Token parsing is fine');
67
68my $output = $tokens->to_data;
69
70is(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');
71is($output->{data}->{name}, 'tokens', 'tokenName');
72is($output->{data}->{tokenSource}, 'base#tokens', 'tokenSource');
73
74is($output->{version}, '0.03', 'version');
75is($output->{data}->{foundries}, '', 'Foundries');
76is($output->{data}->{layerInfos}, '', 'layerInfos');
77is($output->{data}->{stream}->[0]->[4], 's:Fichier', 'data');
78
79$tokens->add('Malt', 'Dependency');
80
81my $stream = $tokens->to_data->{data}->{stream};
82
83# This is not a goot relation example
84is($stream->[77]->[0],
85 '>:malt/d:nsubj$<b>32<i>78',
86 'element to term');
87is($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
94is($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};
100is($stream->[1]->[0], '>:talismane/d:mod$<b>32<i>0', 'Talismane dependency annotation');
101is($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};
Akronb62d92a2020-03-01 16:32:00 +0100108
109is($stream->[1]->[9], 'talismane/l:Sigmund', 'Talismane morpho annotation');
110is($stream->[1]->[10], 'talismane/m:g:m', 'Talismane morpho annotation');
111is($stream->[1]->[11], 'talismane/m:n:s', 'Talismane morpho annotation');
112is($stream->[1]->[12], 'talismane/p:NPP', 'Talismane morpho annotation');
Akron7d5e6382019-08-08 16:36:27 +0200113
114is($stream->[300]->[5], 'talismane/l:son', 'Talismane lemma annotation');
115is($stream->[300]->[6], 'talismane/m:g:m', 'Talismane morph annotation');
116is($stream->[300]->[7], 'talismane/m:n:s', 'Talismane morph annotation');
117is($stream->[300]->[8], 'talismane/m:p:3', 'Talismane morph annotation');
118is($stream->[300]->[9], 'talismane/m:poss:s', 'Talismane morph annotation');
119is($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};
Akronb62d92a2020-03-01 16:32:00 +0100124
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
Akron7d5e6382019-08-08 16:36:27 +0200128is($stream->[1]->[2], '<:malt/d:dep$<b>32<i>2', 'Malt dep annotation');
129is($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};
Akronb62d92a2020-03-01 16:32:00 +0100135
136is($stream->[1]->[13], 'tt/p:ADJ$<b>129<b>26', 'TreeTagger morph annotation');
137is($stream->[1]->[14], 'tt/p:NAM$<b>129<b>200', 'TreeTagger morph annotation');
138is($stream->[1]->[15], 'tt/p:NOM$<b>129<b>27', 'TreeTagger morph annotation');
Akron7d5e6382019-08-08 16:36:27 +0200139
140
141done_testing;
142__END__
143
144
145
146