我有一个Neo4j数据库,其中包含通过Film
关系连接的Person
和ACTED_IN
个节点。使用APOC,我成功地在ACTED_WITH
节点之间直接创建了一组虚拟Person
关系,反映了它们通过同时出现的Film
间接相关的事实:< / p>
MATCH (a:Person)-[:ACTED_IN]->()<-[:ACTED_IN]-(b:Person)
WITH a, b
CALL apoc.create.vRelationship(a, 'ACTED_WITH', {}, b) YIELD rel
RETURN a, rel, b
这似乎捕获了我正在寻找的间接关系。现在,我想将此结果流式传输到Gephi进行可视化。但是相关的APOC函数需要一个paths
参数。如此有效:
MATCH path = ()-[:ACTED_IN]->()
WITH collect(path) AS paths
CALL apoc.gephi.add(null, 'workspace0', paths) YIELD nodes, relationships, time
RETURN nodes, relationships, time
如何从第一个代码块中产生的虚拟关系创建一组路径,以传递给第二个代码块中的Gephi? (或者有更好的方法来处理这种情况?)
答案 0 :(得分:0)
apoc.gephi.add
过程的数据可以是instanceof:节点,关系,路径,可迭代,映射,迭代器,对象。
所以它应该像这样工作:
MATCH (a:Person)-[:ACTED_IN]->()<-[:ACTED_IN]-(b:Person) WHERE ID(a) > ID(b)
WITH DISTINCT a, b
CALL apoc.create.vRelationship(a, 'ACTED_WITH', {}, b) YIELD rel AS rel1
CALL apoc.create.vRelationship(b, 'ACTED_WITH', {}, a) YIELD rel AS rel2
WITH collect(rel1) + collect(rel2) + collect(a) + collect(b) AS data
CALL apoc.gephi.add(null, 'workspace0', data) YIELD nodes, relationships, time
RETURN nodes, relationships, time
更新:如果需要权重,则可以按电影进行汇总:
MATCH (a:Person)-[:ACTED_IN]->(M:Movie)<-[:ACTED_IN]-(b:Person) WHERE ID(a) > ID(b)
WITH a, b,
count(M) as vWeight
CALL apoc.create.vRelationship(a, 'ACTED_WITH', {weight: vWeight}, b) YIELD rel AS rel1
CALL apoc.create.vRelationship(b, 'ACTED_WITH', {weight: vWeight}, a) YIELD rel AS rel2
WITH collect(rel1) + collect(rel2) + collect(a) + collect(b) AS data
CALL apoc.gephi.add(null, 'workspace0', data) YIELD nodes, relationships, time
RETURN nodes, relationships, time