java - Jena Reasoner 无法推断
问题描述
我是本体的新手。最近,我正在尝试使用 Jena API 进行推断。我已经参考了这篇文章的答案。但是,问题是我的耶拿无法推断。我的代码写在下面。我的本体文件在这里,它包含 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
解决方案
推荐阅读
- javascript - 处理“JSX 属性中的 lambda”案例
- angular - 如何在模型类中的任何随机时间点更新组件?
- php - php mysql 在同一查询中的 WHERE 子句中使用子查询结果
- android - 新文章发布时在 android 应用中显示通知
- android - 将 Firebase“依赖项”与 Gradle 同步
- php - 使用 cURL 从 API 访问 JSON
- apache-kafka - 汇合模式注册表并不总是启动
- android - 如何使用不同的 Java 代码构建不同风格的 apk?
- arrays - 我们如何以 5 角内爆或爆炸数组
- jmeter - JMeter:为 multipart/form-data 中的参数添加/删除正文 HEADERS