Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-26-2020 09:31 AM
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.
Solved! Go to Solution.
01-30-2020 10:36 AM
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).
01-26-2020 09:37 AM
check jaccard similarity ,
https://neo4j.com/docs/graph-algorithms/current/labs-algorithms/jaccard/
guess this will help you
01-30-2020 10:19 AM
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?
01-30-2020 10:36 AM
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).
01-30-2020 10:44 AM
Thank you!
That is what I was looking for
All the sessions of the conference are now available online