From deaee77a111e2825ff4fb9fe4b757d766cc8550f Mon Sep 17 00:00:00 2001 From: javathunderman Date: Fri, 28 Aug 2015 20:42:19 +0000 Subject: [PATCH 1/8] Added PaleoIngredientCheck IA --- share/PaleoIngredientCheck/safe.txt | 131 +++++++++++++++ share/PaleoIngredientCheck/triggers.txt | 14 ++ share/PaleoIngredientCheck/unsafe.txt | 208 ++++++++++++++++++++++++ 3 files changed, 353 insertions(+) create mode 100644 share/PaleoIngredientCheck/safe.txt create mode 100644 share/PaleoIngredientCheck/triggers.txt create mode 100644 share/PaleoIngredientCheck/unsafe.txt diff --git a/share/PaleoIngredientCheck/safe.txt b/share/PaleoIngredientCheck/safe.txt new file mode 100644 index 000000000..674c8486b --- /dev/null +++ b/share/PaleoIngredientCheck/safe.txt @@ -0,0 +1,131 @@ +poultry +turkey +chicken breast +pork tenderloin +pork chops +steak +veal +bacon +pork +beef +ground beef +grass-fed beef +grassfed beef +chicken thigh +chicken leg +chicken wings +lamb rack +shrimp +lobster +clams +salmon +venison steaks +buffalo +new york steak +bison +bison steaks +bison jerky +bison ribeye +bison sirloin +lamb chops +rabbit +goat +elk +emu +goose +kangaroo +bear +beef jerky +eggs +duck eggs +chicken eggs +goose eggs +wild boar +reindeer +turtle +ostrich +pheasant +quail +lean veal +chuck steak +rattlesnake +bass +salmon +halibut +mackerel +sardines +tuna +red snapper +shark +sunfish +swordfish +tilapia +trout +walleye +crab +crawfish +crayfish +shrimp +clams +lobster +scallops +oysters +asparagus +avocado +artichoke hearts +brussels sprouts +carrots +spinach +celery +broccoli +zucchini +cabbage +peppers +cauliflower +parsley +eggplant +green onions +butternut squash +acorn squash +yam +yucca +sweet potato +sweet potatoes +beets +coconut oil +olive oil +macadamia oil +avocado oil +grass-fed butter +almonds +cashews +hazelnuts +pecans +pine nuts +pumpkin seeds +sunflower seeds +macadamia nuts +walnuts +apple +avocado +blackberries +papaya +peaches +plums +mango +lychee +blueberries +grapes +lemon +strawberries +watermelon +pineapple guava +lime +raspberries +cantaloupe +tangerine +figs +oranges +bananas +potatoes +potato \ No newline at end of file diff --git a/share/PaleoIngredientCheck/triggers.txt b/share/PaleoIngredientCheck/triggers.txt new file mode 100644 index 000000000..c2827e401 --- /dev/null +++ b/share/PaleoIngredientCheck/triggers.txt @@ -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? \ No newline at end of file diff --git a/share/PaleoIngredientCheck/unsafe.txt b/share/PaleoIngredientCheck/unsafe.txt new file mode 100644 index 000000000..d162e75da --- /dev/null +++ b/share/PaleoIngredientCheck/unsafe.txt @@ -0,0 +1,208 @@ +butter +cheese +cottage cheese +non-fat dairy creamer +milk +skim milk +2% milk +two percent milk +whole milk +dairy spreads +cream cheese +powdered milk +yogurt +pudding +frozen yogurt +ice milk +low fat milk +ice cream +milk +coke +sprite +pepsi +mountain dew +apple juice +orange juice +grape juice +strawberry juice +chinola juice +starfruit juice +mango juice +cereals +bread +english muffins +toast +sandwiches +triscuits +wheat thins +crackers +oatmeal +cream of wheat +corn +corn syrup +high-fructose corn syrup +wheat +pancakes +hash browns +beer +pasta +fettuchini +lasagne +lasagna +black beans +broad beans +fava beans +garbanzo beans +horse beans +kidney beans +lima beans +mung beans +adzuki beans +navy beans +pinto beans +red beans +green beans +string beans +white beans +beans +peas +black-eyed peas +chickpeas +snowpeas +sugar snap peas +peanuts +peanut butter +miso +lentils +lupins +mesquite +soybeans +soybean +tofu +beans +acesulfame potassium +ack +ace k +equal spoonful +sweet one +sunett +aspartame +apm +aminosweet +aspartyl-phenylalanine-1-methyl ester +canderel +equal classic +natrataste blue +nutrasweet +aspartame-acesulfame salt +twinsweet +cyclamate +calcium cyclamate +cologran +cyclamate and saccharin +sucaryl +erythritol +sugar alcohol +zerose +zsweet +glycerol +glycerin +glycerine +glycyrrhizin +licorice +hydrogenated starch hydrolysate +hsh +sugar alcohol +isomalt +sugar alcohol +clearcut isomalt +decomalt +diabetisweet +hydrogenated isomaltulose +isomaltitol +lactitol +sugar alcohol +maltitol +sugar alcohol +maltitol syrup +maltitol powder +hydrogenated high maltose content glucose syrup +hydrogenated maltose +lesys +maltisweet +sweetpearl +mannitol +sugar alcohol +neotame +polydextrose +sugar alcohol +saccharin +acid saccharin +equal saccharin +necta sweet +sodium saccharin +sweet n low +sweet twin +sorbitol +sugar alcohol +d-glucitol +d-glucitol syrup +steviol glycoside +rebiana +sucralose +trichlorosucrose +equal sucralose +natrataste gold +splenda +tagatose +natrulose +xylitol +sugar alcohol +smart sweet +xylipure +xylosweet +spam +hot dogs +french fries +ketchup +pretzels +chips +triscuits +wheat thins +cookies +sunchips +pastries +red bull +monster +rockstar +starbucks refreshers +mountain dew mdx +vault +xs energy drink +5-hour energy +beer +whiskey +tequila +rum +vodka +alcohol and mixers +candy bars +snickers +snickers peanut butter +100 grand +butterfinger +milky way +reese’s +payday +m&ms +skittles +red vines +twizzlers +hershey’s +nestle crunch +almond joy +mounds +reese’s fast break +reeses’s pieces +twix +twix peanut butter \ No newline at end of file From b533ceca4c33e0070b05dd93eee78fece5ef8a76 Mon Sep 17 00:00:00 2001 From: javathunderman Date: Fri, 28 Aug 2015 20:42:46 +0000 Subject: [PATCH 2/8] Added PaleoIngredientCheck IA --- lib/DDG/Goodie/PaleoIngredientCheck.pm | 70 ++++++++++++++++++++++++++ t/PaleoIngredientCheck.t | 24 +++++++++ 2 files changed, 94 insertions(+) create mode 100644 lib/DDG/Goodie/PaleoIngredientCheck.pm create mode 100644 t/PaleoIngredientCheck.t diff --git a/lib/DDG/Goodie/PaleoIngredientCheck.pm b/lib/DDG/Goodie/PaleoIngredientCheck.pm new file mode 100644 index 000000000..2853b65bf --- /dev/null +++ b/lib/DDG/Goodie/PaleoIngredientCheck.pm @@ -0,0 +1,70 @@ +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; +use List::MoreUtils 'any'; + +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"]; +attribuion github => ["javathunderman", "Thomas Denizou"]; +attribution twitter => ["javathunderman", "Thomas Denizou"]; +my @safe_keywords = share('safe.txt')->slurp; +my @unsafe_keywords = share('unsafe.txt')->slurp; + +handle remainder => sub { + + 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($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"; + } + } 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"; + } + } elsif (!$is_plural) { + # If nothing was found and the query was not plural, try it pluralized. + if (any {/$item."s"/} @safe_keywords) { + $result = "is"; + } elsif (any {/$item."s"/} @unsafe_keywords) { + $result = "is not"; + } + } 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"; + } elsif (any {/$depluralized/} @unsafe_keywords) { + $result = "are not"; + } + } + + return unless $result; + return sprintf("%s %s allowed on the paleo diet.", ucfirst($item), $result); +}; + +1; \ No newline at end of file diff --git a/t/PaleoIngredientCheck.t b/t/PaleoIngredientCheck.t new file mode 100644 index 000000000..4b219ce38 --- /dev/null +++ b/t/PaleoIngredientCheck.t @@ -0,0 +1,24 @@ +#!/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('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.'), + 'Is foobar allowed on the paleo diet?' => undef, + 'are notarealfood paleo friendly' => undef, + 'paleo diet recipes' => undef, + 'paleo recipes' => undef, +); + +done_testing; \ No newline at end of file From 4fd3761df78fff8695464730195a664651bad7d3 Mon Sep 17 00:00:00 2001 From: javathunderman Date: Thu, 10 Sep 2015 17:38:27 +0000 Subject: [PATCH 3/8] Few bug fixes- not finished --- lib/DDG/Goodie/PaleoIngredientCheck.pm | 18 +++++++++++++----- .../paleo_ingredient_check}/safe.txt | 0 .../paleo_ingredient_check}/triggers.txt | 0 .../paleo_ingredient_check}/unsafe.txt | 0 4 files changed, 13 insertions(+), 5 deletions(-) rename share/{PaleoIngredientCheck => goodie/paleo_ingredient_check}/safe.txt (100%) rename share/{PaleoIngredientCheck => goodie/paleo_ingredient_check}/triggers.txt (100%) rename share/{PaleoIngredientCheck => goodie/paleo_ingredient_check}/unsafe.txt (100%) diff --git a/lib/DDG/Goodie/PaleoIngredientCheck.pm b/lib/DDG/Goodie/PaleoIngredientCheck.pm index 2853b65bf..c597b5651 100644 --- a/lib/DDG/Goodie/PaleoIngredientCheck.pm +++ b/lib/DDG/Goodie/PaleoIngredientCheck.pm @@ -3,8 +3,9 @@ package DDG::Goodie::PaleoIngredientCheck; use DDG::Goodie; use List::MoreUtils 'any'; +use YAML::XS qw(Load); -triggers startend => share('triggers.txt')->slurp; +triggers startend => Load(scalar share('triggers.txt')->slurp); zci answer_type => "paleo_ingredient_check"; zci is_cached => 1; @@ -17,10 +18,11 @@ 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"]; -attribuion github => ["javathunderman", "Thomas Denizou"]; +attribution github => ["javathunderman", "Thomas Denizou"]; attribution twitter => ["javathunderman", "Thomas Denizou"]; -my @safe_keywords = share('safe.txt')->slurp; -my @unsafe_keywords = share('unsafe.txt')->slurp; + +my @safe_keywords = Load(scalar share ('safe.txt')->slurp); +my @unsafe_keywords = Load(scalar share ('unsafe.txt')->slurp); handle remainder => sub { @@ -64,7 +66,13 @@ handle remainder => sub { } return unless $result; - return sprintf("%s %s allowed on the paleo diet.", ucfirst($item), $result); + my $plaintext = ucfirst($item) . " $result allowed on the paleo diet."; + return $plaintext, + structured_answer => { + input => "Is $item paleo-diet friendly", # or just the original query + operation => "", + result => $plaintext, # this could possibly be shortened to a simple "Yes" or "No" +}; }; 1; \ No newline at end of file diff --git a/share/PaleoIngredientCheck/safe.txt b/share/goodie/paleo_ingredient_check/safe.txt similarity index 100% rename from share/PaleoIngredientCheck/safe.txt rename to share/goodie/paleo_ingredient_check/safe.txt diff --git a/share/PaleoIngredientCheck/triggers.txt b/share/goodie/paleo_ingredient_check/triggers.txt similarity index 100% rename from share/PaleoIngredientCheck/triggers.txt rename to share/goodie/paleo_ingredient_check/triggers.txt diff --git a/share/PaleoIngredientCheck/unsafe.txt b/share/goodie/paleo_ingredient_check/unsafe.txt similarity index 100% rename from share/PaleoIngredientCheck/unsafe.txt rename to share/goodie/paleo_ingredient_check/unsafe.txt From 6a03a3fb3395587460f0b75e23b90c28f55009dc Mon Sep 17 00:00:00 2001 From: javathunderman Date: Mon, 14 Sep 2015 17:41:18 +0000 Subject: [PATCH 4/8] Yay, working on this again --- lib/DDG/Goodie/PaleoIngredientCheck.pm | 64 +--- share/goodie/paleo_ingredient_check/safe.txt | 131 ------- share/goodie/paleo_ingredient_check/safe.yml | 339 ++++++++++++++++++ .../paleo_ingredient_check/triggers.txt | 14 - .../goodie/paleo_ingredient_check/unsafe.txt | 208 ----------- 5 files changed, 355 insertions(+), 401 deletions(-) delete mode 100644 share/goodie/paleo_ingredient_check/safe.txt create mode 100644 share/goodie/paleo_ingredient_check/safe.yml delete mode 100644 share/goodie/paleo_ingredient_check/triggers.txt delete mode 100644 share/goodie/paleo_ingredient_check/unsafe.txt diff --git a/lib/DDG/Goodie/PaleoIngredientCheck.pm b/lib/DDG/Goodie/PaleoIngredientCheck.pm index c597b5651..d301e8879 100644 --- a/lib/DDG/Goodie/PaleoIngredientCheck.pm +++ b/lib/DDG/Goodie/PaleoIngredientCheck.pm @@ -5,7 +5,7 @@ use DDG::Goodie; use List::MoreUtils 'any'; use YAML::XS qw(Load); -triggers startend => Load(scalar share('triggers.txt')->slurp); +triggers any => 'paleo', 'paleo friendly', 'paleo diet', 'paleo friendly?', 'paleo?'; zci answer_type => "paleo_ingredient_check"; zci is_cached => 1; @@ -21,58 +21,26 @@ attribution github => ["murz", "Mike Murray"]; attribution github => ["javathunderman", "Thomas Denizou"]; attribution twitter => ["javathunderman", "Thomas Denizou"]; -my @safe_keywords = Load(scalar share ('safe.txt')->slurp); -my @unsafe_keywords = Load(scalar share ('unsafe.txt')->slurp); - +my $safeornot = Load(scalar share('safeornot.yml')->slurp); handle remainder => sub { +my ($query,$ingredient,$safe); #Define vars - my $item = lc($_); + s/^paleo friendly (diet)?//g; # strip common words + $query = $_; - # Remove any preceding "is" or "are" text from the query. - $item =~ s/^(is|are)[\W]+//; - my $is_plural = substr($item, -1) eq "s"; - my($result); +return unless $ingredient; +$safe= $safeornot->{$ingredient} +return unless $safe; +if ($safe eq "0") {$safe = $ingredient." is safe";} +else if ($safe eq "1") {$safe= $ingredient."is not safe";} +return $ingredient . " is $safe", + structured_answer => { + input => [$ingredient], + operation => 'paleo', + result => $safe + }; - 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"; - } - } 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"; - } - } elsif (!$is_plural) { - # If nothing was found and the query was not plural, try it pluralized. - if (any {/$item."s"/} @safe_keywords) { - $result = "is"; - } elsif (any {/$item."s"/} @unsafe_keywords) { - $result = "is not"; - } - } 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"; - } elsif (any {/$depluralized/} @unsafe_keywords) { - $result = "are not"; - } - } - - return unless $result; - my $plaintext = ucfirst($item) . " $result allowed on the paleo diet."; - return $plaintext, - structured_answer => { - input => "Is $item paleo-diet friendly", # or just the original query - operation => "", - result => $plaintext, # this could possibly be shortened to a simple "Yes" or "No" -}; }; 1; \ No newline at end of file diff --git a/share/goodie/paleo_ingredient_check/safe.txt b/share/goodie/paleo_ingredient_check/safe.txt deleted file mode 100644 index 674c8486b..000000000 --- a/share/goodie/paleo_ingredient_check/safe.txt +++ /dev/null @@ -1,131 +0,0 @@ -poultry -turkey -chicken breast -pork tenderloin -pork chops -steak -veal -bacon -pork -beef -ground beef -grass-fed beef -grassfed beef -chicken thigh -chicken leg -chicken wings -lamb rack -shrimp -lobster -clams -salmon -venison steaks -buffalo -new york steak -bison -bison steaks -bison jerky -bison ribeye -bison sirloin -lamb chops -rabbit -goat -elk -emu -goose -kangaroo -bear -beef jerky -eggs -duck eggs -chicken eggs -goose eggs -wild boar -reindeer -turtle -ostrich -pheasant -quail -lean veal -chuck steak -rattlesnake -bass -salmon -halibut -mackerel -sardines -tuna -red snapper -shark -sunfish -swordfish -tilapia -trout -walleye -crab -crawfish -crayfish -shrimp -clams -lobster -scallops -oysters -asparagus -avocado -artichoke hearts -brussels sprouts -carrots -spinach -celery -broccoli -zucchini -cabbage -peppers -cauliflower -parsley -eggplant -green onions -butternut squash -acorn squash -yam -yucca -sweet potato -sweet potatoes -beets -coconut oil -olive oil -macadamia oil -avocado oil -grass-fed butter -almonds -cashews -hazelnuts -pecans -pine nuts -pumpkin seeds -sunflower seeds -macadamia nuts -walnuts -apple -avocado -blackberries -papaya -peaches -plums -mango -lychee -blueberries -grapes -lemon -strawberries -watermelon -pineapple guava -lime -raspberries -cantaloupe -tangerine -figs -oranges -bananas -potatoes -potato \ No newline at end of file diff --git a/share/goodie/paleo_ingredient_check/safe.yml b/share/goodie/paleo_ingredient_check/safe.yml new file mode 100644 index 000000000..932d0bd87 --- /dev/null +++ b/share/goodie/paleo_ingredient_check/safe.yml @@ -0,0 +1,339 @@ +poultry:0 +turkey:0 +chicken breast:0 +pork tenderloin:0 +pork chops:0 +steak:0 +veal:0 +bacon:0 +pork:0 +beef:0 +ground beef:0 +grass-fed beef:0 +grassfed beef:0 +chicken thigh:0 +chicken leg:0 +chicken wings:0 +lamb rack:0 +shrimp:0 +lobster:0 +clams:0 +salmon:0 +venison steaks:0 +buffalo:0 +new york steak:0 +bison:0 +bison steaks:0 +bison jerky:0 +bison ribeye:0 +bison sirloin:0 +lamb chops:0 +rabbit:0 +goat:0 +elk:0 +emu:0 +goose:0 +kangaroo:0 +bear:0 +beef jerky:0 +eggs:0 +duck eggs:0 +chicken eggs:0 +goose eggs:0 +wild boar:0 +reindeer:0 +turtle:0 +ostrich:0 +pheasant:0 +quail:0 +lean veal:0 +chuck steak:0 +rattlesnake:0 +bass:0 +salmon:0 +halibut:0 +mackerel:0 +sardines:0 +tuna:0 +red snapper:0 +shark:0 +sunfish:0 +swordfish:0 +tilapia:0 +trout:0 +walleye:0 +crab:0 +crawfish:0 +crayfish:0 +shrimp:0 +clams:0 +lobster:0 +scallops:0 +oysters:0 +asparagus:0 +avocado:0 +artichoke hearts:0 +brussels sprouts:0 +carrots:0 +spinach:0 +celery:0 +broccoli:0 +zucchini:0 +cabbage:0 +peppers:0 +cauliflower:0 +parsley:0 +eggplant:0 +green onions:0 +butternut squash:0 +acorn squash:0 +yam:0 +yucca:0 +sweet potato:0 +sweet potatoes:0 +beets:0 +coconut oil:0 +olive oil:0 +macadamia oil:0 +avocado oil:0 +grass-fed butter:0 +almonds:0 +cashews:0 +hazelnuts:0 +pecans:0 +pine nuts:0 +pumpkin seeds:0 +sunflower seeds:0 +macadamia nuts:0 +walnuts:0 +apple:0 +avocado:0 +blackberries:0 +papaya:0 +peaches:0 +plums:0 +mango:0 +lychee:0 +blueberries:0 +grapes:0 +lemon:0 +strawberries:0 +watermelon:0 +pineapple guava:0 +lime:0 +raspberries:0 +cantaloupe:0 +tangerine:0 +figs:0 +oranges:0 +bananas:0 +potatoes:0 +potato:0 +butter:1 +cheese:1 +cottage cheese:1 +non-fat dairy creamer:1 +milk:1 +skim milk:1 +2% milk:1 +two percent milk:1 +whole milk:1 +dairy spreads:1 +cream cheese:1 +powdered milk:1 +yogurt:1 +pudding:1 +frozen yogurt:1 +ice milk:1 +low fat milk:1 +ice cream:1 +milk:1 +coke:1 +sprite:1 +pepsi:1 +mountain dew:1 +apple juice:1 +orange juice:1 +grape juice:1 +strawberry juice:1 +chinola juice:1 +starfruit juice:1 +mango juice:1 +cereals:1 +bread:1 +english muffins:1 +toast:1 +sandwiches:1 +triscuits:1 +wheat thins:1 +crackers:1 +oatmeal:1 +cream of wheat:1 +corn:1 +corn syrup:1 +high-fructose corn syrup:1 +wheat:1 +pancakes:1 +hash browns:1 +beer:1 +pasta:1 +fettuchini:1 +lasagne:1 +lasagna:1 +black beans:1 +broad beans:1 +fava beans:1 +garbanzo beans:1 +horse beans:1 +kidney beans:1 +lima beans:1 +mung beans:1 +adzuki beans:1 +navy beans:1 +pinto beans:1 +red beans:1 +green beans:1 +string beans:1 +white beans:1 +beans:1 +peas:1 +black-eyed peas:0 +chickpeas:1 +snowpeas:1 +sugar snap peas:1 +peanuts:1 +peanut butter:1 +miso:1 +lentils:1 +lupins:1 +mesquite:1 +soybeans:1 +soybean:1 +tofu:1 +beans:1 +acesulfame potassium:1 +ack:1 +ace k:1 +equal spoonful:1 +sweet one:1 +sunett:1 +aspartame:1 +apm:1 +aminosweet:1 +aspartyl-phenylalanine-1-methyl ester:1 +canderel:1 +equal classic:1 +natrataste blue:1 +nutrasweet:1 +aspartame-acesulfame salt:1 +twinsweet:1 +cyclamate:1 +calcium cyclamate:1 +cologran:1 +cyclamate and saccharin:1 +sucaryl:1 +erythritol:1 +sugar alcohol:1 +zerose:1 +zsweet:1 +glycerol:1 +glycerin:1 +glycerine:1 +glycyrrhizin:1 +licorice:1 +hydrogenated starch hydrolysate:1 +hsh:1 +sugar alcohol:1 +isomalt:1 +sugar alcohol:1 +clearcut isomalt:1 +decomalt:1 +diabetisweet:1 +hydrogenated isomaltulose:1 +isomaltitol:1 +lactitol:1 +sugar alcohol:1 +maltitol:1 +sugar alcohol:1 +maltitol syrup:1 +maltitol powder:1 +hydrogenated high maltose content glucose syrup:1 +hydrogenated maltose:1 +lesys:1 +maltisweet:1 +sweetpearl:1 +mannitol:1 +sugar alcohol:1 +neotame:1 +polydextrose:1 +sugar alcohol:1 +saccharin:1 +acid saccharin:1 +equal saccharin:1 +necta sweet:1 +sodium saccharin:1 +sweet n low:1 +sweet twin:1 +sorbitol:1 +sugar alcohol:1 +d-glucitol:1 +d-glucitol syrup:1 +steviol glycoside:1 +rebiana:1 +sucralose:1 +trichlorosucrose:1 +equal sucralose:1 +natrataste gold:1 +splenda:1 +tagatose:1 +natrulose:1 +xylitol:1 +sugar alcohol:1 +smart sweet:1 +xylipure:1 +xylosweet:1 +spam:1 +hot dogs:1 +french fries:1 +ketchup:1 +pretzels:1 +chips:1 +triscuits:1 +wheat thins:1 +cookies:1 +sunchips:1 +pastries:1 +red bull:1 +monster:1 +rockstar:1 +starbucks refreshers:1 +mountain dew mdx:1 +vault:1 +xs energy drink:1 +5-hour energy:1 +beer:1 +whiskey:1 +tequila:1 +rum:1 +vodka:1 +alcohol and mixers:1 +candy bars:1 +snickers:1 +snickers peanut butter:1 +100 grand:1 +butterfinger:1 +milky way:1 +reese’s:1 +payday:1 +m&ms:1 +skittles:1 +red vines:1 +twizzlers:1 +hershey’s:1 +nestle crunch:1 +almond joy:1 +mounds:1 +reese’s fast break:1 +reeses’s pieces:1 +twix:1 +twix peanut butter:1 \ No newline at end of file diff --git a/share/goodie/paleo_ingredient_check/triggers.txt b/share/goodie/paleo_ingredient_check/triggers.txt deleted file mode 100644 index c2827e401..000000000 --- a/share/goodie/paleo_ingredient_check/triggers.txt +++ /dev/null @@ -1,14 +0,0 @@ -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? \ No newline at end of file diff --git a/share/goodie/paleo_ingredient_check/unsafe.txt b/share/goodie/paleo_ingredient_check/unsafe.txt deleted file mode 100644 index d162e75da..000000000 --- a/share/goodie/paleo_ingredient_check/unsafe.txt +++ /dev/null @@ -1,208 +0,0 @@ -butter -cheese -cottage cheese -non-fat dairy creamer -milk -skim milk -2% milk -two percent milk -whole milk -dairy spreads -cream cheese -powdered milk -yogurt -pudding -frozen yogurt -ice milk -low fat milk -ice cream -milk -coke -sprite -pepsi -mountain dew -apple juice -orange juice -grape juice -strawberry juice -chinola juice -starfruit juice -mango juice -cereals -bread -english muffins -toast -sandwiches -triscuits -wheat thins -crackers -oatmeal -cream of wheat -corn -corn syrup -high-fructose corn syrup -wheat -pancakes -hash browns -beer -pasta -fettuchini -lasagne -lasagna -black beans -broad beans -fava beans -garbanzo beans -horse beans -kidney beans -lima beans -mung beans -adzuki beans -navy beans -pinto beans -red beans -green beans -string beans -white beans -beans -peas -black-eyed peas -chickpeas -snowpeas -sugar snap peas -peanuts -peanut butter -miso -lentils -lupins -mesquite -soybeans -soybean -tofu -beans -acesulfame potassium -ack -ace k -equal spoonful -sweet one -sunett -aspartame -apm -aminosweet -aspartyl-phenylalanine-1-methyl ester -canderel -equal classic -natrataste blue -nutrasweet -aspartame-acesulfame salt -twinsweet -cyclamate -calcium cyclamate -cologran -cyclamate and saccharin -sucaryl -erythritol -sugar alcohol -zerose -zsweet -glycerol -glycerin -glycerine -glycyrrhizin -licorice -hydrogenated starch hydrolysate -hsh -sugar alcohol -isomalt -sugar alcohol -clearcut isomalt -decomalt -diabetisweet -hydrogenated isomaltulose -isomaltitol -lactitol -sugar alcohol -maltitol -sugar alcohol -maltitol syrup -maltitol powder -hydrogenated high maltose content glucose syrup -hydrogenated maltose -lesys -maltisweet -sweetpearl -mannitol -sugar alcohol -neotame -polydextrose -sugar alcohol -saccharin -acid saccharin -equal saccharin -necta sweet -sodium saccharin -sweet n low -sweet twin -sorbitol -sugar alcohol -d-glucitol -d-glucitol syrup -steviol glycoside -rebiana -sucralose -trichlorosucrose -equal sucralose -natrataste gold -splenda -tagatose -natrulose -xylitol -sugar alcohol -smart sweet -xylipure -xylosweet -spam -hot dogs -french fries -ketchup -pretzels -chips -triscuits -wheat thins -cookies -sunchips -pastries -red bull -monster -rockstar -starbucks refreshers -mountain dew mdx -vault -xs energy drink -5-hour energy -beer -whiskey -tequila -rum -vodka -alcohol and mixers -candy bars -snickers -snickers peanut butter -100 grand -butterfinger -milky way -reese’s -payday -m&ms -skittles -red vines -twizzlers -hershey’s -nestle crunch -almond joy -mounds -reese’s fast break -reeses’s pieces -twix -twix peanut butter \ No newline at end of file From 0d72258f52c44f9aae92e1ddce429dc2753fdbb1 Mon Sep 17 00:00:00 2001 From: javathunderman Date: Tue, 29 Sep 2015 17:12:56 +0000 Subject: [PATCH 5/8] Reverting... --- lib/DDG/Goodie/PaleoIngredientCheck.pm | 61 +++- share/goodie/paleo_ingredient_check/safe.txt | 131 +++++++ share/goodie/paleo_ingredient_check/safe.yml | 339 ------------------ .../paleo_ingredient_check/triggers.txt | 14 + .../goodie/paleo_ingredient_check/unsafe.txt | 208 +++++++++++ 5 files changed, 395 insertions(+), 358 deletions(-) create mode 100644 share/goodie/paleo_ingredient_check/safe.txt delete mode 100644 share/goodie/paleo_ingredient_check/safe.yml create mode 100644 share/goodie/paleo_ingredient_check/triggers.txt create mode 100644 share/goodie/paleo_ingredient_check/unsafe.txt diff --git a/lib/DDG/Goodie/PaleoIngredientCheck.pm b/lib/DDG/Goodie/PaleoIngredientCheck.pm index d301e8879..e399285e0 100644 --- a/lib/DDG/Goodie/PaleoIngredientCheck.pm +++ b/lib/DDG/Goodie/PaleoIngredientCheck.pm @@ -3,9 +3,8 @@ package DDG::Goodie::PaleoIngredientCheck; use DDG::Goodie; use List::MoreUtils 'any'; -use YAML::XS qw(Load); -triggers any => 'paleo', 'paleo friendly', 'paleo diet', 'paleo friendly?', 'paleo?'; +triggers startend => share('triggers.txt')->slurp; zci answer_type => "paleo_ingredient_check"; zci is_cached => 1; @@ -18,29 +17,53 @@ 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"]; -attribution twitter => ["javathunderman", "Thomas Denizou"]; -my $safeornot = Load(scalar share('safeornot.yml')->slurp); +my @safe_keywords = share('safe.txt')->slurp; +my @unsafe_keywords = share('unsafe.txt')->slurp; + handle remainder => sub { -my ($query,$ingredient,$safe); #Define vars - s/^paleo friendly (diet)?//g; # strip common words - $query = $_; + my $item = lc($_); + # Remove any preceding "is" or "are" text from the query. + $item =~ s/^(is|are)[\W]+//; -return unless $ingredient; -$safe= $safeornot->{$ingredient} -return unless $safe; -if ($safe eq "0") {$safe = $ingredient." is safe";} -else if ($safe eq "1") {$safe= $ingredient."is not safe";} -return $ingredient . " is $safe", - structured_answer => { - input => [$ingredient], - operation => 'paleo', - result => $safe - }; + my $is_plural = substr($item, -1) eq "s"; + 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"; + } + } 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"; + } + } elsif (!$is_plural) { + # If nothing was found and the query was not plural, try it pluralized. + if (any {/$item."s"/} @safe_keywords) { + $result = "is"; + } elsif (any {/$item."s"/} @unsafe_keywords) { + $result = "is not"; + } + } 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"; + } elsif (any {/$depluralized/} @unsafe_keywords) { + $result = "are not"; + } + } + + return unless $result; + return sprintf("%s %s allowed on the paleo diet.", ucfirst($item), $result); }; 1; \ No newline at end of file diff --git a/share/goodie/paleo_ingredient_check/safe.txt b/share/goodie/paleo_ingredient_check/safe.txt new file mode 100644 index 000000000..674c8486b --- /dev/null +++ b/share/goodie/paleo_ingredient_check/safe.txt @@ -0,0 +1,131 @@ +poultry +turkey +chicken breast +pork tenderloin +pork chops +steak +veal +bacon +pork +beef +ground beef +grass-fed beef +grassfed beef +chicken thigh +chicken leg +chicken wings +lamb rack +shrimp +lobster +clams +salmon +venison steaks +buffalo +new york steak +bison +bison steaks +bison jerky +bison ribeye +bison sirloin +lamb chops +rabbit +goat +elk +emu +goose +kangaroo +bear +beef jerky +eggs +duck eggs +chicken eggs +goose eggs +wild boar +reindeer +turtle +ostrich +pheasant +quail +lean veal +chuck steak +rattlesnake +bass +salmon +halibut +mackerel +sardines +tuna +red snapper +shark +sunfish +swordfish +tilapia +trout +walleye +crab +crawfish +crayfish +shrimp +clams +lobster +scallops +oysters +asparagus +avocado +artichoke hearts +brussels sprouts +carrots +spinach +celery +broccoli +zucchini +cabbage +peppers +cauliflower +parsley +eggplant +green onions +butternut squash +acorn squash +yam +yucca +sweet potato +sweet potatoes +beets +coconut oil +olive oil +macadamia oil +avocado oil +grass-fed butter +almonds +cashews +hazelnuts +pecans +pine nuts +pumpkin seeds +sunflower seeds +macadamia nuts +walnuts +apple +avocado +blackberries +papaya +peaches +plums +mango +lychee +blueberries +grapes +lemon +strawberries +watermelon +pineapple guava +lime +raspberries +cantaloupe +tangerine +figs +oranges +bananas +potatoes +potato \ No newline at end of file diff --git a/share/goodie/paleo_ingredient_check/safe.yml b/share/goodie/paleo_ingredient_check/safe.yml deleted file mode 100644 index 932d0bd87..000000000 --- a/share/goodie/paleo_ingredient_check/safe.yml +++ /dev/null @@ -1,339 +0,0 @@ -poultry:0 -turkey:0 -chicken breast:0 -pork tenderloin:0 -pork chops:0 -steak:0 -veal:0 -bacon:0 -pork:0 -beef:0 -ground beef:0 -grass-fed beef:0 -grassfed beef:0 -chicken thigh:0 -chicken leg:0 -chicken wings:0 -lamb rack:0 -shrimp:0 -lobster:0 -clams:0 -salmon:0 -venison steaks:0 -buffalo:0 -new york steak:0 -bison:0 -bison steaks:0 -bison jerky:0 -bison ribeye:0 -bison sirloin:0 -lamb chops:0 -rabbit:0 -goat:0 -elk:0 -emu:0 -goose:0 -kangaroo:0 -bear:0 -beef jerky:0 -eggs:0 -duck eggs:0 -chicken eggs:0 -goose eggs:0 -wild boar:0 -reindeer:0 -turtle:0 -ostrich:0 -pheasant:0 -quail:0 -lean veal:0 -chuck steak:0 -rattlesnake:0 -bass:0 -salmon:0 -halibut:0 -mackerel:0 -sardines:0 -tuna:0 -red snapper:0 -shark:0 -sunfish:0 -swordfish:0 -tilapia:0 -trout:0 -walleye:0 -crab:0 -crawfish:0 -crayfish:0 -shrimp:0 -clams:0 -lobster:0 -scallops:0 -oysters:0 -asparagus:0 -avocado:0 -artichoke hearts:0 -brussels sprouts:0 -carrots:0 -spinach:0 -celery:0 -broccoli:0 -zucchini:0 -cabbage:0 -peppers:0 -cauliflower:0 -parsley:0 -eggplant:0 -green onions:0 -butternut squash:0 -acorn squash:0 -yam:0 -yucca:0 -sweet potato:0 -sweet potatoes:0 -beets:0 -coconut oil:0 -olive oil:0 -macadamia oil:0 -avocado oil:0 -grass-fed butter:0 -almonds:0 -cashews:0 -hazelnuts:0 -pecans:0 -pine nuts:0 -pumpkin seeds:0 -sunflower seeds:0 -macadamia nuts:0 -walnuts:0 -apple:0 -avocado:0 -blackberries:0 -papaya:0 -peaches:0 -plums:0 -mango:0 -lychee:0 -blueberries:0 -grapes:0 -lemon:0 -strawberries:0 -watermelon:0 -pineapple guava:0 -lime:0 -raspberries:0 -cantaloupe:0 -tangerine:0 -figs:0 -oranges:0 -bananas:0 -potatoes:0 -potato:0 -butter:1 -cheese:1 -cottage cheese:1 -non-fat dairy creamer:1 -milk:1 -skim milk:1 -2% milk:1 -two percent milk:1 -whole milk:1 -dairy spreads:1 -cream cheese:1 -powdered milk:1 -yogurt:1 -pudding:1 -frozen yogurt:1 -ice milk:1 -low fat milk:1 -ice cream:1 -milk:1 -coke:1 -sprite:1 -pepsi:1 -mountain dew:1 -apple juice:1 -orange juice:1 -grape juice:1 -strawberry juice:1 -chinola juice:1 -starfruit juice:1 -mango juice:1 -cereals:1 -bread:1 -english muffins:1 -toast:1 -sandwiches:1 -triscuits:1 -wheat thins:1 -crackers:1 -oatmeal:1 -cream of wheat:1 -corn:1 -corn syrup:1 -high-fructose corn syrup:1 -wheat:1 -pancakes:1 -hash browns:1 -beer:1 -pasta:1 -fettuchini:1 -lasagne:1 -lasagna:1 -black beans:1 -broad beans:1 -fava beans:1 -garbanzo beans:1 -horse beans:1 -kidney beans:1 -lima beans:1 -mung beans:1 -adzuki beans:1 -navy beans:1 -pinto beans:1 -red beans:1 -green beans:1 -string beans:1 -white beans:1 -beans:1 -peas:1 -black-eyed peas:0 -chickpeas:1 -snowpeas:1 -sugar snap peas:1 -peanuts:1 -peanut butter:1 -miso:1 -lentils:1 -lupins:1 -mesquite:1 -soybeans:1 -soybean:1 -tofu:1 -beans:1 -acesulfame potassium:1 -ack:1 -ace k:1 -equal spoonful:1 -sweet one:1 -sunett:1 -aspartame:1 -apm:1 -aminosweet:1 -aspartyl-phenylalanine-1-methyl ester:1 -canderel:1 -equal classic:1 -natrataste blue:1 -nutrasweet:1 -aspartame-acesulfame salt:1 -twinsweet:1 -cyclamate:1 -calcium cyclamate:1 -cologran:1 -cyclamate and saccharin:1 -sucaryl:1 -erythritol:1 -sugar alcohol:1 -zerose:1 -zsweet:1 -glycerol:1 -glycerin:1 -glycerine:1 -glycyrrhizin:1 -licorice:1 -hydrogenated starch hydrolysate:1 -hsh:1 -sugar alcohol:1 -isomalt:1 -sugar alcohol:1 -clearcut isomalt:1 -decomalt:1 -diabetisweet:1 -hydrogenated isomaltulose:1 -isomaltitol:1 -lactitol:1 -sugar alcohol:1 -maltitol:1 -sugar alcohol:1 -maltitol syrup:1 -maltitol powder:1 -hydrogenated high maltose content glucose syrup:1 -hydrogenated maltose:1 -lesys:1 -maltisweet:1 -sweetpearl:1 -mannitol:1 -sugar alcohol:1 -neotame:1 -polydextrose:1 -sugar alcohol:1 -saccharin:1 -acid saccharin:1 -equal saccharin:1 -necta sweet:1 -sodium saccharin:1 -sweet n low:1 -sweet twin:1 -sorbitol:1 -sugar alcohol:1 -d-glucitol:1 -d-glucitol syrup:1 -steviol glycoside:1 -rebiana:1 -sucralose:1 -trichlorosucrose:1 -equal sucralose:1 -natrataste gold:1 -splenda:1 -tagatose:1 -natrulose:1 -xylitol:1 -sugar alcohol:1 -smart sweet:1 -xylipure:1 -xylosweet:1 -spam:1 -hot dogs:1 -french fries:1 -ketchup:1 -pretzels:1 -chips:1 -triscuits:1 -wheat thins:1 -cookies:1 -sunchips:1 -pastries:1 -red bull:1 -monster:1 -rockstar:1 -starbucks refreshers:1 -mountain dew mdx:1 -vault:1 -xs energy drink:1 -5-hour energy:1 -beer:1 -whiskey:1 -tequila:1 -rum:1 -vodka:1 -alcohol and mixers:1 -candy bars:1 -snickers:1 -snickers peanut butter:1 -100 grand:1 -butterfinger:1 -milky way:1 -reese’s:1 -payday:1 -m&ms:1 -skittles:1 -red vines:1 -twizzlers:1 -hershey’s:1 -nestle crunch:1 -almond joy:1 -mounds:1 -reese’s fast break:1 -reeses’s pieces:1 -twix:1 -twix peanut butter:1 \ No newline at end of file diff --git a/share/goodie/paleo_ingredient_check/triggers.txt b/share/goodie/paleo_ingredient_check/triggers.txt new file mode 100644 index 000000000..c2827e401 --- /dev/null +++ b/share/goodie/paleo_ingredient_check/triggers.txt @@ -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? \ No newline at end of file diff --git a/share/goodie/paleo_ingredient_check/unsafe.txt b/share/goodie/paleo_ingredient_check/unsafe.txt new file mode 100644 index 000000000..d162e75da --- /dev/null +++ b/share/goodie/paleo_ingredient_check/unsafe.txt @@ -0,0 +1,208 @@ +butter +cheese +cottage cheese +non-fat dairy creamer +milk +skim milk +2% milk +two percent milk +whole milk +dairy spreads +cream cheese +powdered milk +yogurt +pudding +frozen yogurt +ice milk +low fat milk +ice cream +milk +coke +sprite +pepsi +mountain dew +apple juice +orange juice +grape juice +strawberry juice +chinola juice +starfruit juice +mango juice +cereals +bread +english muffins +toast +sandwiches +triscuits +wheat thins +crackers +oatmeal +cream of wheat +corn +corn syrup +high-fructose corn syrup +wheat +pancakes +hash browns +beer +pasta +fettuchini +lasagne +lasagna +black beans +broad beans +fava beans +garbanzo beans +horse beans +kidney beans +lima beans +mung beans +adzuki beans +navy beans +pinto beans +red beans +green beans +string beans +white beans +beans +peas +black-eyed peas +chickpeas +snowpeas +sugar snap peas +peanuts +peanut butter +miso +lentils +lupins +mesquite +soybeans +soybean +tofu +beans +acesulfame potassium +ack +ace k +equal spoonful +sweet one +sunett +aspartame +apm +aminosweet +aspartyl-phenylalanine-1-methyl ester +canderel +equal classic +natrataste blue +nutrasweet +aspartame-acesulfame salt +twinsweet +cyclamate +calcium cyclamate +cologran +cyclamate and saccharin +sucaryl +erythritol +sugar alcohol +zerose +zsweet +glycerol +glycerin +glycerine +glycyrrhizin +licorice +hydrogenated starch hydrolysate +hsh +sugar alcohol +isomalt +sugar alcohol +clearcut isomalt +decomalt +diabetisweet +hydrogenated isomaltulose +isomaltitol +lactitol +sugar alcohol +maltitol +sugar alcohol +maltitol syrup +maltitol powder +hydrogenated high maltose content glucose syrup +hydrogenated maltose +lesys +maltisweet +sweetpearl +mannitol +sugar alcohol +neotame +polydextrose +sugar alcohol +saccharin +acid saccharin +equal saccharin +necta sweet +sodium saccharin +sweet n low +sweet twin +sorbitol +sugar alcohol +d-glucitol +d-glucitol syrup +steviol glycoside +rebiana +sucralose +trichlorosucrose +equal sucralose +natrataste gold +splenda +tagatose +natrulose +xylitol +sugar alcohol +smart sweet +xylipure +xylosweet +spam +hot dogs +french fries +ketchup +pretzels +chips +triscuits +wheat thins +cookies +sunchips +pastries +red bull +monster +rockstar +starbucks refreshers +mountain dew mdx +vault +xs energy drink +5-hour energy +beer +whiskey +tequila +rum +vodka +alcohol and mixers +candy bars +snickers +snickers peanut butter +100 grand +butterfinger +milky way +reese’s +payday +m&ms +skittles +red vines +twizzlers +hershey’s +nestle crunch +almond joy +mounds +reese’s fast break +reeses’s pieces +twix +twix peanut butter \ No newline at end of file From 508ace02cd4fc76a443b81e9b193ee68bea09531 Mon Sep 17 00:00:00 2001 From: javathunderman Date: Tue, 29 Sep 2015 17:30:28 +0000 Subject: [PATCH 6/8] Yay, structured answer --- lib/DDG/Goodie/PaleoIngredientCheck.pm | 31 +++++++++++--------------- t/PaleoIngredientCheck.t | 10 ++++----- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/lib/DDG/Goodie/PaleoIngredientCheck.pm b/lib/DDG/Goodie/PaleoIngredientCheck.pm index e399285e0..76a209860 100644 --- a/lib/DDG/Goodie/PaleoIngredientCheck.pm +++ b/lib/DDG/Goodie/PaleoIngredientCheck.pm @@ -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; \ No newline at end of file diff --git a/t/PaleoIngredientCheck.t b/t/PaleoIngredientCheck.t index 4b219ce38..d0cc173ed 100644 --- a/t/PaleoIngredientCheck.t +++ b/t/PaleoIngredientCheck.t @@ -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, From b8c284485557ae6655a7a5c53ef5f6e89f78cbf3 Mon Sep 17 00:00:00 2001 From: javathunderman Date: Fri, 30 Oct 2015 17:20:35 +0000 Subject: [PATCH 7/8] Alpha-sort --- lib/DDG/Goodie/PaleoIngredientCheck.pm | 3 +- share/goodie/paleo_ingredient_check/safe.txt | 230 +++++------ .../goodie/paleo_ingredient_check/unsafe.txt | 382 +++++++++--------- 3 files changed, 308 insertions(+), 307 deletions(-) diff --git a/lib/DDG/Goodie/PaleoIngredientCheck.pm b/lib/DDG/Goodie/PaleoIngredientCheck.pm index 76a209860..abac7759f 100644 --- a/lib/DDG/Goodie/PaleoIngredientCheck.pm +++ b/lib/DDG/Goodie/PaleoIngredientCheck.pm @@ -52,8 +52,9 @@ handle remainder => sub { $result = "No"; } } - + #return unless any {/$item/} @safe_keywords return $result; + structured_answer => { input => "Is $item paleo-diet friendly", # or just the original query operation => "", diff --git a/share/goodie/paleo_ingredient_check/safe.txt b/share/goodie/paleo_ingredient_check/safe.txt index 674c8486b..a7e1cb924 100644 --- a/share/goodie/paleo_ingredient_check/safe.txt +++ b/share/goodie/paleo_ingredient_check/safe.txt @@ -1,131 +1,131 @@ -poultry -turkey -chicken breast -pork tenderloin -pork chops -steak -veal +acorn squash +almonds +apple +artichoke hearts +asparagus +avocado +avocado +avocado oil bacon -pork +bananas +bass +bear beef -ground beef -grass-fed beef -grassfed beef -chicken thigh -chicken leg -chicken wings -lamb rack -shrimp -lobster -clams -salmon -venison steaks -buffalo -new york steak +beef jerky +beets bison -bison steaks bison jerky bison ribeye bison sirloin -lamb chops -rabbit -goat -elk -emu -goose -kangaroo -bear -beef jerky -eggs -duck eggs +bison steaks +blackberries +blueberries +broccoli +brussels sprouts +buffalo +butternut squash +cabbage +cantaloupe +carrots +cashews +cauliflower +celery +chicken breast chicken eggs -goose eggs -wild boar -reindeer -turtle -ostrich -pheasant -quail -lean veal +chicken leg +chicken thigh +chicken wings chuck steak -rattlesnake -bass -salmon -halibut -mackerel -sardines -tuna -red snapper -shark -sunfish -swordfish -tilapia -trout -walleye +clams +clams +coconut oil crab crawfish crayfish -shrimp -clams -lobster -scallops -oysters -asparagus -avocado -artichoke hearts -brussels sprouts -carrots -spinach -celery -broccoli -zucchini -cabbage -peppers -cauliflower -parsley +duck eggs eggplant +eggs +elk +emu +figs +goat +goose +goose eggs +grapes +grassfed beef +grass-fed beef +grass-fed butter green onions -butternut squash -acorn squash -yam -yucca +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 -beets -coconut oil -olive oil -macadamia oil -avocado oil -grass-fed butter -almonds -cashews -hazelnuts -pecans -pine nuts -pumpkin seeds -sunflower seeds -macadamia nuts -walnuts -apple -avocado -blackberries -papaya -peaches -plums -mango -lychee -blueberries -grapes -lemon -strawberries -watermelon -pineapple guava -lime -raspberries -cantaloupe +swordfish tangerine -figs -oranges -bananas -potatoes -potato \ No newline at end of file +tilapia +trout +tuna +turkey +turtle +veal +venison steaks +walleye +walnuts +watermelon +wild boar +yam +yucca +zucchini diff --git a/share/goodie/paleo_ingredient_check/unsafe.txt b/share/goodie/paleo_ingredient_check/unsafe.txt index d162e75da..2b60d6ce2 100644 --- a/share/goodie/paleo_ingredient_check/unsafe.txt +++ b/share/goodie/paleo_ingredient_check/unsafe.txt @@ -1,208 +1,208 @@ -butter -cheese -cottage cheese -non-fat dairy creamer -milk -skim milk +100 grand 2% milk -two percent milk -whole milk -dairy spreads -cream cheese -powdered milk -yogurt -pudding -frozen yogurt -ice milk -low fat milk -ice cream -milk -coke -sprite -pepsi -mountain dew +5-hour energy +ace k +acesulfame potassium +acid saccharin +ack +adzuki beans +alcohol and mixers +almond joy +aminosweet +apm apple juice -orange juice -grape juice -strawberry juice -chinola juice -starfruit juice -mango juice -cereals +aspartame +aspartame-acesulfame salt +aspartyl-phenylalanine-1-methyl ester +beans +beans +beer +beer +black beans +black-eyed peas bread -english muffins -toast -sandwiches -triscuits -wheat thins -crackers -oatmeal -cream of wheat +broad beans +butter +butterfinger +calcium cyclamate +canderel +candy bars +cereals +cheese +chickpeas +chinola juice +chips +clearcut isomalt +coke +cologran +cookies corn corn syrup -high-fructose corn syrup -wheat -pancakes -hash browns -beer -pasta -fettuchini -lasagne -lasagna -black beans -broad beans -fava beans -garbanzo beans -horse beans -kidney beans -lima beans -mung beans -adzuki beans -navy beans -pinto beans -red beans -green beans -string beans -white beans -beans -peas -black-eyed peas -chickpeas -snowpeas -sugar snap peas -peanuts -peanut butter -miso -lentils -lupins -mesquite -soybeans -soybean -tofu -beans -acesulfame potassium -ack -ace k -equal spoonful -sweet one -sunett -aspartame -apm -aminosweet -aspartyl-phenylalanine-1-methyl ester -canderel -equal classic -natrataste blue -nutrasweet -aspartame-acesulfame salt -twinsweet +cottage cheese +crackers +cream cheese +cream of wheat cyclamate -calcium cyclamate -cologran cyclamate and saccharin -sucaryl -erythritol -sugar alcohol -zerose -zsweet -glycerol -glycerin -glycerine -glycyrrhizin -licorice -hydrogenated starch hydrolysate -hsh -sugar alcohol -isomalt -sugar alcohol -clearcut isomalt +dairy spreads decomalt -diabetisweet -hydrogenated isomaltulose -isomaltitol -lactitol -sugar alcohol -maltitol -sugar alcohol -maltitol syrup -maltitol powder -hydrogenated high maltose content glucose syrup -hydrogenated maltose -lesys -maltisweet -sweetpearl -mannitol -sugar alcohol -neotame -polydextrose -sugar alcohol -saccharin -acid saccharin -equal saccharin -necta sweet -sodium saccharin -sweet n low -sweet twin -sorbitol -sugar alcohol d-glucitol d-glucitol syrup -steviol glycoside -rebiana -sucralose -trichlorosucrose +diabetisweet +english muffins +equal classic +equal saccharin +equal spoonful equal sucralose -natrataste gold -splenda -tagatose -natrulose -xylitol -sugar alcohol -smart sweet -xylipure -xylosweet -spam -hot dogs +erythritol +fava beans +fettuchini french fries -ketchup -pretzels -chips -triscuits -wheat thins -cookies -sunchips -pastries -red bull -monster -rockstar -starbucks refreshers -mountain dew mdx -vault -xs energy drink -5-hour energy -beer -whiskey -tequila -rum -vodka -alcohol and mixers -candy bars -snickers -snickers peanut butter -100 grand -butterfinger -milky way -reese’s -payday -m&ms -skittles -red vines -twizzlers +frozen yogurt +garbanzo beans +glycerin +glycerine +glycerol +glycyrrhizin +grape juice +green beans +hash browns hershey’s -nestle crunch -almond joy +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 +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 +reese’s reese’s fast break reeses’s pieces +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 alcohol +sugar alcohol +sugar alcohol +sugar alcohol +sugar alcohol +sugar alcohol +sugar alcohol +sugar alcohol +sugar alcohol +sugar snap peas +sunchips +sunett +sweet n low +sweet one +sweet twin +sweetpearl +tagatose +tequila +toast +tofu +trichlorosucrose +triscuits +triscuits +twinsweet twix -twix peanut butter \ No newline at end of file +twix peanut butter +twizzlers +two percent milk +vault +vodka +wheat +wheat thins +wheat thins +whiskey +white beans +whole milk +xs energy drink +xylipure +xylitol +xylosweet +yogurt +zerose +zsweet From eb2777a3d0807d93ef43f7c4934d87df3f2bf7ca Mon Sep 17 00:00:00 2001 From: javathunderman Date: Fri, 30 Oct 2015 22:00:25 +0000 Subject: [PATCH 8/8] Clean up code, tests, etc. --- lib/DDG/Goodie/PaleoIngredientCheck.pm | 58 +++++++++---------- .../goodie/paleo_ingredient_check/unsafe.txt | 31 ++++------ t/PaleoIngredientCheck.t | 45 ++++++++++++-- 3 files changed, 76 insertions(+), 58 deletions(-) diff --git a/lib/DDG/Goodie/PaleoIngredientCheck.pm b/lib/DDG/Goodie/PaleoIngredientCheck.pm index abac7759f..a4b51abab 100644 --- a/lib/DDG/Goodie/PaleoIngredientCheck.pm +++ b/lib/DDG/Goodie/PaleoIngredientCheck.pm @@ -2,7 +2,6 @@ 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; -use List::MoreUtils 'any'; triggers startend => share('triggers.txt')->slurp; @@ -17,49 +16,44 @@ 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_keywords = share('safe.txt')->slurp; -my @unsafe_keywords = share('unsafe.txt')->slurp; +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($result); + my $itemAlt = $is_plural ? substr($item, 0, -1) : $item."s"; # pluralized or unpluralized form + my $result; - if (any {/$item/} @safe_keywords) { - - $result= "Yes"; - } elsif (any {/$item/} @unsafe_keywords) { - $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 = "Yes"; - } elsif (any {/$item."s"/} @unsafe_keywords) { - $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 = "Yes"; - } elsif (any {/$depluralized/} @unsafe_keywords) { - $result = "No"; - } + # 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 any {/$item/} @safe_keywords -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" -}; + 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; \ No newline at end of file diff --git a/share/goodie/paleo_ingredient_check/unsafe.txt b/share/goodie/paleo_ingredient_check/unsafe.txt index 2b60d6ce2..204a4caa4 100644 --- a/share/goodie/paleo_ingredient_check/unsafe.txt +++ b/share/goodie/paleo_ingredient_check/unsafe.txt @@ -4,7 +4,7 @@ ace k acesulfame potassium acid saccharin -ack +ack adzuki beans alcohol and mixers almond joy @@ -13,10 +13,8 @@ apm apple juice aspartame aspartame-acesulfame salt -aspartyl-phenylalanine-1-methyl ester +aspartyl-phenylalanine-1-methyl ester beans -beans -beer beer black beans black-eyed peas @@ -26,7 +24,7 @@ butter butterfinger calcium cyclamate canderel -candy bars +candy bars cereals cheese chickpeas @@ -44,10 +42,11 @@ cream cheese cream of wheat cyclamate cyclamate and saccharin -dairy spreads -decomalt d-glucitol d-glucitol syrup +dairy +dairy spreads +decomalt diabetisweet english muffins equal classic @@ -86,7 +85,7 @@ lactitol lasagna lasagne lentils -lesys +lesys licorice lima beans low fat milk @@ -100,7 +99,6 @@ mango juice mannitol mesquite milk -milk milky way miso monster @@ -136,9 +134,9 @@ rebiana red beans red bull red vines +reeses’s pieces reese’s reese’s fast break -reeses’s pieces rockstar rum saccharin @@ -163,14 +161,7 @@ strawberry juice string beans sucaryl sucralose -sugar alcohol -sugar alcohol -sugar alcohol -sugar alcohol -sugar alcohol -sugar alcohol -sugar alcohol -sugar alcohol +sugar sugar alcohol sugar snap peas sunchips @@ -185,7 +176,6 @@ toast tofu trichlorosucrose triscuits -triscuits twinsweet twix twix peanut butter @@ -195,7 +185,6 @@ vault vodka wheat wheat thins -wheat thins whiskey white beans whole milk @@ -205,4 +194,4 @@ xylitol xylosweet yogurt zerose -zsweet +zsweet \ No newline at end of file diff --git a/t/PaleoIngredientCheck.t b/t/PaleoIngredientCheck.t index d0cc173ed..87b4e560a 100644 --- a/t/PaleoIngredientCheck.t +++ b/t/PaleoIngredientCheck.t @@ -10,11 +10,46 @@ zci is_cached => 1; ddg_goodie_test( [qw( DDG::Goodie::PaleoIngredientCheck )], - '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'), + '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,