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]:=
(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]:=
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]:=
EntityValue[EntityGroup[EntityInstance @@@ ingredients],
EntityProperty["Food", "AbsoluteTotalCaloriesContent"]]
Out[3]=
Finally, summarize the ingredients and their calorie contents.
show complete Wolfram Language input
Out[4]//TraditionalForm=