【问题标题】:Serialize Ontology Reasoner Results with OWL API for web site使用网站的 OWL API 序列化 Ontology Reasoner 结果
【发布时间】: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


【解决方案1】:

保存推断的本体(您从 InferredOntologyGenerator 获得)似乎是最好的方法。

据我了解,当您创建新的推理器时,推理器仍会检查一致性并对本体进行分类,但速度更快,因为您已明确所有推理。

【讨论】:

    猜你喜欢
    • 2019-08-23
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2012-09-20
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多