我解決了我的問題題。我認爲我的本體論存在問題。因此,我創建了另一個本體來推斷個體。我創建的本體包含Person和Person的子類:MalePerson,FemalePerson和MarriedPerson。並且,有兩個對象屬性(hasSpouse,hasSibling)和一個數據類型屬性(hasAge)。 而且,我創建了3個人。 約翰 - MalePerson - hasAge(20) - hasSibling(簡) 簡 - FemalePerson - hasSibling(約翰) - hasSpouse(BOB) 鮑勃 - MalePerson - hasSpouse(簡)
而且,我放了兩個限制爲MalePerson和FemalePerson類。 對於MalePerson: hasSpouse最大1 hasSpouse僅MalePerson 對於FemalePerson: hasSpouse最大1 hasSpouse僅FemalePerson
最後,我提出MarriedPerson是一個定義的類。在推理之前,MarriedPerson沒有個人。但是,該模型應該推斷Jane和Bob已婚。因此,最後,MarriedPerson班應該有2個人。
當我使用Jena在Java中運行此代碼時,我得到了2個推斷個體。
OntModel ontModel = ModelFactory.createOntologyModel();
InputStream in = FileManager.get().open(inputFileName);
if (in == null) {
throw new IllegalArgumentException("File: " + inputFileName + " not found");
}
ontModel.read(in, "");
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
reasoner = reasoner.bindSchema(ontModel);
// Obtain standard OWL-DL spec and attach the Pellet reasoner
OntModelSpec ontModelSpec = OntModelSpec.OWL_DL_MEM;
ontModelSpec.setReasoner(reasoner);
// Create ontology model with reasoner support
OntModel model = ModelFactory.createOntologyModel(ontModelSpec, ontModel);
// MarriedPerson has no asserted instances
// However, if an inference engine is used, two of the three
// individuals in the example presented here will be
// recognized as MarriedPersons
//ns is the uri
OntClass marPerson = model.getOntClass(ns + "OWLClass_00000003866036241880"); // this is the uri for MarriedPerson class
ExtendedIterator married = marPerson.listInstances();
while(married.hasNext()) {
OntResource mp = (OntResource)married.next();
System.out.println(mp.getURI());
} // this code returns 2 individuals with the help of reasoner
如果你包含一個指向pizza.owl文件的指針(假設它在某處公開),並且你還提供了用於設置'reasoner'變量的代碼將會很有幫助。 – cygri 2010-06-11 17:57:12
非常感謝你的興趣cygri。我解決了我的問題,並在下面提供了一個示例。 – Mikae 2010-06-12 12:42:37