Try now in the
Open Cloud »
(no sign-in required)

Story Flow in Alice

Get a sense of the flow of Alice in Wonderland by plotting where Alice and Queen occur in the story.

Run the code to get the text of Alice in Wonderland. Try other texts, like TheRaven or Hamlet:

SHOW/HIDE DETAILS

This text is very long; give it the name text and suppress the output with a semicolon (;) at the end of the expression:

In[1]:=
X

Here are the first 1,000 characters of the text:

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X

Find the positions of Alice in the text. Find the positions of other words:

SHOW/HIDE DETAILS

Get a list of the start and end character positions of the name Alice in the text:

In[1]:=
X
Out[1]=

If you count the characters, you can verify that the first occurrence of Alice is indeed from characters 25 to 29:

In[2]:=
X
Out[2]=

Map First over the list to get a list of just the starting positions:

In[3]:=
X
Out[3]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Plot where Alice occurs in the story. Make plots for other words:

SHOW/HIDE DETAILS

Make a smooth histogram showing how often Alice occurs in various parts of the story:

In[1]:=
X
Out[1]=

Add a fill underneath the plot line:

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Add a legend:

SHOW/HIDE DETAILS

Add a legend with Legended:

In[1]:=
X
Out[1]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Show Alice and the Queen at the same time:

SHOW/HIDE DETAILS

Show the story flow for the Queen:

In[1]:=
X
Out[1]=

Show both Alice and the Queen at the same time. Enclose the two datasets in a list (indicated by curly braces):

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Make it a function. Try other character names:

SHOW/HIDE DETAILS

This expression can be written more concisely using a pure function so that the parts of the Legended subexpressions that are similar are not duplicated:

In[1]:=
X
Out[1]=

The only parts of the Legended subexpressions that differ are the names Alice and Queen. Replace them with # in a pure function (indicated by &) that is applied to a list of the names:

In[2]:=
X
Out[2]=

This form of the expression is easy to turn into a function that will work with any number of names. Replace the names list with the variable names and define the function storyflowinalice with the parameter names:

In[3]:=
X

Test the function on three character names:

In[4]:=
X
Out[4]=

HIDE DETAILS

Run this first to define the function:

In[1]:=
X

Plot the story flow using the function:

In[1]:=
X
Out[1]=