Marc Kupietz | 1e882fb | 2020-09-09 00:05:46 +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 Test::XML::Loy; |
| 7 | |
| 8 | use FindBin; |
| 9 | use utf8; |
| 10 | |
| 11 | BEGIN { |
| 12 | eval { |
| 13 | require KorAP::XML::TEI::Tokenizer::KorAP; |
| 14 | 1; |
| 15 | } or do { |
| 16 | plan skip_all => "KorAP::XML::TEI::Tokenizer::KorAP cannot be used"; |
| 17 | }; |
| 18 | } |
| 19 | |
| 20 | require_ok('KorAP::XML::TEI::Tokenizer::KorAP'); |
| 21 | |
| 22 | my $f = dirname(__FILE__); |
| 23 | my $cmd = catfile($f, 'cmd', 'tokenizer.pl'); |
| 24 | |
| 25 | my $ext = KorAP::XML::TEI::Tokenizer::KorAP->new(); |
| 26 | |
| 27 | $ext->tokenize("Der alte Mann"); |
| 28 | my $str = $ext->to_string('unknown'); |
| 29 | my $t = Test::XML::Loy->new($str); |
| 30 | $t->attr_is('layer spanList span:nth-child(1)', 'to', 3); |
| 31 | $t->attr_is('layer spanList span:nth-child(2)', 'from', 4); |
| 32 | $t->attr_is('layer spanList span:nth-child(2)', 'to', 8); |
| 33 | $t->attr_is('layer spanList span:nth-child(3)', 'from', 9); |
| 34 | $t->attr_is('layer spanList span:nth-child(3)', 'to', 13); |
| 35 | $t->element_count_is('layer spanList span', 3); |
| 36 | |
| 37 | $ext->tokenize("ging über die Straße"); |
| 38 | $str = $ext->to_string('unknown'); |
| 39 | $t = Test::XML::Loy->new($str); |
| 40 | $t->attr_is('layer spanList span:nth-child(1)', 'to', 4); |
| 41 | $t->attr_is('layer spanList span:nth-child(2)', 'from', 5); |
| 42 | $t->attr_is('layer spanList span:nth-child(2)', 'to', 9); |
| 43 | $t->attr_is('layer spanList span:nth-child(3)', 'from', 10); |
| 44 | $t->attr_is('layer spanList span:nth-child(3)', 'to', 13); |
| 45 | $t->attr_is('layer spanList span:nth-child(4)', 'from', 14); |
| 46 | $t->attr_is('layer spanList span:nth-child(4)', 'to', 20); |
| 47 | $t->element_count_is('layer spanList span', 4); |
| 48 | |
| 49 | $ext->reset; |
| 50 | $ext->tokenize("Hu aha\x{04}\ndas ist cool"); |
| 51 | $str = $ext->to_string('unknown'); |
| 52 | $t = Test::XML::Loy->new($str); |
| 53 | $t->attr_is('layer spanList span:nth-child(1)', 'to', 2); |
| 54 | $t->attr_is('layer spanList span:nth-child(2)', 'from', 3); |
| 55 | $t->attr_is('layer spanList span:nth-child(2)', 'to', 6); |
| 56 | $t->element_count_is('layer spanList span', 2); |
| 57 | |
| 58 | my $string = "Pluto.\" Eris-Entdecker Mike Brown, der im Kurznachrichtendienst Twitter unter \"\@plutokiller"; |
| 59 | $ext->reset; |
| 60 | $ext->tokenize($string); |
| 61 | $str = $ext->to_string('unknown'); |
| 62 | $t = Test::XML::Loy->new($str); |
| 63 | $t->attr_is('layer spanList span:nth-child(14)', 'from', 80); |
| 64 | $t->attr_is('layer spanList span:nth-child(14)', 'to', 92); |
| 65 | $t->element_count_is('layer spanList span', 14); |
| 66 | done_testing; |