cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Similar Nodes

Hi,

i'm looking for a cypher that detects other nodes with the same relationships.

In my example i have persons and skills. This nodes are conenct with the relation has.

Person A has skills like "php" and "mysql".
Person B has skills like "php", "mysql" and "c#"
Person C has skills like "php", "c#", "ios"

Person B can be an substitute for Person A. Starting with Person A, the query should find Person B.
Unfortunately, I have no idea what s the right query for this.

Do you have any idea? Thank you very much.

1 ACCEPTED SOLUTION

We have a knowledge base article on performing MATCH intersection that may be helpful here, but with some adjustments for this particular case.

This might work for you:

MATCH (start:Person {name:'Person A'})
WITH start, size((start)-[:has]-()) as skillCount
MATCH (start)-[:has*2]-(similarPerson)
WITH start, skillCount, similarPerson, count(similarPerson) as skillsInCommon
WHERE skillCount = skillsInCommon
RETURN similarPerson.name

This should only find persons that have all of the skills that person A has (though they may have more than that).

View solution in original post

4 REPLIES 4

check jaccard similarity ,
https://neo4j.com/docs/graph-algorithms/current/labs-algorithms/jaccard/

guess this will help you

Thanks for the answer, but that's not what I'm looking for.
It is easy to formulate the statement in SQL, maybe the SQL says more than my text:

person A has the ID 7

SELECT personid from skillofperson where personId != 7 and
skillId in (SELECT skillid FROM `skillofperson `  where personId = 7)
group by personid
having count(skillId) = (SELECT count(skillid) FROM `skillofperson `  where personId = 7)

in response i get a list of people who have at least the skills that person7 has
i can't translate that into cypher - can you?

We have a knowledge base article on performing MATCH intersection that may be helpful here, but with some adjustments for this particular case.

This might work for you:

MATCH (start:Person {name:'Person A'})
WITH start, size((start)-[:has]-()) as skillCount
MATCH (start)-[:has*2]-(similarPerson)
WITH start, skillCount, similarPerson, count(similarPerson) as skillsInCommon
WHERE skillCount = skillsInCommon
RETURN similarPerson.name

This should only find persons that have all of the skills that person A has (though they may have more than that).

Thank you!
That is what I was looking for