blob: 33fbc90427e4a719e6b189c2e57bc399e4d193ed [file] [log] [blame]
Akron414ec952020-08-03 15:48:43 +02001use strict;
2use warnings;
3use Test::More;
4use File::Basename 'dirname';
5use File::Spec::Functions 'catdir';
6use Data::Dumper;
7use KorAP::XML::Tokenizer;
8use KorAP::XML::Krill;
9use utf8;
10
11if ($ENV{SKIP_REAL}) {
12 plan skip_all => 'Skip real tests';
13};
14
15my $path = catdir(dirname(__FILE__), 'TEST', 'BSP', 1);
16
17ok(my $doc = KorAP::XML::Krill->new(
18 path => $path . '/'
19), 'Create Document');
20
21ok($doc->parse, 'Parse document');
22
23ok(my $tokens = KorAP::XML::Tokenizer->new(
24 path => $doc->path,
25 doc => $doc,
26 foundry => 'Sgbr',
27 layer => 'Lemma',
28 name => 'tokens'
29), 'Create tokens based on lemmata');
30
31ok($tokens->parse, 'Parse tokenization based on lemmata');
32
33ok($tokens->add('Sgbr', 'Morpho'), 'Add Structure');
34
35my $data = $tokens->to_data->{data};
36
37my $stream = $data->{stream};
38
39is($stream->[0]->[0], '-:tokens$<i>51', 'Token number');
40is($stream->[0]->[1], '<>:base/s:t$<b>64<i>0<i>365<i>51<b>0', 'Text boundary');
41is($stream->[0]->[2], '_0$<i>0<i>18', 'Position');
42is($stream->[0]->[3], 'i:sommerüberraschung', 'First term');
43is($stream->[0]->[4], 's:Sommerüberraschung', 'First term');
44is($stream->[0]->[5], 'sgbr/p:NN', 'First term POS');
45
46is($stream->[1]->[3], 'sgbr/p:PPER', 'First term POS');
47is($stream->[-1]->[3], 'sgbr/p:NE', 'Last term POS');
48
49
50ok($tokens->add('Sgbr', 'Lemma'), 'Add Structure');
51
52$data = $tokens->to_data->{data};
53$stream = $data->{stream};
54
55is($stream->[-1]->[0], '_50$<i>359<i>364', 'Token number');
56is($stream->[-1]->[1], 'i:kevin', 'Position');
57is($stream->[-1]->[2], 's:Kevin', 'Last term');
58is($stream->[-1]->[3], 'sgbr/l:Kevin', 'Last term');
59is($stream->[-1]->[4], 'sgbr/p:NE', 'Last term');
60ok(!defined $stream->[-1]->[5], 'Last term');
61
62done_testing;