blob: 4ab9937bec0ac35f51ccbab76d70e92b97b6c569 [file] [log] [blame]
Akron1924bbe2016-06-22 16:05:41 +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/REI/BNG/00128');
20
21ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
22ok($doc->parse, 'Parse document');
23
24is($doc->text_sigle, 'REI/BNG/00128', 'Correct text sigle');
25is($doc->doc_sigle, 'REI/BNG', 'Correct document sigle');
26is($doc->corpus_sigle, 'REI', 'Correct corpus sigle');
27
28my $meta = $doc->meta;
29is($meta->{title}, 'Friedensgutachten der führenden Friedensforschungsinstitute', 'Title');
30is($meta->{sub_title}, 'Rede im Deutschen Bundestag am 14.06.2002', 'SubTitle');
31is($meta->{author}, 'Nachtwei, Winfried', 'Author');
32ok(!$meta->{editor}, 'Editor');
33is($meta->{pub_place}, 'Berlin', 'PubPlace');
34ok(!$meta->{publisher}, 'Publisher');
35
36ok(!$meta->{text_type}, 'No Text Type');
37ok(!$meta->{text_type_art}, 'No Text Type Art');
38ok(!$meta->{text_type_ref}, 'No Text Type Ref');
39ok(!$meta->{text_domain}, 'No Text Domain');
40ok(!$meta->{text_column}, 'No Text Column');
41
42is($meta->{text_class}->[0], 'politik', 'Correct Text Class');
43is($meta->{text_class}->[1], 'inland', 'Correct Text Class');
44ok(!$meta->{text_class}->[2], 'Correct Text Class');
45
46is($meta->{pub_date}, '20020614', 'Creation date');
47is($meta->{creation_date}, '20020614', 'Creation date');
48is($meta->{availability}, 'CC-BY-SA', 'License');
49ok(!$meta->{pages}, 'Pages');
50
51ok(!$meta->{file_edition_statement}, 'File Statement');
52ok(!$meta->{bibl_edition_statement}, 'Bibl Statement');
53
54is($meta->{reference} . "\n", <<'REF', 'Reference');
55Nachtwei, Winfried: Friedensgutachten der führenden Friedensforschungsinstitute. Rede im Deutschen Bundestag am 14.06.2002, Hrsg: Bundestagsfraktion Bündnis 90/DIE GRÜNEN [Ausführliche Zitierung nicht verfügbar]
56REF
57is($meta->{language}, 'de', 'Language');
58
59is($meta->{corpus_title}, 'Reden und Interviews', 'Correct Corpus title');
60ok(!$meta->{corpus_sub_title}, 'Correct Corpus sub title');
61ok(!$meta->{corpus_author}, 'Correct Corpus author');
62ok(!$meta->{corpus_editor}, 'Correct Corpus editor');
63
64is($meta->{doc_title}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Correct Doc title');
65ok(!$meta->{doc_sub_title}, 'Correct Doc sub title');
66ok(!$meta->{doc_author}, 'Correct Doc author');
67ok(!$meta->{doc_editor}, 'Correct doc editor');
68
69# Tokenization
70use_ok('KorAP::XML::Tokenizer');
71
72my ($token_base_foundry, $token_base_layer) = (qw/Base tokens_conservative/);
73
74# Get tokenization
75my $tokens = KorAP::XML::Tokenizer->new(
76 path => $doc->path,
77 doc => $doc,
78 foundry => $token_base_foundry,
79 layer => $token_base_layer,
80 name => 'tokens'
81);
82
83ok($tokens, 'Token Object is fine');
84ok($tokens->parse, 'Token parsing is fine');
85
86my $output = decode_json( $tokens->to_json );
87
88is(substr($output->{data}->{text}, 0, 100), 'Winfried Nachtwei, Friedensgutachten der führenden Friedensforschungsinstitute 14. Juni 2002 Vizeprä', 'Primary Data');
89
90is($output->{data}->{name}, 'tokens', 'tokenName');
91is($output->{data}->{tokenSource}, 'base#tokens_conservative', 'tokenSource');
92is($output->{version}, '0.03', 'version');
93
94is($output->{data}->{foundries}, '', 'Foundries');
95is($output->{data}->{layerInfos}, '', 'layerInfos');
96is($output->{data}->{stream}->[0]->[4], 's:Winfried', 'data');
97
98is($output->{textSigle}, 'REI/BNG/00128', 'Correct text sigle');
99is($output->{docSigle}, 'REI/BNG', 'Correct document sigle');
100is($output->{corpusSigle}, 'REI', 'Correct corpus sigle');
101
102is($output->{title}, 'Friedensgutachten der führenden Friedensforschungsinstitute', 'Title');
103is($output->{subTitle}, 'Rede im Deutschen Bundestag am 14.06.2002', 'Correct SubTitle');
104is($output->{author}, 'Nachtwei, Winfried', 'Author');
105ok(!exists $output->{editor}, 'Publisher');
106
107is($output->{pubPlace}, 'Berlin', 'PubPlace');
108ok(!exists $output->{publisher}, 'Publisher');
109
110ok(!exists $output->{textType}, 'Correct Text Type');
111ok(!exists $output->{textTypeArt}, 'Correct Text Type Art');
112ok(!exists $output->{textTypeRef}, 'Correct Text Type Ref');
113ok(!exists $output->{textDomain}, 'Correct Text Domain');
114
115is($output->{creationDate}, '20020614', 'Creation date');
116is($output->{availability}, 'CC-BY-SA', 'License');
117
118ok(!exists $output->{pages}, 'Pages');
119ok(!exists $output->{fileEditionStatement}, 'File Statement');
120ok(!exists $output->{biblEditionStatement}, 'Bibl Statement');
121
122is($output->{reference} . "\n", <<'REF', 'Reference');
123Nachtwei, Winfried: Friedensgutachten der führenden Friedensforschungsinstitute. Rede im Deutschen Bundestag am 14.06.2002, Hrsg: Bundestagsfraktion Bündnis 90/DIE GRÜNEN [Ausführliche Zitierung nicht verfügbar]
124REF
125is($output->{language}, 'de', 'Language');
126
127is($output->{corpusTitle}, 'Reden und Interviews', 'Correct Corpus title');
128ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title');
129ok(!exists $output->{corpusAuthor}, 'Correct Corpus author');
130ok(!exists $output->{corpusEditor}, 'Correct Corpus editor');
131
132is($output->{docTitle}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Correct Doc title');
133ok(!exists $output->{docSubTitle}, 'Correct Doc sub title');
134ok(!exists $output->{docAuthor}, 'Correct Doc author');
135ok(!exists $output->{docEditor}, 'Correct doc editor');
136
137## Base
138$tokens->add('Base', 'Sentences');
139$tokens->add('Base', 'Paragraphs');
140
141$output = decode_json( $tokens->to_json );
142
143is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
144is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
145my $first_token = join('||', @{$output->{data}->{stream}->[0]});
146like($first_token, qr/s:Winfried/, 'data');
147like($first_token, qr/_0\$<i>0<i>8/, 'data');
148
149
150done_testing;
151__END__