In Activity 7, you wrote an interactive story. In Activity 8, you augmented your story with sentiment analysis. In this activity, you will find the most negative and most positive simple paths through your story!
In graph theory, a simple path is a path between two points on a graph that contains no repeated nodes [Read more on Wikipedia].
In order to complete this activity, Activity 8 must be complete and working (you must have computed your if-sa.json file). If you see a visual rendering of your graph in the visualization portion of Activity 8, you're all set!
Additionally, you need to merge the files for this activity into your workbook:
For this activity, the core algorithm has been provided for you in Activity 9. That algorithm already in compute.py is as follows:
In Step 2, the code uses our graph library to find all simple paths between the startNode
of your story and every endNode
. For each path, this code calls find_path_total_sentiment
to compute the total sentiment of the each path.
In Step 3, the list of all possible paths and their total sentiments are sorted and then saved to a JSON file to be rendered in the visualization.
All you need to do is to program the three functions that this code uses:
find_start_node_id
, a function that takes a NetworkX graph G
and returns the node ID of the start node. (Remember from Activity 7, that
the start node has an attribute start=True
.)
find_end_node_ids
, a function that takes a NetworkX graph G
and returns the node ID of every ending node (as a list of strings). An ending node is
a node that does not have any edges coming from of the node (no outbound edges).
find_path_total_sentiment
, a function that takes a NetworkX graph G
plush an array of node IDs, path
, and returns the total sentiment of the path.
The total sentiment of the path should be the sum of the sentiment of each node plus the sentiment of
each edge.
After you story is complete, use the Workbook to view two of your stories! 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.
Your two stories will be different. If they're the same, make sure
your find_path_total_sentiment
is correct. Here's
an example of my story:
This activity is submitted digitally via git. View detailed submission instructions here.