File Coverage

blib/lib/Text/WagnerFischer/Amharic.pm
Criterion Covered Total %
statement 41 48 85.4
branch 11 20 55.0
condition 6 18 33.3
subroutine 8 8 100.0
pod n/a
total 66 94 70.2


line stmt bran cond sub pod time code
1             package Text::WagnerFischer::Amharic;
2 1     1   123277 use base qw( Text::WagnerFischer );
  1         4  
  1         483  
3              
4 1     1   789 use utf8;
  1         1  
  1         4  
5             BEGIN
6             {
7 1     1   24 use strict;
  1         1  
  1         14  
8 1     1   3 use warnings;
  1         1  
  1         40  
9 1     1   3 use vars qw( @EXPORT_OK %IMCapsMismatch $VERSION );
  1         2  
  1         60  
10              
11 1     1   433 use Regexp::Ethiopic::Amharic ( 'getForm', 'setForm', ':forms' );
  1         7971  
  1         8  
12              
13 1     1   598 $VERSION = "0.06";
14             #
15             # This linking is done so that the export of "distance" works
16             # as before:
17             #
18 1         3 *distance = \&Text::WagnerFischer::distance;
19 1         3 @EXPORT_OK = qw( &distance );
20              
21              
22             #
23             # "override" the _weight function with the local one:
24             #
25 1         44 *Text::WagnerFischer::_weight = \&_am_weight;
26              
27              
28             #
29             # Set a new default penalty costs:
30             #
31             # WagnerFischer : equal, insert/delete, mismatch,
32             # Right Family but: phoneme/glyph equiv, zemene, wrong form
33             # Right Form but : phoneme/glyph equiv, shift slip, wrong base
34             # other : phoneme equiv
35 1         4 $Text::WagnerFischer::REFC = [0,2,3, 1,2,1, 1,1,2, 1];
36              
37              
38 1         317 %IMCapsMismatch =(
39             ስ => "ጽ",
40             ጽ => "ስ",
41             ቅ => "ቕ",
42             ቕ => "ቅ",
43             ት => "ጥ",
44             ጥ => "ት",
45             ች => "ጭ",
46             ጭ => "ች",
47             ን => "ኝ",
48             ኝ => "ን",
49             ክ => "ኽ",
50             ኽ => "ክ",
51             ዝ => "ዥ",
52             ዥ => "ዝ",
53             ጵ => "ፕ",
54             ፕ => "ጵ"
55             );
56             }
57              
58              
59              
60             sub _am_weight
61             {
62 135     135   208292 my ($x,$y,$refc)=@_;
63              
64 135         140 my $value;
65              
66             # print "Comparing: $x/$y\n";
67              
68 135 100 100     336 if ($x eq $y) {
    100          
69 8         9 $value = $refc->[0]; # cost for letter match
70             } elsif ( ($x eq '-') or ($y eq '-') ) {
71 90         126 $value = $refc->[1]; # cost for insertion/deletion operation
72             } else {
73 37         64 my $yግዕዝ = setForm ( $y, $ግዕዝ );
74              
75 37         432 my $yEquiv = Regexp::Ethiopic::Amharic::getRe ( "[=$yግዕዝ=]" );
76 37         864 my $yFamily = Regexp::Ethiopic::Amharic::getRe ( "[#$yግዕዝ#]" );
77              
78             # print " $yግዕዝ: $yEquiv / $yFamily\n";
79             # print "yEquiv/yFamily: <$yEquiv><$yFamily>\n";
80              
81 37 50 33     1174 if ( $x =~ /$yFamily/ ) { # x & y are in the same family
    100          
    50          
82 0 0 0     0 if ( $yEquiv && $x =~ /$yEquiv/ ) {
    0 0        
    0 0        
83 0         0 $value = $refc->[3]; # phono/glyph equivalence: ኮ/ኰ, ቁ/ቍ
84             }
85             elsif ( ($x =~ /[ዉው]/) && ($y =~ /[ዉው]/) ) {
86 0         0 $value = $refc->[3]; #
87             }
88             elsif ( (getForm($x) > 7) || (getForm($y) > 7) ) {
89 0         0 $value = $refc->[4]; # labiovelar mismatch
90             }
91             else {
92 0         0 $value = $refc->[5]; # form mismatch
93             }
94             } elsif ( getForm($x) == getForm($y) ) { # right form, wrong family
95 22 100 66     496 if ( $yEquiv && $x =~ /$yEquiv/ ) {
96 5         11 $value = $refc->[6]; # phono/glyph equivalence: ሳ/ሣ
97             }
98             else {
99 17         31 my $xሳድስ = setForm ( $x, $ሳድስ );
100 17         163 my $yሳድስ = setForm ( $y, $ሳድስ );
101 17 50       154 if ( $IMCapsEquivalence{$xሳድስ} eq $yሳድስ ) {
102 0         0 $value = $refc->[7]; # finger slipped on shift key: ት/ጥ
103             }
104             else {
105 17         30 $value = $refc->[8]; # family mismatch
106             }
107             }
108             } elsif ( $yEquiv && $x =~ /$yEquiv/ ) { # different family, differnt form but related: ሀ/ሐ/ኀ/ሃ/ሓ/ኃ/ኻ
109 0         0 $value = $refc->[9];
110             } else {
111 15         307 $value = $refc->[2]; # cost for letter mismatch
112             }
113             }
114              
115             # print "Comparing: $x/$y => $value\n";
116 135         254 $value;
117             }
118              
119              
120             #########################################################
121             # Do not change this, Do not put anything below this.
122             # File must return "true" value at termination
123             1;
124             ##########################################################
125              
126             __END__