Function Repository Resource:

FoodEntityCommonName

Source Notebook

Transform a food entity to its common name

Contributed by: Wolfram Staff

ResourceFunction["FoodEntityCommonName"][entity]

transforms an implicit food entity to its common name.

ResourceFunction["FoodEntityCommonName"][entityinstance]

transforms an implicit food entity and quantity to its common name and quantity.

Details and Options

FoodEntityCommonName can be applied to a single food entity, a list of entities, or a food entity and quantity, such as 6 ounces or 200 grams.
FoodEntityCommonName can be used with the yellow-box form of the food entity or the InputForm.
Food common names are useful for communicating with an LLM about food, for example in recipe development and creating chart labels for food and nutrition visualizations.

Examples

Basic Examples (3) 

Apply FoodEntityCommonName to an implicit food entity:

In[1]:=
ResourceFunction["FoodEntityCommonName"][
Entity["Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Potato"]}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}], EntityProperty["Food", "Preparation"] -> Entity[
    "FoodPreparation", "Mashed"]}]]
Out[1]=

The input form of a food entity is supported:

In[2]:=
ResourceFunction["FoodEntityCommonName"][
 Entity["Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{Entity["FoodType", "OliveOil"]}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}]}]]
Out[2]=

Apply FoodEntityCommonName to a list of food entities:

In[3]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/359ed793-db9d-402b-bcbe-662e016c452a"]
Out[3]=

Scope (1) 

Apply FoodEntityCommonName to an EntityInstance of a food and quantity:

In[4]:=
ResourceFunction["FoodEntityCommonName"][
 EntityInstance[Entity[
  "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Flour"]}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}], EntityProperty["Food", "Variety"] -> Entity[
     "FoodVariety", "AllPurpose"]}], Quantity[250, "Grams"]]]
Out[4]=

Neat Examples (2) 

Use FoodEntityCommonName to create labels for a BarChart:

In[5]:=
luteinFoods = {Entity[
   "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Kale"]}], EntityProperty[
      "Food", "AddedFoodTypes"] -> ContainsExactly[{}]}], Entity[
   "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Spinach"]}], EntityProperty[
      "Food", "AddedFoodTypes"] -> ContainsExactly[{}]}], Entity[
   "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "MustardGreens"]}], EntityProperty[
      "Food", "AddedFoodTypes"] -> ContainsExactly[{}]}], Entity[
   "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "CollardGreens"]}], EntityProperty[
      "Food", "AddedFoodTypes"] -> ContainsExactly[{}]}], Entity[
   "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Arugula"]}], EntityProperty[
      "Food", "AddedFoodTypes"] -> ContainsExactly[{}]}]};
luteinStrings = ResourceFunction["FoodEntityCommonName"] /@ luteinFoods;
luteinValues = EntityValue[#, EntityProperty["Food", "RelativeLuteinPlusZeaxanthinContent"]] & /@ luteinFoods // N;
BarChart[luteinValues, AxesLabel -> "\[Mu]g/g", ChartLabels -> Placed[luteinStrings, Top, Rotate[#, Pi/4] &], ChartStyle -> ColorData["Crayola", "ForestGreen"], PlotLabel -> "Lutein in Leafy Greens"]
Out[8]=

Convert a list of ingredients to string names:

In[9]:=
ingredients = ResourceFunction[
  "FoodEntityCommonName"]@{Entity[
   "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "OliveOil"]}], EntityProperty[
      "Food", "AddedFoodTypes"] -> ContainsExactly[{}]}], Entity[
   "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Shallot"]}], EntityProperty[
      "Food", "AddedFoodTypes"] -> ContainsExactly[{}]}], Entity[
   "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Pork"]}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}], EntityProperty["Food", "MeatCut"] -> Entity[
      "FoodMeatCut", "Loin"]}], Entity[
   "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Mustard"]}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}], EntityProperty["Food", "Variety"] -> Entity[
      "FoodVariety", "Dijon"]}], Entity[
   "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Honey"]}], EntityProperty[
      "Food", "AddedFoodTypes"] -> ContainsExactly[{}]}], Entity[
   "Food", {EntityProperty["Food", "FoodTypeGroup"] -> Entity[
      "FoodTypeGroup", "Wines"], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}], EntityProperty["Food", "Variety"] -> Entity[
      "FoodVariety", "White"]}], Entity[
   "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Salt"]}], EntityProperty[
      "Food", "AddedFoodTypes"] -> ContainsExactly[{}]}], Entity[
   "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Parsley"]}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}]}]
   }
Out[9]=

Pass the names to the LLM to create a recipe:

In[10]:=
LLMResourceFunction[
  "RecipeSuggest"][ingredients, "Include ingredients with amounts and instructions. No extra headings in the instructions. Add ingredients if needed for a complete recipe."]
Out[10]=

Requirements

Wolfram Language 14.0 (January 2024) or above

Version History

  • 1.0.0 – 06 September 2024

Related Resources

License Information