blob: 4a28c2f5883356a5fc7689b6057cf21388c86878 [file] [log] [blame]
Akron7d5e6382019-08-08 16:36:27 +02001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
6
7use Benchmark qw/:hireswallclock/;
8
9my $t = Benchmark->new;
10
11use utf8;
12use lib 'lib', '../lib';
13
14use File::Basename 'dirname';
15use File::Spec::Functions 'catdir';
16
17use_ok('KorAP::XML::Krill');
18
19my $path = catdir(dirname(__FILE__), '../corpus/WPF19/P00/0042242');
20
21ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
22ok($doc->parse, 'Parse document');
23
24is($doc->text_sigle, 'WPF19/P00/0042242', 'Correct text sigle');
25is($doc->doc_sigle, 'WPF19/P00', 'Correct document sigle');
26is($doc->corpus_sigle, 'WPF19', 'Correct corpus sigle');
27
28my $meta = $doc->meta;
29
30is($meta->{T_title}, 'Psychanalyse', 'Title');
31is($meta->{S_pub_place}, 'URL:http://fr.wikipedia.org', 'PubPlace');
32is($meta->{D_pub_date}, '20190220', 'Creation Date');
33is($meta->{S_text_type}, 'Enzyklopädie', 'Text type');
34is($meta->{T_author}, 'Pierrette13, u.a.', 'Author');
35is($meta->{S_language}, 'fr', 'Author');
36
37is($meta->{T_doc_title}, 'Wikipedia, Artikel mit Anfangsbuchstabe P, Teil 00', 'Correct Doc title');
38ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title');
39ok(!$meta->{T_doc_author}, 'Correct Doc author');
40ok(!$meta->{A_doc_editor}, 'Correct Doc editor');
41
42is($meta->{T_corpus_title}, 'Wikipedia', 'Correct Corpus title');
43ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title');
44
45# This link is broken, but that's due to the data
46is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http://fr.wikipedia.org/wiki/Psychanalyse', 'No link');
47
48# Tokenization
49use_ok('KorAP::XML::Tokenizer');
50
51my ($token_base_foundry, $token_base_layer) = (qw/Base Tokens/);
52
53# Get tokenization
54my $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);
61ok($tokens, 'Token Object is fine');
62ok($tokens->parse, 'Token parsing is fine');
63
64my $output = $tokens->to_data;
65
66is(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');
67is($output->{data}->{name}, 'tokens', 'tokenName');
68is($output->{data}->{tokenSource}, 'base#tokens', 'tokenSource');
69
70is($output->{version}, '0.03', 'version');
71is($output->{data}->{foundries}, '', 'Foundries');
72is($output->{data}->{layerInfos}, '', 'layerInfos');
73is($output->{data}->{stream}->[0]->[4], 's:Fichier', 'data');
74
75$tokens->add('Malt', 'Dependency');
76
77my $stream = $tokens->to_data->{data}->{stream};
78
79# This is not a goot relation example
80is($stream->[77]->[0],
81 '>:malt/d:nsubj$<b>32<i>78',
82 'element to term');
83is($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
90is($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};
96is($stream->[1]->[0], '>:talismane/d:mod$<b>32<i>0', 'Talismane dependency annotation');
97is($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};
104is($stream->[1]->[10], 'talismane/l:Sigmund', 'Talismane morpho annotation');
105is($stream->[1]->[11], 'talismane/m:g:m', 'Talismane morpho annotation');
106is($stream->[1]->[12], 'talismane/m:n:s', 'Talismane morpho annotation');
107is($stream->[1]->[13], 'talismane/p:NPP', 'Talismane morpho annotation');
108
109is($stream->[300]->[5], 'talismane/l:son', 'Talismane lemma annotation');
110is($stream->[300]->[6], 'talismane/m:g:m', 'Talismane morph annotation');
111is($stream->[300]->[7], 'talismane/m:n:s', 'Talismane morph annotation');
112is($stream->[300]->[8], 'talismane/m:p:3', 'Talismane morph annotation');
113is($stream->[300]->[9], 'talismane/m:poss:s', 'Talismane morph annotation');
114is($stream->[300]->[10], 'talismane/p:DET', 'Talismane pos annotation');
115
116# Add Malt dependency
117$tokens->add('Malt', 'Dependency');
118$stream = $tokens->to_data->{data}->{stream};
119is($stream->[1]->[1], '>:malt/d:dep$<b>33<i>7<i>8<i>0<i>1', 'Malt dep annotation');
120is($stream->[1]->[2], '<:malt/d:dep$<b>32<i>2', 'Malt dep annotation');
121is($stream->[300]->[1], '>:malt/d:punct$<b>32<i>302', 'Malt dep annotation');
122
123
124# Add TreeTagger morpho
125$tokens->add('TreeTagger', 'Morpho');
126$stream = $tokens->to_data->{data}->{stream};
127is($stream->[1]->[14], 'tt/p:ADJ$<b>129<b>26', 'TreeTagger morph annotation');
128is($stream->[1]->[15], 'tt/p:NAM$<b>129<b>200', 'TreeTagger morph annotation');
129is($stream->[1]->[16], 'tt/p:NOM$<b>129<b>27', 'TreeTagger morph annotation');
130
131
132done_testing;
133__END__
134
135
136
137