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/; |
| 6 | use File::Temp 'tempfile'; |
| 7 | |
| 8 | use FindBin; |
| 9 | BEGIN { |
| 10 | unshift @INC, "$FindBin::Bin/../lib"; |
| 11 | }; |
| 12 | |
| 13 | require_ok('KorAP::XML::TEI::Tokenization'); |
| 14 | |
| 15 | # Test aggressive |
| 16 | my $aggr = KorAP::XML::TEI::Tokenization::aggressive("Der alte Mann"); |
| 17 | is_deeply($aggr, [0,3,4,8,9, 13]); |
| 18 | |
| 19 | # Test conservative |
| 20 | my $cons = KorAP::XML::TEI::Tokenization::conservative("Der alte Mann"); |
| 21 | is_deeply($cons, [0,3,4,8,9,13]); |
| 22 | |
| 23 | # Test data |
| 24 | my $dataf = catfile(dirname(__FILE__), 'data', 'wikipedia.txt'); |
| 25 | my $data = ''; |
| 26 | |
| 27 | ok(open(FH, '<' . $dataf), 'Open file'); |
| 28 | while (!eof(FH)) { |
| 29 | $data .= <FH> |
| 30 | }; |
| 31 | close(FH); |
| 32 | |
| 33 | is(137166, length($data)); |
| 34 | |
| 35 | $aggr = KorAP::XML::TEI::Tokenization::aggressive($data); |
| 36 | is_deeply([@{$aggr}[0..7]], [1,7,8,12,14,18,19,22]); |
| 37 | is(47242, scalar(@$aggr)); |
| 38 | |
| 39 | $cons = KorAP::XML::TEI::Tokenization::conservative($data); |
| 40 | is_deeply([@{$cons}[0..7]], [1,7,8,12,14,18,19,22]); |
| 41 | is(43068, scalar(@$cons)); |
| 42 | |
| 43 | done_testing; |