1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
use strict;
use utf8;
use Test::More qw(no_plan);
use Encode qw(encode from_to);
BEGIN
{
use_ok("Text::MeCab");
}
my $text = encode(Text::MeCab::ENCODING, "となりの客は良く柿食う客だ");
my $mecab = Text::MeCab->new({
node_format => "%m",
});
for( my $node = $mecab->parse($text);
$node;
$node = $node->next
) {
my $surface = $node->surface;
from_to( $surface, Text::MeCab::ENCODING, 'utf-8');
next unless $surface;
my $format = $node->format($mecab);
my $feature = $node->feature;
if (ok($format, "format returns " . (defined $format ? $format : '(null)') . "'")) {
unlike($format, qr/,/, "'$format' doesn't contain any comma");
like($feature, qr/,/, "'$feature' does contain commas");
}
}
for( my $node = $mecab->parse($text)->dclone;
$node;
$node = $node->next
) {
my $surface = $node->surface;
from_to( $surface, Text::MeCab::ENCODING, 'utf-8');
next unless $surface;
my $format = $node->format($mecab);
my $feature = $node->feature;
if (ok($format, "format returns '" . (defined $format ? $format : '(null)') . "' for surface '$surface'") ) {
unlike($format, qr/,/, "'$format' doesn't contain any comma");
like($feature, qr/,/, "'$feature' does contain commas");
}
}
|