【发布时间】:2012-08-08 16:41:00
【问题描述】:
我想使用 OWL API 或直接使用 Hermit 推理器之类的东西在本体上生成推理。这很容易(代码如下所示)。但是,我想缓存/存储/保存这些结果,这样我就不必每次都重新运行推理器。这就是在 VM 中发生的情况。我第一次这样称呼:
Set<OWLClass> classes = reasoner.getSubClasses(parent, false).getFlattened();
大约需要 20 秒(在本例中)。第二次不需要时间就可以生成相同的结果,因为它们已被缓存。这太棒了。但是,如果我退回我的虚拟机,我必须重新运行推理器(我有一些相当长的查询)或将输出保存到数据库以立即显示它们。
Reasoner 不可序列化(从 Hermit 或通过 OWL API),我似乎没有明显的方法来重新创建 Reasoner 并将任何以前的结果加载到其中。每次都必须重新计算。
序列化本体很简单,但我没有看到任何方法 将结果重新加载到推理器中以使您不必 同样的电话。
我有什么遗漏吗?耶拿会是更好的选择吗?
OWLOntologyManager owlOntologyManager = OWLManager.createOWLOntologyManager();
File file = new File("resource/RDFData/release", "NEMOv2.85_GAFLP1_diffwave_data.rdf");
IRI iri = IRI.create(file);
OWLDataFactory factory = owlOntologyManager.getOWLDataFactory();
OWLOntology owlOntology = owlOntologyManager.loadOntologyFromOntologyDocument(iri);
Reasoner reasoner = new Reasoner(owlOntology);
OWLClass parent = factory.getOWLClass(IRI.create(DataSet.NS + "#NEMO_0877000"));
Set<OWLClass> classes = reasoner.getSubClasses(parent, false).getFlattened();
FileOutputStream fos = null;
ObjectOutputStream out = null;
try {
fos = new FileOutputStream("reasoner.ser");
out = new ObjectOutputStream(fos);
out.writeObject(reasoner);
out.close();
} catch (IOException ex) {
ex.printStackTrace();
}
【问题讨论】:
-
答案是使用推断的本体导出您的 OWL 本体。在读入新的推断本体并用它创建一个推理器后,推理器不觉得有必要重新推理。按照此处描述的导出:owlapi.svn.sourceforge.net/viewvc/owlapi/owl1_1/trunk/examples/… 然后重新导入:OWLOntology readOntology = owlOntologyManager.loadOntology(iriOut); Reasoner r2 = new Reasoner(readOntology); classes = r2.getSubClasses(parent, false).getFlattened();
标签: serialization ontology owl