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