blob: d197617af31df8be25ba75de88bed350b8ba9e3f [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');
47is($meta->{pages}, '529-547', 'Pages');
48ok(!$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');
112is($output->{pages}, '529-547', 'Pages');
113ok(!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
Akron3741f8b2016-12-21 19:55:21 +0100131$tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs');
Akron53167fd2016-12-21 15:01:01 +0100132
133$output = $tokens->to_data;
134
Akron3741f8b2016-12-21 19:55:21 +0100135is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs', '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');
Akron3741f8b2016-12-21 19:55:21 +0100141like($first_token, qr!<>:base\/s:t\$<b>64<i>0<i>35250<i>5233<b>0!, 'data');
142like($first_token, qr!<>:base/s:s\$<b>64<i>0<i>30<i>2<b>2!, 'data');
143like($first_token, qr!-:base\/paragraphs\$\<i\>14!, 'data');
144like($first_token, qr!-:base\/sentences\$\<i\>215!, 'data');
145
146# Check paragraph
147$first_token = join('||', @{$output->{data}->{stream}->[4]});
148like($first_token, qr/s:immer/, 'data');
149like($first_token, qr!<>:base\/s:s\$<b>64<i>53<i>254<i>32<b>2!, 'data');
150like($first_token, qr!<>:dereko\/s:s\$<b>64<i>53<i>254<i>32<b>5<s>1!, 'data');
151like($first_token, qr!<>:base/s:p\$\<b>64<i>53<i>3299<i>504<b>1!, 'data');
152like($first_token, qr!<>:dereko/s:p\$\<b>64<i>53<i>3299<i>504<b>4!, 'data');
153
154$first_token = join('||', @{$output->{data}->{stream}->[180]});
155like($first_token, qr/i:geschäften/, 'data');
Akron53167fd2016-12-21 15:01:01 +0100156
157done_testing;
158__END__