Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-21-2021 05:42 PM
Please keep the following things in mind:
CREATE (n:Subject {title: 'Python', cp: '6' ,prerequisite:["cs23",or,"Ics12"], prohibited: ["cs207",OR "asd207",OR cs119"]})
Solved! Go to Solution.
10-24-2021 12:15 PM
Hi,
Then, in that case you should follow the second option I gave on my first reply, related to build a new Relationship, and you can add attributes to set up the "AND" or "OR". Like, for example:
MATCH (n:Subject {title: 'Python'}), (n2:Subject)
WHERE n2.title IN ['cs23', 'Ics12']
CREATE (n)-[r:PREREQUISITE ]->(n2)
SET r.operator = 'OR'
Also, you can tune your entities and relationships according to your requirements.
Hope this helps
10-23-2021 02:22 PM
Hi,
Neo4j does not support logical expressions (like 'cs23' OR 'Ics12'
), as per the documentation.
Here, you have several options to define "prerequisite" and "prohibited":
1 . First option: create attributes prohibited
and prerequisites
as a list of strings (assumming you will have only one logical operator applied to all strings). The CREATE code will be the following
CREATE (n:Subject {title: 'Pythonlala', cp: '6' ,prerequisite:['cs23','Ics12'], prohibited: ['cs207','asd207','cs119']})
2 . Second option: In this case, you can take advantage of graph structure and convert prerequisite
and prohibited
attributes into relationships between two Subjects (or a Subject and other entity). So, you can convert prerequisites and prohibited strings into new Subject nodes, and then connect them to the Python node using relationships, as done on the code below:
CREATE (n:Subject {title: 'Python', cp: '6'}),
(pr1:Subject {title: 'cs23'}),
(pr2:Subject {title: 'Ics12'}),
(pr3:Subject {title: 'cs207'}),
(pr4:Subject {title: 'asd207'}),
(pr5:Subject {title: 'cs119'});MATCH (n:Subject {title: 'Python'}), (n2:Subject)
WHERE n2.title IN ['cs23', 'Ics12']
CREATE (n)-[:PREREQUISITE]->(n2);
MATCH (n:Subject {title: 'Python'}), (n2:Subject)
WHERE n2.title IN ['cs207','asd207', 'cs119']
CREATE (n)-[:PROHIBITED]->(n2);
In this case, you can also add some relationship attributes (for example, indicating if the relationship involves an "OR" or "AND"). And also you can reuse same entities without duplicating information (a Subject can be a prerequisite for other subject) and do queries in an easier way. I'd rather go with second option
Hope it helps
10-24-2021 06:22 AM
Thanks for answering the question, what if the prerequisites become more complex? something combined with OR and AND. ("cs23" or "cs37") AND("cs38" or "cs40)?
10-24-2021 12:15 PM
Hi,
Then, in that case you should follow the second option I gave on my first reply, related to build a new Relationship, and you can add attributes to set up the "AND" or "OR". Like, for example:
MATCH (n:Subject {title: 'Python'}), (n2:Subject)
WHERE n2.title IN ['cs23', 'Ics12']
CREATE (n)-[r:PREREQUISITE ]->(n2)
SET r.operator = 'OR'
Also, you can tune your entities and relationships according to your requirements.
Hope this helps
10-24-2021 11:00 PM
Thank you so much for helping me to solve the issues!
All the sessions of the conference are now available online