我可以在我的图中创建一个关系,分配权重并在磁盘中写入,如下所示:
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 *
上面说找不到这种关系。
有什么帮助吗?