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