| 1 | package Lingua::EN::Inflexion; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 32 | ▶ | use 5.010; use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 32 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 32 | our $VERSION = '0.002007'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Import noun, verb, and adj classes... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 32 | ▶ | use Lingua::EN::Inflexion::Term; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 32 | ▶ | my (undef, @exports) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # Export interface... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 32 | ▶ | @exports = qw< noun verb adj inflect wordlist > if !@exports; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # Handle renames... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 32 | my %export_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 32 | ▶ | @exports = map { ref eq 'HASH' ? do { @export_name{keys %$_} = values %$_; keys %$_ } : $_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | @exports; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 32 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 32 | for my $func (@exports) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 158 | ▶ | *{caller().'::'.($export_name{$func}//$func)} = \&{$func}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$export_name{$func} // $func
MC/DC0%0/2
$export_name{$func} // $func
$export_name{$func}
$func
Truth table66%2/3
A // B
A= $export_name{$func}B= $func
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # Noun constructor... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | sub noun ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 21835 | ▶ | my ($noun) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
noun: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 21835 | return Lingua::EN::Inflexion::Noun->new($noun); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # Verb constructor... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | sub verb ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 4173 | ▶ | my ($verb) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verb: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 4173 | return Lingua::EN::Inflexion::Verb->new($verb); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # Adjective constructor... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | sub adj ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 152 | ▶ | my ($adj) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
adj: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 152 | return Lingua::EN::Inflexion::Adjective->new($adj); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # Convert a list of words to...a list of words in a single string... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | sub wordlist { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 29 | ▶ | my (@words, %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wordlist: called CC=9 SCAR=22.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # Unpack the argument list... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 29 | my $sep = ','; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 29 | my $conj = 'and'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 29 | for my $arg (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 101 | my $argtype = ref($arg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 101 | ▶ | if ($argtype eq q{}) { push @words, $arg; $sep = ';' if $arg =~ /,/; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 24 | elsif ($argtype eq q{HASH}) { @opt{keys %$arg} = values %$arg } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | else { croak 'Invalid $argtype argument to wordlist' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # Fill in defaults... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 29 | ▶ | $conj = $opt{conj} // $conj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opt{"conj"} // $conj
MC/DC0%0/2
$opt{"conj"} // $conj
$opt{"conj"}
$conj
Truth table66%2/3
A // B
A= $opt{"conj"}B= $conj
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 29 | ▶ | $sep = $opt{sep} // $sep; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opt{"sep"} // $sep
MC/DC0%0/2
$opt{"sep"} // $sep
$opt{"sep"}
$sep
Truth table33%1/3
A // B
A= $opt{"sep"}B= $sep
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # Set the Oxford comma... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 29 | ▶ | my $oxford = $opt{final_sep} // $sep; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opt{"final_sep"} // $sep
MC/DC0%0/2
$opt{"final_sep"} // $sep
$opt{"final_sep"}
$sep
Truth table66%2/3
A // B
A= $opt{"final_sep"}B= $sep
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # Construct the list phrase... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 29 | ▶ | my $list = @words < 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ? join(" $conj ", @words) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | : join("$sep ", @words[0..$#words-1]) . "$oxford $conj $words[-1]"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # Condense any extra whitespace... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 29 | $list =~ s/(\s)\s+/$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 29 | return $list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # All-in-one inflexions... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 32 | my %word_for_number = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 => 'zero', 5 => 'five', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 => 'one', 6 => 'six', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 => 'two', 7 => 'seven', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 => 'three', 8 => 'eight', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 => 'four', 9 => 'nine', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 10 => 'ten', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | my $normalize_opts = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 64 | ▶ | my ($opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 64 | ▶ | if ($opts =~ m{ [[:upper:]] }x) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $opts =~ s{ [[:lower:]] }{}gx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 64 | return lc $opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 32 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | sub inflect($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 22 | ▶ | my ($string) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inflect: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 22 | my $inflexion = 'singular'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | my $transform = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 'N' => sub{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 21 | ▶ | my ($term, $opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | carp "Unknown '$_' option to <N:...> command" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 21 | for $opts =~ /([^cps])/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 21 | my $word = noun($term); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 21 | ▶ | $word = $word->classical if $opts =~ /c/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 21 | ▶ | return $opts =~ /p/i ? $word->plural | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | : $opts =~ /s/i ? $word->singular | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | : $word->$inflexion; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 21 | ▶ | 'V' => sub{ return verb(shift)->$inflexion; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | 'A' => sub{ return adj(shift)->$inflexion; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | '#' => sub{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 22 | ▶ | my ($count, $opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=21 SCAR=31.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 22 | $opts =~ s{e}{asw}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | carp "Unknown '$_' option to <#:...> command" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 22 | for $opts =~ /([^acdefinosw\d])/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Increment count if requested... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 22 | ▶ | if ($opts =~ /i/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | $count++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # Decide which inflexion the count requires... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | $inflexion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 22 | ▶ | = $count == 1 || $opts =~ /s/i && $count == 0 || $opts =~ /o/i ? 'singular' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
$count == 1 or $opts =~ /s/i and $count == 0 or $opts =~ /o/i
$count == 1 or $opts =~ /s/i and $count == 0
$opts =~ /s/i and $count == 0
MC/DC25%1/4
$count == 1 or $opts =~ /s/i and $count == 0 or $opts =~ /o/i
$count == 1
$opts =~ /s/i
$count == 0
$opts =~ /o/i
Truth table33%2/6
A or B and C or D
A= $count == 1B= $opts =~ /s/iC= $count == 0D= $opts =~ /o/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | : 'plural'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # Defer handling of A/AN... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 22 | ▶ | if ($count == 1 && $opts =~ /a/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$count == 1 and $opts =~ /a/i
MC/DC100%2/2
$count == 1 and $opts =~ /a/i
$count == 1
$opts =~ /a/i
Truth table100%3/3
A and B
A= $count == 1B= $opts =~ /a/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | return "<#a:>"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 20 | ▶ | my $count_word = $opts =~ /w|o/i ? noun($count) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 20 | ▶ | $count_word = $count_word->classical if $count_word && $opts =~ /c/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$count_word and $opts =~ /c/i
MC/DC0%0/2
$count_word and $opts =~ /c/i
$count_word
$opts =~ /c/i
Truth table66%2/3
A and B
A= $count_wordB= $opts =~ /c/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 20 | ▶ | my $count_thresh = $opts =~ /w(\d+)/i ? $1 : 11; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # Otherwise, interpolate count or its equivalent (deferring fuzzies)... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 20 | ▶ | return $opts =~ /n|s/i && $count == 0 ? 'no' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition83%5/6
$opts =~ /n|s/i and $count == 0
$opts =~ /w/i and $opts =~ /o/i
MC/DC100%2/2
$opts =~ /n|s/i and $count == 0
$opts =~ /n|s/i
$count == 0
MC/DC0%0/2
$opts =~ /w/i and $opts =~ /o/i
$opts =~ /w/i
$opts =~ /o/i
Truth table100%3/3
A and B
A= $opts =~ /n|s/iB= $count == 0
Truth table66%2/3
A and B
A= $opts =~ /w/iB= $opts =~ /o/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | : $opts =~ /w/i && $opts =~ /o/i ? $count_word->ordinal($count_thresh) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | : $opts =~ /w/i ? $count_word->cardinal($count_thresh) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | : $opts =~ /o/i ? $count_word->ordinal(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | : $opts =~ /f/i ? "<#f:$count>" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | : $opts =~ /d/ ? q{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | : $count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 22 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # Inflect markups... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 22 | $string =~ s{ (?<ORIG> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | < (?<FUNC> (?-i: [#NVA] ) ) # FUNC is case-sensitive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | (?<OPTS> [^:]* ) \s* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | : \s* (?<TERM> [^>]+? ) \s* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | (?<TWS> \s* ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | }{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 64 | my %parsed = %+; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 64 | my $opts = $normalize_opts->($parsed{OPTS}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 64 | ▶ | my $func = $transform->{ uc $parsed{FUNC} } // sub{shift}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
$$transform{uc $parsed{"FUNC"}} // sub {
shift();
}
MC/DC0%0/2
$$transform{uc $parsed{"FUNC"}} // sub {
shift();
}
$$transform{uc $parsed{"FUNC"}}
sub {
shift();
}
Truth table33%1/3
A // B
A= $$transform{uc $parsed{"FUNC"}}B= sub {
shift();
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 64 | my $replacement = $func->( $parsed{TERM}, $opts ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 63 | ▶ | length $replacement > 0 ? $replacement . $parsed{TWS} : q{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | }gexmsi; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # Inflect consequent A/AN's... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 21 | $string =~ s{ <[#]a:> \s*+ (?<next_word> \S++) }{ noun($+{next_word})->indefinite }gxe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 21 | $string =~ s{ <[#]a:> \s*+ \Z }{ "a" }xe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # Inflect fuzzies... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | state $fuzzy = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | my ($count, $is_postfix) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | return $count >= 10 ? 'many' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | : $count >= 6 ? 'several' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | : $count >= 3 ? 'a few' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | : $count == 2 ? 'a couple' . ($is_postfix ? q{} : ' of') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | : $count == 1 ? 'one' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | : ($is_postfix ? 'none' : 'no') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 21 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 21 | $string =~ s{ <\#f: (?<count> \d++) > (?= \s*+ [[:alpha:]]) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | { $fuzzy->($+{count}) }gxe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 21 | $string =~ s{ <\#f: (?<count> \d++) > (?= [^[:alpha:]]*+ \Z) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | { $fuzzy->($+{count}, 'postfix') }xe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # And we're done... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 21 | return $string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 32 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||