我对Neo4j数据库非常陌生。目前,我正在尝试找出具有相似邻居的节点。因此,例如,如果图中有五个节点A, B, C, D, E
。 A
的邻居是[B, C, D ,E]
,节点D
的邻居是[B, C, A]
,那么对[A,D]
是我要寻找的,因为他们有{{1 }}在常见邻居中,百分比为[B, C]
,即SIZE([B,C]) / SIZE (MIN([B, C, A]))
。我正在尝试基于阈值(在这种情况下为2/3
)。
有两个库:一个是 apoc.coll.intersection ,另一个是 algo.similarity.overlap < / strong>,但我没有想出使用这些库的方法...
请帮助:(
答案 0 :(得分:0)
我创建了您的方案:
`MERGE (a:Alpha {name: "A"})
MERGE (a1:Alpha {name: "B"})
MERGE (a2:Alpha {name: "C"})
MERGE (a3:Alpha {name: "D"})
MERGE (a4:Alpha {name: "E"})
MERGE (a)-[:CLOSE]->(a1)<-[:CLOSE]-(a3)
MERGE (a)-[:CLOSE]->(a2)<-[:CLOSE]-(a3)
MERGE (a)-[:CLOSE]->(a3)
MERGE (a)-[:CLOSE]->(a4)`
运行Jaccard的相似性
`MATCH (e1:Alpha)-[:CLOSE]-(p1:Alpha)
WITH e1, collect(id(p1)) AS p11
MATCH (e2:Alpha)-[:CLOSE]-(p2:Alpha) WHERE e1 <> e2
WITH e1, p11, e2, collect(id(p2)) AS p21
RETURN e1.Name as from, e2.Name as to,
algo.similarity.jaccard(p1entity_type, p2entity_type) AS
similarity ORDER BY similarity DESC;`
结果: enter image description here
有关Jaccard相似性的更简单说明,请查看以下链接: