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