简体   繁体   中英

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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