TransMetaphone/am.pm

filter: Statementstmt 73.4% 58 / 79 Branchbran 59.0% 13 / 22 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 70.6% 82 / 116 CC 13 SCAR 27.9
CC
13
Cov
70%
trans_metaphone
24.5
BEGIN
1.0
BEGIN
1.0
CRAP 16.3
« TransMetaphone/he.pm ↑ Summary TransMetaphone.pm »
1 package Text::TransMetaphone::am;
2  
3 # If either of these next two lines are inside
4 # the BEGIN block the package will break.
5 #
6 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Regexp::Ethiopic::Amharic qw(:forms setForm overload);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 BEGIN
10 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶ use vars qw( $VERSION $LocaleRange %IMExpected %IMError %plosives );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 $VERSION = '0.10';
16  
17 1 $LocaleRange = qr/[ሀ-ቍበ-ኾዐ-ዷጀ-ጕጠ-፼]/;
18  
19 1 %plosives = (
20 k => 'ቀ',
21 t => 'ጠ',
22 ʧ => 'ጨ',
23 s => 'ጸ',
24 p => 'ጰ',
25 );
26 1 %IMExpected =(
27 ስ => "s",
28 ጽ => "s'",
29 ቅ => "k'",
30 ቕ => "q",
31 ት => "t",
32 ጥ => "t'",
33 ች => "ʧ",
34 ጭ => "ʧ",
35 ን => "n",
36 ክ => "k",
37 ዝ => "z",
38 ዥ => "ʒ",
39 ጵ => "p'",
40 ፕ => "p"
41 );
42 1 %IMError =(
43 ስ => "s'",
44 ጽ => "s",
45 ቅ => "q",
46 ቕ => "k'",
47 ት => "t'",
48 ጥ => "t",
49 ች => "ʧ'",
50 ጭ => "ʧ'",
51 ን => "ɲ",
52 ክ => "x",
53 ዝ => "ʒ",
54 ዥ => "z",
55 ጵ => "p",
56 ፕ => "p'"
57 );
58 }
59  
60  
61 sub trans_metaphone
62 1 ▶{
Subroutine trans_metaphone: called CC=13 SCAR=32.0
Pod undocumented
63  
64 1 $_ = $_[0];
65  
66 #
67 # strip out all but first vowel:
68 #
69 1 s/^[=#አ#=]/a/;
70 1 s/[=#አ#=]//g;
71  
72 0 s/([#11#])/setForm($1,$ሳድስ)."ዋ"/eg;
73 1 s/[=#ሀ#=]/h/g;
74 1 s/[=#ሰ#=]/ሰ/g;
75 1 s/[=#ጸ#=]/ጸ/g;
76 # s/(.)[=#ጸ#=]/s'/g; # compare this to ts in english, it should be a 2nd key
77  
78 #
79 # now strip vowels, this simplies later code:
80 #
81 1 ▶ s/(\p{InEthiopic})/ ($1 eq 'ኘ') ? $1 : setForm($1,$ሳድስ)/eg;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq "\x{1298}" ? : 0 4 4
82  
83 1 tr/ልምርሽብቭውይድጅግፍ/lmrʃbvwjdʤgf/;
84  
85  
86 1 my @keys = ( $_ );
87 1 my $re = $_;
88  
89  
90 #
91 # mixed glyphs: ዽ for ጵ or ዽ is shift stick for ድ
92 #
93 1 ▶ if ( $keys[0] =~ /ዽ/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keys[0] =~ /\x{12fd}/) 0 1 1
94 0 $keys[2] = $keys[1] = $keys[0];
95 0 $keys[0] =~ s/ዽ/ɗ/; # caps problem
96 0 $keys[1] =~ s/ዽ/d/; # literal
97 0 $keys[2] =~ s/ዽ/p'/; # mistaken glyph
98 0 $re =~ s/ዽ/([dɗ]|p')/g;
99 }
100 #
101 # mixed glyphs: ኘ for ፕ or ኘ is shift stick for ነ
102 #
103 1 ▶ if ( $keys[0] =~ /ኘ/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keys[0] =~ /\x{1298}/) 0 1 1
104 0 my (@newKeysA, @newKeysB);
105 0 ▶ for (my $i=0; $i < @keys; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @keys) 0 0 0
106 0 $newKeysA[$i] = $newKeysB[$i] = $keys[$i]; # copy old keys
107 0 $keys[$i] =~ s/ኘ/ɲ/; # literal
108 0 $newKeysA[$i] =~ s/ኘ/n/; # caps problem
109 0 $newKeysB[$i] =~ s/ኘ/p/; # mistaken glyph
110 }
111 0 push (@keys,@newKeysA); # add new keys to old keys
112 0 push (@keys,@newKeysB); # add new keys to old keys
113 0 $re =~ s/ኘ/[nɲp]/g;
114 }
115 #
116 # handle phonological problems
117 #
118 1 ▶ if ( $keys[0] =~ /mb/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keys[0] =~ /mb/) 0 1 1
119 0 my @newKeys;
120 0 ▶ for (my $i=0; $i < @keys; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @keys) 0 0 0
121 0 $newKeys[$i] = $keys[$i]; # copy old keys
122 0 $newKeys[$i] =~ s/mb/nb/; # update old keys for primary mapping
123 }
124 0 push (@keys,@newKeys); # add new keys to old keys
125 0 $re =~ s/mb/[mn]b/g;
126 }
127  
128 #
129 # try to keep least probable keys last:
130 #
131 #
132 # Handle IM problems
133 #
134 1 ▶ while ( $keys[0] =~ /([ስቅቕትችንክዝዥጥጭጽጵፕ])/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keys[0] =~ /([\x{1235}\x{1245}\x{1255}\x{1275}\x{127d}\x{1295}\x{12ad}\x{12dd}\x{12e5}\x{1325}\x{132d}\x{133d}\x{1335}\x{1355}])/) 2 1 3
135 2 my $a = $1;
136 2 my @newKeys;
137 2 ▶ for (my $i=0; $i < @keys; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @keys) 3 2 5
138 3 $newKeys[$i] = $keys[$i]; # copy old keys
139 3 $keys[$i] =~ s/$a/$IMExpected{$a}/; # update old keys for primary mapping
140 }
141 2 ▶ for (my $i=0; $i < @newKeys; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @newKeys) 3 2 5
142 3 $newKeys[$i] =~ s/$a/$IMError{$a}/; # update new keys for alternative
143 }
144 2 push (@keys,@newKeys); # add new keys to old keys
145  
146 # print "$a => $IMExpected{$a} / $IMError{$a}\n";
147 2 ▶ if ( $plosives{$IMExpected{$a}} || $plosives{$IMError{$a}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plosives{$IMExpected{$a}} or $plosives{$IMError{$a}}) { } 1 1 2
Condition66%2/3
$plosives{$IMExpected{$a}} or $plosives{$IMError{$a}}
l!l&&r!l&&!r
101
MC/DC50%1/2
$plosives{$IMExpected{$a}} or $plosives{$IMError{$a}}
$plosives{$IMExpected{$a}} $plosives{$IMError{$a}}
Truth table66%2/3
A or B
A= $plosives{$IMExpected{$a}}B= $plosives{$IMError{$a}}
ABresult
1X1
011
000
148 1 $re =~ s/$a/($IMExpected{$a}|$IMError{$a})/g;
149 }
150 else {
151 1 $re =~ s/$a/[$IMExpected{$a}$IMError{$a}]/g;
152 }
153 }
154  
155 1 ▶ if ( $#keys ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#keys) 1 0 1
156 1 push ( @keys, qr/$re/ );
157 }
158  
159 1 @keys;
160 }
161  
162  
163 sub reverse_key
164 1 ▶{
Subroutine reverse_key: called CC=1 SCAR=0.0
Pod undocumented
165 1 $_ = $_[0];
166
167 1 s/([stʧkp])'/$plosives{$1}/g;
168 1 tr/hlmrsʃqbvtʧnɲakwjdɗʤzʒgɲfp/ሀለመረሰሸቐበቨተቸነኘአከወየደዸጀዘዠገጘፈፐ/;
169 1 s/(\p{InEthiopic})/[#$1#]/g;
170 1 s/ዸ/ደዸ/g;
171 1 s/ጘ/ገጘ/g;
172  
173 1 $_;
174 }
175  
176  
177  
178 #########################################################
179 # Do not change this, Do not put anything below this.
180 # File must return "true" value at termination
181 1 1;
182 ##########################################################
183  
184 __END__
« TransMetaphone/he.pm ↑ Summary TransMetaphone.pm »