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

时间:2012-04-16 20:26:13

标签: sparql jena ontology inference protege

我想使用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,但我仍然无法得到推断模型,正如我在其他问题中所描述的那样:OutOfMemoryError using Pellet as Reasoner。那么我还能做些什么呢?

1 个答案:

答案 0 :(得分:3)

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

如果直接使用推断数据,您无法获得预期的效果,那么我建议您转到更具伸缩性的三重商店(4storeVirtuoso)。

相关问题