1
我想用OWL API或直接使用類似於隱士推理器的東西生成本體推論。這很簡單(代碼如下所示)。但是,我想緩存/存儲/保存這些結果,以便我不必每次都重新運行推理器。這是VM中發生的事情。我第一次稱此爲:使用OWL API爲網站序列化本體論推理結果
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本體。在閱讀了新的推斷本體並且創建了一個推理器之後,推理者並不覺得需要重新推斷。按照此處所述的輸出: http://owlapi.svn.sourceforge.net/viewvc/owlapi/owl1_1/trunk/examples/src/main/java/org/coode/owlapi/examples/Example11.java?view=標記 然後重新導入: OWLOntology readOntology = owlOntologyManager.loadOntology(iriOut); 推理r2 =新推理(readOntology); classes = r2.getSubClasses(parent,false).getFlattened(); – user695555 2012-08-08 19:50:01