Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graph 通过neo4j执行整个图遍历并使用新关系更新节点_Graph_Neo4j_Cypher - Fatal编程技术网

Graph 通过neo4j执行整个图遍历并使用新关系更新节点

Graph 通过neo4j执行整个图遍历并使用新关系更新节点,graph,neo4j,cypher,Graph,Neo4j,Cypher,如下链接所示,为了在节点之间建立相似关系,我编写了一个查询来更新具有共同主要兴趣的节点。在我的例子中,我有60k个节点,其中200k个对实体和关系之间的关系感兴趣 Match path=(p:Entity)-[:interestedIn]->(i:Interest)<-[:interestedIn]-(p1:Entity) return count(path) Match path=(p:Entity)-[:interestedIn]->(i:Interest)您显然想要统计具有

如下链接所示,为了在节点之间建立相似关系,我编写了一个查询来更新具有共同主要兴趣的节点。在我的例子中,我有60k个节点,其中200k个对实体和关系之间的关系感兴趣

Match path=(p:Entity)-[:interestedIn]->(i:Interest)<-[:interestedIn]-(p1:Entity) return count(path) 

Match path=(p:Entity)-[:interestedIn]->(i:Interest)您显然想要统计具有共同兴趣的成对人员

您当前的查询(如果运行到完成)实际上返回了正确的数字的两倍,因为每个实体对都会被计数两次(作为person1/person2和person2/person1)。不仅如此,您还将占用双倍的内存

原始解决方案 下面的查询通过对
p
p1
的ID施加顺序来消除重复对(以及任何自对)。它应该使用更少的内存,有更好的性能,也给你一个准确的结果

MATCH (p:Entity)-[:interestedIn]->(i:Interest)<-[:interestedIn]-(p1:Entity)
WHERE ID(p)> ID(p1)
RETURN count(*)

这将大大降低内存和CPU复杂性,从O(N^2)降低到O(N)。

我在回答问题时犯了一个错误,我的错。我试图做的是在实体之间创建一个关系,并将相似度值作为属性。这是计算出来的,比如说共同利益/两个向量的共同利益之和或两个向量的余弦积。请更正您问题的措辞,并提供您试图进行的精确计算的更多细节。
MATCH (p:Entity)-[:interestedIn]->(i:Interest)
WITH i, (COUNT(p)*(COUNT(p)-1))/2 AS numPairs
RETURN SUM(numPairs);