line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::TransMetaphone; |
2
|
1
|
|
|
1
|
|
24864
|
use base qw(Exporter); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
116
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
5
|
|
|
|
|
|
|
BEGIN |
6
|
|
|
|
|
|
|
{ |
7
|
1
|
|
|
1
|
|
27
|
use strict; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION @EXPORT_OK %LocaleRanges); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
117
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
2
|
$VERSION = "0.07"; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
|
|
3
|
@EXPORT_OK = qw( trans_metaphone reverse_key ); |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
83
|
%LocaleRanges = (); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub guess_locale |
19
|
|
|
|
|
|
|
{ |
20
|
1
|
|
|
1
|
0
|
3
|
my ($word) = @_; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
2
|
my $locale; |
23
|
1
|
|
|
1
|
|
5
|
$word =~ /(\p{IsLetter})/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
11
|
|
24
|
1
|
|
|
|
|
5
|
my $char = $1; # grab first letter |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
# check ranges of registered locales |
28
|
|
|
|
|
|
|
# |
29
|
1
|
|
|
|
|
6
|
foreach (keys %LocaleRanges) { |
30
|
0
|
0
|
|
|
|
0
|
$locale = $_ if ( $char =~ /$LocaleRanges{$_}/ ); |
31
|
|
|
|
|
|
|
} |
32
|
1
|
50
|
|
|
|
5
|
unless ( $locale ) { |
33
|
1
|
50
|
|
|
|
9
|
$locale = "am" if ( $char =~ /\p{InEthiopic}/ ); |
34
|
1
|
50
|
|
|
|
7
|
$locale = "ar" if ( $char =~ /\p{InArabic}/ ); |
35
|
1
|
50
|
|
|
|
7
|
$locale = "ch" if ( $char =~ /\p{InCherokee}/ ); |
36
|
1
|
50
|
|
|
|
5
|
$locale = "el" if ( $char =~ /\p{InGreekAndCoptic}/ ); |
37
|
1
|
50
|
|
|
|
5
|
$locale = "en_US" if ( $char =~ /\p{InBasicLatin}/ ); |
38
|
1
|
50
|
|
|
|
7
|
$locale = "gu" if ( $char =~ /\p{InGujarati}/ ); |
39
|
1
|
50
|
|
|
|
15
|
$locale = "he" if ( $char =~ /\p{InHebrew}/ ); |
40
|
1
|
50
|
|
|
|
6
|
$locale = "ja_hiragana" if ( $char =~ /\p{InHiragana}/ ); |
41
|
1
|
50
|
|
|
|
6
|
$locale = "ja_katakana" if ( $char =~ /\p{InKatakana}/ ); |
42
|
1
|
50
|
|
|
|
6
|
$locale = "ru" if ( $char =~ /\p{InCyrillic}/ ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
3
|
$locale; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub list_locales |
51
|
|
|
|
|
|
|
{ |
52
|
0
|
|
|
0
|
0
|
0
|
keys %LocaleRanges; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub trans_metaphone |
57
|
|
|
|
|
|
|
{ |
58
|
1
|
|
|
1
|
1
|
644
|
my $word = shift; |
59
|
1
|
50
|
|
|
|
10
|
my $locale = (@_) ? shift : guess_locale ( $word ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
1
|
50
|
|
|
|
5
|
die "No locale identified for $word. Locale must be specified." unless ( $locale ); |
63
|
|
|
|
|
|
|
|
64
|
1
|
50
|
|
|
|
5
|
unless ( exists($LocaleRanges{$locale}) ) { |
65
|
1
|
|
|
|
|
3
|
my $module = "Text::TransMetaphone::$locale"; |
66
|
1
|
50
|
|
|
|
87
|
eval "require $module;" |
67
|
|
|
|
|
|
|
|| die "Unable to load Text::TransMetaphone::$locale : $@"; |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
6
|
$LocaleRanges{$locale} = ${"Text::TransMetaphone::${locale}::LocaleRange"}; |
|
1
|
|
|
|
|
10
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
3
|
my @keys = &{"Text::TransMetaphone::${locale}::trans_metaphone"} ( $word ); |
|
1
|
|
|
|
|
8
|
|
73
|
|
|
|
|
|
|
|
74
|
1
|
50
|
|
|
|
10
|
( wantarray ) ? @keys : $kesy[0]; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub reverse_key |
79
|
|
|
|
|
|
|
{ |
80
|
1
|
|
|
1
|
1
|
554
|
my ($word, $locale) = @_; |
81
|
|
|
|
|
|
|
|
82
|
1
|
50
|
|
|
|
6
|
die "No locale identified for $word. Locale must be specified." unless ( $locale ); |
83
|
|
|
|
|
|
|
|
84
|
1
|
50
|
|
|
|
9
|
unless ( exists($LocaleRanges{$locale}) ) { |
85
|
0
|
|
|
|
|
0
|
my $module = "Text::TransMetaphone::$locale"; |
86
|
0
|
0
|
|
|
|
0
|
eval "require $module;" |
87
|
|
|
|
|
|
|
|| die "Unable to load Text::TransMetaphone::$locale : $@"; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
0
|
$LocaleRanges{$locale} = ${"Text::TransMetaphone::${locale}::LocaleRange"}; |
|
0
|
|
|
|
|
0
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
2
|
&{"Text::TransMetaphone::${locale}::reverse_key"} ( $word ); |
|
1
|
|
|
|
|
7
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
######################################################### |
99
|
|
|
|
|
|
|
# Do not change this, Do not put anything below this. |
100
|
|
|
|
|
|
|
# File must return "true" value at termination |
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
########################################################## |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |