简体   繁体   English

从ObjectPropertyAssertion OWLAPI获取注释

[英]Get annotations from ObjectPropertyAssertion OWLAPI

I'm using the OWL API for OWL 2.0 and there is one thing I can't seem to figure out. 我使用的是OWL 2.0的OWL API,有一件事似乎无法弄清。 I have an OWL/XML file and I would like to retrieve the annotations for my object property assertions. 我有一个OWL / XML文件,我想为我的对象属性声明检索注释。 Here are snippets from my OWL/XML and Java code: 以下是我的OWL / XML和Java代码的片段:

OWL: 猫头鹰:

<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: 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());
  }

Problem is, nothing gets returned even though the OWL states there is one rdfs:comment . 问题是,即使OWL声明存在一个rdfs:comment ,也不会返回任何内容。 It has been troublesome to find any documentations on how to retrieve this information. 很难找到有关如何检索此信息的任何文档。 Adding axioms with comments or whatever is not an issue. 添加带有注释或其他任何问题的公理。

In order to retrieve the annotations you need to walk over the axioms of interest. 为了检索注释,您需要遍历感兴趣的公理。 Using the getSomething() adds things to the ontology, as noted in the comments, it is not possible to retrieve your axiom this way. 如注释中所述,使用getSomething()将事物添加到本体中,无法以这种方式检索公理。 Here is the code adapted from the OWL-API guide : 这是从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);      

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM