[英]com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph cannot be cast to org.mindswap.pellet.jena.PelletInfGraph
i use https://www.jarfire.org/pellet.html我使用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) java.lang.ClassCastException: com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph 无法在 tutorial.HelloWorld.main(HelloWorld.java:178) 中转换为 org.mindswap.pellet.jena.PelletInfGraph
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();
When you do this, you're getting whatever the default OWL reasoner from Jena.当您这样做时,您将获得来自 Jena 的任何默认 OWL 推理器。 That's a reasoner based on Jena's rule based inference.这是一个基于 Jena 基于规则的推理的推理器。 It's not a Pellet reasoner.它不是 Pellet 推理机。
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:这意味着当您创建推理模型时,其推理器是基于规则的推理图,而不是 Pellet 推理图,因此此代码失败:
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.但是,您创建的原始推理模型(包含以下行)背后确实有一个 Pellet 推理器,您可以从中获得 Pellet 推理图。
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.