blob: 9ed0237daea4456d5b854ec950247c997636e425 [file] [log] [blame]
Akrond3a0bad2016-02-26 14:07:58 +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;
12use lib 'lib', '../lib';
13
14use File::Basename 'dirname';
15use File::Spec::Functions 'catdir';
16
17use_ok('KorAP::XML::Krill');
18
Akrond3a0bad2016-02-26 14:07:58 +010019my $path = catdir(dirname(__FILE__), '../corpus/WPD/00001');
Akrond3a0bad2016-02-26 14:07:58 +010020
21ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
22ok($doc->parse, 'Parse document');
23
Akron1cd5b872016-03-22 00:23:46 +010024is($doc->text_sigle, 'WPD/AAA/00001', 'Correct text sigle');
25is($doc->doc_sigle, 'WPD/AAA', 'Correct document sigle');
Akrond3a0bad2016-02-26 14:07:58 +010026is($doc->corpus_sigle, 'WPD', 'Correct corpus sigle');
27
Akron35db6e32016-03-17 22:42:22 +010028my $meta = $doc->meta;
29is($meta->{title}, 'A', 'Title');
30is($meta->{pub_place}, 'URL:http://de.wikipedia.org', 'PubPlace');
31is($meta->{pub_date}, '20050328', 'Creation Date');
32ok(!$meta->{sub_title}, 'SubTitle');
33is($meta->{author}, 'Ruru; Jens.Ol; Aglarech; u.a.', 'Author');
Akrond3a0bad2016-02-26 14:07:58 +010034
Akron35db6e32016-03-17 22:42:22 +010035ok(!$meta->{doc_title}, 'Correct Doc title');
36ok(!$meta->{doc_sub_title}, 'Correct Doc Sub title');
37ok(!$meta->{doc_author}, 'Correct Doc author');
38ok(!$meta->{doc_editor}, 'Correct Doc editor');
Akrond3a0bad2016-02-26 14:07:58 +010039
Akron35db6e32016-03-17 22:42:22 +010040ok(!$meta->{corpus_title}, 'Correct Corpus title');
41ok(!$meta->{corpus_sub_title}, 'Correct Corpus Sub title');
Akrond3a0bad2016-02-26 14:07:58 +010042
43# Tokenization
44use_ok('KorAP::XML::Tokenizer');
45
46my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
47
48# Get tokenization
49my $tokens = KorAP::XML::Tokenizer->new(
50 path => $doc->path,
51 doc => $doc,
52 foundry => $token_base_foundry,
53 layer => $token_base_layer,
54 name => 'tokens'
55);
56ok($tokens, 'Token Object is fine');
57ok($tokens->parse, 'Token parsing is fine');
58
59my $output = $tokens->to_data;
60
61is(substr($output->{data}->{text}, 0, 100), 'A bzw. a ist der erste Buchstabe des lateinischen Alphabets und ein Vokal. Der Buchstabe A hat in de', 'Primary Data');
62is($output->{data}->{name}, 'tokens', 'tokenName');
63is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
64
65is($output->{version}, '0.03', 'version');
66is($output->{data}->{foundries}, '', 'Foundries');
67is($output->{data}->{layerInfos}, '', 'layerInfos');
68is($output->{data}->{stream}->[0]->[4], 's:A', 'data');
69
70$tokens->add('Mate', 'Dependency');
71
72my $stream = $tokens->to_data->{data}->{stream};
73
Akron75ba57d2016-03-07 23:36:27 +010074# This is not a goot relation example
75is($stream->[77]->[0],
76 '<:mate/d:--$<b>34<i>498<i>499<i>78<i>78',
77 'element to term');
Akron75ba57d2016-03-07 23:36:27 +010078is($stream->[78]->[0], '>:mate/d:--$<b>33<i>498<i>499<i>77<i>78', 'term to element');
Akrond3a0bad2016-02-26 14:07:58 +010079
Akronaf0ae3f2016-07-14 16:21:50 +020080$tokens->add('Base', 'Sentences');
81
82$stream = $tokens->to_data->{data}->{stream};
83
84is($stream->[0]->[2], '<>:base/s:s$<b>64<i>0<i>74<i>13<b>2', 'Text starts with sentence');
Akrond3a0bad2016-02-26 14:07:58 +010085
Akron6f9fef52016-11-03 17:06:40 +010086
87# Problematic document
88$path = catdir(dirname(__FILE__), '../corpus/WPD15/W28/65631');
89ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
90ok($doc->parse, 'Parse document');
91
92is($doc->text_sigle, 'WPD15/W28/65631', 'Correct text sigle');
93is($doc->doc_sigle, 'WPD15/W28', 'Correct document sigle');
94is($doc->corpus_sigle, 'WPD15', 'Correct corpus sigle');
95
96# Get tokenization
97$tokens = KorAP::XML::Tokenizer->new(
98 path => $doc->path,
99 doc => $doc,
100 foundry => 'Base',
101 layer => 'tokens_aggr',
102 name => 'tokens'
103);
104ok($tokens, 'Token Object is fine');
105ok($tokens->parse, 'Token parsing is fine');
106
107is($tokens->foundry, 'Base', 'Foundry');
108is($tokens->layer, 'tokens_aggr', 'Layer');
109
110
111# Initialize log4perl object
112Log::Log4perl->init({
113 'log4perl.rootLogger' => 'DEBUG, STDERR',
114 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
115 'log4perl.appender.STDERR.layout' => 'PatternLayout',
116 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
117});
118
119ok($tokens->add('CoreNLP', 'Constituency'), 'Add Structure');
120
121$output = $tokens->to_data;
122
123is($output->{data}->{foundries}, 'corenlp corenlp/constituency', 'Foundries');
124is($output->{data}->{layerInfos}, 'corenlp/c=spans', 'layerInfos');
125
Akrond3a0bad2016-02-26 14:07:58 +0100126done_testing;
127__END__
128
129
130
131