blob: 498f4e2d18036b3c020460c729ba7ccfe868418c [file] [log] [blame]
Akron57510c12019-01-04 14:58:53 +01001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
6use Log::Log4perl;
7use utf8;
8
9use Benchmark qw/:hireswallclock/;
10
11my $t = Benchmark->new;
12
13# Initialize log4perl object
14#Log::Log4perl->init({
15# 'log4perl.rootLogger' => 'TRACE, STDERR',
16# 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
17# 'log4perl.appender.STDERR.layout' => 'PatternLayout',
18# 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
19#});
20
21
22use File::Basename 'dirname';
23use File::Spec::Functions 'catdir';
24
25use_ok('KorAP::XML::Krill');
26
27my $path = catdir(dirname(__FILE__), '..', 'corpus', 'AGD-scrambled', 'DOC', '00001');
28
29ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
30ok($doc->parse, 'Parse document');
31
32is($doc->text_sigle, 'AGD/DOC/00001', 'Correct text sigle');
33is($doc->doc_sigle, 'AGD/DOC', 'Correct document sigle');
34is($doc->corpus_sigle, 'AGD', 'Correct corpus sigle');
35
36my $meta = $doc->meta;
37is($meta->{T_title}, 'FOLK_E_00321_SE_01_T_01_DF_01', 'Title');
38is($meta->{D_creation_date}, '20181112', 'Title');
39
Akron20294552019-11-29 16:15:35 +010040is($meta->{A_externalLink}, 'data:application/x.korap-link;title=DGD,'.
41 'https://dgd.ids-mannheim.de/DGD2Web/ExternalAccessServlet?command=displayData'.
42 '&id=FOLK_E_00321_SE_01_T_01', 'External link');
Akron57510c12019-01-04 14:58:53 +010043
44# Tokenization
45use_ok('KorAP::XML::Tokenizer');
46
47my ($token_base_foundry, $token_base_layer) = (qw/DGD Annot/);
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 non_word_tokens => 1
57);
58
59ok($tokens, 'Token Object is fine');
60ok($tokens->parse, 'Token parsing is fine');
61
62my $output = decode_json( $tokens->to_json );
63
64is(substr($output->{data}->{text}, 0, 100),
65 '+++++++++ ku sqn alxv a pwm ▮ xnj nq qtl ohmdgjqp ▮ ▮ ▮ ▮ ▮ fi ▮ sna ▮ alxv hn ▮ zjc ahyx ftwbramn l',
66 'Primary Data');
67
68is($output->{data}->{name}, 'tokens', 'tokenName');
69is($output->{data}->{tokenSource}, 'dgd#annot', 'tokenSource');
70
71is($output->{version}, '0.03', 'version');
72is($output->{data}->{foundries}, '', 'Foundries');
73is($output->{data}->{layerInfos}, '', 'layerInfos');
74is($output->{data}->{stream}->[1]->[2], 's:ku', 'data');
75is($output->{data}->{stream}->[2]->[2], 's:sqn', 'data');
76is($output->{data}->{stream}->[3]->[2], 's:alxv', 'data');
77is($output->{textSigle}, 'AGD/DOC/00001', 'Correct text sigle');
78is($output->{docSigle}, 'AGD/DOC', 'Correct document sigle');
79is($output->{corpusSigle}, 'AGD', 'Correct corpus sigle');
80
81is($output->{title}, 'FOLK_E_00321_SE_01_T_01_DF_01', 'Title');
82
83## DeReKo
84$tokens->add('DeReKo', 'Structure');
85
86$output = decode_json( $tokens->to_json );
87
88is($output->{data}->{foundries},
89 'dereko dereko/structure',
90 'Foundries');
91is($output->{data}->{layerInfos}, 'dereko/s=spans', 'layerInfos');
92
93my $first_token = join('||', @{$output->{data}->{stream}->[0]});
94like($first_token, qr!<>:dereko/s:text!);
95
96## DGD
Akronc29b8e12019-12-16 14:28:09 +010097ok($tokens->add('DGD', 'Morpho'), 'Add Morpho');
Akron57510c12019-01-04 14:58:53 +010098
99$output = decode_json( $tokens->to_json );
100is($output->{data}->{foundries},
101 'dereko dereko/structure dgd dgd/morpho',
102 'Foundries');
103is($output->{data}->{layerInfos}, 'dereko/s=spans dgd/l=tokens dgd/p=tokens dgd/para=tokens',
104 'layerInfos');
105
106my $third_token = join('||', @{$output->{data}->{stream}->[3]});
107like($third_token, qr!dgd/l:alui!);
108like($third_token, qr!dgd/p:VMGWY!);
109like($third_token, qr!i:alxv!);
110like($third_token, qr!s:alxv!);
111
Akronc29b8e12019-12-16 14:28:09 +0100112## DGD base sentences
113ok($tokens->add('DGD', 'Structure'), 'Add sentences');
114$output = decode_json( $tokens->to_json );
Akron57510c12019-01-04 14:58:53 +0100115
Akronc29b8e12019-12-16 14:28:09 +0100116# Offsets are suboptimal set, but good enough
Akron57510c12019-01-04 14:58:53 +0100117
Akronc29b8e12019-12-16 14:28:09 +0100118$first_token = join('||', @{$output->{data}->{stream}->[0]});
119like($first_token, qr!<>:base/s:s\$<b>64<i>0<i>16<i>3<b>1!);
120
121my $token = join('||', @{$output->{data}->{stream}->[1]});
122unlike($token, qr!<>:base/s:s!);
123
124$token = join('||', @{$output->{data}->{stream}->[2]});
125like($token, qr!<>:base/s:s\$<b>64<i>16<i>23<i>5<b>1!);
Akron57510c12019-01-04 14:58:53 +0100126
127done_testing;
128__END__