What I want to do: Create a validator for an ontology in Java. For this I want to use Jena Rules on a inferred model. Unfortunately I can't use both the standard reasoner (ReasonerRegistry.getOWLReasoner()
) and after this my own reasoner (new GenericRuleReasoner(Rule.rulesFromURL("file:rulefile.txt"))
). Is this possible somehow?

- 27,018
- 16
- 85
- 126

- 43
- 7
-
1You can get an existing reasoner and extract its rules, and add some more of your own rules to create a custom reasoner. See section **You need RDFS reasoning too** of [my answer](http://stackoverflow.com/a/24786478/1281433) to [Problems with inference examples from apache jena framework](http://stackoverflow.com/q/24786035/1281433) for an example. I think that's the main problem here (you called the rest "additional"), so I've removed the other bits. Ask them in a separate question. This helps keeps questions short and self contained, and keeps answers concise. – Joshua Taylor Aug 16 '14 at 22:32
-
Ok. I found out that works. But If I want to use the OWL-Reasoner I get a Class Cast Exception. Is there a solution to use OWL-Reasoner? – msc Aug 18 '14 at 18:12
-
1What does ReasonerRegistry.getOWLReasoner().getClass() return? – Joshua Taylor Aug 18 '14 at 18:19
-
A type Reasoner?! But solved it now by casting it to OWLFBRuleReasoner. – msc Aug 18 '14 at 21:01
-
1OWLFBRuleReasoner is more specific than Reasoner, so I'd be surprised if you the .getClass() call returns Reasoner, but you can cast it to OWLFBRuleReasoner. At any rate, the cast makes sense; the JavaDoc says that [OWLFBRuleReasoner](https://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/reasoner/rulesys/OWLFBRuleReasoner.html) is a Reasoner and a RuleReasoner, but not a GenericRuleReasoner. – Joshua Taylor Aug 18 '14 at 21:06
2 Answers
The default ontological reasoning within Jena should provide decent validation of standard owl ontologies. The following explains how to use that same mechansism for domains that may skirt outside of what owl provides.
In order to have domain-specific conflicts be generated when using the GnericRuleReasoner
, one needs to stimulate the generation of a domain-specific ValidityReport
when FBRuleInfGraph.validate()
is called.
This method introduces a triple to the inference graph:
728 Triple validateOn = new Triple(NodeFactory.createAnon(),
729 ReasonerVocabulary.RB_VALIDATION.asNode();
730 Functor.makeFunctorNode("on", new Node[] {}));
The idea behind this is that rules within the domain will be sensitive to the existance of this triple, and then generate a RB_VALIDATE_REPORT
when a constraint of the domain fails.
Treating the existing OWL domain as an example of this, we can search for rules that signal a violation of OWL's domains-specific constraints (from etc/owl-fb.rules
):
[validationIndiv2: (?v rb:validation on()) (?X owl:disjointWith ?Y) ->
[validationIndiv: (?I rb:violation error('conflict', 'Individual a member of disjoint classes', ?X, ?Y))
<- (?I rdf:type ?X), (?I rdf:type ?Y) noValue(?T rb:prototype ?I)] ]
This forward-chaining rule introduces a backward-chaining rule that expresses a rb:violation
when an individual is a member of disjoint classes.

- 2,693
- 16
- 22
-
Hi, sorry for my late response! I tested your rule now and it's working but I don't know why. Maybe answering the following (as short and specific as possible) questions would help me: 1) Can you explain me why I have to use a backward rule here? 2) And why do you split the two parts (?X owl:disjointWith ?Y) and (?I rdf:type ?X), (?I rdf:type ?Y)? 3) From where does the error description "Two individuals both same and different, may be due to disjoint classes or functional properties" come from? 4) What does noValue(?T rb:prototype ?I) mean? – msc Aug 20 '14 at 14:42
-
Can you please post your answer at my new question? I think the other answer is more appropriate to this initial question. Maybe you can also add the rule to solve the problem in my question. http://stackoverflow.com/questions/25422914/jena-rule-for-validation-af-a-ontology – msc Aug 21 '14 at 09:37
The answer from @Joshua is absolutely correct. The only thing you need to know is that you can parse the rdf reasoner to GenericRuleReasoner or the owl reasoner to OWLFBRuleReasoner. From GenericRuleReasoner/OWLFBRuleReasoner you can get the list of the rules.
List<Rule> rules = new ArrayList<>((OWLFBRuleReasoner)ReasonerRegistry.getOWLReasoner().getRules());
rules.addAll(Rule.rulesFromURL("file:JENA_RULES_FILE"));
GenericRuleReasoner completeReasoner = new GenericRuleReasoner(rules);

- 43
- 7