Instead of using Protégé to add rules to my ontology, I want to use Java or pellet to add SWRL rule to the ontology.
For example, this is the rule that I want to import into my ontology:
[Course(?x),teacherOf(?y,?x),worksFor(?y,?z)] => [coursePresentedInUniversity(?x,?z)]
I want to add the following code into the ontology:
<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>
Could anybody point me out to a sample code to do that?
Actually, I wrote the following code, but it didn't work!
Rule mynewRule=new Rule(ruleHead,ruleBody);
PelletReasoner pelletReasoner =com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory.getInstance().createReasoner(testOntology );
KnowledgeBase knowledgeBase=pelletReasoner.getKB();
knowledgeBase.addRule(mynewRule);