Yay, structured answer

master
javathunderman 2015-09-29 17:30:28 +00:00
parent 0d72258f52
commit 508ace02cd
2 changed files with 18 additions and 23 deletions

View File

@ -32,38 +32,33 @@ handle remainder => sub {
my($result);
if (any {/$item/} @safe_keywords) {
# If we know the item is safe, append the appropriate positive result.
if ($is_plural) {
$result = "are";
} else {
$result = "is";
}
$result= "Yes";
} elsif (any {/$item/} @unsafe_keywords) {
# If we know the item is unsafe, append the appropriate negative result.
if ($is_plural) {
$result = "are not";
} else {
$result = "is not";
}
$result= "No"
} elsif (!$is_plural) {
# If nothing was found and the query was not plural, try it pluralized.
if (any {/$item."s"/} @safe_keywords) {
$result = "is";
$result = "Yes";
} elsif (any {/$item."s"/} @unsafe_keywords) {
$result = "is not";
$result = "No";
}
} elsif ($is_plural) {
# If nothing was found and the query was plural, try it depluralized.
my $depluralized = substr($item, 0, -1);
if (any {/$depluralized/} @safe_keywords) {
$result = "are";
$result = "Yes";
} elsif (any {/$depluralized/} @unsafe_keywords) {
$result = "are not";
$result = "No";
}
}
return unless $result;
return sprintf("%s %s allowed on the paleo diet.", ucfirst($item), $result);
return $result;
structured_answer => {
input => "Is $item paleo-diet friendly", # or just the original query
operation => "",
result => $result, # this could possibly be shortened to a simple "Yes" or "No"
};
};
1;

View File

@ -10,11 +10,11 @@ zci is_cached => 1;
ddg_goodie_test(
[qw( DDG::Goodie::PaleoIngredientCheck )],
'are apples paleo friendly' => test_zci('Apples are allowed on the paleo diet.'),
'Is dairy allowed on the paleo diet?' => test_zci('Dairy is not allowed on the paleo diet.'),
'Is sugar paleo friendly?' => test_zci('Sugar is not allowed on the paleo diet.'),
'beans paleo safe' => test_zci('Beans are not allowed on the paleo diet.'),
'is sugar paleo' => test_zci('Sugar is not allowed on the paleo diet.'),
'are apples paleo friendly' => test_zci('Yes'),
'Is dairy allowed on the paleo diet?' => test_zci('No'),
'Is sugar paleo friendly?' => test_zci('No'),
'beans paleo safe' => test_zci('No'),
'is sugar paleo' => test_zci('No'),
'Is foobar allowed on the paleo diet?' => undef,
'are notarealfood paleo friendly' => undef,
'paleo diet recipes' => undef,