简体   繁体   English

密码查询以测试关系的共通性

[英]cypher query to test relationship commonality

I've got a neo4j dataset, with users and groups. 我有一个带有用户和组的neo4j数据集。

MATCH (user:User)-[r:Memberof]->(group:Group) RETURN *

Now I'd like to rate the commonality of each group, to all other groups, to determine a percentage of likeness between all groups (Group A shares 95% membership with Group B, 82% membership with Group C, etc.) 现在,我想对每个组与所有其他组的共通性进行rate ,以确定所有组之间的相似度百分比(A组与B组共享95%的成员资格,C组与82%的成员拥有82%的成员资格,等等)

Haven't got a clue where to start, any help please! 不清楚从哪里开始,请提供任何帮助! :) :)

There are some graph algorithms for checking similarity in Neo4j Graph Algorithms Library . Neo4j图算法库中有一些用于检查相似性的图算法

Jaccard Similarity algorithm looks a good fit for this use case. Jaccard相似性算法看起来很适合此用例。 Jaccard Similarity algorithm can be used to find out the similarity between two things. Jaccard相似度算法可用于找出两件事之间的相似度。

There is one more algorithm for similarity which can be used here, Overlap Similarity algorithm . 这里还有一种可用的相似度算法 ,即重叠相似度算法 Overlap Similarity algorithm can be used to find out which things are subsets of others. 重叠相似度算法可用于找出哪些事物是其他事物的子集。

You can find more details and some good examples about all the available Similarity algorithms on Neo4j Documentation page . 您可以在Neo4j文档页面上找到有关所有可用相似性算法的更多详细信息和一些好的示例。 You can refer examples on the above page and write Cypher query for your requirement. 您可以参考上一页的示例,并根据需要编写Cypher查询。

match (user:User)-[:Memberof]->(group:GroupA)
WITH COUNT(user) AS NUM_A, user
Match (user)-[:Memberof]->(group:GroupB)
RETURN COUNT(user) AS NUM_B, NUM_A

You can match individual group in this way 您可以通过这种方式匹配单个组

Thanks Raj 谢谢拉吉

Managed with the following query.... 通过以下查询进行管理。...

MATCH (user:User)-[:MemberOf]->(group:Group)
WITH {item:id(group), categories: collect(id(user))} as userData
WITH collect(userData) as data
CALL algo.similarity.jaccard.stream(data, {similarityCutoff: 0.9})
YIELD item1, item2, count1, count2, intersection, similarity
RETURN algo.asNode(item1).name AS from, algo.asNode(item2).name AS to, intersection, (similarity * 100) AS match

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

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