Normal/Type/Title.pm

filter: Statementstmt 100% 39 / 39 Branchbran 83.3% 5 / 6 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 95.1% 59 / 62 CC 8 SCAR 16.1
CC
8
Cov
96%
transform
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.0
« Normal/Config/BusinessStop.pm ↑ Summary Normal/Config/AddressStop.pm »
1 package String::Normal::Type::Title;
2 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use String::Normal::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use String::Normal::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use Lingua::Stem;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 our $STEM;
9 9 our $title_stem;
10 9 our $title_stop;
11  
12 6 ▶sub transform {
Subroutine transform: called CC=8 SCAR=20.8
Pod documented
13 6 my ($self,$value) = @_;
14  
15 6 ▶ $value =~ s/\([^)]*\)/ /g if $value =~ /^[^(]|[^)]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^[^(]|[^)]$/ 6 0 6
16  
17 6 $value = String::Normal::Type::_scrub_value( $value );
18  
19 # tokenize and stem
20 6 my @tokens = ();
21 6 for my $token (split ' ', $value) {
22 #$token = defined( $title_stem->{$token} ) ? $title_stem->{$token} : $token;
23 24 push @tokens, $token;
24 }
25  
26 # Remove all middle stop words that are safe to remove, based on the number of
27 # tokens, of course.
28 my @filtered = map {
29 6 ▶ my $count = $title_stop->{middle}{$_} || '';
Condition100%2/2
$String::Normal::Type::Title::title_stop->{'middle'}{$_} || ''
l!l
1113
MC/DC100%1/1
$String::Normal::Type::Title::title_stop->{'middle'}{$_} || ''
$String::Normal::Type::Title::title_stop->{'middle'}{$_}
Truth table100%2/2
A
A= $String::Normal::Type::Title::title_stop->{'middle'}{$_}
Aresult
11
00
30 24 ▶ (length $count and @tokens >= $count) ? () : $_;
Branch: 1 branch
BranchTrueFalseTotal
length $count && @tokens >= $count ? : 11 13 24
Condition66%2/3
length $count and @tokens >= $count
!ll&&!rl&&r
13011
MC/DC50%1/2
length $count and @tokens >= $count
length $count @tokens >= $count
Truth table66%2/3
A and B
A= length $countB= @tokens >= $count
ABresult
0X0
100
111
31 } @tokens;
32  
33 # stem, but override if Stemmer "blanks out" token
34 6 my @copy = @filtered;
35 6 $STEM->stem_in_place( @copy );
36 6 for my $i (0 .. $#copy) {
37 13 ▶ $filtered[$i] = $copy[$i] unless $filtered[$i] =~ /\d/;
Branch: 1 branch
BranchTrueFalseTotal
unless $filtered[$i] =~ /\d/ 10 3 13
38 }
39  
40 6 return join ' ', @filtered;
41 }
42  
43 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
44 1 my $self = shift;
45 1 $title_stem = String::Normal::Config::TitleStem::_data( @_ );
46 1 $title_stop = String::Normal::Config::TitleStop::_data( @_ );
47 1 $STEM = Lingua::Stem->new;
48 1 $STEM->add_exceptions( $title_stem );
49 1 return bless {@_}, $self;
50 }
51  
52  
53 9 1;
54  
55 __END__
« Normal/Config/BusinessStop.pm ↑ Summary Normal/Config/AddressStop.pm »