line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Mecabist; |
2
|
6
|
|
|
6
|
|
67514
|
use 5.010001; |
|
6
|
|
|
|
|
15
|
|
3
|
6
|
|
|
6
|
|
22
|
use strict; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
93
|
|
4
|
6
|
|
|
6
|
|
24
|
use warnings; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
230
|
|
5
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
3237
|
use Moo; |
|
6
|
|
|
|
|
55208
|
|
|
6
|
|
|
|
|
24
|
|
8
|
6
|
|
|
6
|
|
9164
|
use Encode; |
|
6
|
|
|
|
|
44065
|
|
|
6
|
|
|
|
|
354
|
|
9
|
6
|
|
|
6
|
|
4237
|
use Text::MeCab; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Text::Mecabist::Document; |
11
|
|
|
|
|
|
|
use Text::Mecabist::Node; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has mecab => (is => 'rw'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $encoding; |
16
|
|
|
|
|
|
|
sub encoding { |
17
|
|
|
|
|
|
|
$encoding ||= Encode::find_encoding(Text::MeCab::ENCODING); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub BUILD { |
21
|
|
|
|
|
|
|
my ($self, $args) = @_; |
22
|
|
|
|
|
|
|
my $mecab = delete $args->{mecab} || Text::MeCab->new($args); |
23
|
|
|
|
|
|
|
$self->mecab($mecab); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub parse { |
27
|
|
|
|
|
|
|
my ($self, $text, $cb) = @_; |
28
|
|
|
|
|
|
|
my $doc = Text::Mecabist::Document->new; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$text = $self->encoding->encode($text); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
for my $part (split /(\s+)/, $text) { |
33
|
|
|
|
|
|
|
if ($part =~ /^\s+$/) { |
34
|
|
|
|
|
|
|
my $node = Text::Mecabist::Node->new({ |
35
|
|
|
|
|
|
|
text => $part, |
36
|
|
|
|
|
|
|
}); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$doc->add($node); |
39
|
|
|
|
|
|
|
next; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
foreach ( |
43
|
|
|
|
|
|
|
my $node = $self->mecab->parse($part); |
44
|
|
|
|
|
|
|
$node; |
45
|
|
|
|
|
|
|
$node = $node->next() |
46
|
|
|
|
|
|
|
) { |
47
|
|
|
|
|
|
|
my $node = Text::Mecabist::Node->new($node, $self); |
48
|
|
|
|
|
|
|
$doc->add($node); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
if ($cb) { |
53
|
|
|
|
|
|
|
$doc->each($cb); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$doc; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |