Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use File::Basename 'dirname'; |
| 5 | use File::Spec::Functions qw/catfile/; |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 6 | |
| 7 | use FindBin; |
| 8 | BEGIN { |
| 9 | unshift @INC, "$FindBin::Bin/../lib"; |
| 10 | }; |
| 11 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 12 | require_ok('KorAP::XML::TEI::Tokenizer::Aggressive'); |
| 13 | require_ok('KorAP::XML::TEI::Tokenizer::Conservative'); |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 14 | |
| 15 | # Test aggressive |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 16 | my $aggr = KorAP::XML::TEI::Tokenizer::Aggressive->new; |
| 17 | $aggr->tokenize("Der alte Mann"); |
Akron | 510a88c | 2020-07-07 10:16:50 +0200 | [diff] [blame] | 18 | is_deeply($aggr, [0,3,4,8,9,13]); |
| 19 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 20 | $aggr->reset->tokenize("Der alte bzw. der grau-melierte Mann"); |
Akron | 510a88c | 2020-07-07 10:16:50 +0200 | [diff] [blame] | 21 | is_deeply($aggr, [0,3,4,8,9,12,12,13,14,17,18,22,22,23,23,31,32,36]); |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 22 | |
| 23 | # Test conservative |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 24 | my $cons = KorAP::XML::TEI::Tokenizer::Conservative->new; |
| 25 | $cons->tokenize("Der alte Mann"); |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 26 | is_deeply($cons, [0,3,4,8,9,13]); |
| 27 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 28 | $cons->reset->tokenize("Der alte bzw. der grau-melierte Mann"); |
Akron | 510a88c | 2020-07-07 10:16:50 +0200 | [diff] [blame] | 29 | is_deeply($cons, [0,3,4,8,9,12,12,13,14,17,18,31,32,36]); |
| 30 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 31 | $cons->reset->tokenize(". Der"); |
Akron | 510a88c | 2020-07-07 10:16:50 +0200 | [diff] [blame] | 32 | is_deeply($cons, [0,1,2,5]); |
| 33 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 34 | $cons->reset->tokenize(" . Der"); |
Akron | 510a88c | 2020-07-07 10:16:50 +0200 | [diff] [blame] | 35 | is_deeply($cons, [1,2,3,6]); |
| 36 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 37 | $cons->reset->tokenize(" . Der"); |
Akron | 510a88c | 2020-07-07 10:16:50 +0200 | [diff] [blame] | 38 | is_deeply($cons, [3,4,5,8]); |
| 39 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 40 | $cons->reset->tokenize("... Der"); |
Akron | 510a88c | 2020-07-07 10:16:50 +0200 | [diff] [blame] | 41 | is_deeply($cons, [0,1,1,2,2,3,4,7]); |
| 42 | |
Peter Harders | 41c3562 | 2020-07-12 01:16:22 +0200 | [diff] [blame] | 43 | # TODO: |
| 44 | # bug: '.' is not tokenized |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 45 | $cons->reset->tokenize(".Der"); |
Akron | 510a88c | 2020-07-07 10:16:50 +0200 | [diff] [blame] | 46 | is_deeply($cons, [1,4]); |
| 47 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 48 | $cons->reset->tokenize(".Der.... "); |
Akron | 510a88c | 2020-07-07 10:16:50 +0200 | [diff] [blame] | 49 | is_deeply($cons, [1,4,4,5,5,6,6,7,7,8]); |
| 50 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 51 | $cons->reset->tokenize("..Der.... "); |
Akron | 510a88c | 2020-07-07 10:16:50 +0200 | [diff] [blame] | 52 | is_deeply($cons, [0,1,1,2,2,5,5,6,6,7,7,8,8,9]); |
| 53 | |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 54 | # Test data |
| 55 | my $dataf = catfile(dirname(__FILE__), 'data', 'wikipedia.txt'); |
| 56 | my $data = ''; |
| 57 | |
| 58 | ok(open(FH, '<' . $dataf), 'Open file'); |
| 59 | while (!eof(FH)) { |
| 60 | $data .= <FH> |
| 61 | }; |
| 62 | close(FH); |
| 63 | |
| 64 | is(137166, length($data)); |
| 65 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 66 | $aggr->reset->tokenize($data); |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 67 | is_deeply([@{$aggr}[0..7]], [1,7,8,12,14,18,19,22]); |
| 68 | is(47242, scalar(@$aggr)); |
| 69 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 70 | $cons->reset->tokenize($data); |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 71 | is_deeply([@{$cons}[0..7]], [1,7,8,12,14,18,19,22]); |
| 72 | is(43068, scalar(@$cons)); |
| 73 | |
| 74 | done_testing; |