| 1 | package Ham::Reference::Phonetics; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # -------------------------------------------------------------------------- | ||||||||||||||||||||
| 4 | # Ham::Reference::Phonetics - A quick reference for the ITU Phonetic | ||||||||||||||||||||
| 5 | # Alphabet | ||||||||||||||||||||
| 6 | # | ||||||||||||||||||||
| 7 | # Copyright (c) 2008-2010 Brad McConahay N8QQ. | ||||||||||||||||||||
| 8 | # Cincinnat, Ohio USA | ||||||||||||||||||||
| 9 | # | ||||||||||||||||||||
| 10 | # This module is free software; you can redistribute it and/or | ||||||||||||||||||||
| 11 | # modify it under the terms of the Artistic License 2.0. For | ||||||||||||||||||||
| 12 | # details, see the full text of the license in the file LICENSE. | ||||||||||||||||||||
| 13 | # | ||||||||||||||||||||
| 14 | # This program is distributed in the hope that it will be | ||||||||||||||||||||
| 15 | # useful, but it is provided "as is" and without any express | ||||||||||||||||||||
| 16 | # or implied warranties. For details, see the full text of | ||||||||||||||||||||
| 17 | # the license in the file LICENSE. | ||||||||||||||||||||
| 18 | # -------------------------------------------------------------------------- | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 2 | ▶ | use vars qw($VERSION); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 2 | my $phonetics = {}; | |||||||||||||||||||
| 28 | $phonetics->{itu} = | ||||||||||||||||||||
| 29 | { | ||||||||||||||||||||
| 30 | 2 | 'a' => 'Alfa', | |||||||||||||||||||
| 31 | 'b' => 'Bravo', | ||||||||||||||||||||
| 32 | 'c' => 'Charlie', | ||||||||||||||||||||
| 33 | 'd' => 'Delta', | ||||||||||||||||||||
| 34 | 'e' => 'Echo', | ||||||||||||||||||||
| 35 | 'f' => 'Foxtrot', | ||||||||||||||||||||
| 36 | 'g' => 'Golf', | ||||||||||||||||||||
| 37 | 'h' => 'Hotel', | ||||||||||||||||||||
| 38 | 'i' => 'India', | ||||||||||||||||||||
| 39 | 'j' => 'Juliett', | ||||||||||||||||||||
| 40 | 'k' => 'Kilo', | ||||||||||||||||||||
| 41 | 'l' => 'Lima', | ||||||||||||||||||||
| 42 | 'm' => 'Mike', | ||||||||||||||||||||
| 43 | 'n' => 'November', | ||||||||||||||||||||
| 44 | 'o' => 'Oscar', | ||||||||||||||||||||
| 45 | 'p' => 'Papa', | ||||||||||||||||||||
| 46 | 'q' => 'Quebec', | ||||||||||||||||||||
| 47 | 'r' => 'Romeo', | ||||||||||||||||||||
| 48 | 's' => 'Sierra', | ||||||||||||||||||||
| 49 | 't' => 'Tango', | ||||||||||||||||||||
| 50 | 'u' => 'Uniform', | ||||||||||||||||||||
| 51 | 'v' => 'Victor', | ||||||||||||||||||||
| 52 | 'w' => 'Whiskey', | ||||||||||||||||||||
| 53 | 'x' => 'X-Ray', | ||||||||||||||||||||
| 54 | 'y' => 'Yankee', | ||||||||||||||||||||
| 55 | 'z' => 'Zulu' | ||||||||||||||||||||
| 56 | }; | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | sub new | ||||||||||||||||||||
| 59 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 60 | 0 | my $class = shift; | |||||||||||||||||||
| 61 | 0 | my %args = @_; | |||||||||||||||||||
| 62 | 0 | my $self = {}; | |||||||||||||||||||
| 63 | 0 | bless $self, $class; | |||||||||||||||||||
| 64 | 0 | ▶ | $self->{phonetic_set} = lc($args{phonetic_set}) || 'itu'; | ||||||||||||||||||
|
Condition0%0/2
lc $args{'phonetic_set'} || 'itu'
MC/DC0%0/1
lc $args{'phonetic_set'} || 'itu'
lc $args{'phonetic_set'}
Truth table0%0/2
A
A= lc $args{'phonetic_set'}
| |||||||||||||||||||||
| 65 | 0 | ▶ | $self->{space} = $args{space} || ''; | ||||||||||||||||||
|
Condition0%0/2
$args{'space'} || ''
MC/DC0%0/1
$args{'space'} || ''
$args{'space'}
Truth table0%0/2
A
A= $args{'space'}
| |||||||||||||||||||||
| 66 | 0 | return $self; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | sub get | ||||||||||||||||||||
| 70 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
get: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||
| 71 | 0 | my $self = shift; | |||||||||||||||||||
| 72 | 0 | my $string = shift; | |||||||||||||||||||
| 73 | 0 | ▶ | return undef if !$string; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 0 | $string = lc($string); | |||||||||||||||||||
| 75 | 0 | my $p = ''; | |||||||||||||||||||
| 76 | 0 | foreach my $letter (split '',$string) { | |||||||||||||||||||
| 77 | 0 | ▶ | if ($phonetics->{$self->{phonetic_set}}->{$letter}) | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 78 | { | ||||||||||||||||||||
| 79 | 0 | $p .= $phonetics->{$self->{phonetic_set}}->{$letter}.' '; | |||||||||||||||||||
| 80 | } elsif ($letter eq ' ') { | ||||||||||||||||||||
| 81 | 0 | $p .= $self->{space}; | |||||||||||||||||||
| 82 | 0 | ▶ | $p .= ' ' if $self->{space}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | 0 | $p =~ s/\s$//; | |||||||||||||||||||
| 86 | 0 | return $p; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | sub get_arrayref | ||||||||||||||||||||
| 90 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_arrayref: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||
| 91 | 0 | my $self = shift; | |||||||||||||||||||
| 92 | 0 | my $string = shift; | |||||||||||||||||||
| 93 | 0 | ▶ | return undef if !$string; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 0 | $string = lc($string); | |||||||||||||||||||
| 95 | 0 | my $p = (); | |||||||||||||||||||
| 96 | 0 | foreach my $letter (split '',$string) { | |||||||||||||||||||
| 97 | 0 | ▶ | if ($phonetics->{$self->{phonetic_set}}->{$letter}) | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 98 | { | ||||||||||||||||||||
| 99 | 0 | push( @$p, $phonetics->{$self->{phonetic_set}}->{$letter}); | |||||||||||||||||||
| 100 | ▶ | } elsif ($letter eq ' ' and $self->{space}) { | |||||||||||||||||||
|
Condition0%0/3
$letter eq " " and $self->{"space"}
MC/DC0%0/2
$letter eq " " and $self->{"space"}
$letter eq " "
$self->{"space"}
Truth table0%0/3
A and B
A= $letter eq " "B= $self->{"space"}
| |||||||||||||||||||||
| 101 | 0 | push( @$p, $self->{space} ); | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | 0 | return $p; | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | sub get_hashref | ||||||||||||||||||||
| 108 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_hashref: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 109 | 0 | my $self = shift; | |||||||||||||||||||
| 110 | 0 | return $phonetics->{$self->{phonetic_set}}; | |||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 2 | 1; | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =head1 NAME | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | Ham::Reference::Phonetics - A quick reference for the ITU Phonetic Alphabet. | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | =head1 VERSION | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | Version 0.02 | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | =head1 SYNOPSIS | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | use Ham::Reference::Phonetics; | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | my $phonetics = Ham::Reference::Phonetics->new( | ||||||||||||||||||||
| 128 | space => '<space>' | ||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | # use the get() function to get a string of phonetics | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | print $phonetics->get('abc xyz'); | ||||||||||||||||||||
| 134 | print "\n"; | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | # use the get_array() function to get an array of phonetics | ||||||||||||||||||||
| 137 | # with each one in an element | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | my $arrayref = $phonetics->get_arrayref('abc xyz'); | ||||||||||||||||||||
| 140 | foreach (@$arrayref) { | ||||||||||||||||||||
| 141 | print "$_\n"; | ||||||||||||||||||||
| 142 | } | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | # use a hash reference to get all phonetics | ||||||||||||||||||||
| 145 | # the following will display all letters and corresponding phonetics | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | my $hashref = $phonetics->get_hashref(); | ||||||||||||||||||||
| 148 | foreach (sort keys %$hashref) | ||||||||||||||||||||
| 149 | { | ||||||||||||||||||||
| 150 | print "$_ = $hashref->{$_}\n"; | ||||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =head1 DESCRIPTION | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | The C<Ham::Reference::Phonetics> module is a quick reference to the ITU phonetic alphabet | ||||||||||||||||||||
| 156 | suggested by the ARRL for Amateur Radio use. Other phonetic alphabets may be included in the | ||||||||||||||||||||
| 157 | future. Some can already be found in C<Lingua::Alphabet::Phonetic>. | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =head1 CONSTRUCTOR | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | =head2 new() | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | Usage : my $phonetics = Ham::Reference::Phonetics->new(); | ||||||||||||||||||||
| 164 | Function : creates a new Ham::Reference::Phonetics object | ||||||||||||||||||||
| 165 | Returns : A Ham::Reference::Phonetics object | ||||||||||||||||||||
| 166 | Args : an anonymous hash: | ||||||||||||||||||||
| 167 | key required? value | ||||||||||||||||||||
| 168 | ------- --------- ----- | ||||||||||||||||||||
| 169 | phonetic_set no select the phonetic alphabet set | ||||||||||||||||||||
| 170 | the only set for now, and the default set | ||||||||||||||||||||
| 171 | is itu | ||||||||||||||||||||
| 172 | space no set a string to represent a space when | ||||||||||||||||||||
| 173 | using methods to convert to phonetics | ||||||||||||||||||||
| 174 | default is an empty string | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | =head1 METHODS | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | =head2 get() | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | Usage : my $string = $phonetics->get( 'this is my string' ); | ||||||||||||||||||||
| 181 | Function : converts a string to a string of corresponding phonetic words | ||||||||||||||||||||
| 182 | Returns : a string | ||||||||||||||||||||
| 183 | Args : a string | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | =head2 get_arrayref() | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | Usage : my $arrayref = $phonetics->get_arrayref( 'this is my string' ); | ||||||||||||||||||||
| 188 | Function : converts a string to an array reference of corresponding phonetic words | ||||||||||||||||||||
| 189 | one phonetic word per element | ||||||||||||||||||||
| 190 | Returns : an array reference | ||||||||||||||||||||
| 191 | Args : a string | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | =head2 get_hashref() | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | Usage : my $hashref = $phonetics->get_hashref(); | ||||||||||||||||||||
| 196 | Function : get the phonetic alphabet in a hash referenece | ||||||||||||||||||||
| 197 | Returns : a hash reference | ||||||||||||||||||||
| 198 | Args : n/a | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | The ITU phonetic alphabet for Amateur Radio use was taken from http://www.arrl.org/FandES/field/forms/fsd220.html#alphabet, | ||||||||||||||||||||
| 203 | courtesy of the American Radio Relay League. | ||||||||||||||||||||
| 204 | |||||||||||||||||||||
| 205 | =head1 SEE ALSO | ||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | Other phonetic alphabets can found in C<Lingua::Alphabet::Phonetic>. | ||||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | =head1 AUTHOR | ||||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | Brad McConahay N8QQ, C<< <brad at n8qq.com> >> | ||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||
| 214 | |||||||||||||||||||||
| 215 | C<Ham::Reference::Phonetics> is Copyright (C) 2008-2010 Brad McConahay N8QQ. | ||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | This module is free software; you can redistribute it and/or | ||||||||||||||||||||
| 218 | modify it under the terms of the Artistic License 2.0. For | ||||||||||||||||||||
| 219 | details, see the full text of the license in the file LICENSE. | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | This program is distributed in the hope that it will be | ||||||||||||||||||||
| 222 | useful, but it is provided "as is" and without any express | ||||||||||||||||||||
| 223 | or implied warranties. For details, see the full text of | ||||||||||||||||||||
| 224 | the license in the file LICENSE. | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | |||||||||||||||||||||