简体   繁体   English

neo4j查找具有相似连接的节点

[英]neo4j find nodes with similar connections

I am trying to figure out the following problem: I have two nodes :Merchant and :Customer . 我试图找出以下问题:我有两个节点:Merchant:Customer The two are related with a :BUY relationship. 两者与:BUY关系有关。 I am trying to find :Merchant nodes that have the same :Customer nodes, or even better, that share let's say 90% of the :Customer nodes. 我试图找到具有相同:Customer节点,甚至更好的共享:90% :Customer节点的:Merchant节点。 Thank you. 谢谢。

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

It's important that all nodes you want to compare are in the same graph and connected. 重要的是要比较的所有节点都在同一图中并已连接。

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

should be something like this, (it depends on your db) 应该是这样的(取决于您的数据库)

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

By my understanding it uses the jaccard ( https://en.wikipedia.org/wiki/Jaccard_index ) to the id of the node. 据我了解,它使用jaccard( https://en.wikipedia.org/wiki/Jaccard_index )作为节点的ID。

PS: It is important to install the plugin to use it: https://neo4j.com/docs/graph-algorithms/current/introduction/#_installation PS:重要的是安装插件以使用它: https : //neo4j.com/docs/graph-algorithms/current/introduction/#_installation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM