File: 05_format.t

package info (click to toggle)
libtext-mecab-perl 0.20013-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 520 kB
  • sloc: perl: 2,637; ansic: 572; makefile: 4
file content (48 lines) | stat: -rw-r--r-- 1,325 bytes parent folder | download | duplicates (5)
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");
    }
}