blib/lib/App/cdif/Command/Mecab.pm

filter: Statementstmt 39.5% 19 / 48 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 6 / 12 Podpod 0.0% 0 / 2 totaltotal 32.8% 25 / 76 CC 9 SCAR 24.6
CC
9
Cov
31%
wordlist
30.0
__ANON__
12.0
uniqchar
12.0
CRAP 11.7
« script/cdif ↑ Summary blib/lib/App/sdif/Util.pm »
1 package App::cdif::Command::Mecab;
2  
3 15 ▶use parent "App::cdif::Command";
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 15 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 15 our $debug;
12  
13 0 ▶sub wordlist {
Subroutine wordlist: not called CC=5 SCAR=34.0
Pod undocumented
14 0 my $obj = shift;
15 0 my $text = shift;
16  
17 ##
18 ## mecab ignores trailing spaces.
19 ##
20 0 ▶ my $removeme = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
21 0 local *_ = shift;
22 0 ▶ return sub { 0 } unless /[ \t]+$/m;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless /[ \t]+$/mu 0 0 0
23 0 my $magic = "15570"."67583";
24 0 ▶ $magic++ while /$magic/;
Branch: 1 branch
BranchTrueFalseTotal
/$magic/u and do { ++$magic } 0 0 0
25 0 s/[ \t]+\K$/$magic/mg;
26 0 ▶ sub { $_ eq $magic };
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 }->(\$text);
28  
29 0 my $eos = "EOS" . "000";
30 0 ▶ $eos++ while $text =~ /$eos/;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /$eos/u and do { ++$eos } 0 0 0
31 0 ▶ my $is_newline = sub { $_ eq $eos };
Subroutine __ANON__: not called CC=1 SCAR=6.9
32  
33 0 my @mecab = ('mecab', '--node-format', '%M\\n', '--eos-format', "$eos\\n");
34 0 my $result = $obj->command(@mecab)->setstdin($text)->update->data;
35 0 ▶ warn $result =~ s/^/MECAB: /mgr if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $App::cdif::Command::Mecab::debug 0 0 0
36 0 do {
37 0 ▶ map { $is_newline->() ? "\n" : $_ }
Branch: 1 branch
BranchTrueFalseTotal
&$is_newline() ? : 0 0 0
38 0 grep { not $removeme->() }
39 0 ▶ map { /\A\w/ ? $_ : uniqchar($_) }
Branch: 1 branch
BranchTrueFalseTotal
/\A\w/u ? : 0 0 0
40 0 grep { length }
41 $result =~ /^([^\w\n]*+)(.*)\n/mg;
42 };
43 }
44  
45 0 ▶sub uniqchar {
Subroutine uniqchar: not called CC=3 SCAR=24.8
Pod undocumented
46 0 my @s;
47 0 for (@_) {
48 0 ▶ while (/(\X)\g{-1}*/pg) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(\X)\g{-1}*/gpu) 0 0 0
49 0 push @s, ${^MATCH};
50 }
51 }
52 0 @s;
53 }
54  
55 15 1;
« script/cdif ↑ Summary blib/lib/App/sdif/Util.pm »