blob: 08be909633f3a5f66a7591d3f347ed9ce0eb5fcc [file] [log] [blame]
Akron4e1712c2019-02-04 22:29:37 +01001use 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
Akron4e1712c2019-02-04 22:29:37 +010011use Benchmark qw/:hireswallclock/;
12
13my $t = Benchmark->new;
14
15use utf8;
16
17use File::Basename 'dirname';
18use File::Spec::Functions 'catdir';
19
20use_ok('KorAP::XML::Krill');
21
Akron414ec952020-08-03 15:48:43 +020022my $path = catdir(dirname(__FILE__), 'corpus','WPE15','G00','11973');
Akron4e1712c2019-02-04 22:29:37 +010023
24ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
25ok($doc->parse, 'Parse document');
26
27is($doc->text_sigle, 'WPE15/G00/11973', 'Correct text sigle');
28is($doc->doc_sigle, 'WPE15/G00', 'Correct document sigle');
29is($doc->corpus_sigle, 'WPE15', 'Correct corpus sigle');
30
31my $meta = $doc->meta;
32is($meta->{T_title}, 'Generation X', 'Title');
33is($meta->{S_pub_place}, 'URL:http://en.wikipedia.org', 'PubPlace');
34is($meta->{D_pub_date}, '20150808', 'Creation Date');
35ok(!$meta->{T_sub_title}, 'Title');
36is($meta->{T_author}, 'Bnosnhoj, u.a.', 'Author');
37is($meta->{T_doc_title}, 'Wikipedia, Artikel mit Anfangsbuchstabe G, Teil 00', 'Correct Doc title');
38
39is($meta->{A_reference}, 'Generation X, In: Wikipedia - URL:http://en.wikipedia.org/wiki/Generation_X: Wikipedia, 2015', 'Reference');
40
Akron8ad06c42022-01-11 17:07:49 +010041is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FGeneration_X', 'link');
Akron6bf3cc92019-02-07 12:11:20 +010042
Akron4e1712c2019-02-04 22:29:37 +010043is($meta->{'S_availability'}, 'CC-BY-SA', 'Availability');
44is($meta->{'S_language'}, 'en', 'Language');
45
46# Tokenization
47use_ok('KorAP::XML::Tokenizer');
48
49my ($token_base_foundry, $token_base_layer) = (qw/Base Tokens/);
50
51# Get tokenization
52my $tokens = KorAP::XML::Tokenizer->new(
53 path => $doc->path,
54 doc => $doc,
55 foundry => $token_base_foundry,
56 layer => $token_base_layer,
57 name => 'tokens'
58);
59ok($tokens, 'Token Object is fine');
60ok($tokens->parse, 'Token parsing is fine');
61
62my $output = $tokens->to_data;
63
64is(substr($output->{data}->{text}, 0, 100), ' Generation X, commonly abbreviated to Gen X, is the generation born after the Western Post–', 'Primary Data');
65is($output->{data}->{name}, 'tokens', 'tokenName');
66is($output->{data}->{tokenSource}, 'base#tokens', 'tokenSource');
67
68is($output->{version}, '0.03', 'version');
69is($output->{data}->{foundries}, '', 'Foundries');
70is($output->{data}->{layerInfos}, '', 'layerInfos');
71is($output->{data}->{stream}->[0]->[4], 's:Generation', 'data');
72is($output->{data}->{stream}->[3]->[2], 's:abbreviated', 'data');
73
74$tokens->add('Malt', 'Dependency');
75
76my $stream = $tokens->to_data->{data}->{stream};
77
78# This is not a goot relation example
79is($stream->[77]->[0],
80 '>:malt/d:pobj$<b>32<i>75',
81 'Relation');
82is($stream->[100]->[0], '>:malt/d:dep$<b>32<i>101', 'relation');
83
84$tokens->add('DeReKo', 'Structure', 'base-sentences-paragraphs-pagebreaks');
85
86$stream = $tokens->to_data->{data}->{stream};
87
88is($stream->[0]->[8], '<>:base/s:s$<b>64<i>8<i>123<i>19<b>2', 'Text starts with sentence');
89
90$tokens->add('TreeTagger', 'Morpho');
91
92$stream = $tokens->to_data->{data}->{stream};
93
94is($stream->[20]->[4], 'tt/l:historian', 'Treetagger');
95is($stream->[20]->[5], 'tt/p:NNS', 'Treetagger');
96
Akron6bf3cc92019-02-07 12:11:20 +010097
98my $koral = decode_json($tokens->to_json(0.4));
99
Akron0d68a4b2019-11-13 15:42:11 +0100100my $link = $koral->{fields}->[6];
101
Akron6bf3cc92019-02-07 12:11:20 +0100102is($link->{'@type'}, 'koral:field', 'attachement');
103is($link->{type}, 'type:attachement', 'attachement');
104is($link->{key}, 'externalLink', 'attachement');
Akron8ad06c42022-01-11 17:07:49 +0100105is($link->{value}, 'data:application/x.korap-link;title=Wikipedia,http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FGeneration_X', 'attachement');
Akron6bf3cc92019-02-07 12:11:20 +0100106
Akron4e1712c2019-02-04 22:29:37 +0100107done_testing;
108__END__