5 Aggregate, Merge, and f(x)

In this Session…​ Before you begin…​
  • Using Transforms:

  • f(x) and Link to reformat and reorganize data.

  • Aggregate to enumerate and/or evaluate nodes or edges.

  • Merge to merge nodes or edges.

To follow along, download the files:

HowTo_05_START.graphxr

and https://kineviz.com/s/GXR_QSG.zip

Slide Text

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.
We can do this using Merge and Aggregate transforms. Drag and drop Episodes.csv onto the graph space, creating the new Episodes category and properties.

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!).
Under Aggregate to Category, select Episodes.
Under Aggregate Along select SPOKEN_ON.
Click Property from Neighbor Nodes and select lineCount.
For the New Property enter totalLines, select the sum preset, and click Run.

14

We can also use Aggregate to return the number of unique characters per Episode.
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.

15

Now display a table to see the new totalLines and totalCharacters properties.
And before we move on, create another Snapshot.
Note that at any time, you can download your snapshots as a single .ZIP archive.

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.
Go to the Transform panel and Merge tab.

17

With Merge we can use the seasonEpisode property to merge Lines nodes for an episode into a single node.
Click Category and select Lines, and select seasonEpisode as the property.
Click Clear Unselected Properties since only the seasonEpisode property is meaningful.

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.
Click Category and select Lines, and select seasonEpisode as the key property. Click Clear Unselected Properties since only the seasonEpisode property will be meaningful.

19

Now click Run. With only one Lines node per Episode, we can now visualize the content of Episodes more clearly.
But we can simplify the graph even further. In Module 6. Shortcut, we’ll return to the Snapshot we created before merging to see how.