blob: 87f1d83ba4a48c63c7862629d062586098773244 [file] [log] [blame]
Akron3d47ca42016-01-25 20:55:55 +01001use strict;
2use warnings;
3use Test::More;
4use File::Basename 'dirname';
5use File::Spec::Functions 'catdir';
6use Data::Dumper;
Akrone4c2e412016-01-28 15:10:50 +01007use KorAP::XML::Tokenizer;
8use KorAP::XML::Krill;
Akron3d47ca42016-01-25 20:55:55 +01009use utf8;
10
11my $path = catdir(dirname(__FILE__), 'TEST', 'BSP', 1);
12
Akrone4c2e412016-01-28 15:10:50 +010013ok(my $doc = KorAP::XML::Krill->new(
Akron3d47ca42016-01-25 20:55:55 +010014 path => $path . '/'
15), 'Create Document');
16
17ok($doc->parse, 'Parse document');
18
Akrone4c2e412016-01-28 15:10:50 +010019ok(my $tokens = KorAP::XML::Tokenizer->new(
Akron3d47ca42016-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
Akron93d620e2016-02-05 19:40:05 +010029ok($tokens->add('Sgbr', 'Lemma'), 'Add Structure');
Akron3d47ca42016-01-25 20:55:55 +010030
31my $data = $tokens->to_data->{data};
32
33my $stream = $data->{stream};
34is($stream->[0]->[0], '-:tokens$<i>51', 'Token number');
35is($stream->[0]->[1], '_0$<i>0<i>18', 'Position');
36is($stream->[0]->[2], 'i:sommerüberraschung', 'First term');
37is($stream->[0]->[3], 's:Sommerüberraschung', 'First term');
38is($stream->[0]->[4], 'sgbr/l:Sommerüberraschung', 'First term');
39ok(!defined $stream->[0]->[5], 'First term');
40
41is($stream->[1]->[0], '_1$<i>19<i>21', 'Position');
42is($stream->[1]->[1], 'i:es', 'Second term');
43is($stream->[1]->[2], 's:Es', 'Second term');
44is($stream->[1]->[3], 'sgbr/l:es', 'Second term');
45is($stream->[1]->[4], 'sgbr/lv:er', 'Second term');
46is($stream->[1]->[5], 'sgbr/lv:sie', 'Second term');
47
48is($stream->[16]->[0], '_16$<i>107<i>115', 'Position');
49is($stream->[16]->[1], 'i:guenther', '16th term');
50is($stream->[16]->[2], 's:Guenther', '16th term');
51is($stream->[16]->[3], 'sgbr/l:Günther', '16th term');
52is($stream->[16]->[4], 'sgbr/lv:Günter', '16th term');
53
54is($stream->[-1]->[0], '_50$<i>359<i>364', 'Position');
55is($stream->[-1]->[1], 'i:kevin', 'Last term');
56is($stream->[-1]->[2], 's:Kevin', 'Last term');
57is($stream->[-1]->[3], 'sgbr/l:Kevin', 'Last term');
58
Akron8c84aa52016-02-13 21:26:54 +010059
60# Real data 1
61$path = catdir(dirname(__FILE__), 'CMC-TSK', '2014-09', '2843');
62
63ok($doc = KorAP::XML::Krill->new(
64 path => $path . '/'
65), 'Create Document');
66
67ok($doc->parse, 'Parse document');
68
69ok($tokens = KorAP::XML::Tokenizer->new(
70 path => $doc->path,
71 doc => $doc,
72 foundry => 'Sgbr',
73 layer => 'Lemma',
74 name => 'tokens'
75), 'Create tokens based on lemmata');
76
77ok($tokens->parse, 'Parse tokenization based on lemmata');
78
79ok(!$tokens->add('Sgbr', 'Lemma'), 'Add Structure impossible - no token data');
80
81
82# Real data 2
83$path = catdir(dirname(__FILE__), 'CMC-TSK', '2014-09', '3401');
84
85ok($doc = KorAP::XML::Krill->new(
86 path => $path . '/'
87), 'Create Document');
88
89ok($doc->parse, 'Parse document');
90
91ok($tokens = KorAP::XML::Tokenizer->new(
92 path => $doc->path,
93 doc => $doc,
94 foundry => 'Sgbr',
95 layer => 'Lemma',
96 name => 'tokens'
97), 'Create tokens based on lemmata');
98
99ok($tokens->parse, 'Parse tokenization based on lemmata');
100
101ok($tokens->add('Sgbr', 'Lemma'), 'Add Structure');
102
Akron3d47ca42016-01-25 20:55:55 +0100103done_testing;
Akron8c84aa52016-02-13 21:26:54 +0100104
105__END__