如何使用 Jena 库从 Ontology in Java 中读取所有对象属性?
How to read all object properties from Ontology in Java using Jena library?
我想读取 OWL 文件中存在的所有对象属性。我使用 Protege 工具创建了 OWL 文件。我也加载了模型,但无法获取对象属性。
For Example: if I have a class in Ontology named as Car and which has
several Object and Data properties linked to it, such as hasColor,
hasAudioSystem,hasGps.
我想通过域和范围或仅通过 class 的名称获取与特定 class 链接的所有对象属性。请帮忙..
如果您想获取类型声明为域或范围的对象属性列表,使用 Jena 的一种方法如下:
public void objectPropertiesForType(Model m, final Resource type) {
StmtIterator i = m.listStatements(new SimpleSelector() {
@Override
public boolean test(Statement s) {
if (s.getPredicate().equals(RDFS.domain)
|| s.getPredicate().equals(RDFS.range)) {
return (s.getObject().equals(type));
}
return false;
}
});
while (i.hasNext()) {
Statement s = i.next();
System.out.println("Property: " + s.getSubject().getURI());
}
}
在耶拿,您可能想要为 class 检索 OntClass 的实例,然后使用 listDeclaredProperties 方法,这将:
Return an iterator over the properties associated with a frame-like
view of this class. This captures an intuitive notion of the
properties of a class. This can be useful in presenting an ontology
class in a user interface, for example by automatically constructing a
form to instantiate instances of the class. The properties in the
frame-like view of the class are determined by comparing the domain of
properties in this class's OntModel with the class itself.
我想读取 OWL 文件中存在的所有对象属性。我使用 Protege 工具创建了 OWL 文件。我也加载了模型,但无法获取对象属性。
For Example: if I have a class in Ontology named as Car and which has several Object and Data properties linked to it, such as hasColor, hasAudioSystem,hasGps.
我想通过域和范围或仅通过 class 的名称获取与特定 class 链接的所有对象属性。请帮忙..
如果您想获取类型声明为域或范围的对象属性列表,使用 Jena 的一种方法如下:
public void objectPropertiesForType(Model m, final Resource type) {
StmtIterator i = m.listStatements(new SimpleSelector() {
@Override
public boolean test(Statement s) {
if (s.getPredicate().equals(RDFS.domain)
|| s.getPredicate().equals(RDFS.range)) {
return (s.getObject().equals(type));
}
return false;
}
});
while (i.hasNext()) {
Statement s = i.next();
System.out.println("Property: " + s.getSubject().getURI());
}
}
在耶拿,您可能想要为 class 检索 OntClass 的实例,然后使用 listDeclaredProperties 方法,这将:
Return an iterator over the properties associated with a frame-like view of this class. This captures an intuitive notion of the properties of a class. This can be useful in presenting an ontology class in a user interface, for example by automatically constructing a form to instantiate instances of the class. The properties in the frame-like view of the class are determined by comparing the domain of properties in this class's OntModel with the class itself.