首先我知道这个话题可能会重复,但实际上我还有更多问题。
我正在使用 Jena 来操纵 OWL 本体。给定一个类 A
,我想找到 A
为其域的所有属性,无论这是显式的还是推断的。
让我们考虑以下本体:A1 subClassOf A; P结构域A; P范围B;
我创建了一个带有深度学习规则推理的本体模型,这应该会打开推理器。
ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF)
解决方法引入了两种完成此任务的方法:
- 使用
listDeclaredProperties()
:这是代码,其中 cls 是我的 OntClass
ExtendedIterator<OntProperty> exItr;
exItr = cls.listDeclaredProperties(false);
while (exItr.hasNext()) {
OntProperty prop = exItr.next();
System.out.println("Object Property Name: "+ prop.getLocalName());
System.out.println("Domain: "+ prop.getDomain());
System.out.println("Range: "+ prop.getRange());
}
这将检索正确的答案:其域是显式和推断的 A
的属性,但打印的域和范围设置为 Thing。这是 A
和 A1
的输出:
Object Property Name: P
Domain: http://www.w3.org/2002/07/owl#Thing
Range: http://www.w3.org/2002/07/owl#Thing
问题 1
为什么会发生这种情况(域和范围中的事物
)?
此外,如果某些属性的域是交集,则它会被忽略,即如果 P 域 A 交集 B
,我将其称为 A
、P
将不会被检索,这是典型的,因为 A 交集 B
是 subClassOf A
。
问题 2
但是,如何检索其域为 A
或 subClassOf A
的属性,以便检索 A 交集 B
?
- 使用
listStatements
这只会检索明确声明的答案,即:
StmtIterator it = model.listStatements(null, RDFS.domain, cls);
while (it.hasNext()) {
Statement stmt = it.next();
System.out.println("Object Property Name: "+ prop.getLocalName());
System.out.println("Domain: "+ stmt.getSubject());
}
这不会为 A1
提供任何结果。这是 A
Object Property Name: P
Domain: http://www.w3.org/2002/07/owl#A
Range: http://www.w3.org/2002/07/owl#B
问题 3
为什么会发生这种情况(只有明确的结果)?以及如何检索显式结果和推断结果?
此外,这种方式还检索A
或A交集B
为其域的属性(问题2的答案),为什么会发生这种情况?我有点迷失了。
最佳答案
This retrieves correct answer: properties that its domain is A both explicit and inferred, but the printed domains and ranges are set to Thing. This is the output for both A and A1 :
Object Property Name: P Domain: http://www.w3.org/2002/07/owl#Thing Range: http://www.w3.org/2002/07/owl#Thing
Why is this happening (Thing in domain and range)?
OWL 中的属性可以具有任意数量的域和范围。当属性 P 将 D 作为域时,这意味着任何时候看到断言 P(x,y),都可以推断 x 是 D 的实例。这意味着在 OWL 中,owl :Thing 是每个属性的域,因为每个断言的主题必须是 owl:Thing 的实例。现在,考虑 Jena 的 OntProperty#getDomain() 的文档(强调):
Answer a resource that represents the domain class of this property. If there is more than one such resource, an arbitrary selection is made.
Jena 返回该属性的一个域。 owl:Thing 是属性的域,因此 owl:Thing 是合法的响应。如果你想查看所有域名,那么你需要使用OntProperty#listDomain() .
However, how can I retrieve the properties which their domain is either A or a subClassOf A in order to retrieve A intersection B?
您需要使用推理器,即使使用推理器,将其表达为 SPARQL 查询可能会更容易。然后您就可以编写更简洁的查询:
select ?property where {
?property rdfs:domain/rdfs:subClassOf* ex:A
}
此查询将获取域为 A 或 A 子类的所有属性。不过,您仍然需要推理器,以便推断 A 和 B 的交集是 A 的子类。
Why is this happening (only explicit results)? and how to retrieve both explicit and inferred results?
只有使用推理机才会得出推断结果。 Jena 的推理器在逻辑上也不完整,这意味着有些结果是 Jena 的合法 OWL 结果 推理者不会产生。您可能遇到过其中一种情况,或者代码中可能仍然存在问题。不过,在这些情况下,您可能应该生成一个完整的工作示例,并使用完整的代码提出问题,以及我们可以用来重现问题的完整本体。您还应该尝试不同的推理器(Jena 提供的其他推理器以及 Pellet、HermiT 等推理器)。
关于java - 对于 OWL A 级;获取 A 为其域的所有属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27924868/