The "there exists" construct in SADL merits special explanation. This construct can only appear in the conclusion of a rule. It is related to existential quantification, that is, reasoning about what must exist.
For example, suppose that we define the class Parent as a Person who has at least 1 child:
A
Person is a Parent only if child has at least 1 value.If we encounter an instance definition such as:
Eve is a Parent.
then we know, given that the range of child is Person, that there must exist an instance of Person who is the child of Eve. However, inference over OWL entailments will not create an instance. The "there exists" construct allows us to author if-then rules to do reasoning about scenarios in which such existence can be inferred.
OWL, and therefore SADL, does not require that graph nodes be given unique identity. Rather unnamed instances (or classes) can be identified by their relationships with other things and/or their innate properties. The question arises as to how much must be known about these relationships and/or properties to uniquely identify a concept--to distinguish a concept from all others, or at least all others in a given context.
The combination of properties that uniquely identify an instance is sometimes referred to as the "primary key". For example, given a rule in which, for a given Parent, we wish to identify a child of that Parent, how much information must be known about the unidentified instance of Person which is the child in order to find or create the Person of interest that is known to exist?
The context matters as more or less information is needed to ensure unique identification in different contexts. For example, in a world where a Parent can only have 1 child, knowing the identity of the Parent would be sufficient to uniquely identify the child. In a world where twins are not possible, knowing the identity of the Parent and the birth date of the child would be sufficient. Or perhaps in the context of a rule it is sufficient simply to identify a Person who is a child of the Parent.
When "there exists" is used in the conclusion of a rule, the domain ontology and conditions of the rule create a context for the existence reasoning. Any additional conditions for uniquely identifying an instance satisfying the "there exists" must be explicitly stated. In addition, the rule may add additional information about the matching instance which is not part of the identifying criteria to the inferred model. If there is no instance in the data that matches the criteria, we do not want to create one unless the rule conditions are all met. For this reason, the "there exists" construct is only legal in the rule conclusion.
The grammar for "there exists" contains the following information:
The form of the SADL rule grammar for "there exists" depends on whether or not indefinite and definite articles are being used in translation, a SADL preference setting. When articles are used, the form is as follows:
... then there exists a <Class> and <subject-1> [has] <predicate-1> <object-1> and <subject-2> [has] <predicate-2> <object-2> and .... plus <subject-n> [has] <predicate-n> <object-n> and <subject-n+1> [has] <predicate-n+1> <object-n+1>....
where <subject-x> or <object-x> can be "the <Class>", referring to the instance found or created and identified earlier in the statement as "a <Class>".
If articles are not being used, then an explicit variable is used to identify the matching instance:
... then there exists a <Class> <var> and <subject-1> [has] <predicate-1> <object-1> and <subject-2> [has] <predicate-2> <object-2> and .... plus <subject-n> [has] <predicate-n> <object-n> and <subject-n+1> [has] <predicate-n+1> <object-n+1>....
where <subject-x> or <object-x> can be <var>.
These forms are illustrated with an example. Suppose we have this simple domain model.
Person is a class described by age with values of type int,
If articles are being used in translation, then we might have the following rule.
Rule SP: if iq of a Parent >= 120 then there exists A Person and the Parent has child the Person and the Person has commentary "This is the child of a smart parent".
If articles are not being used in translation, explicit variables are necessary and the rule might look like this.
Rule SP: if x is a Parent and iq of x >= 120 then there exists a Person y and x has child y and y has commentary "This is the child of a smart parent".
Now imagine that we wish to express two rules, one that adds commentary to children of smart parents and one that adds commentary to children of young parents. Of course the Parent of a particular child might be both smart and young or neither one, so the commentary is not part of the unique criteria for identifying a child of a given Parent. Hence the use of the "plus" keyword instead of "and".
Rule SP: if iq of a Parent >= 120 then there exists A Person and the Parent has child the Person plus the Person has commentary "This is the child of a smart parent". Rule YP: if age of a Parent < 30 then there exists a Person and the Parent has child the Person plus the Person has commentary "This is the child of a young parent".
The same two rules with explicit variables are as follows.
Rule SP: if x is a Parent and iq of x >= 120 then there exists a Person y and x has child y plus y has commentary "This is the child of a smart parent". Rule YP: if x is a Parent and age of x < 30 then there exists a Person y and x has child y plus y has commentary "This is the child of a young parent".
With reference to the example rules above, note that if the scenario data already contains multiple Person instances that match the criteria, that is they are the child of a Parent, then the plus triples will be added for each matching instance. However, if there are no pre-existing instances of Person with a child relationship to the Parent, then one will be created, associated with the Parent per the criteria, and the commentary added. Given no pre-existing match to a given Parent, which ever of the two rules above fires first will create the instance of Person and the second rule will find and use this instance, adding the conclusion commentary.
Note that it is an error for any of the triple patterns in the SADL grammar above to not reference the matching instance. In other words, the "there exists" rule conclusion cannot be mixed with other triples to be inferred. A separate rule must be used for other inferences with the same conditions.
The various rule formulations illustrated above using the SADL grammar are all translated to the "thereExists" built-in function in the SADL Intermediate Form and then translated by the reasoner-specific translator into the form that can be used by the designated reasoner. The Jena-based reasoner uses a custom built-in named "thereExists" to implement the "there exists" functionality. The arguments of the function fall into 3 categories corresponding to the three types of information described above.
The built-in thereExists has this signature:
thereExists(<Class>, <m1a>, <m1b>, <m2a>, <m2b>, ... , Plus, <n1a>, <n1b>, <n2a>, <n2b>, ...)
where <m1a>, <m1b> are either a subject and predicate to take the matching instance as object or a predicate and object to take the matching instance as subject, etc.
The "thereExists" built-in can be used directly in a rule like any other built-in function. For example, the two rules above using this direct call format would be as follows.
Rule SP: if x is a Parent and iq of x >= 120 then thereExists(Person, x, child, Plus, commentary, "This is the child of a smart parent"). Rule YP: if x is Parent and age of x < 30 then thereExists(Person, x, child, Plus, commentary, "This is the child of a young parent").