| 1 | package String::Equivalence::Amharic; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # If either of these next two lines are inside | ||||||||||||||||||||||||||||
| 4 | # the BEGIN block the package will break. | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | 2 | binmode(STDOUT, ":utf8"); | |||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Regexp::Ethiopic::Amharic qw(:forms overload setForm subForm %AmharicEquivalence); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | BEGIN | ||||||||||||||||||||||||||||
| 13 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use base qw( Exporter ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use vars qw( $VERSION @EXPORT %HaMaps ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | $VERSION = "0.08"; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | @EXPORT = qw( &downgrade &inflate &isEquivalentTo &isReducible &hasEquivalence ); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | %HaMaps =( | |||||||||||||||||||||||||||
| 22 | ሐ => "ኀኃሀሃ", | ||||||||||||||||||||||||||||
| 23 | ኀ => "ሐኃሀሃ", | ||||||||||||||||||||||||||||
| 24 | ኃ => "ኀሐሀሃ", | ||||||||||||||||||||||||||||
| 25 | ሓ => "ሐኀኃሀሃ", | ||||||||||||||||||||||||||||
| 26 | ኻ => "ሀሃ", | ||||||||||||||||||||||||||||
| 27 | ኍ => "ኁሁሑ" | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub new | ||||||||||||||||||||||||||||
| 33 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | 2 | bless ( {}, shift ); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub _downgradeMultiTarget | ||||||||||||||||||||||||||||
| 39 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_downgradeMultiTarget: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 40 | 1 | my ( $list, $re, $from, $targets ) = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | my @to = split ( //, $targets ); | |||||||||||||||||||||||||||
| 43 | 1 | my @outList = (); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | foreach my $to (@to) { | |||||||||||||||||||||||||||
| 46 | 4 | my @newList; | |||||||||||||||||||||||||||
| 47 | 4 | ▶ | for (my $i=0; $i < @{$list}; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 8 | $newList[$i] = $list->[$i]; # copy old list | |||||||||||||||||||||||||||
| 49 | 8 | $newList[$i] =~ s/$from/$to/; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 4 | push ( @outList, @newList ); # add new keys to old keys | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 1 | push ( @{$list}, @outList ); # add new keys to old keys | |||||||||||||||||||||||||||
| 54 | 1 | $$re =~ s/$from(?!\])/[$from$targets]/; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub _downgrade | ||||||||||||||||||||||||||||
| 59 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_downgrade: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 60 | 1 | my ( $list, $re, $from, $to ) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | ▶ | unless ( $to ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 1 | $to = $from; | |||||||||||||||||||||||||||
| 64 | 1 | $to =~ tr/ሀሃሗሠ-ሧኣእኧቍኵጕቈኰጐቆኮጎዑዒዔዕዖፀ-ፆኹኺኼኽኾ/ሃሀኋሰ-ሷአእቁኩጉቆኮጎቈኰጐዕኡኢኤእኦጸ-ጾሁሂሄህሆ/; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 1 | my @newList; | |||||||||||||||||||||||||||
| 68 | 1 | ▶ | for (my $i=0; $i < @{$list}; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 1 | $newList[$i] = $list->[$i]; # copy old list | |||||||||||||||||||||||||||
| 70 | 1 | $newList[$i] =~ s/$from/$to/; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 1 | push ( @{$list}, @newList ); # add new keys to old keys | |||||||||||||||||||||||||||
| 73 | 1 | $$re =~ s/$from(?!\])/[$from$to]/; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | sub downgrade | ||||||||||||||||||||||||||||
| 78 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
downgrade: called CC=12 SCAR=30.4
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 1 | my $self; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | ($self, $_) = @_; | |||||||||||||||||||||||||||
| 82 | 1 | ▶ | $_ = $self unless ( ref($self) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 1 | my @list = ( $_ ); | |||||||||||||||||||||||||||
| 85 | 1 | my $re = $_; | |||||||||||||||||||||||||||
| 86 | 1 | my @letters = split ( // ); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | foreach ( @letters ) { | |||||||||||||||||||||||||||
| 89 | 3 | ▶ | if ( /([#ሠፀ#]|[ሀሃሗኣእኧቍኵጕቈኰጐቆኮጎዑዒዔዕዖኹኺኼኽኾ])/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 1 | my $from = $1; | |||||||||||||||||||||||||||
| 91 | 1 | ▶ | _downgrade ( \@list, \$re, $from ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$from eq "\x{12a5}" and $re =~ /^\x{12a5}/
MC/DC0%0/2
$from eq "\x{12a5}" and $re =~ /^\x{12a5}/
$from eq "\x{12a5}"
$re =~ /^\x{12a5}/
Truth table33%1/3
A and B
A= $from eq "\x{12a5}"B= $re =~ /^\x{12a5}/
| |||||||||||||||||||||||||||||
| 92 | unless ( $from eq "እ" && $re =~ /^እ/ ); | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 3 | ▶ | if ( /([ዓዐ])/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $to = ( $1 eq "ዓ" ) ? "አዐ" : "አዓ" ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | _downgradeMultiTarget ( \@list, \$re, $1, $to ); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 3 | ▶ | if ( /([ሑሒሔሕሖኁኂኄኅኆ])/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | my $from = $1; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $compliment = ( $from =~ /[#ኀ#]/ ) ? "ሐ" : "ኀ" ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | my $to = subForm ( $compliment, $from ).subForm ( 'ሀ', $from ); | |||||||||||||||||||||||||||
| 102 | 0 | _downgradeMultiTarget ( \@list, \$re, $from, $to ); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | 3 | ▶ | if ( /([ሐኀኃሓኻኍ])/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 1 | my $to = $HaMaps{$1}; | |||||||||||||||||||||||||||
| 106 | 1 | _downgradeMultiTarget ( \@list, \$re, $1, $to ); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | ▶ | wantarray ? ( @list, $re ) : $list[$#list] ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | sub isReducible | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
isReducible: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 0 | my $self; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ($self, $_) = @_; | |||||||||||||||||||||||||||
| 120 | 0 | ▶ | $_ = $self unless ( ref($self) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | /[#ሐኀሠዐፀ#]|[ቍኍኵጕቈኈኰጐ]/; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | sub hasEquivalence | ||||||||||||||||||||||||||||
| 128 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
hasEquivalence: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 129 | 0 | my $self; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ($self, $_) = @_; | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | $_ = $self unless ( ref($self) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | /[=#ሀሠዐፀ#=]|[=ቍ=]|[=ኍ=]|[=ኵ=]|[=ጕ=]|[=ቈ=]|[=ኈ=]|[=ኰ=]|[=ጐ=]/; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | sub _inflate | ||||||||||||||||||||||||||||
| 139 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_inflate: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 140 | 2 | my ($re, @words); | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 2 | foreach (@_) { | |||||||||||||||||||||||||||
| 143 | 3 | $re = $_; | |||||||||||||||||||||||||||
| 144 | 3 | $re =~ s/\[(\w+)\]/<replace>/; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 3 | my @letters = split ( //, $1 ); | |||||||||||||||||||||||||||
| 147 | 3 | foreach ( @letters ) { | |||||||||||||||||||||||||||
| 148 | 14 | push ( @words,$re ); | |||||||||||||||||||||||||||
| 149 | 14 | $words[ $#words ] =~ s/<replace>/$_/; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 2 | ▶ | if ( $words[0] =~ /\[/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 1 | push ( @words, _inflate( @words ) ); | |||||||||||||||||||||||||||
| 156 | 1 | @words = grep { !/\[/ } @words; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 2 | return @words; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | sub inflate | ||||||||||||||||||||||||||||
| 164 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
inflate: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 165 | 1 | my $self; | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 1 | ($self, $_) = @_; | |||||||||||||||||||||||||||
| 168 | 1 | ▶ | $_ = $self unless ( ref($self) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 1 | my @words = ( $_ ); | |||||||||||||||||||||||||||
| 171 | 1 | my $re = $_; | |||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 1 | my @letters = split ( // ); | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 1 | foreach ( @letters ) { | |||||||||||||||||||||||||||
| 176 | 3 | ▶ | if ( $AmharicEquivalence{$_} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | # | ||||||||||||||||||||||||||||
| 178 | # these next 3 lines are here to skip over old Amharic | ||||||||||||||||||||||||||||
| 179 | # | ||||||||||||||||||||||||||||
| 180 | 2 | my $equiv = $AmharicEquivalence{$_}; | |||||||||||||||||||||||||||
| 181 | 2 | $equiv =~ s/[#ኸ#]//g; | |||||||||||||||||||||||||||
| 182 | 2 | $re =~ s/$_/[$equiv]/g; | |||||||||||||||||||||||||||
| 183 | # $re =~ s/$_/[$AmharicEquivalence{$_}]/g; | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 1 | ▶ | if ( $re =~ /\[/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 1 | push ( @words, _inflate( $re ) ); | |||||||||||||||||||||||||||
| 189 | 1 | @words = grep { !/\[/ } @words; | |||||||||||||||||||||||||||
| 190 | 1 | push ( @words, $re ); | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 1 | return @words; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | sub isEquivalentTo | ||||||||||||||||||||||||||||
| 198 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
isEquivalentTo: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 199 | 0 | my ($self, $a, $b) = @_; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | unless ( ref($self) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 0 | $b = $a; | |||||||||||||||||||||||||||
| 203 | 0 | $a = $self; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | my @b = $self->inflate( $b ); | |||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 0 | ( $a =~ /^$b[$#b]$/ ); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | ######################################################### | ||||||||||||||||||||||||||||
| 213 | # Do not change this, Do not put anything below this. | ||||||||||||||||||||||||||||
| 214 | # File must return "true" value at termination | ||||||||||||||||||||||||||||
| 215 | 2 | 1; | |||||||||||||||||||||||||||
| 216 | ########################################################## | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | __END__ | ||||||||||||||||||||||||||||