The Shortcut transform connects two nodes that share a common neighbor with a new edge, and in the process creates a new relationship. The source pattern remains, but it can be hidden or deleted. This enables you to simplify a graph without merging nodes.
Generally, for the pattern:
(Category A)→[Relationship 1]→(Category B)→[Relationship 2]→(Category C)
a new shortcut pattern is created:
(Category A)→[New Relationship3]→(Category C), where:
Categories A, B, and C contain nodes that share a common neighbor,
[Relationship1] and [Relationship2] contain edges of the two relationships, and
[Relationship3] contains edges of the new shortcut relationship. If desired, you can select one or more properties from the center category (Category B) to be added to the new [Relationship3].
You can also transform the property values using a preset (or custom) Input Formula.
Preset formulas for properties of a Shortcut relationship
(centerNodePropValues) => .join(centerNodePropValues,"")
Copies the first value of another property
(centerNodePropValues) => _.size(centerNodePropValues) > 0 ? centerNodePropValues : null
Calculates a value based on number of connections.
(centerNodePropValues) => _.size(centerNodePropValues)
Sums the values of the selected property.
(centerNodePropValues) => _.sumBy(centerNodePropValues,d => Number(d) || 0)
Averages the values of the selected property.
(centerNodePropValues) => .sumBy(centerNodePropValues,d => Number(d) || 0)/(.size(centerNodePropValues) > 0 ? _.size(neighborPropValues) : 1)
Finds the lowest and highest value of the selected property.
Finds the maximum value of the selected property.
(centerNodePropValues) => _.maxBy(centerNodePropValues, d => Number(d) || 0)
Finds the minimum value of the selected property.
(centerNodePropValues) => _.minBy(centerNodePropValues, d => Number(d) || 0)
Editing a preset moves it to the custom item, where you can test or run the edited formula.
Creating a Shortcut
Using the graph pattern for photo assets illustrated above as a basic example, we can use a shortcut pattern to connect Authors (i.e. photographers) directly to the Locations where they took an Image through a new WORKED_AT relationship.
To create a Shortcut:
Open the Transform panel and Shortcut tab. To create a shortcut, you must first select at least one center node of the source edge-node-edge pattern. You can do this simply by selecting all the nodes of the center category (Photos) from the legend list.
Now enter the following details in the Shortcut panel:
• In Center Category(B), select Photos.
NOTE: If your selection includes more than one category, they all appear on the dropdown menu.
• In Relationship(R1) select CREATED.
• In Relationship(R2) select TAKEN_AT.
• In New Relationship(R3) enter WORKED_AT.
Optionally, you can copy properties from the central category (Photos) to the new [R3] (WORKED_AT) relationship, and transform the property values using an Input Formula.
We’ll compute an average rating for the photos taken at each location, and add it as a new averageRating property of the WORKED_AT relationship.
• Select the Rating property from the dropdown menu to add it to Selected Property(B).
• Enter a New Property Name (averageRating).
• In Input Formula, select average, and edit the input formula to:
(Rating) => .sumBy(Rating,d => Number(d) || 0)/(.size(Rating) > 0 ? _.size(Rating) : 1)CODE
• Check the Directional Edge and Count Links checkboxes. Count Links adds a count property to the new relationship. This automatic count may not always be meaningful, but in this example, it represents the number of photos at a location taken by the connected author.
Click Run. Processing messages display below the Run button indicating success or errors.
The new shortcut pattern has now been created and added to the graph.
The source pattern with its Photos nodes are still present in the graph space.
To view the shortcut graph, click the Photos category on the legend to select its nodes. Then either click the Hide Selected icon to hide all the Photos nodes, or press the Delete icon (or del or backspace) to delete them from the graph.
We now see only Author and Location nodes connected by the new WORKED_AT edges.
To see added properties, you can display an info panel or quick info rollover for one of the new edges, or display a table of the edges for the new relationship (e.g. WORKED_AT).