blob: dfc645bbe6424c134a0e379cbca9d5227e789bc6 [file] [log] [blame]
Akron88d063a2022-03-21 15:10:01 +01001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
6
7if ($ENV{SKIP_REAL}) {
8 plan skip_all => 'Skip real tests';
9};
10
11use utf8;
12use lib 'lib', '../lib';
13
14use File::Basename 'dirname';
15use File::Spec::Functions 'catdir';
16
17use_ok('KorAP::XML::Krill');
18
19my $path = catdir(dirname(__FILE__), 'corpus','NKJP','NKJP','KOT');
20
21ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
22ok($doc->parse, 'Parse document');
23
24is($doc->text_sigle, 'NKJP/NKJP/KOT', 'Correct text sigle');
25is($doc->doc_sigle, 'NKJP/NKJP', 'Correct document sigle');
26is($doc->corpus_sigle, 'NKJP', 'Correct corpus sigle');
27
28my $meta = $doc->meta;
29
30is($meta->{T_title}, 'TEI P5 encoded version of sample(s) of "Kot"', 'Title');
31ok(!$meta->{T_sub_title}, 'SubTitle');
32ok(!$meta->{T_author}, 'Author');
33ok(!$meta->{A_editor}, 'Editor');
34ok(!$meta->{S_pub_place}, 'PubPlace');
35ok(!$meta->{A_publisher}, 'Publisher');
36
37ok(!$meta->{S_text_type}, 'No Text Type');
38ok(!$meta->{S_text_type_art}, 'No Text Type Art');
39ok(!$meta->{S_text_type_ref}, 'No Text Type Ref');
40ok(!$meta->{S_text_domain}, 'No Text Domain');
41ok(!$meta->{S_text_column}, 'No Text Column');
42
43
44# Tokenization
45use_ok('KorAP::XML::Tokenizer');
46
47my ($token_base_foundry, $token_base_layer) = (qw/nkjp Morpho/);
48
49# Get tokenization
50my $tokens = KorAP::XML::Tokenizer->new(
51 path => $doc->path,
52 doc => $doc,
53 foundry => $token_base_foundry,
54 layer => $token_base_layer,
55 name => 'tokens'
56);
57ok($tokens, 'Token Object is fine');
58ok($tokens->parse, 'Token parsing is fine');
59
60my $output = decode_json( $tokens->to_json );
61
62is($output->{data}->{stream}->[0]->[0], '-:tokens$<i>43', 't');
63is($output->{data}->{stream}->[0]->[3], 'i:nie', 't');
64is($output->{data}->{stream}->[1]->[2], 's:zdążyła', 't');
65
66## Base
67ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'));
68ok($tokens->add('NKJP', 'Morpho'), 'Add Gingko');
69
70$output = $tokens->to_data;
71
72is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs nkjp nkjp/morpho', 'Foundries');
73
74is($output->{data}->{layerInfos}, 'dereko/s=spans nkjp/l=tokens nkjp/m=tokens nkjp/p=tokens', 'layerInfos');
75
76my $token = join('||', @{$output->{data}->{stream}->[7]});
77
78like($token, qr!<>:dereko\/s:seg\$<b>64!);
79like($token, qr!<>:dereko\/s:seg\$<b>64!);
80like($token, qr!iadu!);
81like($token, qr!nkjp\/lad!);
82like($token, qr!nkjp\/m:sg:gen:m3!);
83like($token, qr!nkjp\/p:subst!);
84like($token, qr!sadu!);
85
86done_testing;
87__END__
88