我对本体论是新手。最近,我尝试使用jenaapi来推断。我引用了这篇文章的答案。然而,问题是我的耶拿无法推断。我的代码写在下面。我的本体文件在这里,它包含swrl规则和一些示例。我试过在protege中推断,而且很管用。所以,这意味着我的规则是好的。有人能告诉我我的代码出了什么问题,或者怎么改正吗?谢谢!
String baseURI = "http://www.semanticweb.org/ncuis/ontologies/2021/2/People#";
String ns = "http://www.semanticweb.org/ncuis/ontologies/2021/2/People#";
OntModel ontModel = ModelFactory.createOntologyModel();
String inputFileName = "src/main/java/org/isq/Onto/People.owl";
// create ontology model using jena
InputStream in = FileManager.get().open(inputFileName);
try {
File file = new File(inputFileName);
FileReader reader = new FileReader(file);
ontModel.read(reader, null);
} catch (Exception e) {
e.printStackTrace();
}
// Inferring using Jena: https://stackoverflow.com/questions/3024273/inferring-using-jena
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
reasoner = reasoner.bindSchema(ontModel);
// Obtain standard OWL-DL spec and attach the Pellet reasoner
OntModelSpec ontModelSpec = OntModelSpec.OWL_DL_MEM;
ontModelSpec.setReasoner(reasoner);
// Create ontology model with reasoner support
OntModel model = ModelFactory.createOntologyModel(ontModelSpec, ontModel);
OntClass marPerson = model.getOntClass(ns + "MarriedPerson"); // this is the uri for MarriedPerson class
ExtendedIterator married = marPerson.listInstances();
while(married.hasNext()) {
OntResource mp = (OntResource) married.next();
System.out.println(mp.getLocalName());
} // it should infer two names
暂无答案!
目前还没有任何答案,快来回答吧!