1

我正在为 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>

爪哇:

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。查找有关如何检索此信息的任何文档一直很麻烦。添加带有注释的公理或任何不是问题的东西。

4

1 回答 1

0

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

//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);      
于 2013-06-17T21:40:44.327 回答