blob: 0163ed1871446080e7025893f04b894b5c133979 [file] [log] [blame]
Akrond1eed342016-01-25 20:55:55 +01001use strict;
2use warnings;
3use Test::More;
4use File::Basename 'dirname';
5use File::Spec::Functions 'catdir';
6use Data::Dumper;
Akron8fa76bc2016-01-28 15:10:50 +01007use KorAP::XML::Tokenizer;
8use KorAP::XML::Krill;
Akrond1eed342016-01-25 20:55:55 +01009use utf8;
10
11my $path = catdir(dirname(__FILE__), 'TEST', 'BSP', 1);
12
Akron8fa76bc2016-01-28 15:10:50 +010013ok(my $doc = KorAP::XML::Krill->new(
Akrond1eed342016-01-25 20:55:55 +010014 path => $path . '/'
15), 'Create Document');
16
17ok($doc->parse, 'Parse document');
18
Akron8fa76bc2016-01-28 15:10:50 +010019ok(my $tokens = KorAP::XML::Tokenizer->new(
Akrond1eed342016-01-25 20:55:55 +010020 path => $doc->path,
21 doc => $doc,
22 foundry => 'Sgbr',
23 layer => 'Lemma',
24 name => 'tokens'
25), 'Create tokens based on lemmata');
26
27ok($tokens->parse, 'Parse tokenization based on lemmata');
28
Akron9a04c712016-02-05 19:40:05 +010029ok($tokens->add('Sgbr', 'Morpho'), 'Add Structure');
Akrond1eed342016-01-25 20:55:55 +010030
31my $data = $tokens->to_data->{data};
32
33my $stream = $data->{stream};
34
35is($stream->[0]->[0], '-:tokens$<i>51', 'Token number');
Akrone7bc37d2016-02-26 00:21:16 +010036is($stream->[0]->[1], '<>:base/s:t$<b>64<i>0<i>365<i>50<b>0', 'Text boundary');
37is($stream->[0]->[2], '_0$<i>0<i>18', 'Position');
38is($stream->[0]->[3], 'i:sommerüberraschung', 'First term');
39is($stream->[0]->[4], 's:Sommerüberraschung', 'First term');
40is($stream->[0]->[5], 'sgbr/p:NN', 'First term POS');
Akrond1eed342016-01-25 20:55:55 +010041
42is($stream->[1]->[3], 'sgbr/p:PPER', 'First term POS');
43is($stream->[-1]->[3], 'sgbr/p:NE', 'Last term POS');
44
Akroncc86a8e2016-02-13 21:26:54 +010045
46ok($tokens->add('Sgbr', 'Lemma'), 'Add Structure');
47
48$data = $tokens->to_data->{data};
49$stream = $data->{stream};
50
51is($stream->[-1]->[0], '_50$<i>359<i>364', 'Token number');
52is($stream->[-1]->[1], 'i:kevin', 'Position');
53is($stream->[-1]->[2], 's:Kevin', 'Last term');
54is($stream->[-1]->[3], 'sgbr/l:Kevin', 'Last term');
55is($stream->[-1]->[4], 'sgbr/p:NE', 'Last term');
56ok(!defined $stream->[-1]->[5], 'Last term');
57
Akrond1eed342016-01-25 20:55:55 +010058done_testing;