blob: a59f6d44cc3b5fed960287b6b0a991bf6cf460b7 [file] [log] [blame]
Akron53167fd2016-12-21 15:01:01 +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
Akron53167fd2016-12-21 15:01:01 +010011use Benchmark qw/:hireswallclock/;
12
13my $t = Benchmark->new;
14
15use utf8;
16use lib 'lib', '../lib';
17
18use File::Basename 'dirname';
19use File::Spec::Functions 'catdir';
20
21use_ok('KorAP::XML::Krill');
22
23# This will Check Goethe-Files without base annotations!
24
25# GOE/AGA/03828
Akron414ec952020-08-03 15:48:43 +020026my $path = catdir(dirname(__FILE__), 'corpus','GOE2','AGA','03828');
Akron53167fd2016-12-21 15:01:01 +010027
28ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
29ok($doc->parse, 'Parse document');
30
31is($doc->text_sigle, 'GOE/AGA/03828', 'Correct text sigle');
32is($doc->doc_sigle, 'GOE/AGA', 'Correct document sigle');
33is($doc->corpus_sigle, 'GOE', 'Correct corpus sigle');
34
35my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010036is($meta->{T_title}, 'Autobiographische Einzelheiten', 'Title');
37is($meta->{S_pub_place}, 'München', 'PubPlace');
38is($meta->{D_pub_date}, '19820000', 'Creation Date');
39ok(!$meta->{T_sub_title}, 'SubTitle');
40is($meta->{T_author}, 'Goethe, Johann Wolfgang von', 'Author');
Akron53167fd2016-12-21 15:01:01 +010041
Akron5eb3aa02019-01-25 18:30:47 +010042is($meta->{A_publisher}, 'Verlag C. H. Beck', 'Publisher');
43ok(!$meta->{A_editor}, 'Publisher');
44is($meta->{S_text_type}, 'Autobiographie', 'Correct Text Type');
45ok(!$meta->{S_text_type_art}, 'Correct Text Type Art');
46ok(!$meta->{S_text_type_ref}, 'Correct Text Type Ref');
47ok(!$meta->{S_text_column}, 'Correct Text Column');
48ok(!$meta->{S_text_domain}, 'Correct Text Domain');
49is($meta->{D_creation_date}, '18200000', 'Creation Date');
50is($meta->{S_availability}, 'QAO-NC', 'License');
51is($meta->{A_src_pages}, '529-547', 'Pages');
52ok(!$meta->{A_file_edition_statement}, 'File Ed Statement');
53ok(!$meta->{A_bibl_edition_statement}, 'Bibl Ed Statement');
54is($meta->{A_reference} . "\n", <<'REF', 'Author');
Akron53167fd2016-12-21 15:01:01 +010055Goethe, Johann Wolfgang von: Autobiographische Einzelheiten, (Geschrieben bis 1832), In: Goethe, Johann Wolfgang von: Goethes Werke, Bd. 10, Autobiographische Schriften II, Hrsg.: Trunz, Erich. München: Verlag C. H. Beck, 1982, S. 529-547
56REF
Akron5eb3aa02019-01-25 18:30:47 +010057is($meta->{S_language}, 'de', 'Language');
Akron53167fd2016-12-21 15:01:01 +010058
59
Akron5eb3aa02019-01-25 18:30:47 +010060is($meta->{T_corpus_title}, 'Goethes Werke', 'Correct Corpus title');
61ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title');
62is($meta->{T_corpus_author}, 'Goethe, Johann Wolfgang von', 'Correct Corpus author');
63is($meta->{A_corpus_editor}, 'Trunz, Erich', 'Correct Corpus editor');
Akron53167fd2016-12-21 15:01:01 +010064
Akron5eb3aa02019-01-25 18:30:47 +010065is($meta->{T_doc_title}, 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)',
Akron53167fd2016-12-21 15:01:01 +010066 'Correct Doc title');
Akron5eb3aa02019-01-25 18:30:47 +010067ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title');
68ok(!$meta->{T_doc_author}, 'Correct Doc author');
69ok(!$meta->{A_doc_editor}, 'Correct Doc editor');
Akron53167fd2016-12-21 15:01:01 +010070
71# Tokenization
72use_ok('KorAP::XML::Tokenizer');
73
74my ($token_base_foundry, $token_base_layer) = (qw/Base Tokens_conservative/);
75
76# Get tokenization
77my $tokens = KorAP::XML::Tokenizer->new(
78 path => $doc->path,
79 doc => $doc,
80 foundry => $token_base_foundry,
81 layer => $token_base_layer,
82 name => 'tokens'
83);
84ok($tokens, 'Token Object is fine');
85ok($tokens->parse, 'Token parsing is fine');
86
87my $output = decode_json( $tokens->to_json );
88
89is(substr($output->{data}->{text}, 0, 100), 'Autobiographische einzelheiten Selbstschilderung (1) immer tätiger, nach innen und außen fortwirkend', 'Primary Data');
90is($output->{data}->{name}, 'tokens', 'tokenName');
91is($output->{data}->{tokenSource}, 'base#tokens_conservative', 'tokenSource');
92is($output->{version}, '0.03', 'version');
93is($output->{data}->{foundries}, '', 'Foundries');
94is($output->{data}->{layerInfos}, '', 'layerInfos');
95is($output->{data}->{stream}->[0]->[4], 's:Autobiographische', 'data');
96
97is($output->{textSigle}, 'GOE/AGA/03828', 'Correct text sigle');
98is($output->{docSigle}, 'GOE/AGA', 'Correct document sigle');
99is($output->{corpusSigle}, 'GOE', 'Correct corpus sigle');
100
101is($output->{author}, 'Goethe, Johann Wolfgang von', 'Author');
102is($output->{pubPlace}, 'München', 'PubPlace');
103is($output->{pubDate}, '19820000', 'Creation Date');
104is($output->{title}, 'Autobiographische Einzelheiten', 'Title');
105ok(!exists $output->{subTitle}, 'subTitle');
106
107is($output->{publisher}, 'Verlag C. H. Beck', 'Publisher');
108ok(!exists $output->{editor}, 'Editor');
109is($output->{textType}, 'Autobiographie', 'Correct Text Type');
110ok(!exists $output->{textTypeArt}, 'Correct Text Type');
111ok(!exists $output->{textTypeRef}, 'Correct Text Type');
112ok(!exists $output->{textColumn}, 'Correct Text Type');
113ok(!exists $output->{textDomain}, 'Correct Text Type');
114is($output->{creationDate}, '18200000', 'Creation Date');
115is($output->{availability}, 'QAO-NC', 'License');
Akron08d54452017-02-16 23:19:49 +0100116is($output->{srcPages}, '529-547', 'Pages');
Akron53167fd2016-12-21 15:01:01 +0100117ok(!exists $output->{fileEditionStatement}, 'Correct Text Type');
118ok(!exists $output->{biblEditionStatement}, 'Correct Text Type');
119is($output->{reference} . "\n", <<'REF', 'Author');
120Goethe, Johann Wolfgang von: Autobiographische Einzelheiten, (Geschrieben bis 1832), In: Goethe, Johann Wolfgang von: Goethes Werke, Bd. 10, Autobiographische Schriften II, Hrsg.: Trunz, Erich. München: Verlag C. H. Beck, 1982, S. 529-547
121REF
122is($output->{language}, 'de', 'Language');
123
124is($output->{corpusTitle}, 'Goethes Werke', 'Correct Corpus title');
125ok(!exists $output->{corpusSubTitle}, 'Correct Text Type');
126is($output->{corpusAuthor}, 'Goethe, Johann Wolfgang von', 'Correct Corpus title');
127is($output->{corpusEditor}, 'Trunz, Erich', 'Editor');
128
129is($output->{docTitle}, 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)', 'Correct Corpus title');
130ok(!exists $output->{docSubTitle}, 'Correct Text Type');
131ok(!exists $output->{docAuthor}, 'Correct Text Type');
132ok(!exists $output->{docEditor}, 'Correct Text Type');
133
134## Base
Akron3c119642017-02-10 14:54:08 +0100135$tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs_pagebreaks');
Akron53167fd2016-12-21 15:01:01 +0100136
137$output = $tokens->to_data;
138
Akron3c119642017-02-10 14:54:08 +0100139is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs_pagebreaks', 'Foundries');
Akron53167fd2016-12-21 15:01:01 +0100140is($output->{data}->{layerInfos}, 'dereko/s=spans', 'layerInfos');
141my $first_token = join('||', @{$output->{data}->{stream}->[0]});
142like($first_token, qr/s:Autobiographische/, 'data');
143like($first_token, qr/_0\$<i>0<i>17/, 'data');
144like($first_token, qr!<>:dereko/s:s\$<b>64<i>0<i>30<i>2<b>4!, 'data');
Akrondec43122020-03-03 11:22:25 +0100145like($first_token, qr!<>:base\/s:t\$<b>64<i>0<i>35242<i>5234<b>0!, 'data');
Akrond35d2d32017-02-13 16:57:42 +0100146# like($first_token, qr!<>:base\/s:t\$<b>64<i>0<i>35250<i>5233<b>0!, 'data');
Akron3741f8b2016-12-21 19:55:21 +0100147like($first_token, qr!<>:base/s:s\$<b>64<i>0<i>30<i>2<b>2!, 'data');
148like($first_token, qr!-:base\/paragraphs\$\<i\>14!, 'data');
149like($first_token, qr!-:base\/sentences\$\<i\>215!, 'data');
150
Akrond35d2d32017-02-13 16:57:42 +0100151is($output->{data}->{stream}->[378]->[-1], '~:base/s:pb$<i>530<i>2469', 'Pagebreaks');
Akron3c119642017-02-10 14:54:08 +0100152
Akron3741f8b2016-12-21 19:55:21 +0100153# Check paragraph
154$first_token = join('||', @{$output->{data}->{stream}->[4]});
155like($first_token, qr/s:immer/, 'data');
156like($first_token, qr!<>:base\/s:s\$<b>64<i>53<i>254<i>32<b>2!, 'data');
157like($first_token, qr!<>:dereko\/s:s\$<b>64<i>53<i>254<i>32<b>5<s>1!, 'data');
158like($first_token, qr!<>:base/s:p\$\<b>64<i>53<i>3299<i>504<b>1!, 'data');
159like($first_token, qr!<>:dereko/s:p\$\<b>64<i>53<i>3299<i>504<b>4!, 'data');
160
161$first_token = join('||', @{$output->{data}->{stream}->[180]});
162like($first_token, qr/i:geschäften/, 'data');
Akron53167fd2016-12-21 15:01:01 +0100163
Akronb2f1ab82017-02-22 19:13:15 +0100164## MarMoT
165ok($tokens->add('MarMoT', 'Morpho'), 'Add marmot');
166
167$output = $tokens->to_data;
168
169is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs_pagebreaks marmot marmot/morpho', 'Foundries');
170
171is($output->{data}->{layerInfos}, 'dereko/s=spans marmot/m=tokens marmot/p=tokens', 'layerInfos');
172$first_token = join('||', @{$output->{data}->{stream}->[0]});
173like($first_token, qr!marmot/m:case:nom!, 'Marmot case');
174like($first_token, qr!marmot/m:degree:pos!, 'Marmot degree');
175like($first_token, qr!marmot/m:gender:fem!, 'Marmot gender');
176like($first_token, qr!marmot/m:number:pl!, 'Marmot number');
177like($first_token, qr!marmot/p:ADJA!, 'Marmot part of speech');
178
Akron53167fd2016-12-21 15:01:01 +0100179done_testing;
180__END__