【发布时间】:2021-04-26 19:41:04
【问题描述】:
我正在使用 OWL-API 通过 SWRL 规则加载和 owl 本体。
我用以下代码加载了一个本体:
IRI iri = IRI.create(BASE_URL);
OntologyManager manager = OntManagers.createManager();
// Load an ontology
Ontology ontologyWithRules = manager.loadOntologyFromOntologyDocument(iri);
然后我实例化一个隐士推理器:
import org.semanticweb.HermiT.ReasonerFactory;
OWLReasonerFactory reasonerFactory = new ReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ontologyWithRules);
最后,我想查询一下这个模型:
try (
QueryExecution qexec = QueryExecutionFactory.create(QueryFactory
.create("SELECT ?s ?p ?o WHERE { ?s ?p ?o }"), ontologyWithRules.asGraphModel())
) {
ResultSet res = qexec.execSelect();
while (res.hasNext()) {
System.out.println(res.next());
}
}
但是没有使用推理器。有没有办法在打开推理器的情况下对图使用 SPARQL 查询?
【问题讨论】:
-
这与 OWL-API 无关,而是 ONT-API - OntAPI 实现 OWLAPI,但这些类和方法是 OWLAPI 之外的扩展。
-
这里应该发生什么?我的意思是,对于推理,您必须使用推理器,而不是基础本体。当然,您将本体加载到推理器中,但分配并非相反,即本体不使用推理器,因此,
ontologyWithRules.asGraphModel()仍然是普通本体。在耶拿,这通常需要InfModel作为参数。不确定 Ont-API 如何设法提供由推理支持的Model实现。 -
@Ignazio,我认为这个问题与 OWLAPI+Hermit 明确相关,但仅与 ONT-API 隐式相关。似乎@marcelo-machado 在调用
createReasoner方法后期望本体发生一些变化,但自然不会收到它们。这是对隐士的不当用法。 @UniformedUser 至于推理,ONT-API 没有自己的推理支持,但显然,此功能必须以两种方式工作 - 通过外部OWLReasoner和通过InfModel。最后一种方式有点复杂,默认是GraphMem,而不是InfGraph。 -
@UninformedUser 你说得对,少了一个步骤,而那个步骤是我不知道的。但是,我想我刚刚使用
InferredOntologyGenerator类解决了这个问题。我会测试,如果它有效,我会回答这个问题。
标签: sparql jena owl-api hermit