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 | |
Peter Harders | 71f072b | 2020-07-15 14:15:01 +0200 | [diff] [blame] | 31 | $cons->reset->tokenize(" Der alte bzw. der grau-melierte Mann"); |
| 32 | is_deeply($cons, [2,5,6,10,11,14,14,15,16,19,20,33,34,38]); |
| 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, [0,1,2,5]); |
| 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, [1,2,3,6]); |
| 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, [3,4,5,8]); |
| 42 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 43 | $cons->reset->tokenize("... Der"); |
Akron | 510a88c | 2020-07-07 10:16:50 +0200 | [diff] [blame] | 44 | is_deeply($cons, [0,1,1,2,2,3,4,7]); |
| 45 | |
Peter Harders | 41c3562 | 2020-07-12 01:16:22 +0200 | [diff] [blame] | 46 | # TODO: |
| 47 | # bug: '.' is not tokenized |
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]); |
| 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, [1,4,4,5,5,6,6,7,7,8]); |
| 53 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 54 | $cons->reset->tokenize("..Der.... "); |
Akron | 510a88c | 2020-07-07 10:16:50 +0200 | [diff] [blame] | 55 | is_deeply($cons, [0,1,1,2,2,5,5,6,6,7,7,8,8,9]); |
| 56 | |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 57 | # Test data |
| 58 | my $dataf = catfile(dirname(__FILE__), 'data', 'wikipedia.txt'); |
| 59 | my $data = ''; |
| 60 | |
| 61 | ok(open(FH, '<' . $dataf), 'Open file'); |
| 62 | while (!eof(FH)) { |
| 63 | $data .= <FH> |
| 64 | }; |
| 65 | close(FH); |
| 66 | |
| 67 | is(137166, length($data)); |
| 68 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 69 | $aggr->reset->tokenize($data); |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 70 | is_deeply([@{$aggr}[0..7]], [1,7,8,12,14,18,19,22]); |
| 71 | is(47242, scalar(@$aggr)); |
| 72 | |
Akron | d962747 | 2020-07-09 16:53:09 +0200 | [diff] [blame] | 73 | $cons->reset->tokenize($data); |
Akron | eac374d | 2020-07-07 09:00:44 +0200 | [diff] [blame] | 74 | is_deeply([@{$cons}[0..7]], [1,7,8,12,14,18,19,22]); |
| 75 | is(43068, scalar(@$cons)); |
| 76 | |
| 77 | done_testing; |