我不想使用Protégé向本体添加规则,而是使用Java或pellet将SWRL规则添加到本体中。
例如,这是我想要导入到本体中的规则:
课程(X),teacherOf(?y,?x),worksFor(?y,?z) => coursePresentedInUniversity(?x,?z)
我想将以下代码添加到本体中:
<swrl:Imp rdf:about="#CoursePresentedInUniversityRule">
<swrl:head rdf:parseType="Collection">
<swrl:IndividualPropertyAtom>
<swrl:propertyPredicate rdf:resource="#coursePresentedInUniversity" />
<swrl:argument1 rdf:resource="#x" />
<swrl:argument2 rdf:resource="#z" />
</swrl:IndividualPropertyAtom>
</swrl:head>
<swrl:body rdf:parseType="Collection">
<swrl:ClassAtom>
<swrl:classPredicate rdf:resource="#Course" />
<swrl:argument1 rdf:resource="#x" />
</swrl:ClassAtom>
<swrl:IndividualPropertyAtom>
<swrl:propertyPredicate rdf:resource="#teacherOf" />
<swrl:argument1 rdf:resource="#y" />
<swrl:argument2 rdf:resource="#x" />
</swrl:IndividualPropertyAtom>
<swrl:IndividualPropertyAtom>
<swrl:propertyPredicate rdf:resource="#worksFor" />
<swrl:argument1 rdf:resource="#y" />
<swrl:argument2 rdf:resource="#z" />
</swrl:IndividualPropertyAtom>
</swrl:body>
</swrl:Imp>有人能指给我一个示例代码吗?
实际上,我写了下面的代码,但它没有工作!
Rule mynewRule=new Rule(ruleHead,ruleBody);
PelletReasoner pelletReasoner =com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory.getInstance().createReasoner(testOntology );
KnowledgeBase knowledgeBase=pelletReasoner.getKB();
knowledgeBase.addRule(mynewRule);发布于 2016-05-28 09:28:44
使用Java代码的一种方法是通过OWL - OWLDataFactory类具有创建SWRL规则的方法,并且可以将生成的规则添加到本体中并保存--这与Protege 4和5使用的过程相同。
文档可获得这里
https://stackoverflow.com/questions/37487339
复制相似问题