我想使用Jena的推理功能,但在使用InfModel時遇到一些性能問題。Jena:如何推斷數據/性能問題
這裏是我的本體論的簡單概述:
屬性:
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分鐘才放棄。 (該triplestore的大小爲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提供),我是否可以提高性能?
編輯: 我的同時,我已經試過用球,但我仍然無法得到一個推斷模型,正如我在我的其他問題已經描述:OutOfMemoryError using Pellet as Reasoner。那我還能做什麼?
感謝您的回答!但我不確定如何'在斷言數據前進行推理'。你能解釋一下怎麼做嗎? – Pedro 2012-04-16 23:32:51
因此,您可以使用任何推理器,例如Pellet。 – 2012-04-16 23:39:43
我想我可以使用'infModel.getDeductionsModel()'來訪問推斷的模型,但是它需要一段時間來計算,並且由我的代碼導致的性能問題可能是因爲內部推理被應用於整個數據庫。但是,由於我的本體仍在改變,我不想將推斷的數據存儲在同一個TDB中。那麼這種情況下的最佳做法是什麼?推斷的數據通常存儲在不同的三重存儲中? – Pedro 2012-04-17 00:32:10