Merge pull request #1450 from javathunderman/master

Paleo Ingredient Check IA
master
Zaahir Moolla 2015-11-04 18:00:24 -05:00
commit 14089ded5e
5 changed files with 460 additions and 0 deletions

View File

@ -0,0 +1,59 @@
package DDG::Goodie::PaleoIngredientCheck;
# ABSTRACT: Indicates if a given food item is known to be safe or unsafe on the paleo diet.
use DDG::Goodie;
triggers startend => share('triggers.txt')->slurp;
zci answer_type => "paleo_ingredient_check";
zci is_cached => 1;
name "PaleoIngredientCheck";
description "Indicates if a given food item is known to be safe or unsafe on the paleo diet.";
primary_example_queries "are apples paleo friendly", "Is dairy allowed on the paleo diet?";
secondary_example_queries "Is sugar paleo friendly?", "beans paleo safe";
category "food";
topics "food_and_drink";
code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/PaleoIngredientCheck.pm";
attribution github => ["murz", "Mike Murray"];
attribution github => ["javathunderman", "Thomas Denizou"];
my @safe_array = share('safe.txt')->slurp;
my %safe_keywords = map { chomp; $_ => 1 } @safe_array;
my @unsafe_array = share('unsafe.txt')->slurp;
my %unsafe_keywords = map { chomp; $_ => 1 } @unsafe_array;
# p(%safe_keywords);
# warn($safe_keywords{"apple"});
handle remainder => sub {
return unless $_;
my $item = lc($_);
# Remove any preceding "is" or "are" text from the query.
$item =~ s/^(is|are)[\W]+//;
my $is_plural = substr($item, -1) eq "s";
my $itemAlt = $is_plural ? substr($item, 0, -1) : $item."s"; # pluralized or unpluralized form
my $result;
# warn "ITEM IS: $item";
# warn "ITEM ALT IS: $itemAlt";
if (exists $safe_keywords{$item} || exists $safe_keywords{$itemAlt}) {
$result = "Yes";
} elsif (exists $unsafe_keywords{$item} || exists $unsafe_keywords{$itemAlt}) {
$result = "No";
}
return unless $result; # ensure we have a result
return $result,
structured_answer => {
input => [$item], # or just the original query
operation => "Paleo Friendly",
result => $result
};
};
1;

View File

@ -0,0 +1,131 @@
acorn squash
almonds
apple
artichoke hearts
asparagus
avocado
avocado
avocado oil
bacon
bananas
bass
bear
beef
beef jerky
beets
bison
bison jerky
bison ribeye
bison sirloin
bison steaks
blackberries
blueberries
broccoli
brussels sprouts
buffalo
butternut squash
cabbage
cantaloupe
carrots
cashews
cauliflower
celery
chicken breast
chicken eggs
chicken leg
chicken thigh
chicken wings
chuck steak
clams
clams
coconut oil
crab
crawfish
crayfish
duck eggs
eggplant
eggs
elk
emu
figs
goat
goose
goose eggs
grapes
grassfed beef
grass-fed beef
grass-fed butter
green onions
ground beef
halibut
hazelnuts
kangaroo
lamb chops
lamb rack
lean veal
lemon
lime
lobster
lobster
lychee
macadamia nuts
macadamia oil
mackerel
mango
new york steak
olive oil
oranges
ostrich
oysters
papaya
parsley
peaches
pecans
peppers
pheasant
pine nuts
pineapple guava
plums
pork
pork chops
pork tenderloin
potato
potatoes
poultry
pumpkin seeds
quail
rabbit
raspberries
rattlesnake
red snapper
reindeer
salmon
salmon
sardines
scallops
shark
shrimp
shrimp
spinach
steak
strawberries
sunfish
sunflower seeds
sweet potato
sweet potatoes
swordfish
tangerine
tilapia
trout
tuna
turkey
turtle
veal
venison steaks
walleye
walnuts
watermelon
wild boar
yam
yucca
zucchini

View File

@ -0,0 +1,14 @@
paleo friendly
paleo friendly?
paleo diet friendly
paleo diet friendly?
paleo safe
paleo safe?
paleo
paleo?
allowed on the paleo diet
allowed on the paleo diet?
allowed on paleo diet
allowed on paleo diet?
allowed on paleo
allowed on paleo?

View File

@ -0,0 +1,197 @@
100 grand
2% milk
5-hour energy
ace k
acesulfame potassium
acid saccharin
ack
adzuki beans
alcohol and mixers
almond joy
aminosweet
apm
apple juice
aspartame
aspartame-acesulfame salt
aspartyl-phenylalanine-1-methyl ester
beans
beer
black beans
black-eyed peas
bread
broad beans
butter
butterfinger
calcium cyclamate
canderel
candy bars
cereals
cheese
chickpeas
chinola juice
chips
clearcut isomalt
coke
cologran
cookies
corn
corn syrup
cottage cheese
crackers
cream cheese
cream of wheat
cyclamate
cyclamate and saccharin
d-glucitol
d-glucitol syrup
dairy
dairy spreads
decomalt
diabetisweet
english muffins
equal classic
equal saccharin
equal spoonful
equal sucralose
erythritol
fava beans
fettuchini
french fries
frozen yogurt
garbanzo beans
glycerin
glycerine
glycerol
glycyrrhizin
grape juice
green beans
hash browns
hersheys
high-fructose corn syrup
horse beans
hot dogs
hsh
hydrogenated high maltose content glucose syrup
hydrogenated isomaltulose
hydrogenated maltose
hydrogenated starch hydrolysate
ice cream
ice milk
isomalt
isomaltitol
ketchup
kidney beans
lactitol
lasagna
lasagne
lentils
lesys
licorice
lima beans
low fat milk
lupins
m&ms
maltisweet
maltitol
maltitol powder
maltitol syrup
mango juice
mannitol
mesquite
milk
milky way
miso
monster
mounds
mountain dew
mountain dew mdx
mung beans
natrataste blue
natrataste gold
natrulose
navy beans
necta sweet
neotame
nestle crunch
non-fat dairy creamer
nutrasweet
oatmeal
orange juice
pancakes
pasta
pastries
payday
peanut butter
peanuts
peas
pepsi
pinto beans
polydextrose
powdered milk
pretzels
pudding
rebiana
red beans
red bull
red vines
reesess pieces
reeses
reeses fast break
rockstar
rum
saccharin
sandwiches
skim milk
skittles
smart sweet
snickers
snickers peanut butter
snowpeas
sodium saccharin
sorbitol
soybean
soybeans
spam
splenda
sprite
starbucks refreshers
starfruit juice
steviol glycoside
strawberry juice
string beans
sucaryl
sucralose
sugar
sugar alcohol
sugar snap peas
sunchips
sunett
sweet n low
sweet one
sweet twin
sweetpearl
tagatose
tequila
toast
tofu
trichlorosucrose
triscuits
twinsweet
twix
twix peanut butter
twizzlers
two percent milk
vault
vodka
wheat
wheat thins
whiskey
white beans
whole milk
xs energy drink
xylipure
xylitol
xylosweet
yogurt
zerose
zsweet

59
t/PaleoIngredientCheck.t Normal file
View File

@ -0,0 +1,59 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use DDG::Test::Goodie;
zci answer_type => "paleo_ingredient_check";
zci is_cached => 1;
ddg_goodie_test(
[qw( DDG::Goodie::PaleoIngredientCheck )],
'are apples paleo friendly' => test_zci(
'Yes',
structured_answer => {
input => ['apples'],
operation => 'Paleo Friendly',
result => 'Yes',
},
),
'Is dairy allowed on the paleo diet?' => test_zci(
'No',
structured_answer => {
input => ['dairy'],
operation => 'Paleo Friendly',
result => 'No',
},
),
'Is sugar paleo friendly?' => test_zci(
'No',
structured_answer => {
input => ['sugar'],
operation => 'Paleo Friendly',
result => 'No',
},
),
'beans paleo safe' => test_zci(
'No',
structured_answer => {
input => ['beans'],
operation => 'Paleo Friendly',
result => 'No',
},
),
'is sugar paleo' => test_zci(
'No',
structured_answer => {
input => ['sugar'],
operation => 'Paleo Friendly',
result => 'No',
},
),
'Is foobar allowed on the paleo diet?' => undef,
'are notarealfood paleo friendly' => undef,
'paleo diet recipes' => undef,
'paleo recipes' => undef,
);
done_testing;