我解决了我的问题题。我认为我的本体论存在问题。因此,我创建了另一个本体来推断个体。我创建的本体包含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