Creating node programmtically

Hi all:

I am new to Neo4j and I am currently working on building an ontology using OWL in Protege 5. However, I encountered a problem about creating individuals programmtically, thus I attempt to try Neo4j and really need some kind advice.

Specifically, in Neo4j, I have a node with Label "Task", a relation named "isConstrainedBy", and another node with Label "Constraints". Then, if I define a logic rule which says that any node labelled by "Task" should be related to at least one node labelled by "Constraints" with the relation "isConstrainedBy".

Then, when I create a new node labelled by "Task", and suppose there is no node labelled by "Constraints". Is it possible that Neo4j can automatically reason that there should be another new node, say "constraints_1" labelled by "Constraints", create it, and establish the relation "isConstrainedBy" between the two new nodes?

The process above seems to be quite difficult to realize in OWL due to the Open World Assumption (despite it can be done using Jena or other external packages). However, I found that the APOC library of Neo4j seems to be able to create, update and delete nodes porgrammtically. What concerns me is the reasoning capacity of Neo4j, can Neo4j automatically detect the implicit fact that there should be a new node labelled by "Constraints", and then realize the automatic node and relation creation??

I apologize that this question maybe stupid and any suggestions will be much appreciated, thanks a lot in advance!!

Hello,

Due to the flexible nature of graph dbs, there isn't any reasoning component that fits what you describe. What might be closest (and we don't have this at this time, though it may be a possibility for the future) is some constraint that a node of some type must have some relationship to some node of another type. Even if we had this, this would merely prevent the creation or a graph change that would violate the constraint, it wouldn't create new nodes automatically to fulfill the constraint. The idea of creating a new node of some label automatically to fulfill some kind of pattern isn't something that has ever come up, I don't think, most use cases would want to have more control over node creation, including properties to set on those nodes.

You can however create a trigger in Neo4j (via APOC) that can test for nodes of the desired labels and ensure your pattern exists for that node, otherwise it can create a new one.

But then this is all driven by your own logic, since as mentioned there hasn't really been a need for such reasoning or automatic node creation.