Neo4j:在投影中使用权重的虚拟关系

Neo4j: use in a projection a virtual relationship with weights

提问人:albertovpd 提问时间:11/9/2023 更新时间:11/9/2023 访问量:26

问:

我可以在我的图形中创建关系,分配权重并在磁盘中写入,如下所示:

MATCH (a1:node1)-[rel1]-(p:other_node)-[rel2]-(a2:node2)
// create the weight
with a1.id as id1, a2.id as id2, count(p) as common_ocurrences
// create the rel
MERGE (a1)-[r:NEW_REL]-(a2)
// use the weights as a property of the created relationship
ON CREATE SET r.counter = common_occurrences
ON MATCH SET r.counter = common_occurrences

// create projection 
CALL gds.graph.project(
 'new-graph',
 'node1',
 {NEW_REL:{
 orientation:'UNDIRECTED',
 properties:'counter'
 }
 }
)
yield *

但我想要的是做同样的事情,不写关系,也不写相关的权重。 为此,我尝试使用虚拟关系,例如使用这种方法:

MATCH (a1:node1)-[rel1]-(p:other_node)-[rel2]-(a2:node2)
with a1, a2, count(p) as common_occurrences
where a1.id>a2.id
return 
a1, a2, 
apoc.create.vRelationship(a1, 'COAUTHORS_WITH_VIRTUAL2', {weight: common_occurrences}, a2) as REL_VIRTUAL2;

这部分似乎有效,但现在我对如何使用它感到非常困惑。如果在最后一个子句之后,我写如下

CALL gds.graph.project(
 'graph42',
 'node1',
 {REL_VIRTUAL_2:{
 orientation:'UNDIRECTED',
 properties:'common_occurrences'
 }
 }

)
yield *

它说找不到关系。 对此有什么帮助吗?

尼奥4J-APOC

评论


答:

1赞 cybersam 11/9/2023 #1

这两个查询都存在几个问题。

例如,只是一个临时变量名称,而不是关系类型。 是应在投影中使用的关系类型。但是,更改它仍然无法解决问题,因为GDS不支持投影虚拟节点或关系REL_VIRTUAL2COAUTHORS_WITH_VIRTUAL2

第一种方法应该有效,但可能需要先解决其他一些问题。例如,投影应使用而不是仅用于节点标签。你可以用 .['node1', 'node2']'node1'ON CREATE SET x = y ON MATCH SET x = ySET x = y