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