owl-api

How to retrieve assertions about an ontology by using OWL-API


My ontology has the following triples, where the subject is the ontology itself. Protégé visualizes them as "Annotations" in the "active ontology" tab ("Ontology header" section).

<http://myOntology/testOnto> rdf:type owl:Ontology ;
    <http://purl.org/dc/elements/1.1/creator> "Andrea"@it ;
    <http://purl.org/dc/elements/1.1/title> "test"@it ;
    rdfs:label "Andrea"@it .

How can I retrieve them by using OWL API ?


Solution

  • OWLOntology implements the HasAnnotations interface and these are annotations on the ontology itself. You can thus use the annotations (or annotationsAsList) method for that:

    StringDocumentSource source = new StringDocumentSource("""                
                    <http://myOntology/testOnto> rdf:type owl:Ontology ;
                        <http://purl.org/dc/elements/1.1/creator> "Andrea"@it ;
                        <http://purl.org/dc/elements/1.1/title> "test"@it ;
                        rdfs:label "Andrea"@it .""");
    OWLOntologyManager ontologyManager; // Init ontology manager
    OWLOntology loaded = ontologyManager.loadOntologyFromOntologyDocument(source);
    List<OWLAnnotation> annotations = loaded.annotationsAsList();
    System.out.println(annotations);