gpt4 book ai didi

java - 从 ObjectPropertyAssertion OWLAPI 获取注释

转载 作者:行者123 更新时间:2023-12-01 04:37:26 26 4
gpt4 key购买 nike

我正在使用 OWL 2.0 的 OWL API,但有一件事我似乎无法弄清楚。我有一个 OWL/XML 文件,我想检索我的对象属性断言的注释。以下是我的 OWL/XML 和 Java 代码的片段:

猫头鹰:

<ObjectPropertyAssertion>
<Annotation>
<AnnotationProperty abbreviatedIRI="rdfs:comment"/>
<Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#string">Bob likes sushi</Literal>
</Annotation>
<ObjectProperty IRI="#Likes"/>
<NamedIndividual IRI="#UserBob"/>
<NamedIndividual IRI="#FoodSushi"/>
</ObjectPropertyAssertion>

Java:

OWLIndividual bob = manager.getOWLDataFactory().getOWLNamedIndividual(IRI.create(base + "#UserBob"));
OWLObjectProperty likes = manager.getOWLDataFactory().getOWLObjectProperty(IRI.create(base + "#Likes"));
OWLIndividual sushi = factory.getOWLNamedIndividual(IRI.create(base + "#FoodSushi"));

OWLObjectPropertyAssertionAxiom ax = factory.getOWLObjectPropertyAssertionAxiom(likes, bob, sushi);

for(OWLAnnotation a: ax.getAnnotations()){
System.out.println(a.getValue());
}

问题是,即使 OWL 声明有一个 rdfs:comment,也不会返回任何内容。找到有关如何检索此信息的任何文档都很麻烦。添加带注释的公理或其他任何内容都不是问题。

最佳答案

为了检索注释,您需要遍历感兴趣的公理。使用 getSomething() 将内容添加到本体中,如注释中所述,不可能以这种方式检索公理。这是改编自 OWL-API guide 的代码:

//Get rdfs:comment
final OWLAnnotationProperty comment = factory.getRDFSComment();

//Create a walker
OWLOntologyWalker walker =
new OWLOntologyWalker(Collections.singleton(ontology));

//Define what's going to visited
OWLOntologyWalkerVisitor<Object> visitor =
new OWLOntologyWalkerVisitor<Object>(walker) {

//In your case you visit the annotations made with rdfs:comment
//over the object properties assertions
@Override
public Object visit(OWLObjectPropertyAssertionAxiom axiom) {
//Print them
System.out.println(axiom.getAnnotations(comment));
return null;
}
};

//Walks over the structure - triggers the walk
walker.walkStructure(visitor);

关于java - 从 ObjectPropertyAssertion OWLAPI 获取注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17149146/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com