将有向关系转换为无向关系
此功能处于 Beta 阶段。有关功能阶段的更多信息,请参阅 API 阶段。
语法
CALL gds.graph.relationships.toUndirected(
graphName: String,
configuration: Map
)
YIELD
inputRelationships: Integer,
relationshipsWritten: Integer,
mutateMillis: Integer,
postProcessingMillis: Integer,
preProcessingMillis: Integer,
computeMillis: Integer,
configuration: Map
名称 | 类型 | 可选 | 描述 |
---|---|---|---|
graphName |
字符串 |
否 |
图在目录中存储的名称。 |
configuration |
映射 |
是 |
配置 streamNodeProperties 的其他参数。 |
名称 | 类型 | 默认值 | 可选 | 描述 |
---|---|---|---|---|
relationshipType |
字符串 |
n/a |
否 |
要转换为无向的关系类型。 |
mutateRelationshipType |
字符串 |
n/a |
否 |
要添加到图中的关系类型。 |
aggregation |
映射或字符串 |
|
是 |
并行关系的处理方式。允许的值为 |
整数 |
4 |
是 |
运行算法时使用的并发线程数。 |
|
字符串 |
内部生成 |
是 |
可以提供的 ID,以便更轻松地跟踪算法的进度。 |
|
布尔值 |
true |
是 |
如果禁用,则不会记录进度百分比。 |
名称 | 类型 | 描述 |
---|---|---|
inputRelationships |
整数 |
已处理的关系数。 |
relationshipsWritten |
整数 |
已添加的关系数。 |
preProcessingMillis |
整数 |
预处理图所用的毫秒数。 |
computeMillis |
整数 |
运行算法所用的毫秒数。 |
postProcessingMillis |
整数 |
未使用。 |
mutateMillis |
整数 |
将关系添加到投影图中所用的毫秒数。 |
configuration |
映射 |
运行算法时使用的配置。 |
示例
以下所有示例都应在空数据库中运行。 这些示例使用Cypher 投影作为规范。原生投影将在未来版本中弃用。 |
为了演示如何将有向关系转换为无向关系,我们将要在 Neo4j 中创建一个小型图并将其投影到我们的图目录中。
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 }
}
)
以下显示了如何通过创建新的类型为 INTERACTS
的无向关系,将图中类型为 LIKES
的关系从有向转换为无向。
CALL gds.graph.relationships.toUndirected(
'personsAndInstruments', (1)
{relationshipType: 'LIKES', mutateRelationshipType: 'INTERACTS'} (2)
)
YIELD
inputRelationships, relationshipsWritten
1 | 投影图的名称。 |
2 | 包含要转换为无向的关系类型和要添加到图中的关系类型的映射。 |
inputRelationships | relationshipsWritten |
---|---|
9 |
18 |
以下是执行上述示例后,示例图在 Neo4j 中的外观示意图。