com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph无法强制转换为org.mindswap.pellet.jena.PelletInfGraph

时间:2015-06-24 13:21:51

标签: java jena pellet

我使用https://www.jarfire.org/pellet.html

运行示例,出现错误

  

java.lang.ClassCastException:   com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph无法转换为   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 个答案:

答案 0 :(得分:1)

Reasoner reasoner = ReasonerRegistry.getOWLReasoner();

当你这样做时,你得到了Jena的默认OWL推理器。这是基于耶拿基于规则推理的推理器。它不是Pellet的推理者。

这意味着当您创建推理模型时,其推理器是基于规则的推理图,而不是Pellet推理图,因此此代码失败:

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

您创建的原始推理模型,使用以下行, 后面有一个Pellet推理器,您可以从中获得一个Pellet推理图。

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

也就是说,你应该使用更像这样的东西:

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