Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-18-2020 07:33 AM
I would like to retrieve node couples, for which both nodes only differ from each other in a single relationship (with a certain label).
I have no clue how to do this :-S
Any help? pointers?
05-18-2020 07:40 AM
Hello,
Can you show us your graph model where we can see Label?
05-18-2020 07:57 AM
Hi,
Sorry, I was way to fast with my question.
Basically there are 2 scenario's:
CREATE (john:Person {name: 'John'})
CREATE (joe:Person {name: 'Joe'})
CREATE (steve:Person {name: 'Steve'})
CREATE (sara:Person {name: 'Sara'})
CREATE (maria:Person {name: 'Maria'})
CREATE (dog1:Dog{name: 'dog1'})
CREATE (dog2:Dog{name: 'dog2'})
CREATE (dog3:Dog{name: 'dog3'})
CREATE (cat1:Cat{name: 'cat1'})
CREATE (cat2:Cat{name: 'cat2'})
CREATE (john)--(dog1)
CREATE (john)--(dog2)
CREATE (joe)--(dog1)
CREATE (joe)--(dog2)
CREATE (joe)--(cat1)
CREATE (sara)--(dog1)
CREATE (sara)--(dog2)
CREATE (sara)--(dog3)
CREATE (maria)--(dog1)
CREATE (maria)--(dog3)
solution should yield:
in case 1:
john -- joe
joe -- john
in case2:
john -- sara
sara -- john
sara -- maria
maria -- sara
05-18-2020 08:11 AM
I'm sorry but what you want to get is a bit unclear for me, you just want couples who have an animal in common?
Can you execute this command in Neo4j Desktop and show us what it shows please: CALL db.schema.visualization()
05-18-2020 09:00 AM
In scenario one, I would like to retrieve couple that are linked to exactly the same nodes.
So the nodes are identical when looking at relationships (not features)
Joe and John are connected to the same dog, and to nothing else.
I would like to retrieve
Joe, John
in scenario2 they are identical except that one of the two Person has an extra connection.
sara has one extra dog (dog3) in comparison with Joe and John.
I would like to retrieve
Joe, Sara
John, Sara
This might be simple, I don't know. I don't know how to enforce the same relationships on both nodes (when not knowing the relationships before hand).
So the query is: give me all node-couples with exactly the same relationships (scenario1). Scenario2: give me all node couple that only differ in a single relationship?
Hope this helps... Thanks for your time!
05-18-2020 09:14 AM
Can you give me the script to recreate your database please?
05-18-2020 09:20 AM
CREATE (john:Person {name: 'John'})
CREATE (joe:Person {name: 'Joe'})
CREATE (steve:Person {name: 'Steve'})
CREATE (sara:Person {name: 'Sara'})
CREATE (maria:Person {name: 'Maria'})
CREATE (dog1:Dog{name: 'dog1'})
CREATE (dog2:Dog{name: 'dog2'})
CREATE (dog3:Dog{name: 'dog3'})
CREATE (cat1:Cat{name: 'cat1'})
CREATE (cat2:Cat{name: 'cat2'})
CREATE (john)-[:has_dog]->(dog1)
CREATE (john)-[:has_dog]->(dog2)
CREATE (joe)-[:has_dog]->(dog1)
CREATE (joe)-[:has_dog]->(dog2)
CREATE (joe)-[:has_cat]->(cat1)
CREATE (sara)-[:has_dog]->(dog1)
CREATE (sara)-[:has_dog]->(dog2)
CREATE (sara)-[:has_dog]->(dog3)
CREATE (maria)-[:has_dog]->(dog1)
CREATE (maria)-[:has_dog]->(dog3)
05-18-2020 09:52 AM
To be honest, it's breaking my mind since 30min, what is the objective of this?
05-18-2020 12:01 PM
auch, sorry...
You mean the things i describe are not clear, or what I want is difficult/complex?
05-18-2020 10:15 AM
You can change this cypher request to get what you want
MATCH (p1:Person)-[]->(a)
WITH p1.name AS p1m, collect(a.name) AS col
CALL apoc.cypher.run('
WITH $p1m AS p1m, $col AS col
MATCH (p2:Person)-[]->(a2)
WHERE p1m <> p2.name
WITH p2.name AS p2m, collect(a2.name) AS col2, p1m, col
WHERE ALL(x IN col2 WHERE x IN col) RETURN p1m, p2m', {p1m:p1m, col:col})
YIELD value
RETURN value.p1m, value.p2m
05-18-2020 12:02 PM
I'll give it a shot as soon as possible.
Thanks for the help.
05-18-2020 12:03 PM
We are here to help so we will continue until the problem is solved:)
Did you tried the request I sent you?
It returns Persons who has pets in common:)
You can update it to get something more close to what you want:)
All the sessions of the conference are now available online