In Activity 7, you wrote an interactive story. In doing so, you built a graph as well as a large amount of text. In this activity, you will use Natural Language Processing (NLP) to find the sentiment of paths through your story.
In order to complete Activity 8, your Activity 7 must be complete and computed. You must have a if.json file in exp_activity7/res in order to complete Activity 8. (The if.json is generated when you run your compute.py file when your story is complete.)
Additionally, you need to merge the files for this activity into your workbook:
Using NLTK, add the sentiment for each piece of text in of your story
(both the narrative
for nodes and the text
for edges).
Store this sentiment of each piece of text as the attribute sentiment
in each node and edge.
To do this, compute.py already has code to load your story, as a graph, from the JSON that was saved as part of the previous activity. As a strategy, you will need to only two things:
narrative
attribute and saving the
sentiment in the sentiment
attribute.
text
attribute and saving the
sentiment in the sentiment
attribute.
To perform the sentiment analysis, you can refer to demo_peopleInHungerGames.
Specifically, compute.py:40
contains the following logic that
you can use to compute sentiment:
Using networkx, you can loop through each node via a for-loop:
Likewise, you can loop through each edge via a similar for-loop:
The dictionary of attributes is both readable and writable, allowing you to add a new key to store the sentiment.
After you story is complete, use the Workbook to view a graph of your story. You will need to compute (by clicking compute in the workbook) to generate the JSON that will be used to render your story. Once complete, viewing your visualization will allow you to explore your story.
In the visualization, you can scroll over each node and edge to find out details about your story. Every node and edge must have a sentiment. For example, here is a node from my story:
As part of exploring the graph you created, ensure that:
This activity is submitted digitally via git. View detailed submission instructions here.