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.

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

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

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

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

Click for copyable input
EntityValue[EntityGroup[EntityInstance @@@ ingredients], EntityProperty["Food", "AbsoluteTotalCaloriesContent"]]

Finally, summarize the ingredients and their calorie contents.

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

Related Examples

de es ja ko pt-br ru zh