Food and Nutrition in the Wolfram Language

Isabel Skidmore - Tommy Peters - Gay Wilson

Wolfram | Alpha
October 20, 2022

Review: Nutritional Information

We have nutritional information properties for over 450,000 foods and over 150 nutrients:

(Entity["Crustaceans, lobster, northern, raw", Entity["Food","CrustaceansLobsterNorthernRaw::bqdp2"], "Entity[\"Food\", \"CrustaceansLobsterNorthernRaw::bqdp2\"]", "food"])[{(EntityProperty["relative omega six fatty acid content", EntityProperty["Food","RelativeTotalOmegaSixFattyAcidContent"], "EntityProperty[\"Food\", \"RelativeTotalOmegaSixFattyAcidContent\"]"]),(EntityProperty["relative omega three fatty acid content", EntityProperty["Food","RelativeTotalOmegaThreeFattyAcidContent"], "EntityProperty[\"Food\", \"RelativeTotalOmegaThreeFattyAcidContent\"]"]),(EntityProperty["relative butyric acid content", EntityProperty["Food","RelativeButyricAcidContent"], "EntityProperty[\"Food\", \"RelativeButyricAcidContent\"]"]),(EntityProperty["relative linoleic acid content", EntityProperty["Food","RelativeLinoleicAcidContent"], "EntityProperty[\"Food\", \"RelativeLinoleicAcidContent\"]"])},"Dataset"]

(Entity["Crustaceans, lobster, northern, raw", Entity["Food","CrustaceansLobsterNorthernRaw::bqdp2"], "Entity[\"Food\", \"CrustaceansLobsterNorthernRaw::bqdp2\"]", "food"])[(EntityProperty["nutrition label", EntityProperty["Food","NutritionLabel"], "EntityProperty[\"Food\", \"NutritionLabel\"]"])]

Review: Food Classification and Representation

With a growing set of over 15,000 attributes and nearly 60 categories, we can represent a wide range of foods:

EntityValue[{(Entity["Apples, raw, red delicious, with skin", Entity["Food","ApplesRawRedDeliciousWithSkin::v353h"], "Entity[\"Food\", \"ApplesRawRedDeliciousWithSkin::v353h\"]", "food"]),(Entity["Da Vinci Gourmet Vanilla Syrup Sugar Free", Entity["Food","DaVinciGourmetVanillaSyrupSugarFree::ftgm3"], "Entity[\"Food\", \"DaVinciGourmetVanillaSyrupSugarFree::ftgm3\"]", "food"]),(Entity["Weight Watchers Blueberry Muffin", Entity["Food","WeightWatchersBlueberryMuffin::k48q8"], "Entity[\"Food\", \"WeightWatchersBlueberryMuffin::k48q8\"]", "food"])},"CategoricalPropertyValues","Dataset"]

Food Ontology Graph: Overview

Print@Row[{Show[,ImageSize->Scaled[0.45]],Column[{Style[Hyperlink[#],36,FontFamily->"Source Sans Pro"],Show[BarcodeImage[#,"QR"],ImageSize->Scaled[0.2]]},Alignment->Center]&["wolfr.am/foodgraph"]},Spacer[20]]

Review: Natural Language Processing

The Wolfram Language offers several ways to harness the NLP capabilities of Wolfram|Alpha:

Interpreter[“Food”]

Implicit entities allow for representing and querying for foods with implicit entity syntax:

AssociationMap[Interpreter["Food"],{"red delicious apple","big mac burger","pepsi"}]

Interpreter[“FoodType”]

Food types give a “fuzzier” way to navigate the food data that is available:

AssociationMap[Interpreter["FoodType"],{"spring onion","yam","rapini"}]

Improved: Number of Foods

Our food database is always growing, and was recently updated in 2021 with over 300k more foods:

BarChart[
KeyMap[Style[#,16]&,<|"pre-2015"->12000,2015->38000,2016->100000,2017->148000,2018->148000,2019->148000,2021->EntityValue["Food","EntityCount"]|>],
ChartLabels->Placed[Automatic,Top],
PlotTheme->"Detailed",
FrameLabel->(Style[#,25]&/@{"WTC Year","Food entities"}),
ImageSize->Large,
FrameStyle->Directive[18]
]

Improved: Number of Foods

With so many individual data points, we can create visualizations of nutrient distribution across many foods:

Improved: Number of Foods

With so many individual data points, we can create visualizations of nutrient distribution across many foods:

Improved: New Alcoholic Beverages Data

We have added curated alcoholic beverages data, including over 100 different FoodTypes:

EntityValue[Entity["FoodTypeGroup","AlcoholicBeverages"],"FoodTypes"]//RandomSample[#,20]&

These entities come with nutritional information as well as qualitative information, such as location of origin:

EntityValue[,"Location"]

New Properties: Cold Storage Times

Using recommendations from the USDA, we have curated two properties covering the maximum recommended refrigerated and frozen storage times for foods:

EntityValue[,{(EntityProperty["maximum frozen storage time", EntityProperty["Food","RecommendedFrozenStorageTime"], "EntityProperty[\"Food\", \"RecommendedFrozenStorageTime\"]"]),(EntityProperty["maximum refrigerated storage time", EntityProperty["Food","RecommendedRefrigeratedStorageTime"], "EntityProperty[\"Food\", \"RecommendedRefrigeratedStorageTime\"]"])},"Dataset"]

Should I Eat That?

Food Safety with the Wolfram Language

getFoodImage[food_Entity]:= With[{baseFood=First@Cases[food,Entity["FoodType"|"FoodTypeGroup",___],Infinity]},
	Replace[baseFood,
		{
		ft:Entity["FoodType",_]:>ft["Image"],
		ftg:Entity["FoodTypeGroup",_]:>ftg["CanonicalFoodType"]["Image"],
		_ -> Missing[]
		}
	]
];
convertWhiteBackgroundToGray[image_]:=
If[
	ColorDistance[First@DominantColors[image,1],White]<0.001,
	Rasterize@Show[RemoveBackground[image,White],Background->Lighter@LightGray],
	image
];
foodChartStrings={"raw shrimp","pie","lasagna","squash","spinach","melon","cake","peppers","pepperoni","cheddar cheese"};
foodChartFoods=Interpreter["Food"][foodChartStrings];
foodChartStorageTimes=EntityValue[foodChartFoods,(EntityProperty["maximum refrigerated storage time", EntityProperty["Food","RecommendedRefrigeratedStorageTime"], "EntityProperty[\"Food\", \"RecommendedRefrigeratedStorageTime\"]"]),"EntityAssociation"];
BarChart[Map[Max]@foodChartStorageTimes,ChartElements->Map[convertWhiteBackgroundToGray@getFoodImage[#]&]@Keys[foodChartStorageTimes],ChartLabels->Placed[foodChartStrings,Above],AxesLabel->Automatic,ImageSize->600]

“It’s Monday lunchtime. I have leftover pizza in the fridge from Friday night. Should I eat that?”

[(EntityProperty["maximum refrigerated storage time", EntityProperty["Food","RecommendedRefrigeratedStorageTime"], "EntityProperty[\"Food\", \"RecommendedRefrigeratedStorageTime\"]"])]

“It’s Monday lunchtime. I have leftover pizza in the fridge from Friday night. Should I eat that?”

[(EntityProperty["maximum refrigerated storage time", EntityProperty["Food","RecommendedRefrigeratedStorageTime"], "EntityProperty[\"Food\", \"RecommendedRefrigeratedStorageTime\"]"])]

“I bought ground beef Tuesday for a family cookout Saturday. Can I keep the raw ground beef in the refrigerator until then?”

[(EntityProperty["maximum refrigerated storage time", EntityProperty["Food","RecommendedRefrigeratedStorageTime"], "EntityProperty[\"Food\", \"RecommendedRefrigeratedStorageTime\"]"])]

“I bought ground beef Tuesday for a family cookout Saturday. Can I keep the raw ground beef in the refrigerator until then?”

[(EntityProperty["maximum refrigerated storage time", EntityProperty["Food","RecommendedRefrigeratedStorageTime"], "EntityProperty[\"Food\", \"RecommendedRefrigeratedStorageTime\"]"])]

“I love grilled salmon with dill sauce. How long can I keep raw salmon in my freezer? 2 - 3 months or 6 - 8 months?”

[(EntityProperty["maximum frozen storage time", EntityProperty["Food","RecommendedFrozenStorageTime"], "EntityProperty[\"Food\", \"RecommendedFrozenStorageTime\"]"])]

“I love grilled salmon with dill sauce. How long can I keep raw salmon in my freezer? 2 - 3 months or 6 - 8 months?”

[(EntityProperty["maximum frozen storage time", EntityProperty["Food","RecommendedFrozenStorageTime"], "EntityProperty[\"Food\", \"RecommendedFrozenStorageTime\"]"])]

“I bought a fresh butternut squash at the farmer’s market, but only need half of it for my recipe. How long can I store the rest in the refrigerator? 4 - 5 days or 8 - 10 days?”

[(EntityProperty["maximum refrigerated storage time", EntityProperty["Food","RecommendedRefrigeratedStorageTime"], "EntityProperty[\"Food\", \"RecommendedRefrigeratedStorageTime\"]"])]

“I bought a fresh butternut squash at the farmer’s market, but only need half of it for my recipe. How long can I store the rest in the refrigerator? 4 - 5 days or 8 - 10 days?”

[(EntityProperty["maximum refrigerated storage time", EntityProperty["Food","RecommendedRefrigeratedStorageTime"], "EntityProperty[\"Food\", \"RecommendedRefrigeratedStorageTime\"]"])]

Thank you
for joining us today!