Mecabist.pm

filter: Statementstmt 88.2% 15 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.3% 21 / 23 CC 1 SCAR 0.5
CC
1
Cov
88%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Mecabist/Iter.pm ↑ Summary
1 package Text::Mecabist;
2 7 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 our $VERSION = "0.02";
6  
7 7 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 0 ▶use Text::MeCab;
Subroutine BEGIN: called CC=1 SCAR=2.6
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__
« Mecabist/Iter.pm ↑ Summary