耶拿:如何推断数据/性能问题



我想使用 Jena 的推理功能,但在使用 InfModel 时遇到了一些性能问题。

以下是我的本体的简化概述:

性能:

hasX            (Ranges(intersection): X, inverse properties: isXOf)
|-- hasSpecialX (Ranges(intersection): X, inverse properties: isSpecialXOf)
isXOf           (Domains(intersection): X, inverse properties: hasX)
|--isSpecialXOf (Domains(intersection): X, inverse properties: hasSpecialX)
此外,还有一个

类"对象":

Object hasSpecialX some X

显式存储的是以下数据:

SomeObject a Object 
SomeX a X
SomeObject hasSpecialX SomeX  

使用以下查询,我想确定实例属于哪个类。根据所做的假设,只应返回"SomeObject"。

SELECT ?x WHERE { ?x :hasX :SomeX . } 

但是,针对ds.getDefaultModel()进行查询不起作用,因为数据未显式存储。另一方面,当我使用infModel时,查询永远不会完成。最长的一段时间,我已经等了 25 分钟才中止。(三重存储的大小约为 180 MB)

这是我的代码:

OntModel ont = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF, null); 
ont.read("file:..." , "RDF/XML"); 
Reasoner reasoner = ReasonerRegistry.getOWLMicroReasoner(); 
reasoner = reasoner.bindSchema(ont); 
Dataset dataset = TDBFactory.createDataset(...); 
Model model = dataset.getDefaultModel(); 
InfModel infModel = ModelFactory.createInfModel(reasoner, model);
QueryExecution qe = null;
ResultSet rs;
try {
    String qry = "SELECT ?x WHERE { ?x :hasX :SomeX . }"; 
    qe = QueryExecutionFactory.create(qry, infModel); 
    rs = qe.execSelect(); 
    while(rs.hasNext()) {
        QuerySolution sol = rs.nextSolution(); 
        System.out.println(sol.get("x"));
    }
} finally {
    qe.close();
    infModel.close();
    model.close(); 
    dataset.close();
}

上面的代码有什么问题吗,或者它不起作用的原因是什么?

除此之外,我想知道如果我做"将推断公理导出为本体"(由 Protege 提供)是否可以提高性能?

编辑:与此同时,我尝试使用Pellet,但仍然无法获得推断模型,正如我在另一个问题中所描述的那样:使用Pellet作为推理器的OutOfMemoryError。那我还能做什么呢?

关于性能,最好在断言数据之前进行推理,而不是在关闭耶拿推理机制的情况下进行SPARQL。您已经在使用TDB,它是大数据集的正确耶拿组件。

如果直接使用推断的数据无法获得预期的性能,那么我建议迁移到更具可扩展性的三重存储(4store或Virtuoso)。

最新更新