All the food WolframAlpha knows about
Go to a new cell in a notebook and write "=", this will create an orange equality sign in the beginning of the cell. This means that you have entered the free form input mode. Write the name of a food item or a type of food and evaluate the cell, Mathematica will then return the entity corresponding to that food item or food type. You can hover the entity to see what kind of entity it is. Then you can use EntityList
to see all entities of this type. For example:
Here I searched for "pasta" and hovered on the resulting entity, which is of the food type, to find out that the entity type is called "Food". I can now retrieve all entities of this type:
Length@EntityList[Entity["Food"]]
(* Out: 33158 *)
This is a list of 33158 food items that Mathematica knows about. It is probably the same as what Wolfram Alpha knows, although this kind of correspondence between Mathematica and Wolfram Alpha is not guaranteed.
EntityProperties
can be used to list the kind of information that you can retrieve about a food item.
The result is a bunch of entities. All of that information is not available for all items, but those are the properties that you can try to retrieve at least. Sometimes it works, sometimes it doesn't work. EntityValue
is the function that is used to retrieve a property.
I remember from last years conference (Wolfram Technology Conference 2015) that there was a presentation on food entities. It doesn't seem to have been recorded but you can get the presentation (Food in the Wolfram Language).
It shows a great deal on how to access foods and gives details on some of their properties. The food data is somewhat deep and very wide. Below I look at nutritional properties and the "FoodType"
entity. Then I use these to examine a food's vitamins starting from the food type and working down to a particular food.
RandomEntity["Food", 3]
Nutritional properties
EntityValue["Food", "PropertyCount"]
(* 561 *)
RandomSample[EntityValue["Food", "Properties"], 3]
EntityValue["Food", EntityProperty["Food", "RelativeProteinCaloriesContent"], "Definition"]
(* "The amount of protein calories in a food." *)
FoodType
A "FoodType"
entity is a more generic food that has no specific nutritional information, but instead represents a class of foods that could come in many variations.
EntityValue["FoodType", "EntityCount"]
(* 1057 *)
RandomEntity["FoodType", 3]
A look at Milk
EntityProperties[Entity["FoodType", "Milk"]]
We can use "CategoricalPropertyValues"
to narrow down to a certain instance of milk. The "Variety"
list for milk is used below. This can be left off for an Association of all categorical property values.
EntityValue[Entity["FoodType", "Milk"], "CategoricalPropertyValues"][
EntityProperty["Food", "Variety"]]
Now lets look at the vitamins available in one of these varieties of milk by creating an implicit entity for human milk.
breastIsBest =
Entity["Food", {EntityProperty["Food", "FoodType"] -> Entity["FoodType", "Milk"],
EntityProperty["Food", "Variety"] -> Entity["FoodVariety", "Human"]}]
With EntityList
we can obtain a human milk food entity to query.
laLecheLeague = First@EntityList[breastIsBest]
As was seen above there are many nutritional properties. Below the selection is limited to those with "vitamins"
in their CanonicalName
.
vitamins =
Select[StringContainsQ[CanonicalName@#, "vitamin", IgnoreCase -> True] &]@
EntityProperties[laLecheLeague];
Now we can query laLecheLeague
for the vitamins
information. The Missing
entries are deleted.
DeleteMissing@
EntityValue[laLecheLeague, vitamins, "PropertyAssociation"]
The typical serving size can also be queried.
EntityValue[laLecheLeague, "DefaultServingSizeMass"]
(* Quantity[30.8, "Grams"] *)
Hope this helps.
For more information on breast feeding visit La Leche League International