| 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
| |||||||||||||||||||||||||||||
| 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'}{$_} || ''
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'}{$_}
| |||||||||||||||||||||||||||||
| 30 | 24 | ▶ | (length $count and @tokens >= $count) ? () : $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $count and @tokens >= $count
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||