Converting directed relationships to undirected
This feature is in the beta tier. For more information on feature tiers, see API Tiers.
Introduction
In GDS, some algorithms such as Triangle Count and Link Prediction expect undirected relationships. This procedure converts directed relationships to undirected and outputs the result as a new relationship type. This can be useful to convert relationships produced by algorithms such as path algorithms.
Syntax
CALL gds.graph.relationships.toUndirected(
graphName: String,
configuration: Map
)
YIELD
inputRelationships: Integer,
relationshipsWritten: Integer,
mutateMillis: Integer,
postProcessingMillis: Integer,
preProcessingMillis: Integer,
computeMillis: Integer,
configuration: Map
Name | Type | Optional | Description |
---|---|---|---|
graphName |
String |
no |
The name under which the graph is stored in the catalog. |
configuration |
Map |
yes |
Additional parameters to configure streamNodeProperties. |
Name | Type | Default | Optional | Description |
---|---|---|---|---|
relationshipType |
String |
n/a |
no |
The relationship type to make undirected. |
mutateRelationshipType |
String |
n/a |
no |
The relationship type to be added to the graph. |
aggregation |
Map or String |
|
yes |
Handling of parallel relationships. Allowed values are |
Integer |
4 |
yes |
The number of concurrent threads used for running the algorithm. |
|
String |
Generated internally |
yes |
An ID that can be provided to more easily track the algorithm’s progress. |
|
Boolean |
true |
yes |
If disabled the progress percentage will not be logged. |
Name | Type | Description |
---|---|---|
inputRelationships |
Integer |
The number of relationships that were processed. |
relationshipsWritten |
Integer |
The number of relationships that were added. |
preProcessingMillis |
Integer |
Milliseconds for preprocessing the graph. |
computeMillis |
Integer |
Milliseconds for running the algorithm. |
postProcessingMillis |
Integer |
Unused. |
mutateMillis |
Integer |
Milliseconds for adding relationships to the projected graph. |
configuration |
Map |
The configuration used for running the algorithm. |
Example
All the examples below should be run in an empty database. The examples use Cypher projections as the norm. Native projections will be deprecated in a future release. |
In order to demonstrate converting directed relationships to undirected, we are going to create a small graph in Neo4j and project it into our graph catalog.
CREATE
(alice:Person {name: 'Alice'}),
(bob:Person {name: 'Bob'}),
(carol:Person {name: 'Carol'}),
(dave:Person {name: 'Dave'}),
(eve:Person {name: 'Eve'}),
(guitar:Instrument {name: 'Guitar'}),
(synth:Instrument {name: 'Synthesizer'}),
(bongos:Instrument {name: 'Bongos'}),
(trumpet:Instrument {name: 'Trumpet'}),
(alice)-[:LIKES { score: 5 }]->(guitar),
(alice)-[:LIKES { score: 4 }]->(synth),
(alice)-[:LIKES { score: 3}]->(bongos),
(bob)-[:LIKES { score: 4 }]->(guitar),
(bob)-[:LIKES { score: 5 }]->(synth),
(carol)-[:LIKES { score: 2 }]->(bongos),
(dave)-[:LIKES { score: 3 }]->(guitar),
(dave)-[:LIKES { score: 1 }]->(synth),
(dave)-[:LIKES { score: 5 }]->(bongos)
MATCH (person:Person)-[r:LIKES]->(instr:Instrument)
RETURN gds.graph.project(
'personsAndInstruments',
person,
instr,
{
sourceNodeLabels: labels(person),
targetNodeLabels: labels(instr),
relationshipType: type(r),
relationshipProperties: r { .score }
}
)
The following shows how to convert the relationships of type LIKES
in the graph from directed to undirected by creating an undirected relationship of new type INTERACTS
.
CALL gds.graph.relationships.toUndirected(
'personsAndInstruments', (1)
{relationshipType: 'LIKES', mutateRelationshipType: 'INTERACTS'} (2)
)
YIELD
inputRelationships, relationshipsWritten
1 | The name of the projected graph. |
2 | A map that includes the relationship type to make undirected and the relationship type to be added to the graph. |
inputRelationships | relationshipsWritten |
---|---|
9 |
18 |
Here is an illustration of how the example graph looks in Neo4j after executing the example above.