line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# $Id: Phonetic.pm,v 1.9 2008/09/07 03:23:24 Martin Exp $ |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Lingua::Alphabet::Phonetic - map ABC's to phonetic alphabets |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Lingua::Alphabet::Phonetic; |
11
|
|
|
|
|
|
|
my $oMilSpeaker = new Lingua::Alphabet::Phonetic('NATO'); |
12
|
|
|
|
|
|
|
my @asMilSpeak = $oMilSpeaker->enunciate('ABC'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
At present, the only alphabet available for conversion is the |
17
|
|
|
|
|
|
|
U.S. Military / NATO standard where "ABC...YZ" is pronounced "Alpha |
18
|
|
|
|
|
|
|
Bravo Charlie ... Yankee Zulu". It is called 'NATO' and it is |
19
|
|
|
|
|
|
|
included with this distribution. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 METHODS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=over |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
##################################################################### |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
package Lingua::Alphabet::Phonetic; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
2
|
|
55309
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
75
|
|
32
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
785
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
our |
35
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/o); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item new |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Create an object of this class. See SYNOPSIS above. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new |
44
|
|
|
|
|
|
|
{ |
45
|
1
|
|
|
1
|
1
|
12
|
my $class = shift; |
46
|
1
|
|
50
|
|
|
4
|
my $sAlphabet = shift || ''; |
47
|
1
|
|
|
|
|
4
|
my $sSubclass = "${class}::$sAlphabet"; |
48
|
1
|
|
|
1
|
|
8
|
eval "use $sSubclass"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
90
|
|
49
|
1
|
50
|
|
|
|
6
|
Carp::croak("Unknown phonetic alphabet $sAlphabet: $@") if ($@); |
50
|
1
|
|
|
|
|
4
|
my $self = bless { |
51
|
|
|
|
|
|
|
}, $sSubclass; |
52
|
1
|
|
|
|
|
4
|
return $self; |
53
|
|
|
|
|
|
|
} # new |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item enunciate |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Given a string, returns a list of phonetic alphabet "words", one word |
59
|
|
|
|
|
|
|
per character of the original string. If there is no "word" in the |
60
|
|
|
|
|
|
|
alphabet for a character, that character is returned in the list |
61
|
|
|
|
|
|
|
position. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub enunciate |
66
|
|
|
|
|
|
|
{ |
67
|
4
|
|
|
4
|
1
|
4180
|
my $self = shift; |
68
|
4
|
|
100
|
|
|
22
|
my $s = shift || ''; |
69
|
4
|
|
|
|
|
15
|
my @ac = split('', $s); |
70
|
4
|
|
|
|
|
13
|
return map { $self->_name_of_letter($_) } @ac; |
|
6
|
|
|
|
|
28
|
|
71
|
|
|
|
|
|
|
} # enunciate |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _name_of_letter |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
# This is the default fallback character --> word mapping. |
77
|
2
|
|
|
2
|
|
5
|
my $self = shift; |
78
|
2
|
|
|
|
|
3
|
my $s = shift; |
79
|
|
|
|
|
|
|
# Just return our argument unchanged: |
80
|
2
|
|
|
|
|
9
|
return $s; |
81
|
|
|
|
|
|
|
} # _name_of_letter |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=back |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 OTHER ALPHABETS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
To create a conversion scheme for another alphabet, simply subclass |
88
|
|
|
|
|
|
|
this module and provide a method _name_of_letter() which takes a |
89
|
|
|
|
|
|
|
character and returns its phonetic name. See NATO.pm as an example. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SEE ALSO |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
http://en.wikipedia.org/wiki/Spelling_alphabet is a brief overview |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
http://www.bckelk.uklinux.net/phon.full.html contains a list of |
96
|
|
|
|
|
|
|
phonetic alphabets from all over the world! |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 TO-DO |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=over |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item Implement more alphabets. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item Investigate how we might handle non-ASCII alphabets. Unicode? |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=back |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 BUGS |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Please tell the author if you find any! |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 LICENSE |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This software is released under the same license as Perl itself. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Martin Thurn (mthurn@cpan.org). |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |