In this Session…
Before you begin…
To follow along, download the ﬁles:
How To GraphXR 5. Aggregate and Merge
Before You Begin…
Ideally, you’ll have worked through Module 4. Link and Filter. If you’re starting here, and you want to follow along, you’ll need to:
So far, we’ve extracted House nodes from Characters.csv data, created BELONGS_TO edges connecting them with Character nodes, created Lines nodes, and SPOKE edges connecting Characters nodes to the Lines they spoke.
Now we’ll use Merge and Aggregate transforms to link lines of dialogue with the broadcast episodes they were spoken on. Drag and drop Episodes.csv onto the graph space to create the nodes of a new Episodes category.
The Episodes.csv file contains the titles, descriptions, air dates, episode numbers, season numbers, and viewership for each broadcast episode. We’ll now connect lines of dialog to corresponding episodes.
We have a little problem, though. In Lines, season and episode number are combined into the single string called seasonEpisode. In Episodes, they occupy separate properties. To fix this, we’ll use a transform to generate a new seasonEpisode property on our Episode nodes. Open the Transform panel and f(x) tab.
Choose toCustom, since we’ll need to enter a custom formula (rather than one of the preset formulas). Enter seasonEpisode as the new property name.
Enter the custom formula:
(propVal,props) => 'S'+props.seasonNumber+'E'+props.episodeNumber
An example result is automatically displayed under the New Property Name.
Click Run and scroll to the bottom of the panel to view the results. Now that we have property values that match, we’ll link Episodes and Lines nodes.
Open the Link tab and choose Lines as the source category, Episodes as the target category, and enter SPOKEN_ON as the new relationship. Select seasonEpisode as the source and target property, and click Run.
The graph now reveals connections and properties we can explore further. Take a Snapshot, and then we’ll use Aggregate to add new properties based on existing ones, and Merge to simplify the graph.
Let’s find the number of lines per episode. Lines nodes have a lineCount property for each speaker and episode. With the Aggregate transform, we’ll sum those values and write the total to a new totalLines property on connected Episode nodes.
Go to the Transform panel and Aggregate tab.
Click Property from Neighbor Nodes, and select lineCount.
Let’s also use Aggregate to calculate the number of unique characters per episode. Again, select the Episodes category and SPOKEN_ON relationship.
Click Property from Neighbor Nodes, and select the speaker property. Under New Property enter totalCharacters, under Formula Name select count, and click Run.
Now display a table to see the new totalLines and totalCharacters properties.
Now let’s simplify the graph using Merge. It combines nodes of a single category or the edges of a single relationship based on a property value. We’ll use the seasonEpisode property to merge Lines nodes for an episode into a single node.
Go to the Transform panel and Merge tab.
Now click Run. With only one Lines node per Episode, the simplified graph now clarifies connections between Episodes, Characters, and Lines of dialogue.
Save a data view, take a snapshot, and download the snapshot archive.
How To GraphXR: Module 6. Shortcut.