blob: 8b5374e32f35817172d7e14a3fbbcb2a35cb0026 [file] [log] [blame]
Akron53167fd2016-12-21 15:01:01 +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
19# This will Check Goethe-Files without base annotations!
20
21# GOE/AGA/03828
22my $path = catdir(dirname(__FILE__), '../corpus/GOE2/AGA/03828');
23
24ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
25ok($doc->parse, 'Parse document');
26
27is($doc->text_sigle, 'GOE/AGA/03828', 'Correct text sigle');
28is($doc->doc_sigle, 'GOE/AGA', 'Correct document sigle');
29is($doc->corpus_sigle, 'GOE', 'Correct corpus sigle');
30
31my $meta = $doc->meta;
32is($meta->{title}, 'Autobiographische Einzelheiten', 'Title');
33is($meta->{pub_place}, 'München', 'PubPlace');
34is($meta->{pub_date}, '19820000', 'Creation Date');
35ok(!$meta->{sub_title}, 'SubTitle');
36is($meta->{author}, 'Goethe, Johann Wolfgang von', 'Author');
37
38is($meta->{publisher}, 'Verlag C. H. Beck', 'Publisher');
39ok(!$meta->{editor}, 'Publisher');
40is($meta->{text_type}, 'Autobiographie', 'Correct Text Type');
41ok(!$meta->{text_type_art}, 'Correct Text Type Art');
42ok(!$meta->{text_type_ref}, 'Correct Text Type Ref');
43ok(!$meta->{text_column}, 'Correct Text Column');
44ok(!$meta->{text_domain}, 'Correct Text Domain');
45is($meta->{creation_date}, '18200000', 'Creation Date');
46is($meta->{availability}, 'QAO-NC', 'License');
Akron08d54452017-02-16 23:19:49 +010047is($meta->{src_pages}, '529-547', 'Pages');
Akron53167fd2016-12-21 15:01:01 +010048ok(!$meta->{file_edition_statement}, 'File Ed Statement');
49ok(!$meta->{bibl_edition_statement}, 'Bibl Ed Statement');
50is($meta->{reference} . "\n", <<'REF', 'Author');
51Goethe, 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
52REF
53is($meta->{language}, 'de', 'Language');
54
55
56is($meta->{corpus_title}, 'Goethes Werke', 'Correct Corpus title');
57ok(!$meta->{corpus_sub_title}, 'Correct Corpus Sub title');
58is($meta->{corpus_author}, 'Goethe, Johann Wolfgang von', 'Correct Corpus author');
59is($meta->{corpus_editor}, 'Trunz, Erich', 'Correct Corpus editor');
60
61is($meta->{doc_title}, 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)',
62 'Correct Doc title');
63ok(!$meta->{doc_sub_title}, 'Correct Doc Sub title');
64ok(!$meta->{doc_author}, 'Correct Doc author');
65ok(!$meta->{doc_editor}, 'Correct Doc editor');
66
67# Tokenization
68use_ok('KorAP::XML::Tokenizer');
69
70my ($token_base_foundry, $token_base_layer) = (qw/Base Tokens_conservative/);
71
72# Get tokenization
73my $tokens = KorAP::XML::Tokenizer->new(
74 path => $doc->path,
75 doc => $doc,
76 foundry => $token_base_foundry,
77 layer => $token_base_layer,
78 name => 'tokens'
79);
80ok($tokens, 'Token Object is fine');
81ok($tokens->parse, 'Token parsing is fine');
82
83my $output = decode_json( $tokens->to_json );
84
85is(substr($output->{data}->{text}, 0, 100), 'Autobiographische einzelheiten Selbstschilderung (1) immer tätiger, nach innen und außen fortwirkend', 'Primary Data');
86is($output->{data}->{name}, 'tokens', 'tokenName');
87is($output->{data}->{tokenSource}, 'base#tokens_conservative', 'tokenSource');
88is($output->{version}, '0.03', 'version');
89is($output->{data}->{foundries}, '', 'Foundries');
90is($output->{data}->{layerInfos}, '', 'layerInfos');
91is($output->{data}->{stream}->[0]->[4], 's:Autobiographische', 'data');
92
93is($output->{textSigle}, 'GOE/AGA/03828', 'Correct text sigle');
94is($output->{docSigle}, 'GOE/AGA', 'Correct document sigle');
95is($output->{corpusSigle}, 'GOE', 'Correct corpus sigle');
96
97is($output->{author}, 'Goethe, Johann Wolfgang von', 'Author');
98is($output->{pubPlace}, 'München', 'PubPlace');
99is($output->{pubDate}, '19820000', 'Creation Date');
100is($output->{title}, 'Autobiographische Einzelheiten', 'Title');
101ok(!exists $output->{subTitle}, 'subTitle');
102
103is($output->{publisher}, 'Verlag C. H. Beck', 'Publisher');
104ok(!exists $output->{editor}, 'Editor');
105is($output->{textType}, 'Autobiographie', 'Correct Text Type');
106ok(!exists $output->{textTypeArt}, 'Correct Text Type');
107ok(!exists $output->{textTypeRef}, 'Correct Text Type');
108ok(!exists $output->{textColumn}, 'Correct Text Type');
109ok(!exists $output->{textDomain}, 'Correct Text Type');
110is($output->{creationDate}, '18200000', 'Creation Date');
111is($output->{availability}, 'QAO-NC', 'License');
Akron08d54452017-02-16 23:19:49 +0100112is($output->{srcPages}, '529-547', 'Pages');
Akron53167fd2016-12-21 15:01:01 +0100113ok(!exists $output->{fileEditionStatement}, 'Correct Text Type');
114ok(!exists $output->{biblEditionStatement}, 'Correct Text Type');
115is($output->{reference} . "\n", <<'REF', 'Author');
116Goethe, 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
117REF
118is($output->{language}, 'de', 'Language');
119
120is($output->{corpusTitle}, 'Goethes Werke', 'Correct Corpus title');
121ok(!exists $output->{corpusSubTitle}, 'Correct Text Type');
122is($output->{corpusAuthor}, 'Goethe, Johann Wolfgang von', 'Correct Corpus title');
123is($output->{corpusEditor}, 'Trunz, Erich', 'Editor');
124
125is($output->{docTitle}, 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)', 'Correct Corpus title');
126ok(!exists $output->{docSubTitle}, 'Correct Text Type');
127ok(!exists $output->{docAuthor}, 'Correct Text Type');
128ok(!exists $output->{docEditor}, 'Correct Text Type');
129
130## Base
Akron3c119642017-02-10 14:54:08 +0100131$tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs_pagebreaks');
Akron53167fd2016-12-21 15:01:01 +0100132
133$output = $tokens->to_data;
134
Akron3c119642017-02-10 14:54:08 +0100135is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs_pagebreaks', 'Foundries');
Akron53167fd2016-12-21 15:01:01 +0100136is($output->{data}->{layerInfos}, 'dereko/s=spans', 'layerInfos');
137my $first_token = join('||', @{$output->{data}->{stream}->[0]});
138like($first_token, qr/s:Autobiographische/, 'data');
139like($first_token, qr/_0\$<i>0<i>17/, 'data');
140like($first_token, qr!<>:dereko/s:s\$<b>64<i>0<i>30<i>2<b>4!, 'data');
Akrond35d2d32017-02-13 16:57:42 +0100141like($first_token, qr!<>:base\/s:t\$<b>64<i>0<i>35242<i>5233<b>0!, 'data');
142# like($first_token, qr!<>:base\/s:t\$<b>64<i>0<i>35250<i>5233<b>0!, 'data');
Akron3741f8b2016-12-21 19:55:21 +0100143like($first_token, qr!<>:base/s:s\$<b>64<i>0<i>30<i>2<b>2!, 'data');
144like($first_token, qr!-:base\/paragraphs\$\<i\>14!, 'data');
145like($first_token, qr!-:base\/sentences\$\<i\>215!, 'data');
146
Akrond35d2d32017-02-13 16:57:42 +0100147is($output->{data}->{stream}->[378]->[-1], '~:base/s:pb$<i>530<i>2469', 'Pagebreaks');
Akron3c119642017-02-10 14:54:08 +0100148
Akron3741f8b2016-12-21 19:55:21 +0100149# Check paragraph
150$first_token = join('||', @{$output->{data}->{stream}->[4]});
151like($first_token, qr/s:immer/, 'data');
152like($first_token, qr!<>:base\/s:s\$<b>64<i>53<i>254<i>32<b>2!, 'data');
153like($first_token, qr!<>:dereko\/s:s\$<b>64<i>53<i>254<i>32<b>5<s>1!, 'data');
154like($first_token, qr!<>:base/s:p\$\<b>64<i>53<i>3299<i>504<b>1!, 'data');
155like($first_token, qr!<>:dereko/s:p\$\<b>64<i>53<i>3299<i>504<b>4!, 'data');
156
157$first_token = join('||', @{$output->{data}->{stream}->[180]});
158like($first_token, qr/i:geschäften/, 'data');
Akron53167fd2016-12-21 15:01:01 +0100159
160done_testing;
161__END__