CITE THIS NOTEBOOK: Wolfram R&D LIVE: A Computational Exploration of Alcoholic Beverages by Isabel Skidmore. Wolfram Community OCT 5 2022.
https://youtu.be/nvQ09RDrtlk
Adapted from “Cheers! A Computational Exploration of Alcoholic Beverages with the Wolfram Language” blog post (https://blog.wolfram.com/2022/09/15/cheers-a-computational-exploration-of-alcoholic-beverages-with-the-wolfram-language/ )​
​For 10,000 years, humans have been using fermentation to produce beverages for pleasure, for rituals and for healing. In ancient Greece, honey was fermented to produce mead. Today, popular sources of beverage fermentation are grains, grapes, berries and rice. The science of fermentation — known as zymology (or zymurgy) — is a fascinating blend of chemistry, biology, history and geography. Wolfram Language now brings a new dimension to the study of alcoholic beverages, through an extensive data set ready to be explored and analyzed.

Food Basics


In[]:=
refried beans
»
food
In[]:=
RandomSampleEntityList@
food
food type
:exactly
bean
FOOD TYPE
added food types
:exactlynone
preparation
:
refried
PREPARATION
,10
Out[]=

San Marcos, Emsanmar, Refried Black Beans
(USDA: Branded, LabelInsight)
,
Cadia, Organic Refried Vegetarian Beans
(USDA: Branded, LabelInsight)
,
FAT FREE REFRIED BEANS
(USDA: Branded, LabelInsight)
,
ROSARITA Non Fat Refried Beans, 16 OZ
(USDA: Branded, GS1)
,
TRADITIONAL REFRIED BEANS
(USDA: Branded, LabelInsight)
,
TRADITIONAL REFRIED BEANS
(USDA: Branded, LabelInsight)
,
ORGANIC FAT FREE REFRIED BLACK BEANS
(USDA: Branded, LabelInsight)
,
REFRIED BEANS
(USDA: Branded, LabelInsight)
,
Ducal, Refried Black Beans
(USDA: Branded, LabelInsight)
,
Original Refried Beans - #10 Can, Unprepared
(USDA: Branded)

EntityProperty["Food","AlanineContentPerServing"]
In[]:=
EntityValue["Food","Properties"]//Select[StringContainsQ[Last@#,"calorie",IgnoreCase->True]&]
Out[]=

alcohol calorie content per typical item size
,
alcohol calorie content per typical serving size
,
calorie label
,
carbohydrate-calorie factor
,
carbohydrate calories per typical item size
,
carbohydrate calories per typical serving size
,
fat calorie factor
,
fat calorie content per typical item size
,
fat calorie content per typical serving size
,
protein calorie factor
,
protein calorie content per typical item size
,
protein calorie content per typical serving size
,
relative alcohol calorie content
,
relative carbohydrate calorie content
,
relative fat calorie content
,
relative protein calorie content
,
relative calorie content
,
calorie content per typical item size
,
calorie content per typical serving size

In[]:=
EntityValue
food
food type
:exactly
bean
FOOD TYPE
added food types
:exactlynone
preparation
:
refried
PREPARATION
,
relative fat calorie content

Out[]=
0.147123
Cal/g

In[]:=
100g of refried beans
EntityInstance
food
,
100
g

Out[]=
EntityInstance
food
food type
:exactly
bean
added food types
:exactlynone
preparation
:
refried
,
100
g


Alcohol Arithmetic

Wolfram Language offers more than 5,000 functions, including arithmetic functions like Max, Min, Mean and Median. Let’s look at the median alcohol content per serving and default serving size volume for all rums in the alcoholic beverages data.
In[]:=
MedianDeleteMissingEntityValueEntityList@
food
food type
:exactly
rum
FOOD TYPE
added food types
:exactlynone
,{"AlcoholContentPerServing","DefaultServingSizeVolume"},"PropertyAssociation",1,2
Out[]=
AlcoholContentPerServing
15.7479
g
,DefaultServingSizeVolume
44.3603
mL

This mimics EntityValue’s default behavior when working with attributed Food entities:
In[]:=
EntityValue
food
food type
:exactly
rum
FOOD TYPE
added food types
:exactlynone
,{"AlcoholContentPerServing","DefaultServingSizeVolume"},"PropertyAssociation"
Out[]=
AlcoholContentPerServing
15.9697
g
,DefaultServingSizeVolume
44.3603
mL

You can apply the same calculation to other alcoholic beverages, including alcohol FoodTypes “Cognac,” “Sake” and “Brandy,” to see how they compare with “Rum.”
​
Wolfram Language data on the alcohol content of beverages can help when deciding how much to drink. On a night out, approximately how many drafts of beer equate to the usual glass of Chardonnay you have at home? The average glass of wine is about 5 fluid ounces:
In[]:=
glassOfWine=EntityInstance
food
food type group
:
wines
FOOD TYPE GROUP
added food types
:exactlynone
variety
:
Chardonnay
FOOD VARIETY
,Quantity[5,"FluidOunces"]["AbsoluteAlcoholContent"]
Out[]=
15.6755
g
A serving of draft beer is usually 1 pint:
In[]:=
draftBeer=EntityInstance
food
food type group
:
beers
FOOD TYPE GROUP
added food types
:exactlynone
,Quantity[1,"Pints"]["AbsoluteAlcoholContent"]
Out[]=
26.4
g
So, every pint of beer is equivalent in alcohol content to slightly more than 1 ½ glasses of wine:
In[]:=
N[draftBeer/glassOfWine]
Out[]=
1.68416
Knowledge of alcohol content can be useful when designing or choosing cocktails. Once liquors start to mix, it becomes harder to determine the actual alcohol content of the drink. Disclosing this information on menus could help less experienced bar patrons have a better understanding of what’s on offer.
Here’s a function that gets the total alcohol content of a group of alcohols (assuming the density of most alcohols is about 1 g/mL, the density of water):
In[]:=
totalAlcoholContent[ingredients_Association]:=​​Module[{approxDensity,alcoholContents},​​approxDensity=Quantity[1,"GramsPerMilliliter"];​​alcoholContents=KeyValueMap[#1["RelativeAlcoholContent"]*approxDensity*UnitConvert[#2,"Milliliters"]&]@ingredients;If[AnyTrue[alcoholContents,!FreeQ[#,_Missing]&],​​Missing["NotAvailable"],​​Plus@@alcoholContents​​]​​];
Let’s apply this function to a whiskey sour and a gin martini to compare the total alcohol content for these mixed drinks. A whiskey sour is often made with 2 fl oz of whiskey, and a classic gin martini can include 2 fl oz of gin and 1 fl oz of dry vermouth.
In[]:=
whiskeySour=<|
food
food type group
:
whiskeys
FOOD TYPE GROUP
added food types
:exactlynone
->Quantity[2,"FluidOunces"]|>;​​ginMartini=<|
food
food type
:exactly
gin
FOOD TYPE
added food types
:exactlynone
->Quantity[2,"FluidOunces"],
food
food type
:exactly
vermouth
FOOD TYPE
added food types
:exactlynone
->Quantity[1,"FluidOunces"]|>;
In[]:=
totalAlcoholContent[ginMartini]
Out[]=
30.0319
g
In[]:=
totalAlcoholContent[whiskeySour]
Out[]=
25.4332
g
In this example, the martini has a higher total alcohol content than the whiskey sour. But we are leaving the most important question for you to decide — shaken or stirred?

Counting Calories

If you count calories, have you ever wondered whether red wines and white wines differ in calorie content? Or, do all white wines have similar calories? You can create informative plots that answer questions like these.
First, query the “RelativeTotalCaloriesContent” for both red and white wines using EntityValue:
In[]:=
{redWineCalories,whiteWineCalories}=DeleteMissing[EntityValue[EntityList@#,"RelativeTotalCaloriesContent","EntityAssociation"]]&/@
food
added food types
:exactly​
food type group
:
wines
FOOD TYPE GROUP
variety
:
red
FOOD VARIETY
,
food
added food types
:exactly​
food type group
:
wines
FOOD TYPE GROUP
variety
:
white
FOOD VARIETY
;
Create ListPlots to visualize the data:

World of Whiskey

If you enjoy whiskey, geography or travel, GeoBubbleChart can answer the question, “Where in the world are the whiskey producers?” You come away with an informative visualization and an entertaining tongue-twister.
Query the FoodLocation attribute for all whiskeys in the alcoholic beverages data:
Use Interpreter to get the GeoPositions that correspond to the FoodLocation entities:
Tally the GeoPositions and then plot them on a GeoBubbleChart to visualize the data:
According to the data, the most common locations for whiskey producers are Kentucky, Tennessee, Scotland and Ireland, with less prolific whiskey producers in Canada and Japan. In this way, you could make sure that whiskeys from all around the world are represented in your home collection and explore the different flavors produced across different regions.
You can reuse the code above to produce more GeoBubbleCharts and discover where alcohol FoodTypes “Rum”, “Beer” and “Vodka” are produced globally.

Wine or Beer?

Machine learning and neural networks are prevalent in our everyday lives. You can apply Wolfram Language machine learning to the alcoholic beverages data. Use Classify to train a neural network to distinguish wines from beers based on relative alcohol content.
We split the data obtained from EntityValue into a training set (80% of the available data) and a testing set, to make sure we can tell how well our ClassifierFunction works on values it hasn’t seen before:
Create the ClassifierFunction:
Classify a subset of the testing set data we reserved earlier:
“NiceGrid” from the Wolfram Function Repository displays a readable grid:

Flavorful Fruits

The alcoholic beverages available via Wolfram Language are full of flavors. Several functions give you the ability to explore and visualize the data.
You can continue to explore vodka flavors, like “Mango,” “Peach” and “Coconut.”
Use Manipulate to investigate other flavored alcoholic beverages:

Flavors in Focus

Wolfram Language can visualize data in many different ways. ImageCollage can tell your data story in full color.
Find the images corresponding to the vodka FoodFlavor entities:
Use ImageCollage and Scaled to create a visualization of the most common flavors among vodkas in Wolfram Language alcoholic beverages data:
From this image, we can quickly see that citrus fruits are among the most popular vodka flavors, as well as strawberry, cherry, raspberry, cucumber and coconut. The data reveals some surprising flavors like pumpkin, dragon fruit, espresso and caramel.
WordCloud also provides an interesting weighted visualization of the most common vodka flavors:

A Parting Toast

I have enjoyed sharing some of the innovative ways you can analyze and visualize the wide range of alcoholic beverages data now available. I hope you continue to explore Wolfram Language food and beverage data and that you share your exploration with us. (And if you drink, please don’t drive. Arrange a designated driver.) Here’s to our wonderful Wolfram Community: