简体   繁体   中英

cypher query to test relationship commonality

I've got a neo4j dataset, with users and groups.

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.)

Haven't got a clue where to start, any help please! :)

There are some graph algorithms for checking similarity in Neo4j Graph Algorithms Library .

Jaccard Similarity algorithm looks a good fit for this use case. Jaccard Similarity algorithm can be used to find out the similarity between two things.

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 . You can refer examples on the above page and write Cypher query for your requirement.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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