簡體   English   中英

com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph 不能轉換為 org.mindswap.pellet.jena.PelletInfGraph

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

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

運行一個例子,得到錯誤

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();

當您這樣做時,您將獲得來自 Jena 的任何默認 OWL 推理器。 這是一個基於 Jena 基於規則的推理的推理器。 它不是 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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM