zeroclickinfo-goodies/lib/DDG/Goodie/Phonetic.pm

73 lines
1.6 KiB
Perl
Raw Normal View History

package DDG::Goodie::Phonetic;
# ABSTRACT: Take a string and spell it out phonetically using the NATO alphabet
use strict;
use DDG::Goodie;
triggers start => 'phonetic';
zci is_cached => 1;
2012-11-06 15:31:16 -08:00
primary_example_queries 'phonetic what duck';
description 'spell a string phonetically with the NATO alphabet';
name 'Phonetic';
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Phonetic.pm';
category 'reference';
topics 'special_interest';
attribution github => [ 'robotmay', 'Robert May' ],
twitter => [ 'robotmay', 'Robert May' ];
2012-11-06 15:31:16 -08:00
2013-05-21 09:20:54 -07:00
sub components {
my %nato = (
a => "Alfa",
b => "Bravo",
c => "Charlie",
d => "Delta",
e => "Echo",
f => "Foxtrot",
g => "Golf",
h => "Hotel",
i => "India",
j => "Juliet",
k => "Kilo",
l => "Lima",
m => "Mike",
n => "November",
o => "Oscar",
p => "Papa",
q => "Quebec",
r => "Romeo",
s => "Sierra",
t => "Tango",
u => "Uniform",
v => "Victor",
w => "Whiskey",
x => "Xray",
y => "Yankee",
z => "Zulu",
1 => "One",
2 => "Two",
3 => "Three",
4 => "Four",
5 => "Five",
6 => "Six",
7 => "Seven",
8 => "Eight",
9 => "Nine",
0 => "Zero"
);
2013-05-21 09:20:54 -07:00
my @components = map { defined $nato{$_} ? ($nato{$_}) : () } split //, $_;
return join("-", @components);
2013-05-21 09:20:54 -07:00
}
2013-05-21 09:20:54 -07:00
handle remainder => sub {
return unless $_;
$_ = lc;
my @words = split(/\s+/, $_);
my @phonetics = map { components($_) } @words;
return "Phonetic: " . join(" ", @phonetics);
};
2012-11-06 15:31:16 -08:00
1;