5. Aggregate, Merge, and f(x)
In this Session… | Before you begin… |
| To follow along, download the files: |
Slide | |
---|---|
1 | How To GraphXR 5. Aggregate and Merge |
2 | 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:
|
3 | 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. |
4 | Now we want to link lines of dialog with the broadcast Episodes they were spoken on. |
5 | 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. |
6 | 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. |
7 | To fix this, we’ll use the Transform panel and f(x) tab. It lets us run javascript formulas on properties of a category or relationship. Presets are included, but for this we’ll need to entera custom formula. Select Episodes and episodeNumber. |
8 | 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. |
9 | Click Run. You can scroll to the bottom of the panel to view the results. |
10 | 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. |
11 | 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. |
12 | 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. |
13 | Go to the Transform panel and Aggregate tab (take a Snapshot first!). |
14 | We can also use Aggregate to return the number of unique characters per Episode. |
15 | Now display a table to see the new totalLines and totalCharacters properties. |
16 | 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. |
17 | With Merge we can use the seasonEpisode property to merge Lines nodes for an episode into a single node. |
18 | To simplify the graph we’ll use Merge to combine the lines nodes for an episode into a single node, using the seasonEpisode property. |
19 | Now click Run. With only one Lines node per Episode, we can now visualize the content of Episodes more clearly. |
Next Steps…
How To GraphXR: Module 6. Shortcut.