line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Metaphone::Amharic; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# If either of these next two lines are inside |
4
|
|
|
|
|
|
|
# the BEGIN block the package will break. |
5
|
|
|
|
|
|
|
# |
6
|
1
|
|
|
1
|
|
961
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
7
|
1
|
|
|
1
|
|
1000
|
use Regexp::Ethiopic::Amharic qw(:forms overload setForm); |
|
1
|
|
|
|
|
38267
|
|
|
1
|
|
|
|
|
7
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
BEGIN |
10
|
|
|
|
|
|
|
{ |
11
|
1
|
|
|
1
|
|
545
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
12
|
1
|
|
|
1
|
|
5
|
use vars qw( $VERSION %IMExpected %IMError %plosives $GRANULARITY $STYLE ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
358
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
2
|
$VERSION = "0.11"; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
6
|
%plosives = ( |
17
|
|
|
|
|
|
|
ቅ => 'k', |
18
|
|
|
|
|
|
|
ጥ => 't', |
19
|
|
|
|
|
|
|
ጭ => 'ʧ', |
20
|
|
|
|
|
|
|
ጵ => 'p', |
21
|
|
|
|
|
|
|
ጽ => 's' |
22
|
|
|
|
|
|
|
); |
23
|
1
|
|
|
|
|
11
|
%IMExpected =( |
24
|
|
|
|
|
|
|
ስ => "s", |
25
|
|
|
|
|
|
|
ጽ => "s'", |
26
|
|
|
|
|
|
|
ቅ => "k'", |
27
|
|
|
|
|
|
|
ቕ => "q", |
28
|
|
|
|
|
|
|
ት => "t", |
29
|
|
|
|
|
|
|
ጥ => "t'", |
30
|
|
|
|
|
|
|
ች => "ʧ", |
31
|
|
|
|
|
|
|
ጭ => "ʧ", |
32
|
|
|
|
|
|
|
ን => "n", |
33
|
|
|
|
|
|
|
ኝ => "n", |
34
|
|
|
|
|
|
|
ክ => "k", |
35
|
|
|
|
|
|
|
ዝ => "z", |
36
|
|
|
|
|
|
|
ዥ => "ʒ", |
37
|
|
|
|
|
|
|
ጵ => "p'", |
38
|
|
|
|
|
|
|
ፕ => "p" |
39
|
|
|
|
|
|
|
); |
40
|
1
|
|
|
|
|
10
|
%IMError =( |
41
|
|
|
|
|
|
|
ስ => "ጽ", |
42
|
|
|
|
|
|
|
ጽ => "ስ", |
43
|
|
|
|
|
|
|
ቅ => "ቕ", |
44
|
|
|
|
|
|
|
ቕ => "ቅ", |
45
|
|
|
|
|
|
|
ት => "ጥ", |
46
|
|
|
|
|
|
|
ጥ => "ት", |
47
|
|
|
|
|
|
|
ች => "ጭ", |
48
|
|
|
|
|
|
|
ጭ => "ች", |
49
|
|
|
|
|
|
|
ን => "ኝ", |
50
|
|
|
|
|
|
|
ኝ => "ን", |
51
|
|
|
|
|
|
|
ክ => "ኽ", |
52
|
|
|
|
|
|
|
ዝ => "ዥ", |
53
|
|
|
|
|
|
|
ዥ => "ዝ", |
54
|
|
|
|
|
|
|
ጵ => "ፕ", |
55
|
|
|
|
|
|
|
ፕ => "ጵ" |
56
|
|
|
|
|
|
|
); |
57
|
1
|
|
|
|
|
2
|
$GRANULARITY = "low"; |
58
|
1
|
|
|
|
|
239
|
$STYLE = "ethio"; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub import |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
|
|
0
|
|
0
|
my ( $pkg, %args ) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
0
|
$STYLE = lc($args{style}) if ( $args{style} ); |
67
|
0
|
0
|
|
|
|
0
|
$GRANULARITY = lc($args{granularity}) if ( $args{granularity} ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub new |
72
|
|
|
|
|
|
|
{ |
73
|
1
|
|
|
1
|
0
|
1156
|
my $class = shift; |
74
|
1
|
|
|
|
|
6
|
my $self = { _style => $STYLE, _granularity => $GRANULARITY }; |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
7
|
my $blessing = bless ( $self, $class ); |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
3
|
%_ = @_; |
79
|
|
|
|
|
|
|
|
80
|
1
|
50
|
|
|
|
7
|
$self->{_style} = lc($_{style}) if ( $_{style} ); |
81
|
1
|
50
|
|
|
|
4
|
$self->{_granularity} = lc($_{granularity}) if ( $_{granularity} ); |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
3
|
$blessing; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _formatStyle |
88
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
0
|
|
0
|
my ($self, $keys) = @_; |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
0
|
if ( $self->{_style} eq "ipa" ) { |
|
|
0
|
|
|
|
|
|
92
|
0
|
|
|
|
|
0
|
foreach my $i ( 0..$#{$keys} ) { |
|
0
|
|
|
|
|
0
|
|
93
|
0
|
|
|
|
|
0
|
$keys->[$i] =~ s/([ቅጥጭጵጽ])/$plosives{$1}'/og; |
94
|
0
|
|
|
|
|
0
|
$keys->[$i] =~ tr/ህልምርስሽቕብትችንኝእክውይድዽጅዝዥግጝፍፕ/hlmrsʃqbtʧnɲakwjdɗʤzʒgɲfp/; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
elsif ( $self->{_style} eq "sera" ) { |
98
|
0
|
|
|
|
|
0
|
foreach my $i ( 0..$#{$keys} ) { |
|
0
|
|
|
|
|
0
|
|
99
|
0
|
|
|
|
|
0
|
$keys->[$i] =~ tr/ህልምርስሽቅቕብትችንኝእክውይድዽጅዝዥግጝጥጭጵጽፍፕ/hlmrsxqQbtcnNakwydDjzZgGTCPSfp/; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub metaphone |
107
|
|
|
|
|
|
|
{ |
108
|
9
|
|
|
9
|
0
|
3507
|
my $self = shift; |
109
|
|
|
|
|
|
|
|
110
|
9
|
|
|
|
|
27
|
$_ = $self->simplify($_[0]); |
111
|
9
|
|
|
|
|
22
|
my ($re, @keys) = $self->glyphs ( $_ ); |
112
|
9
|
|
|
|
|
22
|
($re, @keys) = $self->phono ( $re, @keys ); |
113
|
9
|
|
|
|
|
28
|
($re, @keys) = $self->im ( $re, @keys ); |
114
|
|
|
|
|
|
|
|
115
|
9
|
50
|
|
|
|
23
|
if ( @keys ) { |
116
|
9
|
|
|
|
|
102
|
push ( @keys, qr/$re/ ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
9
|
50
|
|
|
|
25
|
$self->_formatStyle ( \@keys ) if ( $self->{_style} ne "ethio" ); |
120
|
|
|
|
|
|
|
|
121
|
9
|
100
|
|
|
|
44
|
(wantarray) ? @keys : $keys[0]; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub simplify |
126
|
|
|
|
|
|
|
{ |
127
|
9
|
|
|
9
|
0
|
10
|
my $self = shift; |
128
|
|
|
|
|
|
|
|
129
|
9
|
|
|
|
|
19
|
$_ = $_[0]; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# |
132
|
|
|
|
|
|
|
# strip out all but first vowel: |
133
|
|
|
|
|
|
|
# |
134
|
9
|
|
|
|
|
35
|
s/^[=#አ#=]/አ/o; |
135
|
9
|
|
|
|
|
30
|
s/[=#ሀ#=]/ሀ/og; |
136
|
|
|
|
|
|
|
|
137
|
9
|
|
|
|
|
23
|
s/(.)[=#አ#=]/$1/g; |
138
|
|
|
|
|
|
|
|
139
|
9
|
50
|
|
|
|
29
|
if ( $self->{_granularity} eq "low" ) { |
140
|
9
|
|
|
|
|
25
|
s/(.)[#ወ#]/$1/og; |
141
|
9
|
|
|
|
|
24
|
s/(.)[#የ#]/$1/og; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
else { |
144
|
0
|
|
|
|
|
0
|
s/([#11#])/setForm($1,$ሳድስ)."ዋ"/eg; |
|
0
|
|
|
|
|
0
|
|
145
|
|
|
|
|
|
|
} |
146
|
9
|
|
|
|
|
21
|
s/[=#ሰ#=]/ሰ/og; |
147
|
9
|
|
|
|
|
22
|
s/[=#ጸ#=]/ጸ/og; |
148
|
9
|
|
|
|
|
15
|
s/[#ቨ#]/በ/og; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# |
151
|
|
|
|
|
|
|
# now strip vowels, this simplies later code: |
152
|
|
|
|
|
|
|
# |
153
|
9
|
50
|
|
|
|
35
|
s/(\p{Ethiopic})/ ($1 eq 'ኘ') ? $1 : setForm($1,$ሳድስ)/eg; |
|
24
|
|
|
|
|
299
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
9
|
|
|
|
|
116
|
$_; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub glyphs |
161
|
|
|
|
|
|
|
{ |
162
|
9
|
|
|
9
|
0
|
12
|
my $self = shift; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
9
|
|
|
|
|
16
|
my @keys = ( $_[0] ); |
166
|
9
|
|
|
|
|
14
|
my $re = $_[0]; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# |
169
|
|
|
|
|
|
|
# Confusion with ዽ |
170
|
|
|
|
|
|
|
# |
171
|
9
|
50
|
|
|
|
23
|
if ( $keys[0] =~ /ዽ/ ) { |
172
|
0
|
|
|
|
|
0
|
$keys[2] = $keys[1] = $keys[0]; |
173
|
0
|
|
|
|
|
0
|
$keys[0] =~ s/ዽ/ድ/o; # caps problem |
174
|
|
|
|
|
|
|
# $keys[1] literal |
175
|
0
|
|
|
|
|
0
|
$keys[2] =~ s/ዽ/ጵ/o; # mistaken glyph |
176
|
0
|
|
|
|
|
0
|
$re =~ s/ዽ/([ድዽጵ])/og; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
# |
179
|
|
|
|
|
|
|
# Confusion with ኘ |
180
|
|
|
|
|
|
|
# |
181
|
9
|
50
|
|
|
|
20
|
if ( $keys[0] =~ /ኘ/ ) { |
182
|
0
|
|
|
|
|
0
|
my (@newKeysA, @newKeysB); |
183
|
0
|
|
|
|
|
0
|
for (my $i=0; $i < @keys; $i++) { |
184
|
0
|
|
|
|
|
0
|
$newKeysA[$i] = $newKeysB[$i] = $keys[$i]; # copy old keys |
185
|
|
|
|
|
|
|
# $keys[$i] literal |
186
|
0
|
|
|
|
|
0
|
$newKeysA[$i] =~ s/ኘ/ን/o; # caps problem |
187
|
0
|
|
|
|
|
0
|
$newKeysB[$i] =~ s/ኘ/ፕ/o; # mistaken glyph |
188
|
|
|
|
|
|
|
} |
189
|
0
|
|
|
|
|
0
|
push (@keys,@newKeysA); # add new keys to old keys |
190
|
0
|
|
|
|
|
0
|
push (@keys,@newKeysB); # add new keys to old keys |
191
|
0
|
|
|
|
|
0
|
$re =~ s/ኘ/[ንኝፕ]/og; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
9
|
|
|
|
|
29
|
($re, @keys); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub phono |
199
|
|
|
|
|
|
|
{ |
200
|
9
|
|
|
9
|
0
|
17
|
my ( $self, $re, @keys ) = @_; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
204
|
9
|
100
|
|
|
|
25
|
if ( $keys[0] =~ /ም[ብፍ]/ ) { |
205
|
1
|
|
|
|
|
1
|
my @newKeys; |
206
|
1
|
|
|
|
|
6
|
for (my $i=0; $i < @keys; $i++) { |
207
|
1
|
|
|
|
|
2
|
$newKeys[$i] = $keys[$i]; # copy old keys |
208
|
1
|
|
|
|
|
5
|
$newKeys[$i] =~ s/ምብ/ንብ/o; # update old keys for primary mapping |
209
|
1
|
|
|
|
|
4
|
$newKeys[$i] =~ s/ምፍ/ንፍ/o; # update old keys for primary mapping |
210
|
|
|
|
|
|
|
} |
211
|
1
|
|
|
|
|
2
|
push (@keys,@newKeys); # add new keys to old keys |
212
|
1
|
|
|
|
|
4
|
$re =~ s/ምብ/[ምን]ብ/og; |
213
|
1
|
|
|
|
|
3
|
$re =~ s/ምፍ/[ምን]ፍ/og; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
9
|
|
|
|
|
30
|
($re, @keys); |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub im |
221
|
|
|
|
|
|
|
{ |
222
|
9
|
|
|
9
|
0
|
15
|
my ( $self, $re, @keys ) = @_; |
223
|
|
|
|
|
|
|
|
224
|
9
|
|
|
|
|
11
|
my $first = 1; |
225
|
|
|
|
|
|
|
# |
226
|
|
|
|
|
|
|
# Handle IM problems |
227
|
|
|
|
|
|
|
# try to keep least probable keys last: |
228
|
|
|
|
|
|
|
# |
229
|
9
|
|
|
|
|
16
|
$_ = $keys[0]; # bidi folding # upper-to-lower |
230
|
9
|
50
|
|
|
|
46
|
my $keyboard = ( $self->{_granularity} eq "high" ) ? qr/([ስቅቕትችንኝክዝዥጥጭጽጵፕ])/ : qr/([ቕኝዥጥጭጽጵ])/ ; |
231
|
|
|
|
|
|
|
|
232
|
9
|
|
|
|
|
48
|
while ( /$keyboard/ ) { |
233
|
3
|
|
|
|
|
7
|
my $a = $1; |
234
|
3
|
|
|
|
|
2
|
my @newKeys; |
235
|
3
|
50
|
|
|
|
10
|
if ( $self->{_granularity} eq "low" ) { |
236
|
3
|
|
|
|
|
46
|
s/$a/$IMExpected{$a}/g; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
else { |
239
|
0
|
|
|
|
|
0
|
s/$a/$IMExpected{$a}/; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
3
|
|
|
|
|
13
|
for (my $i=0; $i < @keys; $i++) { |
243
|
3
|
|
|
|
|
12
|
$newKeys[$i] = $keys[$i]; # copy old keys |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
3
|
50
|
|
|
|
6
|
if ( $first ) { |
247
|
|
|
|
|
|
|
# update new keys for alternative |
248
|
3
|
50
|
|
|
|
42
|
$keys[0] =~ s/^$a/ሀ$a/ if ( $self->{_style} ne "ipa" ); |
249
|
3
|
50
|
|
|
|
8
|
if ( $self->{_granularity} eq "low" ) { |
250
|
3
|
|
|
|
|
33
|
$newKeys[0] =~ s/$a/ሀ$IMError{$a}/g; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
else { |
253
|
0
|
|
|
|
|
0
|
$newKeys[0] =~ s/$a/ሀ$IMError{$a}/; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
3
|
|
|
|
|
13
|
for (my $i=$first; $i < @newKeys; $i++) { |
258
|
|
|
|
|
|
|
# update new keys for alternative |
259
|
0
|
0
|
|
|
|
0
|
if ( $self->{_granularity} eq "low" ) { |
260
|
0
|
|
|
|
|
0
|
$newKeys[$i] =~ s/([^ሀ])$a/$1ሀ$IMError{$a}/g; |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
else { |
263
|
0
|
|
|
|
|
0
|
$newKeys[$i] =~ s/([^ሀ])$a/$1ሀ$IMError{$a}/; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
|
267
|
3
|
|
|
|
|
4
|
$first = 0; |
268
|
3
|
|
|
|
|
5
|
push (@keys,@newKeys); # add new keys to old keys |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
# |
271
|
|
|
|
|
|
|
# this still needs work: |
272
|
|
|
|
|
|
|
# |
273
|
|
|
|
|
|
|
# $re =~ s/$a(?!\w+?\])/[$a$IMError{$a}]/g; |
274
|
3
|
|
|
|
|
80
|
$re =~ s/(?
|
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
# |
278
|
|
|
|
|
|
|
# convert symbols that were missed in low granularity mode: |
279
|
|
|
|
|
|
|
# |
280
|
9
|
|
|
|
|
23
|
foreach my $i (0..$#keys) { |
281
|
13
|
|
|
|
|
28
|
$keys[$i] =~ s/ሀ//og; |
282
|
13
|
|
|
|
|
28
|
$keys[$i] =~ s/ኘ/ኝ/og; |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
|
285
|
9
|
|
|
|
|
66
|
($re, @keys); |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
sub reverse |
290
|
|
|
|
|
|
|
{ |
291
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
292
|
|
|
|
|
|
|
|
293
|
0
|
|
|
|
|
|
$_ = $_[0]; |
294
|
|
|
|
|
|
|
|
295
|
0
|
0
|
|
|
|
|
if ( $self->{_style} eq "ipa" ) { |
|
|
0
|
|
|
|
|
|
296
|
0
|
|
|
|
|
|
s/([stʧkp])'/$plosives{$1}/g; |
297
|
0
|
|
|
|
|
|
tr/hlmrsʃqbtʧnɲakwjdɗʤzʒgɲfp/ህልምርስሽቕብትችንኝእክውይድዽጅዝዥግጝፍፕ/; |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
elsif ( $self->{_style} eq "sera" ) { |
300
|
0
|
|
|
|
|
|
tr/hlmrsxqQbtcnNakwydDjzZgTCPSGfp/ህልምርስሽቅቕብትችንኝእክውይድዽጅዝዥግጝጥጭጵጽፍፕ/; |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
|
303
|
0
|
|
|
|
|
|
$_; |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
sub style |
308
|
|
|
|
|
|
|
{ |
309
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
310
|
|
|
|
|
|
|
|
311
|
0
|
0
|
|
|
|
|
$self->{_style} = lc($_[0]) if (@_); |
312
|
|
|
|
|
|
|
|
313
|
0
|
|
|
|
|
|
$self->{_style}; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
sub granularity |
318
|
|
|
|
|
|
|
{ |
319
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
320
|
|
|
|
|
|
|
|
321
|
0
|
0
|
|
|
|
|
$self->{_granularity} = lc($_[0]) if (@_); |
322
|
|
|
|
|
|
|
|
323
|
0
|
|
|
|
|
|
$self->{_granularity}; |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
######################################################### |
329
|
|
|
|
|
|
|
# Do not change this, Do not put anything below this. |
330
|
|
|
|
|
|
|
# File must return "true" value at termination |
331
|
|
|
|
|
|
|
1; |
332
|
|
|
|
|
|
|
########################################################## |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
__END__ |