可视化每日参考营养值
Wolfram Knowledgebase 中不但包括了超过 37,000 种 "Food" 和 1,000 种 "FoodType" 相关详细属性和营养成分信息,还有关于 175 种营养的每日参考值数据. 这些大量数据的一同使用可以计算探索几乎任意膳食的营养成分,并使用简单绘图进行直观可视化.
In[1]:=
EntityValue["Nutrient", "EntityCount"]
Out[1]=
按照 2000 卡/天的饮食提取每日参考营养值的列表.
In[2]:=
allDailyValues =
Append[DeleteMissing[
EntityValue["Nutrient", "DailyValue", "EntityAssociation"]],
Entity["Nutrient", "Energy"] ->
Quantity[2000, ("LargeCalories")/("Days")]]*Quantity[1, "Days"]
Out[2]=
将食品属性映射到营养成分.
In[3]:=
propertyNutrientRules = {EntityProperty["Food",
"AbsoluteSodiumContent"] -> Entity["Nutrient", "Sodium"],
EntityProperty["Food", "AbsoluteTotalCarbohydratesContent"] ->
Entity["Nutrient", "TotalCarbohydrates"],
EntityProperty["Food", "AbsoluteTotalFatContent"] ->
Entity["Nutrient", "TotalFat"],
EntityProperty["Food", "AbsoluteTotalFiberContent"] ->
Entity["Nutrient", "TotalFiber"],
EntityProperty["Food", "AbsoluteIronContent"] ->
Entity["Nutrient", "Iron"],
EntityProperty["Food", "AbsoluteTotalCaloriesContent"] ->
Entity["Nutrient", "Energy"]};
用 EntityGroup 和 EntityInstance 将典型的早餐编码.
In[4]:=
breakfast = EntityGroup[{
EntityInstance[Entity[
"Food", {
EntityProperty["Food", "CookingMethod"] -> Entity[
"CookingMethod", "HardBoiled"],
EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Egg"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
Quantity[2, "Servings"]],
EntityInstance[Entity[
"Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Bacon"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
Quantity[3, "Slices"]],
EntityInstance[Entity[
"Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "HashBrown"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
Quantity[1, "Servings"]],
EntityInstance[Entity[
"Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "OrangeJuice"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
Quantity[2, "Servings"]]
}];
创建一个 “罗盘图”,显示有放射状嵌套的六边形,表明六种主要营养的每日建议值的 50%、100%(用绿色表示)和 150%.
显示完整的 Wolfram 语言输入
In[6]:=
compassPlot[breakfast]
Out[6]=
在早餐的基础上设定午餐和晚餐.
In[7]:=
lunch = EntityGroup[{
EntityInstance[Entity[
"Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "PeanutButter"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
Quantity[2, "Tablespoons"]],
EntityInstance[Entity[
"Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Bread"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
Quantity[2, "Slices"]],
EntityInstance[Entity[
"Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Jelly"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
Quantity[1, "Servings"]]
}];
In[8]:=
dinner = EntityGroup[{
EntityInstance[Entity[
"Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Spaghetti"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
Quantity[1, "Servings"]],
EntityInstance[Entity[
"Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Meatball"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
Quantity[3, "Items"]],
EntityInstance[Entity[
"Food", {
EntityProperty["Food", "BrandName"] -> Entity[
"FoodBrandName", "Bertolli"],
EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Sauce"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
Quantity[1.5, "Servings"]],
EntityInstance[Entity[
"Food", {
EntityProperty["Food", "Flavor"] -> Entity[
"FoodFlavor", "Cola"],
EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "CarbonatedBeverage"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
Quantity[1, "USSodaCanVolumes"]]
}];
可视化每餐之后的营养增加.
显示完整的 Wolfram 语言输入
Out[9]=