com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph cannot be cast to org.mindswap.pellet.jena.PelletInfGraph

96 views Asked by At

i use https://www.jarfire.org/pellet.html

to run an example, got error

java.lang.ClassCastException: com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph cannot be cast to org.mindswap.pellet.jena.PelletInfGraph at tutorial.HelloWorld.main(HelloWorld.java:178)

Model schema = FileManager.get().loadModel("C:/Users/vincent/Downloads/owlDemoSchema.owl");
            Model data = FileManager.get().loadModel("C:/Users/vincent/Downloads/owlDemoData.rdf");
            System.out.println("creating OntModel ");
            OntModel Infmodel = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC, schema);
                                  //dataset.getNamedModel(this.URL));
            // create an inferencing model using Pellet reasoner
            //InfModel model = ModelFactory.createInfModel(r, schema);
            Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
            InfModel model = ModelFactory.createInfModel(reasoner, data);
            // get the underlying Pellet graph
            PelletInfGraph pellet = (PelletInfGraph) model.getGraph();
            // check for inconsistency
            boolean consistent = pellet.isConsistent();
            if(consistent == true) 
                System.out.println("consistent");
            else
                System.out.println("not consistent");
1

There are 1 answers

0
Joshua Taylor On
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();

When you do this, you're getting whatever the default OWL reasoner from Jena. That's a reasoner based on Jena's rule based inference. It's not a Pellet reasoner.

That means that when you create the inference model, its reasoner is a rule based inference graph, not a Pellet inference graph, so this code fails:

InfModel model = ModelFactory.createInfModel(reasoner, data);
// get the underlying Pellet graph
PelletInfGraph pellet = (PelletInfGraph) model.getGraph();

The original inference model that you created, though, with the following line, does have a Pellet reasoner behind it, and you can get a Pellet inference graph from it.

OntModel Infmodel = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC, schema);

That is, you should use something more like this:

OntModel infmodel = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
// load data into the model
PelletInfGraph pellet = (PelletInfGraph) infModel.getGraph();