Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Generate a nutrition report about foods specified in text
ResourceFunction["NutritionReport"][ingredients] returns nutrition information for ingredients as a Dataset. | |
ResourceFunction["NutritionReport"][ingredients, format] returns information in the specified format. |
"ingredients" | a single string, with different foods separated by a delimiting character (default "\n") |
{"ingredient1","ingredient2",…} | a list of strings |
{{"amount1","food1","note1"},…} | a list of lists of foods, amounts and notes, with each element given as a string |
In the third form above, the "notei" parameters can be useful for tagging purposes, but do not affect numerical results.
"Dataset" | (default) returns nutrition as a Dataset |
"Association" | returns nutrition as a nested Association |
"Table" | returns nutrition as a nested List |
"ASCIITable" | returns nutrition as an ASCII table |
"DelimiterCharacter" | "\n" | character used to separate ingredients within a single string |
"NutritionProperties" | {"AbsoluteTotalCaloriesContent","TotalFat", "TotalProtein","TotalCarbohydrates"} | properties to be returned for each food |
"RemoveAfterComma" | True | whether to trim any non-essential text after a comma for each food |
"AdditionalFluff" | {} | additional strings to remove from food text to improve interpretation |
Get nutrition information about the foods specified in a piece of text:
In[1]:= |
Out[1]= |
Get nutrition information as an ASCII table, with columns delimited by pipe characters ("|"):
In[2]:= |
Out[2]= |
Get nutrition information as a nested List:
In[3]:= |
Out[3]= |
Use TableForm to display this output with foods varying horizontally and nutrition properties varying vertically:
In[4]:= |
Out[4]= |
Get nutrition information as a nested Association:
In[5]:= |
Out[5]= |
Use "DelimiterCharacter" to specify how to split up foods in a string:
In[6]:= |
Out[6]= |
Specify the desired nutrition properties using the "NutritionProperties" option:
In[7]:= |
Out[7]= |
Lists of valid "Food" properties can be obtained using EntityValue:
In[8]:= |
Out[9]= |
Finding a particular property of interest can be simplified by querying particular EntityClass expressions:
In[10]:= |
Out[10]= |
In[11]:= |
Out[11]= |
Use "RemoveAfterComma"→False if there is important information to be retained after commas:
In[12]:= |
Out[12]= |
The default setting "RemoveAfterComma"→True ignores the preparation of the chicken in this example, and thus returns different results:
In[13]:= |
Out[13]= |
There are some words that are filtered out of food strings by default as they do not impact nutrition. Use "AdditionalFluff" if there are additional strings that can be removed to improve interpretation (note that "fluff" strings are case-sensitive):
In[14]:= |
Out[14]= |
NutritionReport uses Interpreter["Food"] internally to convert strings into computable "Food" entities:
In[15]:= |
Out[15]= |
In[16]:= |
Out[16]= |
More specific foods can be difficult to find data for:
In[17]:= |
Out[17]= |
Use simple strings with only necessary information to get better results:
In[18]:= |
Out[18]= |
Use options and specific input formats to help NutritionReport understand what information is essential:
In[19]:= |
Out[19]= |
Note that some "Food" properties are non-quantitative in nature. Using these in NutritionReport can cause errors:
In[20]:= |
Out[20]= |
A large subset of strictly quantitative nutritional properties can be obtained as follows:
In[21]:= |
Out[22]= |
This work is licensed under a Creative Commons Attribution 4.0 International License