blob: db626f9f96aed0b6a6cc1aac8c39de89d5d8745d [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
37is($meta->{'S_availability'}, 'CC-BY-SA', 'Availability');
38is($meta->{'S_language'}, 'en', 'Language');
39
40# Tokenization
41use_ok('KorAP::XML::Tokenizer');
42
43my ($token_base_foundry, $token_base_layer) = (qw/Base Tokens/);
44
45# Get tokenization
46my $tokens = KorAP::XML::Tokenizer->new(
47 path => $doc->path,
48 doc => $doc,
49 foundry => $token_base_foundry,
50 layer => $token_base_layer,
51 name => 'tokens'
52);
53ok($tokens, 'Token Object is fine');
54ok($tokens->parse, 'Token parsing is fine');
55
56my $output = $tokens->to_data;
57
58is(substr($output->{data}->{text}, 0, 100), ' Generation X, commonly abbreviated to Gen X, is the generation born after the Western Post–', 'Primary Data');
59is($output->{data}->{name}, 'tokens', 'tokenName');
60is($output->{data}->{tokenSource}, 'base#tokens', 'tokenSource');
61
62is($output->{version}, '0.03', 'version');
63is($output->{data}->{foundries}, '', 'Foundries');
64is($output->{data}->{layerInfos}, '', 'layerInfos');
65is($output->{data}->{stream}->[0]->[4], 's:Generation', 'data');
66is($output->{data}->{stream}->[3]->[2], 's:abbreviated', 'data');
67
68$tokens->add('Malt', 'Dependency');
69
70my $stream = $tokens->to_data->{data}->{stream};
71
72# This is not a goot relation example
73is($stream->[77]->[0],
74 '>:malt/d:pobj$<b>32<i>75',
75 'Relation');
76is($stream->[100]->[0], '>:malt/d:dep$<b>32<i>101', 'relation');
77
78$tokens->add('DeReKo', 'Structure', 'base-sentences-paragraphs-pagebreaks');
79
80$stream = $tokens->to_data->{data}->{stream};
81
82is($stream->[0]->[8], '<>:base/s:s$<b>64<i>8<i>123<i>19<b>2', 'Text starts with sentence');
83
84$tokens->add('TreeTagger', 'Morpho');
85
86$stream = $tokens->to_data->{data}->{stream};
87
88is($stream->[20]->[4], 'tt/l:historian', 'Treetagger');
89is($stream->[20]->[5], 'tt/p:NNS', 'Treetagger');
90
91done_testing;
92__END__