Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-13-2020 02:56 AM
01-13-2020 04:14 AM
Depends on which relationships are fake, but deleting relationships is easy, and done like this:
MATCH (:Person { name: "A" })-[rel:classmate]->(:Person { name: "B" })
DELETE rel
RETURN true;
Now all you have to do is adjust the MATCH to catch the fake ones, and it'll be taken care of.
01-13-2020 04:39 AM
In fact, the task is difficult. Relationships are considered fake when a student is a classmate of only one student from a group of classmates.
01-13-2020 05:30 AM
something like this might work. Not tested so not sure it is corrrect syntax wise or if you need less then or equal in the where clause
MATCH (a:Person { name: "A" })-[rel:classmate]->(b:Person { name: "B" })
WITH size((b)-[:classmate]->() ) AS others_classmates,
size((a)-[:classmate]->() ) AS own_classmates,
WHERE own_classmates < others_classmates
DELETE rel
RETURN true;
01-13-2020 07:10 AM
I tried:
MATCH (a:student)-[rel:classmate]->(b:student)
WITH size((b)-[:classmate]->() ) AS others_classmates,
size((a)-[:classmate]->() ) AS own_classmates,
WHERE own_classmates < others_classmates
DELETE rel
RETURN true;
Error:
Neo.ClientError.Statement.SyntaxError
Invalid input 'w': expected 'r/R' or 'p/P' (line 4, column 8 (offset: 162))
"WHERE own_classmates < others_classmates"
^
01-13-2020 07:24 AM
You inserted a comma before your WHERE statement.
If you remove it, it should work.
So it should be like:
MATCH (a:student)-[rel:classmate]->(b:student)
WITH size((b)-[:classmate]->() ) AS others_classmates,
size((a)-[:classmate]->() ) AS own_classmates
WHERE own_classmates < others_classmates
DELETE rel
RETURN true;
01-13-2020 07:42 PM
Hi. I have an error: Variable rel
not defined (line 5, column 8 (offset: 196))
"DELETE rel".
01-13-2020 11:47 PM
Hey,
the variable is defined in the MATCH-clause, but not in the WITH-clause.
So something like
WITH size((b)-[:classmate]->() ) AS others_classmates,
size((a)-[:classmate]->() ) AS own_classmates,
rel
should work for you.
01-16-2020 01:39 AM
This code seems to have helped me.
MATCH (a:student)-[rel:classmate]->(b:student)
WITH size((b)-[:classmate]->() ) AS others_classmates,
size((a)-[:classmate]->() ) AS own_classmates, a, b, rel
WHERE others_classmates >= own_classmates
DELETE rel
01-16-2020 07:20 AM
Be careful using size though. You could get a fake classmate counting as valid if they have the same number of classmates, but not necessarily the exact same classmates.
You would probably want to compare classmate collections for that.
-Mike
All the sessions of the conference are now available online