我使用https://www.jarfire.org/pellet.html
运行一个示例,得到错误
java.lang.ClassCastException:com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph无法强制转换为org.minswap.pellet.jena.PelletInfGraph辅导的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");
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
当你这样做的时候,你会从Jena那里得到任何默认的OWL推理器。这是一个基于耶拿规则推理的推理器。这不是佩莱推理机。
这意味着,当你创建推理模型时,它的推理器是一个基于规则的推理图,而不是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();