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?
2 回答
Jena 中的默认本体推理应该提供对标准 owl 本体的适当验证。下面解释了如何对可能超出 owl 提供范围的域使用相同的机制。
为了在使用 时生成特定于域的冲突,需要在调用时GnericRuleReasoner
刺激生成特定于域的冲突。ValidityReport
FBRuleInfGraph.validate()
此方法将三元组引入推理图:
728 Triple validateOn = new Triple(NodeFactory.createAnon(),
729 ReasonerVocabulary.RB_VALIDATION.asNode();
730 Functor.makeFunctorNode("on", new Node[] {}));
这背后的想法是域内的规则将对这个三元组的存在敏感,然后RB_VALIDATE_REPORT
在域的约束失败时生成一个。
以现有的 OWL 域为例,我们可以搜索表明违反 OWL 域特定约束的规则(来自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)] ]
这个前向链接规则引入了一个后向链接规则,该规则表示rb:violation
一个个体何时是不相交类的成员。
@Joshua 的回答是绝对正确的。您唯一需要知道的是,您可以将 rdf 推理器解析为 GenericRuleReasoner,或者将 owl 推理器解析为 OWLFBRuleReasoner。从 GenericRuleReasoner/OWLFBRuleReasoner 您可以获得规则列表。
List<Rule> rules = new ArrayList<>((OWLFBRuleReasoner)ReasonerRegistry.getOWLReasoner().getRules());
rules.addAll(Rule.rulesFromURL("file:JENA_RULES_FILE"));
GenericRuleReasoner completeReasoner = new GenericRuleReasoner(rules);