Yay, structured answer
parent
0d72258f52
commit
508ace02cd
|
@ -32,38 +32,33 @@ handle remainder => sub {
|
||||||
my($result);
|
my($result);
|
||||||
|
|
||||||
if (any {/$item/} @safe_keywords) {
|
if (any {/$item/} @safe_keywords) {
|
||||||
# If we know the item is safe, append the appropriate positive result.
|
|
||||||
if ($is_plural) {
|
$result= "Yes";
|
||||||
$result = "are";
|
|
||||||
} else {
|
|
||||||
$result = "is";
|
|
||||||
}
|
|
||||||
} elsif (any {/$item/} @unsafe_keywords) {
|
} elsif (any {/$item/} @unsafe_keywords) {
|
||||||
# If we know the item is unsafe, append the appropriate negative result.
|
$result= "No"
|
||||||
if ($is_plural) {
|
|
||||||
$result = "are not";
|
|
||||||
} else {
|
|
||||||
$result = "is not";
|
|
||||||
}
|
|
||||||
} elsif (!$is_plural) {
|
} elsif (!$is_plural) {
|
||||||
# If nothing was found and the query was not plural, try it pluralized.
|
# If nothing was found and the query was not plural, try it pluralized.
|
||||||
if (any {/$item."s"/} @safe_keywords) {
|
if (any {/$item."s"/} @safe_keywords) {
|
||||||
$result = "is";
|
$result = "Yes";
|
||||||
} elsif (any {/$item."s"/} @unsafe_keywords) {
|
} elsif (any {/$item."s"/} @unsafe_keywords) {
|
||||||
$result = "is not";
|
$result = "No";
|
||||||
}
|
}
|
||||||
} elsif ($is_plural) {
|
} elsif ($is_plural) {
|
||||||
# If nothing was found and the query was plural, try it depluralized.
|
# If nothing was found and the query was plural, try it depluralized.
|
||||||
my $depluralized = substr($item, 0, -1);
|
my $depluralized = substr($item, 0, -1);
|
||||||
if (any {/$depluralized/} @safe_keywords) {
|
if (any {/$depluralized/} @safe_keywords) {
|
||||||
$result = "are";
|
$result = "Yes";
|
||||||
} elsif (any {/$depluralized/} @unsafe_keywords) {
|
} elsif (any {/$depluralized/} @unsafe_keywords) {
|
||||||
$result = "are not";
|
$result = "No";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return unless $result;
|
return $result;
|
||||||
return sprintf("%s %s allowed on the paleo diet.", ucfirst($item), $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;
|
1;
|
|
@ -10,11 +10,11 @@ zci is_cached => 1;
|
||||||
|
|
||||||
ddg_goodie_test(
|
ddg_goodie_test(
|
||||||
[qw( DDG::Goodie::PaleoIngredientCheck )],
|
[qw( DDG::Goodie::PaleoIngredientCheck )],
|
||||||
'are apples paleo friendly' => test_zci('Apples are allowed on the paleo diet.'),
|
'are apples paleo friendly' => test_zci('Yes'),
|
||||||
'Is dairy allowed on the paleo diet?' => test_zci('Dairy is not allowed on the paleo diet.'),
|
'Is dairy allowed on the paleo diet?' => test_zci('No'),
|
||||||
'Is sugar paleo friendly?' => test_zci('Sugar is not allowed on the paleo diet.'),
|
'Is sugar paleo friendly?' => test_zci('No'),
|
||||||
'beans paleo safe' => test_zci('Beans are not allowed on the paleo diet.'),
|
'beans paleo safe' => test_zci('No'),
|
||||||
'is sugar paleo' => test_zci('Sugar is not allowed on the paleo diet.'),
|
'is sugar paleo' => test_zci('No'),
|
||||||
'Is foobar allowed on the paleo diet?' => undef,
|
'Is foobar allowed on the paleo diet?' => undef,
|
||||||
'are notarealfood paleo friendly' => undef,
|
'are notarealfood paleo friendly' => undef,
|
||||||
'paleo diet recipes' => undef,
|
'paleo diet recipes' => undef,
|
||||||
|
|
Loading…
Reference in New Issue