Java 如何使用OWLAPI读取注释内的rdf:description

Java 如何使用OWLAPI读取注释内的rdf:description,java,rdf,owl,owl-api,Java,Rdf,Owl,Owl Api,我不熟悉owlapi。如何获取以下OWL文件中的rdfs:label中的值? oboInOwl:hasSynonym是一个注释属性 心内膜 我正在使用OWLAPI。我不想使用XML解析器。下面的代码重新创建了一个包含您所描述的结构类型的本体,并展示了如何检索您感兴趣的注释属性值getSampleOntology()创建本体(并打印它),main显示如何从x开始,找到它的hasSynonym值,然后找到这些值的rdfs:labels。这是基于文档中的 import org.semanticwe

我不熟悉owlapi。如何获取以下OWL文件中的
rdfs:label
中的值?
oboInOwl:hasSynonym
是一个注释属性


心内膜

我正在使用OWLAPI。我不想使用XML解析器。

下面的代码重新创建了一个包含您所描述的结构类型的本体,并展示了如何检索您感兴趣的注释属性值
getSampleOntology()
创建本体(并打印它),
main
显示如何从
x
开始,找到它的
hasSynonym
值,然后找到这些值的
rdfs:label
s。这是基于文档中的

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.OWLOntologyDocumentTarget;
import org.semanticweb.owlapi.io.RDFXMLOntologyFormat;
import org.semanticweb.owlapi.io.SystemOutDocumentTarget;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLAnnotationSubject;
import org.semanticweb.owlapi.model.OWLAnonymousIndividual;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyFormat;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;

public class OWLAPIAnnotations {
    final static OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    final static OWLDataFactory factory = manager.getOWLDataFactory();
    final static String ns = "http://example.org/";
    final static OWLNamedIndividual x = factory.getOWLNamedIndividual( IRI.create( ns+"x" ));
    final static OWLAnonymousIndividual y = factory.getOWLAnonymousIndividual();
    final static OWLObjectProperty hasSynonym = factory.getOWLObjectProperty(IRI.create(ns + "hasSynonym"));

    public static OWLOntology getSampleOntology() throws OWLOntologyCreationException, OWLOntologyStorageException {
        OWLOntology ontology = manager.createOntology();
        manager.addAxiom( ontology, factory.getOWLClassAssertionAxiom( factory.getOWLClass(IRI.create(ns + "Synonym")), y));
        manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasSynonym, x, y));
        OWLAnnotation ann = factory.getOWLAnnotation( factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()), factory.getOWLLiteral("Endocardium", "en"));
        manager.addAxiom(ontology, factory.getOWLAnnotationAssertionAxiom(y, ann));
        manager.saveOntology(ontology, System.out);
        return ontology;
    }

    public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {
        OWLOntology ontology = getSampleOntology();
        for( OWLIndividual object : x.getObjectPropertyValues( hasSynonym, ontology ) ) {
            for ( OWLAnnotationAssertionAxiom aAxiom : ontology.getAnnotationAssertionAxioms( (OWLAnnotationSubject) object ) ) {
                if ( aAxiom.getProperty().equals( factory.getRDFSLabel() ) ) {
                    System.out.println( aAxiom.getValue() );
                }
            }
        }
    }
}
末尾的输出(显示注释值)为:

生成的本体是(删除注释,用于空格):


心内膜

我认为您需要展示更多本体。您显示的片段只是三元组的一部分
oboInOwl:hasSynonym
是一个属性,对象是一个带有
rdf:type
rdfs:label
的空白节点。了解三元组的主语可能会有所帮助,因为这样我们就可以将其识别为个体并询问其属性。
"Endocardium"@en