[Pellet-users] SWRL and Pellet code: Some Questions
Evren Sirin
evren at clarkparsia.com
Thu Jan 25 20:23:33 UTC 2007
On 1/24/07 11:31 AM, Paolo Bussotti wrote:
> 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") ?
>
It is the step that calls RuleUtils.pruneSWRLIntroducedInds(
reasoner.getKB() ); that causes the problem. Note that I excluded that
call in the example I sent because it was problematic. The problem with
that function call has been fixed (and will be in SVN soon) but until
then simply delete that function call in your program (as a side effect
you will get more junk individuals in your ontology but that's
relatively harmless).
> 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 ?
>
After a query. The query can be anything that requires reasoning, e.g.
asking the consistency of the KB, retrieving the instances of a concept,
etc.
Regards,
Evren
> 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);
> }
> };
>
> _______________________________________________
> Pellet-users mailing list
> Pellet-users at lists.owldl.com
> http://lists.owldl.com/mailman/listinfo/pellet-users
> _______________________________________________
>
> Sponsored by Clark & Parsia, LLC http://clarkparsia.com/
>
>
More information about the Pellet-users
mailing list