blob: 74dfef3ac8806c8542f4d6785f974b4e47e0c86c [file] [log] [blame]
Akronc3881502017-01-20 14:36:37 +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
Akronc3881502017-01-20 14:36:37 +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 DRuKoLa-Files
24
25# New
26# BBU/BLOG/83709_a_82384
Akron414ec952020-08-03 15:48:43 +020027my $path = catdir(dirname(__FILE__), 'corpus','CoRoLa','BBU','BLOG','83709_a_82384');
Akronc3881502017-01-20 14:36:37 +010028
29ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
30ok($doc->parse, 'Parse document');
31
32is($doc->text_sigle, 'BBU/BLOG/83709_a_82384', 'Correct text sigle');
33is($doc->doc_sigle, 'BBU/BLOG', 'Correct document sigle');
34is($doc->corpus_sigle, 'BBU', 'Correct corpus sigle');
35
36my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010037is($meta->{T_title}, 'Schimbă vorba', 'Title');
38is($meta->{S_pub_place}, 'URL:http://www.bucurenci.ro', 'PubPlace');
39is($meta->{D_pub_date}, '20131005', 'Creation Date');
40ok(!$meta->{T_sub_title}, 'SubTitle');
41is($meta->{T_author}, 'Dragoș Bucurenci', 'Author');
Akronc3881502017-01-20 14:36:37 +010042
Akron5eb3aa02019-01-25 18:30:47 +010043ok(!$meta->{A_publisher}, 'Publisher');
44ok(!$meta->{A_editor}, 'Editor');
45is($meta->{A_translator}, '[TRANSLATOR]', 'Translator');
Akronaf18edb2024-07-26 12:11:48 +020046ok(!$meta->{T_translator}, 'Translator');
Akron5eb3aa02019-01-25 18:30:47 +010047#is($meta->{S_text_type}, 'Autobiographie', 'Correct Text Type');
48ok(!$meta->{S_text_type_art}, 'Correct Text Type Art');
49# is($meta->{S_text_type_ref}, '', 'Correct Text Type Ref');
50ok(!$meta->{S_text_column}, 'Correct Text Column');
51ok(!$meta->{S_text_domain}, 'Correct Text Domain');
52ok(!$meta->{D_creation_date}, 'Creation Date');
Akronc3881502017-01-20 14:36:37 +010053
54ok(!$meta->{pages}, 'Pages');
Akron5eb3aa02019-01-25 18:30:47 +010055ok(!$meta->{A_file_edition_statement}, 'File Ed Statement');
56ok(!$meta->{A_bibl_edition_statement}, 'Bibl Ed Statement');
57ok(!$meta->{A_reference}, 'Reference');
58is($meta->{S_language}, 'ro', 'Language');
Akronc3881502017-01-20 14:36:37 +010059
Akron5eb3aa02019-01-25 18:30:47 +010060#is($meta->{T_corpus_title}, 'Goethes Werke', 'Correct Corpus title');
61ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title');
62#is($meta->{T_corpus_author}, 'Goethe, Johann Wolfgang von', 'Correct Corpus author');
63#is($meta->{A_corpus_editor}, 'Trunz, Erich', 'Correct Corpus editor');
Akronc3881502017-01-20 14:36:37 +010064
Akron5eb3aa02019-01-25 18:30:47 +010065#is($meta->{T_doc_title}, 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)',
Akronc3881502017-01-20 14:36:37 +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');
Akronc3881502017-01-20 14:36:37 +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
89## Base
90$tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs');
91ok($tokens->add('DRuKoLa', 'Morpho'), 'Add Drukola');
92
93$output = $tokens->to_data;
94
95is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs drukola drukola/morpho', 'Foundries');
96
97is($output->{data}->{layerInfos}, 'dereko/s=spans drukola/l=tokens drukola/m=tokens drukola/p=tokens', 'layerInfos');
98
99my $token = join('||', @{$output->{data}->{stream}->[7]});
100
101like($token, qr!drukola/l:la!, 'data');
102like($token, qr!drukola/m:msd:Sp!, 'data');
103like($token, qr!drukola/p:ADPOSITION!, 'data');
104
105$token = join('||', @{$output->{data}->{stream}->[9]});
106
107like($token, qr!i:vorba!, 'data');
108like($token, qr!drukola/l:vorbă!, 'data');
109like($token, qr!drukola/m:case:Ncfsry!, 'data');
110like($token, qr!drukola/m:definiteness:yes!, 'data');
111like($token, qr!drukola/m:gender:feminine!, 'data');
112like($token, qr!drukola/p:NOUN!, 'data');
113
Akrona7d0e9f2017-02-03 14:36:21 +0100114
115# New
116# BBU2/BLOG/83709_a_82384
Akron414ec952020-08-03 15:48:43 +0200117$path = catdir(dirname(__FILE__), 'corpus','CoRoLa','BBU2','Blog','83701_a_82376');
Akrona7d0e9f2017-02-03 14:36:21 +0100118
119ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
120ok($doc->parse, 'Parse document');
121
122$meta = $doc->meta;
123
Akron5eb3aa02019-01-25 18:30:47 +0100124ok(!exists $meta->{T_doc_title}, 'No doc title');
Akrona7d0e9f2017-02-03 14:36:21 +0100125ok(!exists $meta->{translator}, 'No translator');
126
Akron5eb3aa02019-01-25 18:30:47 +0100127ok(!exists $meta->{K_text_class}, 'No translator');
Akrona7d0e9f2017-02-03 14:36:21 +0100128
129
Akron38873012017-02-06 20:27:37 +0100130
Akron414ec952020-08-03 15:48:43 +0200131$path = catdir(dirname(__FILE__), 'corpus','CoRoLa','Corola-Journal','-','247_a_537');
Akron38873012017-02-06 20:27:37 +0100132ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
133ok($doc->parse, 'Parse document');
134
135$meta = $doc->meta;
136is($meta->text_sigle, 'Corola-Journal/-/247_a_537', 'Text Sigle');
137is($meta->doc_sigle, 'Corola-Journal/-', 'Doc Sigle');
138is($meta->corpus_sigle, 'Corola-Journal', 'Corpus Sigle');
Akron5eb3aa02019-01-25 18:30:47 +0100139is($meta->{K_text_class}->[0], 'Sport', 'Text class');
Akron38873012017-02-06 20:27:37 +0100140
141
Akron414ec952020-08-03 15:48:43 +0200142$path = catdir(dirname(__FILE__), 'corpus','CoRoLa','Corola-Journal','COLEGIUL NATIONAL „OCTAV BANCILA“ - IASI','326_a_562');
Akron38873012017-02-06 20:27:37 +0100143ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
144ok($doc->parse, 'Parse document');
145
146$meta = $doc->meta;
147is($meta->text_sigle, 'Corola-Journal/COLEGIUL NATIONAL „OCTAV BANCILA“ - IASI/326_a_562', 'Text Sigle');
148is($meta->doc_sigle, 'Corola-Journal/COLEGIUL NATIONAL „OCTAV BANCILA“ - IASI', 'Doc Sigle');
149is($meta->corpus_sigle, 'Corola-Journal', 'Corpus Sigle');
Akron5eb3aa02019-01-25 18:30:47 +0100150is($meta->{T_title}, 'APOGEUL ARHITECTURĂ ȘI DESIGN', 'Title');
Akron38873012017-02-06 20:27:37 +0100151
Akronaf18edb2024-07-26 12:11:48 +0200152
153
154# Old translator behaviour:
155our %ENV;
156$ENV{K2K_TRANSLATOR_TEXT} = 1;
157$path = catdir(dirname(__FILE__), 'corpus','CoRoLa','BBU','BLOG','83709_a_82384');
158ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
159ok($doc->parse, 'Parse document');
160
161is($doc->text_sigle, 'BBU/BLOG/83709_a_82384', 'Correct text sigle');
162$meta = $doc->meta;
163is($meta->{T_translator}, '[TRANSLATOR]', 'Translator');
164ok(!$meta->{A_translator}, 'Translator');
165
166
Akronc3881502017-01-20 14:36:37 +0100167done_testing;
168__END__