blob: d7775d700545f480b698eb41aab2aed7313f83ea [file] [log] [blame]
Akronc893ac32018-07-18 17:59:02 +02001use 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
Akronc893ac32018-07-18 17:59:02 +020011use 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 preliminary HNC-Files
24
25# HNC/DOC00001/00001
26my $path = catdir(dirname(__FILE__), '../corpus/HNC/DOC00001/00001');
27
28ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
29ok($doc->parse, 'Parse document');
30
31is($doc->text_sigle, 'HNC/DOC00001/00001', 'Correct text sigle');
32is($doc->doc_sigle, 'HNC/DOC00001', 'Correct document sigle');
33is($doc->corpus_sigle, 'HNC', 'Correct corpus sigle');
34
35my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010036is($meta->{T_title}, 'GNU Free Documentation License', 'Title');
37is($meta->{S_pub_place}, 'H_PUBPLACE', 'PubPlace');
Akronc893ac32018-07-18 17:59:02 +020038
39# Defined on document level as
40# idsHeader > fileDesc > publicationStmt > pubDate == 2005/08/16
41# idsHeader > fileDesc > biblFull > publicationStmt > pubDate == 2003/07/08-2014/05/03
42# idsHeader > fileDesc > biblFull > publicationStmt > sourceDesc > biblStruct > monogr > imprint > pubDate == 2003/07/08-2014/05/03
Akron5eb3aa02019-01-25 18:30:47 +010043# is($meta->{D_pub_date}, '20030708', 'Publication date');
44ok(!$meta->{T_sub_title}, 'SubTitle');
45is($meta->{T_author}, 'Addbot', 'Author');
Akronc893ac32018-07-18 17:59:02 +020046
Akron5eb3aa02019-01-25 18:30:47 +010047is($meta->{A_publisher}, 'H_PUBLISHER', 'Publisher');
48ok(!$meta->{A_editor}, 'Editor');
Akronc893ac32018-07-18 17:59:02 +020049ok(!$meta->{translator}, 'Translator');
50
Akron5eb3aa02019-01-25 18:30:47 +010051ok(!$meta->{S_text_type}, 'Correct Text Type');
52ok(!$meta->{S_text_type_art}, 'Correct Text Type Art');
53ok(!$meta->{S_text_type_ref}, 'Correct Text Type Ref');
54ok(!$meta->{S_text_column}, 'Correct Text Column');
55ok(!$meta->{S_text_domain}, 'Correct Text Domain');
56is($meta->{D_creation_date}, '20130302', 'Creation Date');
Akronc893ac32018-07-18 17:59:02 +020057
58ok(!$meta->{pages}, 'Pages');
Akron57799fc2020-02-11 11:42:33 +010059is($meta->{A_file_edition_statement}, 'Magyar Nemzeti Szövegtár 2. változat - XML formátum', 'File Ed Statement');
Akron5eb3aa02019-01-25 18:30:47 +010060ok(!$meta->{A_bibl_edition_statement}, 'Bibl Ed Statement');
61ok(!$meta->{A_reference}, 'Reference');
62is($meta->{S_language}, 'hu', 'Language');
Akronc893ac32018-07-18 17:59:02 +020063
Akron0d68a4b2019-11-13 15:42:11 +010064is($meta->{S_availability}, 'Kutatási célokra, megállapodás alapján, hozzáférhető', 'Availability');
65is($meta->{A_distributor}, 'MTA Nyelvtudományi Intézet', 'Distributor');
66
Akron5eb3aa02019-01-25 18:30:47 +010067ok(!$meta->{T_corpus_title}, 'Correct Corpus title');
68ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title');
69ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
70ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akronc893ac32018-07-18 17:59:02 +020071
Akron5eb3aa02019-01-25 18:30:47 +010072is($meta->{T_doc_title}, 'MNSZ hivatalos korpusz: Wikipédia cikkek', 'Correct Doc title');
73ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title');
74ok(!$meta->{T_doc_author}, 'Correct Doc author');
75ok(!$meta->{A_doc_editor}, 'Correct Doc editor');
Akronc893ac32018-07-18 17:59:02 +020076
77# Tokenization
78use_ok('KorAP::XML::Tokenizer');
79
80my ($token_base_foundry, $token_base_layer) = (qw/HNC Morpho/);
81
82# Get tokenization
83my $tokens = KorAP::XML::Tokenizer->new(
84 path => $doc->path,
85 doc => $doc,
86 foundry => $token_base_foundry,
87 layer => $token_base_layer,
88 name => 'tokens'
89);
90ok($tokens, 'Token Object is fine');
91ok($tokens->parse, 'Token parsing is fine');
92
93my $output = decode_json( $tokens->to_json );
94
Akrondec43122020-03-03 11:22:25 +010095is($output->{data}->{stream}->[0]->[1], '<>:base/s:t$<b>64<i>0<i>4368<i>578<b>0', 't');
Akronc893ac32018-07-18 17:59:02 +020096is($output->{data}->{stream}->[0]->[3], 'i:addbot', 't');
Akrondec43122020-03-03 11:22:25 +010097is($output->{data}->{stream}->[-1]->[0], '_577$<i>4359<i>4368', 't');
Akronc893ac32018-07-18 17:59:02 +020098
99
100## Base
101ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'), 'DeReKo');
102ok($tokens->add('HNC', 'Morpho'), 'Add HNC Morphology');
103
104$output = $tokens->to_data;
105
106is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs hnc hnc/morpho', 'Foundries');
107
108is($output->{data}->{layerInfos}, 'dereko/s=spans hnc/l=tokens hnc/m=tokens hnc/p=tokens', 'layerInfos');
109
110my $token = join('||', @{$output->{data}->{stream}->[7]});
111
112like($token, qr!hnc/l:free!, 'data');
113like($token, qr!hnc/m:compound:n!, 'data');
114like($token, qr!hnc/m:hyphenated:n!, 'data');
115like($token, qr!hnc/m:mboundary:free!, 'data');
116like($token, qr!hnc/m:morphemes:ZERO::NOM!, 'data');
117like($token, qr!hnc/m:stem:free::FN!, 'data');
118like($token, qr!hnc/p:FN\.NOM!, 'data');
119like($token, qr!i:free!, 'data');
120like($token, qr!s:Free!, 'data');
121
122$token = join('||', @{$output->{data}->{stream}->[30]});
123
124like($token, qr!hnc/l:tervez!, 'data');
125like($token, qr!hnc/m:compound:n!, 'data');
126like($token, qr!hnc/m:hyphenated:n!, 'data');
127like($token, qr!hnc/m:mboundary:tervez\+ett!, 'data');
128like($token, qr!hnc/m:morphemes:ett::_MIB ZERO::NOM!, 'data');
129like($token, qr!hnc/m:stem:tervez::IGE!, 'data');
130like($token, qr!hnc/p:IGE\._MIB\.NOM!, 'data');
131like($token, qr!i:tervezett!, 'data');
132like($token, qr!s:tervezett!, 'data');
133
134done_testing;
135__END__