vemonet
vemonet

Reputation: 33

Remove ontology annotation using OWLAPI

I am trying to remove some literal Annotations from an ontology using OWLAPI version 4.0.2 (from Maven)

In this purpose I am using the RemoveOntologyAnnotation class and the manager applyChange() method. Here is the (simplified) code I use:

    OWLOntologyManager m = OWLManager.createOWLOntologyManager();
    OWLOntology ontology = null;
    File ontologyFile = new File(ontologyFileName);
    try {
        ontology = m.loadOntologyFromOntologyDocument(ontologyFile);
    } catch (OWLOntologyCreationException e) {
        e.printStackTrace();
    }
    for (OWLClass cls : ontology.getClassesInSignature()) {
        for (OWLAnnotation annotation : EntitySearcher.getAnnotations(cls.getIRI(), ontology)) {
            if (annotation.getValue() instanceof OWLLiteral) {
                RemoveOntologyAnnotation rm = new RemoveOntologyAnnotation(ontology, annotation);
                System.out.println(m.applyChange(rm));
            }
        }
    }

The applyChange() method is always returning "UNSUCCESSFULLY" And I could not find any documentation about why the annotation removing don't work.

N.B.: found some indications here http://sourceforge.net/p/owlapi/mailman/message/28203984/ Where it seems to work

Upvotes: 0

Views: 574

Answers (1)

dhke
dhke

Reputation: 15388

As also noted in the mailing list thread linked in your question, annotations on ontologies and annotations on ontology elements are two different things.

RemoveOntologyAnnotation only removes annotations on the ontology itself.

Annotations on elements are represented using axioms, specifically OWLAnnotationAssertionAxioms: Consequently, they have to be removed using OWLOntologyManager.removeAxiom() or similar means:

for (OWLClass cls : ontology.getClassesInSignature()) {
    for (OWLAnnotationAssertionAxiom annAx : EntitySearcher.getAnnotationAssertionAxioms(cls.getIRI(), ontology)) {
        if (annAx.getValue().getValue() instanceof OWLLiteral) {
            m.removeAxiom(annAx);
        }
    }
}

Upvotes: 1

Related Questions