理解分析食谱中的材料
通过将 Wolfram Knowledgebase 渊博的食物属性与 Interpreter 框架的强大自然语言能力结合,可以简单计算给定食谱中混合烹饪的热量. 首先,导入来自 CloudObject 中纯文本格式的法式薄饼材料.
In[1]:=
![Click for copyable input](assets.zh/parse-and-analyze-recipe-ingredients/In_292.png)
(data = Import[
CloudObject[
"https://www.wolframcloud.com/objects/e6537987-b050-4f39-9032-\
69788e001041"], "TSV"]) // TextGrid[#, Dividers -> All] &
Out[1]=
![](assets.zh/parse-and-analyze-recipe-ingredients/O_194.png)
使用可 Interpreter 的自定义功能框架将材料转换为与食品属性和 Quantity 对象相关的可计算语义表示.
In[2]:=
![Click for copyable input](assets.zh/parse-and-analyze-recipe-ingredients/In_293.png)
ingredients =
Interpreter[
CompoundElement[{"Food",
"ComputedQuantity" | Restricted["Quantity", "Servings"]}]]@
Reverse[data, {2}]
Out[2]=
![](assets.zh/parse-and-analyze-recipe-ingredients/O_195.png)
构成实体实例并计算食谱的总热量.
In[3]:=
![Click for copyable input](assets.zh/parse-and-analyze-recipe-ingredients/In_294.png)
EntityValue[EntityGroup[EntityInstance @@@ ingredients],
EntityProperty["Food", "AbsoluteTotalCaloriesContent"]]
Out[3]=
![](assets.zh/parse-and-analyze-recipe-ingredients/O_196.png)
最后,总结材料和其热量成分.
显示完整的 Wolfram 语言输入
Out[4]//TraditionalForm=
![](assets.zh/parse-and-analyze-recipe-ingredients/O_197.png)