|| apoc.create.vRelationship - APOC 核心文档 - Neo4j 文档

apoc.create.vRelationship

这既是函数也是过程。

函数详情

详情

语法

apoc.create.vRelationship(from, relType, props, to)

描述

返回一个虚拟的 RELATIONSHIP

参数

名称

类型

描述

起始节点

NODE

要分配给虚拟关系的起始节点。

关系类型

STRING

要分配给虚拟关系的类型。

属性

MAP

要分配给虚拟关系的属性映射。

终止节点

NODE

要分配给虚拟关系的终止节点。

返回

RELATIONSHIP

过程详情

详情

语法

apoc.create.vRelationship(from, relType, props, to) :: (rel)

描述

返回一个虚拟的 RELATIONSHIP

输入参数

名称

类型

描述

起始节点

NODE

连接传出虚拟关系的起始节点。

关系类型

STRING

要分配给新虚拟关系的类型。

属性

MAP

要分配给新虚拟关系的属性。

终止节点

NODE

传入虚拟关系将连接到的节点。

返回参数

名称

类型

描述

rel

RELATIONSHIP

创建的虚拟关系。

使用示例

本节中的示例基于以下图谱

CREATE (s1:Student {name: 'Priya'})
CREATE (s2:Student {name: 'Joachim'})
CREATE (s3:Student {name: 'Dominic'})
CREATE (s4:Student {name: 'Amir'})
CREATE (s5:Student {name: 'Natasha'})
CREATE (s6:Student {name: 'Elena'})

CREATE (t1:TestScore {score: 87})
CREATE (t2:TestScore {score: 90})
CREATE (t3:TestScore {score: 78})
CREATE (t4:TestScore {score: 84})
CREATE (t5:TestScore {score: 76})
CREATE (t6:TestScore {score: 92})

CREATE (a:Level {level: 'beginner'})
CREATE (b:Level {level: 'intermediate'})
CREATE (c:Level {level: 'advanced'})

MERGE (s1)-[:HAS]->(t1)-[:ASSIGNED_TO]->(b)
MERGE (s2)-[:HAS]->(t2)-[:ASSIGNED_TO]->(c)
MERGE (s3)-[:HAS]->(t3)-[:ASSIGNED_TO]->(a)
MERGE (s4)-[:HAS]->(t4)-[:ASSIGNED_TO]->(b)
MERGE (s5)-[:HAS]->(t5)-[:ASSIGNED_TO]->(a)
MERGE (s6)-[:HAS]->(t6)-[:ASSIGNED_TO]->(c);

apoc.create.vRelationship 提供了过程和函数版本,因此我们可以独立创建虚拟关系,或根据查询结果返回它们。

例如,我们可能希望在学生之间创建虚拟关系,以查看哪些学生对课堂材料的理解水平相同。

apoc.create.vRelationship 过程
MATCH (s1:Student)-[:HAS]->(:TestScore)-[:ASSIGNED_TO]->(l:Level)<-[:ASSIGNED_TO]-(:TestScore)<-[:HAS]-(s2:Student)
CALL apoc.create.vRelationship(s1,'SIMILAR_LEVEL',{level: l.level},s2) YIELD rel
RETURN s1, rel, s2;
apoc.create.vRelationship proc
图 1. 结果

我们还可以直接创建到其级别的虚拟关系,并使用 apoc.create.vRelationship 的函数版本。

apoc.create.vRelationship 函数
MATCH (s1:Student)-[:HAS]->(:TestScore)-[:ASSIGNED_TO]->(l:Level)
RETURN s1, apoc.create.vRelationship(s1,'HAS_UNDERSTANDING',{},l) as rel, l
apoc.create.vRelationship func
图 2. 结果
© . This site is unofficial and not affiliated with Neo4j, Inc.