blob: cde02d9099689881033c27f19d98eb2557227868 [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;
32is($meta->{title}, 'GNU Free Documentation License', 'Title');
33is($meta->{pub_place}, 'H_PUBPLACE', 'PubPlace');
34
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
39# is($meta->{pub_date}, '20030708', 'Publication date');
40ok(!$meta->{sub_title}, 'SubTitle');
41is($meta->{author}, 'Addbot', 'Author');
42
43is($meta->{publisher}, 'H_PUBLISHER', 'Publisher');
44ok(!$meta->{editor}, 'Editor');
45ok(!$meta->{translator}, 'Translator');
46
47ok(!$meta->{text_type}, 'Correct Text Type');
48ok(!$meta->{text_type_art}, 'Correct Text Type Art');
49ok(!$meta->{text_type_ref}, 'Correct Text Type Ref');
50ok(!$meta->{text_column}, 'Correct Text Column');
51ok(!$meta->{text_domain}, 'Correct Text Domain');
52is($meta->{creation_date}, '20130302', 'Creation Date');
53
54ok(!$meta->{pages}, 'Pages');
55ok(!$meta->{file_edition_statement}, 'File Ed Statement');
56ok(!$meta->{bibl_edition_statement}, 'Bibl Ed Statement');
57ok(!$meta->{reference}, 'Reference');
58is($meta->{language}, 'hu', 'Language');
59
60ok(!$meta->{corpus_title}, 'Correct Corpus title');
61ok(!$meta->{corpus_sub_title}, 'Correct Corpus Sub title');
62ok(!$meta->{corpus_author}, 'Correct Corpus author');
63ok(!$meta->{corpus_editor}, 'Correct Corpus editor');
64
65is($meta->{doc_title}, 'MNSZ hivatalos korpusz: Wikipédia cikkek', 'Correct Doc title');
66ok(!$meta->{doc_sub_title}, 'Correct Doc Sub title');
67ok(!$meta->{doc_author}, 'Correct Doc author');
68ok(!$meta->{doc_editor}, 'Correct Doc editor');
69
70# Tokenization
71use_ok('KorAP::XML::Tokenizer');
72
73my ($token_base_foundry, $token_base_layer) = (qw/HNC Morpho/);
74
75# Get tokenization
76my $tokens = KorAP::XML::Tokenizer->new(
77 path => $doc->path,
78 doc => $doc,
79 foundry => $token_base_foundry,
80 layer => $token_base_layer,
81 name => 'tokens'
82);
83ok($tokens, 'Token Object is fine');
84ok($tokens->parse, 'Token parsing is fine');
85
86my $output = decode_json( $tokens->to_json );
87
88is($output->{data}->{stream}->[0]->[1], '<>:base/s:t$<b>64<i>0<i>4368<i>577<b>0', 't');
89is($output->{data}->{stream}->[0]->[3], 'i:addbot', 't');
90
91
92## Base
93ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'), 'DeReKo');
94ok($tokens->add('HNC', 'Morpho'), 'Add HNC Morphology');
95
96$output = $tokens->to_data;
97
98is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs hnc hnc/morpho', 'Foundries');
99
100is($output->{data}->{layerInfos}, 'dereko/s=spans hnc/l=tokens hnc/m=tokens hnc/p=tokens', 'layerInfos');
101
102my $token = join('||', @{$output->{data}->{stream}->[7]});
103
104like($token, qr!hnc/l:free!, 'data');
105like($token, qr!hnc/m:compound:n!, 'data');
106like($token, qr!hnc/m:hyphenated:n!, 'data');
107like($token, qr!hnc/m:mboundary:free!, 'data');
108like($token, qr!hnc/m:morphemes:ZERO::NOM!, 'data');
109like($token, qr!hnc/m:stem:free::FN!, 'data');
110like($token, qr!hnc/p:FN\.NOM!, 'data');
111like($token, qr!i:free!, 'data');
112like($token, qr!s:Free!, 'data');
113
114$token = join('||', @{$output->{data}->{stream}->[30]});
115
116like($token, qr!hnc/l:tervez!, 'data');
117like($token, qr!hnc/m:compound:n!, 'data');
118like($token, qr!hnc/m:hyphenated:n!, 'data');
119like($token, qr!hnc/m:mboundary:tervez\+ett!, 'data');
120like($token, qr!hnc/m:morphemes:ett::_MIB ZERO::NOM!, 'data');
121like($token, qr!hnc/m:stem:tervez::IGE!, 'data');
122like($token, qr!hnc/p:IGE\._MIB\.NOM!, 'data');
123like($token, qr!i:tervezett!, 'data');
124like($token, qr!s:tervezett!, 'data');
125
126done_testing;
127__END__