blob: 9aca5074b79a3f5d315ea4cbb83027abfaebda7f [file] [log] [blame]
Akronc893ac32018-07-18 17:59:02 +02001use 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 preliminary HNC-Files
20
21# HNC/DOC00001/00001
22my $path = catdir(dirname(__FILE__), '../corpus/HNC/DOC00001/00001');
23
24ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
25ok($doc->parse, 'Parse document');
26
27is($doc->text_sigle, 'HNC/DOC00001/00001', 'Correct text sigle');
28is($doc->doc_sigle, 'HNC/DOC00001', 'Correct document sigle');
29is($doc->corpus_sigle, 'HNC', 'Correct corpus sigle');
30
31my $meta = $doc->meta;
Akron5eb3aa02019-01-25 18:30:47 +010032is($meta->{T_title}, 'GNU Free Documentation License', 'Title');
33is($meta->{S_pub_place}, 'H_PUBPLACE', 'PubPlace');
Akronc893ac32018-07-18 17:59:02 +020034
35# Defined on document level as
36# idsHeader > fileDesc > publicationStmt > pubDate == 2005/08/16
37# idsHeader > fileDesc > biblFull > publicationStmt > pubDate == 2003/07/08-2014/05/03
38# idsHeader > fileDesc > biblFull > publicationStmt > sourceDesc > biblStruct > monogr > imprint > pubDate == 2003/07/08-2014/05/03
Akron5eb3aa02019-01-25 18:30:47 +010039# is($meta->{D_pub_date}, '20030708', 'Publication date');
40ok(!$meta->{T_sub_title}, 'SubTitle');
41is($meta->{T_author}, 'Addbot', 'Author');
Akronc893ac32018-07-18 17:59:02 +020042
Akron5eb3aa02019-01-25 18:30:47 +010043is($meta->{A_publisher}, 'H_PUBLISHER', 'Publisher');
44ok(!$meta->{A_editor}, 'Editor');
Akronc893ac32018-07-18 17:59:02 +020045ok(!$meta->{translator}, 'Translator');
46
Akron5eb3aa02019-01-25 18:30:47 +010047ok(!$meta->{S_text_type}, 'Correct Text Type');
48ok(!$meta->{S_text_type_art}, 'Correct Text Type Art');
49ok(!$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');
52is($meta->{D_creation_date}, '20130302', 'Creation Date');
Akronc893ac32018-07-18 17:59:02 +020053
54ok(!$meta->{pages}, 'Pages');
Akron57799fc2020-02-11 11:42:33 +010055is($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 +010056ok(!$meta->{A_bibl_edition_statement}, 'Bibl Ed Statement');
57ok(!$meta->{A_reference}, 'Reference');
58is($meta->{S_language}, 'hu', 'Language');
Akronc893ac32018-07-18 17:59:02 +020059
Akron0d68a4b2019-11-13 15:42:11 +010060is($meta->{S_availability}, 'Kutatási célokra, megállapodás alapján, hozzáférhető', 'Availability');
61is($meta->{A_distributor}, 'MTA Nyelvtudományi Intézet', 'Distributor');
62
Akron5eb3aa02019-01-25 18:30:47 +010063ok(!$meta->{T_corpus_title}, 'Correct Corpus title');
64ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title');
65ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
66ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
Akronc893ac32018-07-18 17:59:02 +020067
Akron5eb3aa02019-01-25 18:30:47 +010068is($meta->{T_doc_title}, 'MNSZ hivatalos korpusz: Wikipédia cikkek', 'Correct Doc title');
69ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title');
70ok(!$meta->{T_doc_author}, 'Correct Doc author');
71ok(!$meta->{A_doc_editor}, 'Correct Doc editor');
Akronc893ac32018-07-18 17:59:02 +020072
73# Tokenization
74use_ok('KorAP::XML::Tokenizer');
75
76my ($token_base_foundry, $token_base_layer) = (qw/HNC Morpho/);
77
78# Get tokenization
79my $tokens = KorAP::XML::Tokenizer->new(
80 path => $doc->path,
81 doc => $doc,
82 foundry => $token_base_foundry,
83 layer => $token_base_layer,
84 name => 'tokens'
85);
86ok($tokens, 'Token Object is fine');
87ok($tokens->parse, 'Token parsing is fine');
88
89my $output = decode_json( $tokens->to_json );
90
91is($output->{data}->{stream}->[0]->[1], '<>:base/s:t$<b>64<i>0<i>4368<i>577<b>0', 't');
92is($output->{data}->{stream}->[0]->[3], 'i:addbot', 't');
93
94
95## Base
96ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'), 'DeReKo');
97ok($tokens->add('HNC', 'Morpho'), 'Add HNC Morphology');
98
99$output = $tokens->to_data;
100
101is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs hnc hnc/morpho', 'Foundries');
102
103is($output->{data}->{layerInfos}, 'dereko/s=spans hnc/l=tokens hnc/m=tokens hnc/p=tokens', 'layerInfos');
104
105my $token = join('||', @{$output->{data}->{stream}->[7]});
106
107like($token, qr!hnc/l:free!, 'data');
108like($token, qr!hnc/m:compound:n!, 'data');
109like($token, qr!hnc/m:hyphenated:n!, 'data');
110like($token, qr!hnc/m:mboundary:free!, 'data');
111like($token, qr!hnc/m:morphemes:ZERO::NOM!, 'data');
112like($token, qr!hnc/m:stem:free::FN!, 'data');
113like($token, qr!hnc/p:FN\.NOM!, 'data');
114like($token, qr!i:free!, 'data');
115like($token, qr!s:Free!, 'data');
116
117$token = join('||', @{$output->{data}->{stream}->[30]});
118
119like($token, qr!hnc/l:tervez!, 'data');
120like($token, qr!hnc/m:compound:n!, 'data');
121like($token, qr!hnc/m:hyphenated:n!, 'data');
122like($token, qr!hnc/m:mboundary:tervez\+ett!, 'data');
123like($token, qr!hnc/m:morphemes:ett::_MIB ZERO::NOM!, 'data');
124like($token, qr!hnc/m:stem:tervez::IGE!, 'data');
125like($token, qr!hnc/p:IGE\._MIB\.NOM!, 'data');
126like($token, qr!i:tervezett!, 'data');
127like($token, qr!s:tervezett!, 'data');
128
129done_testing;
130__END__