Язык Wolfram Language

Расширение базы знаний

Создание маркировки с информацией о пищевой ценности

Версия 11 представляет детальную информацию о пищевой ценности и других характеристиках для более чем 40000 продуктов. Более 500 возможных характеристик отдельных продуктов могут быть запрошены напрямую, включая созданную программой маркировку с информацией о пещевой ценности.

Рассмотреть случайно выбранную пищевую сущность.

In[1]:=
Click for copyable input
food = RandomEntity["Food"]
Out[1]=

Получить несколько характеристик данного пищевого продукта.

In[2]:=
Click for copyable input
EntityValue[food, {"Image", "Name", EntityProperty["Food", "VitaminAContentPerServing"], EntityProperty["Food", "VitaminB12ContentPerServing"], EntityProperty["Food", "VitaminB6ContentPerServing"], EntityProperty["Food", "VitaminCContentPerServing"]}, "PropertyAssociation"]
Out[2]=

Создать маркировку с информацией о пищевой ценности для 1 чашки апельсинового сока.

In[3]:=
Click for copyable input
EntityValue[\!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{Typeset`query$$ = " 1 cup orange juice", 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[{"\"orange juice\"", RowBox[{"Entity", "[", RowBox[{"\"FoodType\"", ",", "\"OrangeJuice\""}], "]"}], "\"Entity[\\\"FoodType\\\", \ \\\"OrangeJuice\\\"]\"", "\"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\\\", \ \\\"OrangeJuice\\\"]}], EntityProperty[\\\"Food\\\", \ \\\"AddedFoodTypes\\\"] -> ContainsExactly[{}]}]\""}, "GeneralizedEntityToggle"]], Entity["Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{ Entity["FoodType", "OrangeJuice"]}], EntityProperty[ "Food", "AddedFoodTypes"] -> ContainsExactly[{}]}], SelectWithContents -> True], ",", " ", TemplateBox[{"1", "\"cup\"", "cups", "\"Cups\""}, "Quantity", SyntaxForm -> Mod]}], "]"}], Typeset`allassumptions$$ = {{ "type" -> "Clash", "word" -> "cup", "template" -> "Assuming \"${word}\" is ${desc1}. Use as \ ${desc2} instead", "count" -> "2", "Values" -> {{ "name" -> "Unit", "desc" -> "a unit", "input" -> "*C.cup-_*Unit-"}, { "name" -> "FoodPackaging", "desc" -> " referring to food packaging", "input" -> "*C.cup-_*FoodPackaging-"}}}, { "type" -> "Unit", "word" -> "cup", "template" -> "Assuming ${desc1} for \"${word}\". Use ${desc2} \ instead", "count" -> "6", "Values" -> {{ "name" -> "Cups", "desc" -> "US customary cups", "input" -> "UnitClash_*cup.*Cups--"}, { "name" -> "CanadianCups", "desc" -> "Canadian cups", "input" -> "UnitClash_*cup.*CanadianCups--"}, { "name" -> "MetricCups", "desc" -> "metric cups", "input" -> "UnitClash_*cup.*MetricCups--"}, { "name" -> "CupsUK", "desc" -> "UK cups", "input" -> "UnitClash_*cup.*CupsUK--"}, { "name" -> "CupsUSLegal", "desc" -> "US legal cups", "input" -> "UnitClash_*cup.*CupsUSLegal--"}, { "name" -> "CupUnits", "desc" -> "cups", "input" -> "UnitClash_*cup.*CupUnits--"}}}}, Typeset`assumptions$$ = {}, Typeset`open$$ = {1}, Typeset`querystate$$ = { "Online" -> True, "Allowed" -> True, "mparse.jsp" -> 1.910975`6.73279999900569, "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->{132., {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]\), EntityProperty["Food", "NutritionLabel"]]
Out[3]=

Имея в наличии данную информацию, пользователь может строить игры с названиями пищевых продуктов: использовать встроенные данные для создания относящихся к еде акростихов с подсказками в виде изображений еды.

код на языке Wolfram Language целиком
In[4]:=
Click for copyable input
acrostic[string_String, food : (Entity["FoodType", _List | _Rule] | All) : All] := Module[{nameData, groupedByLetter, chars}, nameData = Select[EntityValue[ Replace[food, All -> "FoodType"], {EntityProperty["FoodType", "Name"], EntityProperty["FoodType", "Image", {"Size" -> "Small"}]}, "EntityAssociation"], FreeQ[_Missing]]; groupedByLetter = GroupBy[nameData, StringTake[First[ToLowerCase[#]], 1] &]; chars = Characters[ToLowerCase[string]]; Column[ If[MemberQ[Keys[groupedByLetter], #], Tooltip[ Row[{Style[ToUpperCase[StringTake[#, 1]], FontSize -> 50], StringDrop[#, 1]}, ImageSize -> 150], #2] & @@ RandomChoice[groupedByLetter[#]], Row[{Style[ToUpperCase[#], FontSize -> 50]}, "_"] ] & /@ chars, Selectable -> False ] ];
In[5]:=
Click for copyable input
acrostic["Food"] // TraditionalForm
Out[5]//TraditionalForm=

Создать акростих с определённой группой продуктов.

In[6]:=
Click for copyable input
Row[{acrostic["Vegetables", Entity[ "FoodType", EntityProperty["FoodType", "BasicFoodGroups"] -> Entity[ "BasicFoodGroup", "Vegetables"]]], acrostic["Meat", Entity[ "FoodType", EntityProperty["FoodType", "BasicFoodGroups"] -> Entity[ "BasicFoodGroup", "ProteinFoods"]]]}] // TraditionalForm
Out[6]//TraditionalForm=

Родственные примеры

de en es fr ja ko pt-br zh