问题描述
我是本体的新手。最近,我正在尝试使用 Jena API 进行推断。我参考了this article的回答。但是,问题是我的 Jena 无法推断。 我的代码写在下面。我的本体文件是 here ,它包含 swrl 规则和一些实例。 我试图在保护中进行推断,并且它有效。所以,这意味着我的规则没问题。谁能告诉我我的代码有什么问题,或者如何纠正它?谢谢!
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
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)