5. Aggregate, Merge, and f(x)
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 a House category from the Characters.csv data, created a BELONGS_TO relationship with Character nodes, and a SPOKE relationship between Characters and the Lines they spoke.
Now we want to link lines of dialog with the broadcast Episodes they were spoken on.
The Episodes.csv file contains the titles, descriptions, air dates, episode numbers, seasonnumbers, and viewership for each broadcast episode. We can 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 seasonEpisode. In Episodes, they occupy separate properties.
Enter seasonEpisode as the new property name, and 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. You can scroll to the bottom of the panel to view the results.
Now that the property values match, we can go to the Link transform. In both Episodes and Lines, select the seasonEpisode property, and click Run to link nodes with matching properties via edges of a new SPOKEN_ON relationship.
As we explore patterns in more detail, we can use Aggregate to add new properties to the graph and Merge to simplify and clarify the graph.
We want to add a totalLines property–the total number of lines spoken–to each Episode node. Lines nodes do have a lineCount property for each speaker and episode. We can use the Aggregate transform to sum those values and write the total to connected Episode nodes.
Go to the Transform panel and Aggregate tab (take a Snapshot first!).
We can also use Aggregate to return the number of unique characters per Episode.
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.
With Merge we can use the seasonEpisode property to merge Lines nodes for an episode into a single node.
To simplify the graph we’ll use Merge to combine the lines nodes for an episode into a single node, using the seasonEpisode property.
Now click Run. With only one Lines node per Episode, we can now visualize the content of Episodes more clearly.
How To GraphXR: Module 6. Shortcut.