Marc Kupietz | 1e882fb | 2020-09-09 00:05:46 +0200 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
Marc Kupietz | dcd38b3 | 2022-01-14 13:23:37 +0100 | [diff] [blame] | 3 | use Test::More tests => 33; |
Marc Kupietz | 1e882fb | 2020-09-09 00:05:46 +0200 | [diff] [blame] | 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 | |
Marc Kupietz | 985da0c | 2021-02-15 19:29:50 +0100 | [diff] [blame] | 20 | use_ok('KorAP::XML::TEI::Annotations::Collector'); |
Marc Kupietz | 1e882fb | 2020-09-09 00:05:46 +0200 | [diff] [blame] | 21 | require_ok('KorAP::XML::TEI::Tokenizer::KorAP'); |
| 22 | |
| 23 | my $f = dirname(__FILE__); |
| 24 | my $cmd = catfile($f, 'cmd', 'tokenizer.pl'); |
| 25 | |
Marc Kupietz | 985da0c | 2021-02-15 19:29:50 +0100 | [diff] [blame] | 26 | my $ext = KorAP::XML::TEI::Tokenizer::KorAP->new(1); |
Marc Kupietz | 1e882fb | 2020-09-09 00:05:46 +0200 | [diff] [blame] | 27 | |
| 28 | $ext->tokenize("Der alte Mann"); |
| 29 | my $str = $ext->to_string('unknown'); |
| 30 | my $t = Test::XML::Loy->new($str); |
| 31 | $t->attr_is('layer spanList span:nth-child(1)', 'to', 3); |
| 32 | $t->attr_is('layer spanList span:nth-child(2)', 'from', 4); |
| 33 | $t->attr_is('layer spanList span:nth-child(2)', 'to', 8); |
| 34 | $t->attr_is('layer spanList span:nth-child(3)', 'from', 9); |
| 35 | $t->attr_is('layer spanList span:nth-child(3)', 'to', 13); |
| 36 | $t->element_count_is('layer spanList span', 3); |
| 37 | |
| 38 | $ext->tokenize("ging über die Straße"); |
| 39 | $str = $ext->to_string('unknown'); |
| 40 | $t = Test::XML::Loy->new($str); |
| 41 | $t->attr_is('layer spanList span:nth-child(1)', 'to', 4); |
| 42 | $t->attr_is('layer spanList span:nth-child(2)', 'from', 5); |
| 43 | $t->attr_is('layer spanList span:nth-child(2)', 'to', 9); |
| 44 | $t->attr_is('layer spanList span:nth-child(3)', 'from', 10); |
| 45 | $t->attr_is('layer spanList span:nth-child(3)', 'to', 13); |
| 46 | $t->attr_is('layer spanList span:nth-child(4)', 'from', 14); |
| 47 | $t->attr_is('layer spanList span:nth-child(4)', 'to', 20); |
| 48 | $t->element_count_is('layer spanList span', 4); |
| 49 | |
| 50 | $ext->reset; |
| 51 | $ext->tokenize("Hu aha\x{04}\ndas ist cool"); |
| 52 | $str = $ext->to_string('unknown'); |
| 53 | $t = Test::XML::Loy->new($str); |
| 54 | $t->attr_is('layer spanList span:nth-child(1)', 'to', 2); |
| 55 | $t->attr_is('layer spanList span:nth-child(2)', 'from', 3); |
| 56 | $t->attr_is('layer spanList span:nth-child(2)', 'to', 6); |
| 57 | $t->element_count_is('layer spanList span', 2); |
| 58 | |
| 59 | my $string = "Pluto.\" Eris-Entdecker Mike Brown, der im Kurznachrichtendienst Twitter unter \"\@plutokiller"; |
| 60 | $ext->reset; |
| 61 | $ext->tokenize($string); |
| 62 | $str = $ext->to_string('unknown'); |
| 63 | $t = Test::XML::Loy->new($str); |
| 64 | $t->attr_is('layer spanList span:nth-child(14)', 'from', 80); |
| 65 | $t->attr_is('layer spanList span:nth-child(14)', 'to', 92); |
| 66 | $t->element_count_is('layer spanList span', 14); |
Marc Kupietz | 7c88a7b | 2020-10-14 16:28:57 +0200 | [diff] [blame] | 67 | |
Marc Kupietz | 985da0c | 2021-02-15 19:29:50 +0100 | [diff] [blame] | 68 | my $structures = KorAP::XML::TEI::Annotations::Collector->new; |
| 69 | $ext->sentencize_from_previous_input($structures); |
| 70 | $t = Test::XML::Loy->new($structures->[-1]->to_string(3)); |
| 71 | $t->attr_is('span', 'from', 6) |
| 72 | ->attr_is('span', 'to', 92) |
| 73 | ->attr_is('span', 'l', -1, "sentence splitting with korap tokenizer"); |
| 74 | |
Marc Kupietz | 7c88a7b | 2020-10-14 16:28:57 +0200 | [diff] [blame] | 75 | $string = "Gefunden auf www.wikipedia.de"; |
| 76 | $ext->reset; |
| 77 | $ext->tokenize($string); |
| 78 | $str = $ext->to_string('unknown'); |
| 79 | $t = Test::XML::Loy->new($str); |
| 80 | $t->attr_is('layer spanList span:nth-child(3)', 'from', 13); |
| 81 | $t->attr_is('layer spanList span:nth-child(3)', 'to', 29); |
| 82 | $t->element_count_is('layer spanList span', 3); |
Marc Kupietz | 179f221 | 2021-07-16 18:37:04 +0200 | [diff] [blame] | 83 | |
| 84 | $string = "J'ai j'habite qu'il d'un jusqu'à Aujourd'hui D'accord Quelqu'un Presqu'île"; |
| 85 | $ext->reset; |
| 86 | $ext->tokenize($string); |
| 87 | $str = $ext->to_string('unknown'); |
| 88 | $t = Test::XML::Loy->new($str); |
| 89 | $t->element_count_is('layer spanList span', 15); |
| 90 | |
| 91 | $string = "isn't I've we'll you're"; |
| 92 | $ext->reset; |
| 93 | $ext->tokenize($string); |
| 94 | $str = $ext->to_string('unknown'); |
| 95 | $t = Test::XML::Loy->new($str); |
| 96 | $t->element_count_is('layer spanList span', 8); |
| 97 | |
| 98 | $string = "Lu'hafen W'schaft gibt's"; |
| 99 | $ext->reset; |
| 100 | $ext->tokenize($string); |
| 101 | $str = $ext->to_string('unknown'); |
| 102 | $t = Test::XML::Loy->new($str); |
| 103 | $t->element_count_is('layer spanList span', 3); |
| 104 | |
Marc Kupietz | dcd38b3 | 2022-01-14 13:23:37 +0100 | [diff] [blame] | 105 | $string = "'Luhafen 'Wschaft"; |
| 106 | $ext->reset; |
| 107 | $ext->tokenize($string); |
| 108 | $str = $ext->to_string('unknown'); |
| 109 | $t = Test::XML::Loy->new($str); |
| 110 | $t->element_count_is('layer spanList span', 4); |
| 111 | |
Marc Kupietz | 1e882fb | 2020-09-09 00:05:46 +0200 | [diff] [blame] | 112 | done_testing; |