简体   繁体   English

使用OWLAPI删除本体注释

[英]Remove ontology annotation using OWLAPI

I am trying to remove some literal Annotations from an ontology using OWLAPI version 4.0.2 (from Maven) 我正在尝试使用OWLAPI 4.0.2版(来自Maven)从本体中删除一些文字注释

In this purpose I am using the RemoveOntologyAnnotation class and the manager applyChange() method. 为此,我使用了RemoveOntologyAnnotation类和管理器applyChange()方法。 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. applyChange()方法始终返回“ UNSUCCESSFULLY”,而且我找不到有关为何删除注释无效的任何文档。

NB: found some indications here http://sourceforge.net/p/owlapi/mailman/message/28203984/ Where it seems to work 注意:在这里找到了一些迹象http://sourceforge.net/p/owlapi/mailman/message/28203984/在似乎可行的地方

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. RemoveOntologyAnnotation仅删除本体本身上的注释。

Annotations on elements are represented using axioms, specifically OWLAnnotationAssertionAxiom s: Consequently, they have to be removed using OWLOntologyManager.removeAxiom() or similar means: 元素上的注释使用公理表示,特别是OWLAnnotationAssertionAxiom :因此,必须使用OWLOntologyManager.removeAxiom()或类似方式将其删除:

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

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

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