neo4j找到具有类似连接的节点

时间:2018-03-05 14:13:39

标签: neo4j cypher graph-algorithm

我想弄清楚以下问题:我有两个节点:Merchant:Customer。这两者与:BUY关系有关。 我试图找到具有相同:Merchant个节点的:Customer个节点,甚至更好,这些节点分享90%的:Customer个节点。 谢谢。

1 个答案:

答案 0 :(得分:0)

这对我有帮助: https://neo4j.com/docs/graph-algorithms/current/algorithms/similarity-jaccard/

所有要比较的节点都在同一图中并已连接很重要。

MATCH (p:Person)-[:LIKES]->(cuisine)
WITH {item:id(p), categories: collect(id(cuisine))} as userData
WITH collect(userData) as data
CALL algo.similarity.jaccard.stream(data)
YIELD item1, item2, count1, count2, intersection, similarity
RETURN algo.getNodeById(item1).name AS from, algo.getNodeById(item2).name AS to, intersection, similarity
ORDER BY similarity DESC

应该是这样,(取决于您的数据库)

MATCH (p:Merchant)-[:BUY]->(consumer)
WITH {item:id(p), categories: collect(id(consumer))} as userData
WITH collect(userData) as data
CALL algo.similarity.jaccard.stream(data)
YIELD item1, item2, count1, count2, intersection, similarity
WHERE similarity > 0.9
RETURN algo.getNodeById(item1).name AS from, algo.getNodeById(item2).name AS to, intersection, similarity
ORDER BY similarity DESC

据我了解,它使用jaccard(https://en.wikipedia.org/wiki/Jaccard_index)作为节点的ID。

PS:安装插件以使用它很重要: https://neo4j.com/docs/graph-algorithms/current/introduction/#_installation