我想使用Java或Pellet向本体中添加SWRL规则,而不是使用Protégé。例如,这是我想要导入到我的本体中的规则:
[Course(?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);