Search code examples
jenainferencereasoningjena-rules

Jena GenericRuleReasoner


What happens if we put a variable in the head of a GenericRuleReasoner, which does not appear in the body of the rule?

For instance if we have the following rule :

rule1: (?x rdf:type :Person) -> (?y :father ?x)

The rule says that every person has a father. Suppose we have a triple :a rdf:type :Person How does the reasoner behaves here? Will it create a new triple with blank node like _x :father :a ?


Solution

  • I think it will complain about that. It is, after all, ambiguous: do you mean 'there is a ?y such that...' or 'for any ?y ....'?

    From what you say it's clear that you expect former, the existential version, because that's what introducing a bNode does. So try:

    rule1: makeTemp(?y), (?x rdf:type ex:Person)  -> (?y ex:fatherOf ?x)
    

    or

    rule1: makeInstance(?y, ex:father, ?x), (?x rdf:type ex:Person) -> (?y ex:fatherOf ?x)
    

    the latter of which will give you a consistent father node, whereas the former simply introduces a bNode.