Wolfram Language

Richer Knowledgebase Access

Parse and Analyze Recipe Ingredients

By combining the Wolfram Knowledgebase's erudition on food properties with the powerful natural language abilities of the Interpreter framework, it is easy to calculate the calories of a culinary concoction produced by a given recipe. To begin, import a plain-text form of the ingredients for crêpes from a CloudObject.

In[1]:=
Click for copyable input
(data = Import[ CloudObject[ "https://www.wolframcloud.com/objects/e6537987-b050-4f39-9032-\ 69788e001041"], "TSV"]) // TextGrid[#, Dividers -> All] &
Out[1]=

Use the customizable capabilities of the Interpreter framework to convert the ingredients into a computable semantic representation involving food entities and Quantity objects.

In[2]:=
Click for copyable input
ingredients = Interpreter[ CompoundElement[{"Food", "ComputedQuantity" | Restricted["Quantity", "Servings"]}]]@ Reverse[data, {2}]
Out[2]=

Form entity instances and calculate the total calorie content of the recipe.

In[3]:=
Click for copyable input
EntityValue[EntityGroup[EntityInstance @@@ ingredients], EntityProperty["Food", "AbsoluteTotalCaloriesContent"]]
Out[3]=

Finally, summarize the ingredients and their calorie contents.

show complete Wolfram Language input
In[4]:=
Click for copyable input
TextGrid[Transpose[ Append[Transpose[ingredients], EntityValue[EntityInstance @@@ ingredients, EntityProperty["Food", "AbsoluteTotalCaloriesContent"]]]], Dividers -> All, Alignment -> {{Left, Center, Right}, Automatic}] // TraditionalForm
Out[4]//TraditionalForm=

Related Examples

de es ja ko pt-br ru zh