使用OWL API为网站序列化本体推理器结果

时间:2012-08-08 16:41:01

标签: serialization ontology owl

我想用OWL API或直接用Hermit推理器之类的东西推断本体论。这很容易(代码如下所示)。但是,我想缓存/存储/保存这些结果,这样我就不必每次都重新运行推理器。这就是VM中发生的情况。我第一次这样说:

Set<OWLClass> classes = reasoner.getSubClasses(parent, false).getFlattened();

大约需要20秒(在本例中)。第二次由于它们被缓存而没有时间生成相同的结果。那样太好了。但是,如果我弹出我的VM,我必须重新运行推理器(我有一些相当长的查询)或将输出保存到数据库以立即显示它们。

推理器不可序列化(无论是来自Hermit还是通过OWL API),似乎没有明显的方法来重新创建一个推理器并将任何先前的结果加载到其中。每次都必须重新计算它们。

序列化本体很简单,但我没有看到任何方法 将结果重新加载到推理器中以避免必须制作 同样的电话再次。

有什么我想念的吗?耶拿会是一个更好的选择吗?

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(); 
} 

1 个答案:

答案 0 :(得分:0)

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

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