line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Mecabist; |
2
|
7
|
|
|
7
|
|
81378
|
use 5.010001; |
|
7
|
|
|
|
|
18
|
|
3
|
7
|
|
|
7
|
|
24
|
use strict; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
131
|
|
4
|
7
|
|
|
7
|
|
28
|
use warnings; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
287
|
|
5
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
3201
|
use Moo; |
|
7
|
|
|
|
|
67146
|
|
|
7
|
|
|
|
|
29
|
|
8
|
7
|
|
|
7
|
|
10739
|
use Encode; |
|
7
|
|
|
|
|
54686
|
|
|
7
|
|
|
|
|
399
|
|
9
|
7
|
|
|
7
|
|
5229
|
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__ |