2013-05-14 10:36:05 -07:00
|
|
|
|
package DDG::Goodie::Braille;
|
2014-08-20 11:45:33 -07:00
|
|
|
|
# ABSTRACT: Braille <-> ASCII/Unicode
|
2013-05-14 10:36:05 -07:00
|
|
|
|
|
2015-02-22 12:09:29 -08:00
|
|
|
|
use strict;
|
2013-05-14 10:36:05 -07:00
|
|
|
|
use DDG::Goodie;
|
2014-08-20 11:45:33 -07:00
|
|
|
|
|
2013-05-14 10:36:05 -07:00
|
|
|
|
use Convert::Braille;
|
2014-10-06 11:00:41 -07:00
|
|
|
|
use utf8;
|
2013-05-14 10:36:05 -07:00
|
|
|
|
|
2016-03-29 20:55:05 -07:00
|
|
|
|
triggers query_raw => qr/\p{Braille}|( in| to){1} braille$|^braille:/i;
|
2013-05-14 10:36:05 -07:00
|
|
|
|
|
|
|
|
|
zci is_cached => 1;
|
|
|
|
|
|
2014-10-06 11:00:41 -07:00
|
|
|
|
my $braille_space = '⠀'; # the braille unicode space (U+2800)
|
|
|
|
|
|
2013-05-14 10:36:05 -07:00
|
|
|
|
handle query_raw => sub {
|
2014-10-06 11:00:41 -07:00
|
|
|
|
|
|
|
|
|
my $query = $_;
|
2016-03-29 20:55:05 -07:00
|
|
|
|
$query =~ s/( in| to){1} braille$|^braille:\s?//;
|
2014-10-06 11:00:41 -07:00
|
|
|
|
return unless $query;
|
|
|
|
|
|
2016-03-29 20:55:05 -07:00
|
|
|
|
my $response;
|
2016-03-28 22:45:48 -07:00
|
|
|
|
my $type;
|
2014-10-06 11:00:41 -07:00
|
|
|
|
|
|
|
|
|
if ($query =~ /\p{Braille}/) {
|
2016-03-29 20:55:05 -07:00
|
|
|
|
$response = join(" ", map { lc(brailleDotsToAscii($_)) } split(/$braille_space/, $query));
|
2016-03-28 22:45:48 -07:00
|
|
|
|
$type = "Ascii/Unicode";
|
2014-10-06 11:00:41 -07:00
|
|
|
|
} else {
|
2016-03-29 20:55:05 -07:00
|
|
|
|
$response = join($braille_space, map { brailleAsciiToUnicode(uc $_) } split(/\s/, $query));
|
2016-03-28 22:45:48 -07:00
|
|
|
|
$type = "Braille";
|
2014-10-06 11:00:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-29 20:55:05 -07:00
|
|
|
|
return $response,
|
2014-10-06 11:00:41 -07:00
|
|
|
|
structured_answer => {
|
2016-03-29 20:55:05 -07:00
|
|
|
|
data => {
|
|
|
|
|
title => $response,
|
2016-04-05 23:35:47 -07:00
|
|
|
|
subtitle => 'Braille translation: ' . html_enc($query),
|
2016-03-29 20:55:05 -07:00
|
|
|
|
},
|
|
|
|
|
templates => {
|
|
|
|
|
group => 'text',
|
|
|
|
|
},
|
2014-10-06 11:00:41 -07:00
|
|
|
|
};
|
2013-05-14 10:36:05 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
1;
|