間食,食事,食品の量
Wolfram Knowledgebaseには,37,000項目以上の"Food"実体と1,000項目以上の"FoodType"実体についての詳細な特性と栄養情報が含まれている.自由形式入力,EntityInstance,EntityGroup,Quantityを使うと,食物集合についての栄養特性,特に昼食と夕食のカロリー,繊維含有量,糖質含有量を簡単に表したり計算したりすることができる.
In[1]:=
Table[EntityValue[foodtype,
"EntityCount"], {foodtype, {"Food", "FoodType"}}]
Out[1]=
Ctrl+=(自由形式入力)を使って,隠的に定義された指定量の食物実体のEntityInstanceとして表された特定の食物量を指簡単に取得することができる.
In[2]:=
\!\(
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "2 tbsp peanut butter",
Typeset`boxes$$ = RowBox[{"EntityInstance", "[",
RowBox[{
InterpretationBox[
DynamicModuleBox[{EntityFramework`Formatting`Private`open = False},
TemplateBox[{
TemplateBox[{"\"foods\""}, "GeneralizedEntityBase"],
TagBox[
GridBox[{{
TemplateBox[{
TemplateBox[{"\"food type\"",
RowBox[{"EntityProperty", "[",
RowBox[{"\"Food\"", ",", "\"FoodType\""}], "]"}],
"\"EntityProperty[\\\"Food\\\", \\\"FoodType\\\"]\
\""}, "EntityProperty"],
StyleBox["\":\"", "GeneralizedEntityInfoItem"],
RowBox[{"ContainsExactly", "[",
RowBox[{"{",
TemplateBox[{"\"peanut butter\"",
RowBox[{"Entity", "[",
RowBox[{"\"FoodType\"", ",", "\"PeanutButter\""}], "]"}],
"\"Entity[\\\"FoodType\\\", \\\"PeanutButter\\\"]\
\"", "\"food type\""}, "Entity"], "}"}], "]"}]},
"GeneralizedEntityInfoRow"]}, {
TemplateBox[{
TemplateBox[{"\"added food types\"",
RowBox[{"EntityProperty", "[",
RowBox[{"\"Food\"", ",", "\"AddedFoodTypes\""}], "]"}],
"\"EntityProperty[\\\"Food\\\", \
\\\"AddedFoodTypes\\\"]\""}, "EntityProperty"],
StyleBox["\":\"", "GeneralizedEntityInfoItem"],
RowBox[{"ContainsExactly", "[",
RowBox[{"{", "}"}], "]"}]}, "GeneralizedEntityInfoRow"]}},
GridBoxAlignment -> {"Columns" -> {{Left}}},
DefaultBaseStyle -> "GeneralizedEntityInfoGrid",
GridBoxItemSize -> {
"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}],
"Column"],
Dynamic[EntityFramework`Formatting`Private`open],
"\"Entity[\\\"Food\\\", {EntityProperty[\\\"Food\\\", \
\\\"FoodType\\\"] -> ContainsExactly[{Entity[\\\"FoodType\\\", \
\\\"PeanutButter\\\"]}], EntityProperty[\\\"Food\\\", \
\\\"AddedFoodTypes\\\"] -> ContainsExactly[{}]}]\""},
"GeneralizedEntityToggle"]],
Entity["Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "PeanutButter"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
SelectWithContents -> True], ",", " ",
TemplateBox[{"2", "\"tbsp\"", "tablespoons", "\"Tablespoons\""},
"Quantity", SyntaxForm -> Mod]}], "]"}],
Typeset`allassumptions$$ = {{
"type" -> "Unit", "word" -> "tbsp",
"template" -> "Assuming ${desc1} for \"${word}\". Use ${desc2} \
instead", "count" -> "4",
"Values" -> {{
"name" -> "Tablespoons", "desc" -> "US tablespoons",
"input" -> "UnitClash_*tbsp.*Tablespoons--"}, {
"name" -> "TablespoonsUK", "desc" -> "UK tablespoons",
"input" -> "UnitClash_*tbsp.*TablespoonsUK--"}, {
"name" -> "MetricTablespoons", "desc" -> "metric tablespoons",
"input" -> "UnitClash_*tbsp.*MetricTablespoons--"}, {
"name" -> "TablespoonsAustralian",
"desc" -> "Australian tablespoons",
"input" -> "UnitClash_*tbsp.*TablespoonsAustralian--"}}}},
Typeset`assumptions$$ = {}, Typeset`open$$ = {1},
Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 0.574756`6.211028507153325, "Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{138., {7., 16.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$,
Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)
Out[2]=
もとになっている Quantity式(デフォルトで,出力ではフォーマットされた形で表示される)を見る.
In[3]:=
\!\(
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "2 tbsp peanut butter",
Typeset`boxes$$ = RowBox[{"EntityInstance", "[",
RowBox[{
InterpretationBox[
DynamicModuleBox[{EntityFramework`Formatting`Private`open = False},
TemplateBox[{
TemplateBox[{"\"foods\""}, "GeneralizedEntityBase"],
TagBox[
GridBox[{{
TemplateBox[{
TemplateBox[{"\"food type\"",
RowBox[{"EntityProperty", "[",
RowBox[{"\"Food\"", ",", "\"FoodType\""}], "]"}],
"\"EntityProperty[\\\"Food\\\", \\\"FoodType\\\"]\
\""}, "EntityProperty"],
StyleBox["\":\"", "GeneralizedEntityInfoItem"],
RowBox[{"ContainsExactly", "[",
RowBox[{"{",
TemplateBox[{"\"peanut butter\"",
RowBox[{"Entity", "[",
RowBox[{"\"FoodType\"", ",", "\"PeanutButter\""}], "]"}],
"\"Entity[\\\"FoodType\\\", \\\"PeanutButter\\\"]\
\"", "\"food type\""}, "Entity"], "}"}], "]"}]},
"GeneralizedEntityInfoRow"]}, {
TemplateBox[{
TemplateBox[{"\"added food types\"",
RowBox[{"EntityProperty", "[",
RowBox[{"\"Food\"", ",", "\"AddedFoodTypes\""}], "]"}],
"\"EntityProperty[\\\"Food\\\", \
\\\"AddedFoodTypes\\\"]\""}, "EntityProperty"],
StyleBox["\":\"", "GeneralizedEntityInfoItem"],
RowBox[{"ContainsExactly", "[",
RowBox[{"{", "}"}], "]"}]}, "GeneralizedEntityInfoRow"]}},
GridBoxAlignment -> {"Columns" -> {{Left}}},
DefaultBaseStyle -> "GeneralizedEntityInfoGrid",
GridBoxItemSize -> {
"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}],
"Column"],
Dynamic[EntityFramework`Formatting`Private`open],
"\"Entity[\\\"Food\\\", {EntityProperty[\\\"Food\\\", \
\\\"FoodType\\\"] -> ContainsExactly[{Entity[\\\"FoodType\\\", \
\\\"PeanutButter\\\"]}], EntityProperty[\\\"Food\\\", \
\\\"AddedFoodTypes\\\"] -> ContainsExactly[{}]}]\""},
"GeneralizedEntityToggle"]],
Entity["Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "PeanutButter"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
SelectWithContents -> True], ",", " ",
TemplateBox[{"2", "\"tbsp\"", "tablespoons", "\"Tablespoons\""},
"Quantity", SyntaxForm -> Mod]}], "]"}],
Typeset`allassumptions$$ = {{
"type" -> "Unit", "word" -> "tbsp",
"template" -> "Assuming ${desc1} for \"${word}\". Use ${desc2} \
instead", "count" -> "4",
"Values" -> {{
"name" -> "Tablespoons", "desc" -> "US tablespoons",
"input" -> "UnitClash_*tbsp.*Tablespoons--"}, {
"name" -> "TablespoonsUK", "desc" -> "UK tablespoons",
"input" -> "UnitClash_*tbsp.*TablespoonsUK--"}, {
"name" -> "MetricTablespoons", "desc" -> "metric tablespoons",
"input" -> "UnitClash_*tbsp.*MetricTablespoons--"}, {
"name" -> "TablespoonsAustralian",
"desc" -> "Australian tablespoons",
"input" -> "UnitClash_*tbsp.*TablespoonsAustralian--"}}}},
Typeset`assumptions$$ = {}, Typeset`open$$ = {1},
Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 0.574756`6.211028507153325, "Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{138., {7., 16.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$,
Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\);
Cases[%, _Quantity] // InputForm
Out[3]//InputForm=
[+]をクリックして上記の隠的に定義された実体を拡張する.
In[4]:=
EntityInstance[Entity[
"Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "PeanutButter"]}],
EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
Quantity[2, "Tablespoons"]]
自由形式入力は,プログラム文に直接使うこともできる.
In[5]:=
peanutButter = \!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "2 tbsp peanut butter",
Typeset`boxes$$ = RowBox[{"EntityInstance", "[",
RowBox[{
InterpretationBox[
DynamicModuleBox[{EntityFramework`Formatting`Private`open = False},
TemplateBox[{
TemplateBox[{"\"foods\""}, "GeneralizedEntityBase"],
TagBox[
GridBox[{{
TemplateBox[{
TemplateBox[{"\"food type\"",
RowBox[{"EntityProperty", "[",
RowBox[{"\"Food\"", ",", "\"FoodType\""}], "]"}],
"\"EntityProperty[\\\"Food\\\", \\\"FoodType\\\"]\
\""}, "EntityProperty"],
StyleBox["\":\"", "GeneralizedEntityInfoItem"],
RowBox[{"ContainsExactly", "[",
RowBox[{"{",
TemplateBox[{"\"peanut butter\"",
RowBox[{"Entity", "[",
RowBox[{"\"FoodType\"", ",", "\"PeanutButter\""}], "]"}],
"\"Entity[\\\"FoodType\\\", \\\"PeanutButter\\\"]\
\"", "\"food type\""}, "Entity"], "}"}], "]"}]},
"GeneralizedEntityInfoRow"]}, {
TemplateBox[{
TemplateBox[{"\"added food types\"",
RowBox[{"EntityProperty", "[",
RowBox[{"\"Food\"", ",", "\"AddedFoodTypes\""}], "]"}],
"\"EntityProperty[\\\"Food\\\", \
\\\"AddedFoodTypes\\\"]\""}, "EntityProperty"],
StyleBox["\":\"", "GeneralizedEntityInfoItem"],
RowBox[{"ContainsExactly", "[",
RowBox[{"{", "}"}], "]"}]}, "GeneralizedEntityInfoRow"]}},
GridBoxAlignment -> {"Columns" -> {{Left}}},
DefaultBaseStyle -> "GeneralizedEntityInfoGrid",
GridBoxItemSize -> {
"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}],
"Column"],
Dynamic[EntityFramework`Formatting`Private`open],
"\"Entity[\\\"Food\\\", {EntityProperty[\\\"Food\\\", \\\
\"FoodType\\\"] -> ContainsExactly[{Entity[\\\"FoodType\\\", \
\\\"PeanutButter\\\"]}], EntityProperty[\\\"Food\\\", \
\\\"AddedFoodTypes\\\"] -> ContainsExactly[{}]}]\""},
"GeneralizedEntityToggle"]],
Entity["Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "PeanutButter"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
SelectWithContents -> True], ",", " ",
TemplateBox[{"2", "\"tbsp\"", "tablespoons", "\"Tablespoons\""},
"Quantity", SyntaxForm -> Mod]}], "]"}],
Typeset`allassumptions$$ = {{
"type" -> "Unit", "word" -> "tbsp",
"template" -> "Assuming ${desc1} for \"${word}\". Use ${desc2} \
instead", "count" -> "4",
"Values" -> {{
"name" -> "Tablespoons", "desc" -> "US tablespoons",
"input" -> "UnitClash_*tbsp.*Tablespoons--"}, {
"name" -> "TablespoonsUK", "desc" -> "UK tablespoons",
"input" -> "UnitClash_*tbsp.*TablespoonsUK--"}, {
"name" -> "MetricTablespoons",
"desc" -> "metric tablespoons",
"input" -> "UnitClash_*tbsp.*MetricTablespoons--"}, {
"name" -> "TablespoonsAustralian",
"desc" -> "Australian tablespoons",
"input" -> "UnitClash_*tbsp.*TablespoonsAustralian--"}}}},
Typeset`assumptions$$ = {}, Typeset`open$$ = {1},
Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 0.574756`6.211028507153325, "Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{138., {7., 16.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$,
Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)
Out[5]=
In[6]:=
twoSlicesOfBread = \!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "2 slices of bread",
Typeset`boxes$$ = RowBox[{"EntityInstance", "[",
RowBox[{
InterpretationBox[
DynamicModuleBox[{EntityFramework`Formatting`Private`open = False},
TemplateBox[{
TemplateBox[{"\"foods\""}, "GeneralizedEntityBase"],
TagBox[
GridBox[{{
TemplateBox[{
TemplateBox[{"\"food type\"",
RowBox[{"EntityProperty", "[",
RowBox[{"\"Food\"", ",", "\"FoodType\""}], "]"}],
"\"EntityProperty[\\\"Food\\\", \\\"FoodType\\\"]\
\""}, "EntityProperty"],
StyleBox["\":\"", "GeneralizedEntityInfoItem"],
RowBox[{"ContainsExactly", "[",
RowBox[{"{",
TemplateBox[{"\"bread\"",
RowBox[{"Entity", "[",
RowBox[{"\"FoodType\"", ",", "\"Bread\""}], "]"}],
"\"Entity[\\\"FoodType\\\", \\\"Bread\\\"]\"",
"\"food type\""}, "Entity"], "}"}], "]"}]},
"GeneralizedEntityInfoRow"]}, {
TemplateBox[{
TemplateBox[{"\"added food types\"",
RowBox[{"EntityProperty", "[",
RowBox[{"\"Food\"", ",", "\"AddedFoodTypes\""}], "]"}],
"\"EntityProperty[\\\"Food\\\", \
\\\"AddedFoodTypes\\\"]\""}, "EntityProperty"],
StyleBox["\":\"", "GeneralizedEntityInfoItem"],
RowBox[{"ContainsExactly", "[",
RowBox[{"{", "}"}], "]"}]}, "GeneralizedEntityInfoRow"]}},
GridBoxAlignment -> {"Columns" -> {{Left}}},
DefaultBaseStyle -> "GeneralizedEntityInfoGrid",
GridBoxItemSize -> {
"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}],
"Column"],
Dynamic[EntityFramework`Formatting`Private`open],
"\"Entity[\\\"Food\\\", {EntityProperty[\\\"Food\\\", \\\
\"FoodType\\\"] -> ContainsExactly[{Entity[\\\"FoodType\\\", \
\\\"Bread\\\"]}], EntityProperty[\\\"Food\\\", \
\\\"AddedFoodTypes\\\"] -> ContainsExactly[{}]}]\""},
"GeneralizedEntityToggle"]],
Entity["Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Bread"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
SelectWithContents -> True], ",", " ",
TemplateBox[{"2", "\"slices\"", "slices", "\"Slices\""}, "Quantity",
SyntaxForm -> Mod]}], "]"}],
Typeset`allassumptions$$ = {{
"type" -> "Clash", "word" -> "bread",
"template" -> "Assuming \"${word}\" is ${desc1}. Use as \
${desc2} instead", "count" -> "2",
"Values" -> {{
"name" -> "FoodType", "desc" -> "a food type",
"input" -> "*C.bread-_*FoodType-"}, {
"name" -> "FoodTypeGroup",
"desc" -> " referring to food type group",
"input" -> "*C.bread-_*FoodTypeGroup-"}}}},
Typeset`assumptions$$ = {"*C.bread-_*FoodType-"},
Typeset`open$$ = {1}, Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 0.662875`6.2729766336225925, "Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{117., {7., 16.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$,
Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)
Out[6]=
ひとまとまりの食べ物(食事,間食等)はEntityGroupで表すことができる.
In[7]:=
pbjSandwich = EntityGroup[{
twoSlicesOfBread,
peanutButter,
EntityInstance[Entity[
"Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Jelly"]}],
EntityProperty[
"Food", "AddedFoodTypes"] -> ContainsExactly[{}]}],
Quantity[1, "Servings"]]
}];
ひとまとまりの食物の栄養素含量を全体として見る.
In[8]:=
pbjSandwich[{EntityProperty["Food", "AbsoluteTotalCaloriesContent"],
EntityProperty["Food",
"AbsoluteTotalProteinContent"]}, "PropertyAssociation"]
Out[8]=
EntityGroupとEntityInstanceを使って夕食を分析する.
In[9]:=
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"]]
}];
In[10]:=
dinner[{EntityProperty["Food", "AbsoluteTotalCaloriesContent"],
EntityProperty["Food",
"AbsoluteTotalSugarContent"]}, "PropertyAssociation"]
Out[10]=