[Pellet-users] SWRL and Pellet code: Some Questions
Paolo Bussotti
paolo.bussotti at unifi.it
Wed Jan 24 16:31:48 UTC 2007
Hi everybody,
Please, might someone tell me why this code gives a
"java.lang.NullPointerException" when executed, at the moment that I try
to retrieve the
two SpecialCourse which should be deduced by the firing of the rule (I
refer to "http://www.mindswap.org/~kolovski/rules.owl") ?
I have tried to reproduce the functionality of the code reported on this
list, see"Code examples using SWRL and Pellet", using as much Jena as
possible as it is Pellet.java in the pellet-1.4-RC1 release. Therefore
I have used Jena OntModel instead of the OWL-API OWLOntology (as in the
mention example) . I also have tried to programmatically querying the
model calling the OWLReasoner method "getInstances" (instead of the
Reasoner method "AllInstanceOf") to retrieve the instances which should
be deduced, but it fails. Another thing: Do the rules start to work
after the setRule instruction or after a query ?
Thanks in advance.
Paolo Bussotti
public class swrl_14rc1
{OntModel model;
OWLReasoner reasoner;
public static void main(String args[])
{// ontology and rules files
//String ontFile = "http://www.mindswap.org/~kolovski/rules.owl";
String ontFile="file:rules.owl";
String rulesFile = ontFile;
// load the ontology
InputStream inStream = FileManager.get().open(ontFile);
model = ModelFactory.createOntologyModel(
PelletReasonerFactory.THE_SPEC);
model.read(inStream,"");
reasoner = ((PelletInfGraph) model.getGraph()).getOWLReasoner();
((PelletInfGraph) model.getGraph()).setLazyConsistency( true );
model.prepare();
// load the rules
try{Set rules = RuleUtils.parseRules(rulesFile);
reasoner.getKB().setRules(rules);
RuleUtils.pruneSWRLIntroducedInds( reasoner.getKB() );
}
catch(Exception e1_1){System.out.println(e1_1.toString());}
// query
String ns =
"http://www.mindswap.org/~edna/swoopRules/examples/lubm_owllog.owl#";
Set specialCourses=null;
OntClass specialCourse=null;
specialCourse = model.getOntClass(ns + "SpecialCourse");
try{specialCourses = reasoner.getInstances(specialCourse);
}
catch(Exception
e2_2){System.out.println("e2_2:"+e2_2.toString());}
System.out.println(specialCourses);
}
};
More information about the Pellet-users
mailing list