簡體   English   中英

使用OWLAPI刪除本體注釋

[英]Remove ontology annotation using OWLAPI

我正在嘗試使用OWLAPI 4.0.2版(來自Maven)從本體中刪除一些文字注釋

為此,我使用了RemoveOntologyAnnotation類和管理器applyChange()方法。 這是我使用的(簡化)代碼:

    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));
            }
        }
    }

applyChange()方法始終返回“ UNSUCCESSFULLY”,而且我找不到有關為何刪除注釋無效的任何文檔。

注意:在這里找到了一些跡象http://sourceforge.net/p/owlapi/mailman/message/28203984/在似乎可行的地方

正如在您的問題中鏈接的郵件列表線程中所指出的那樣,本體論的注釋和本體論元素的注釋是兩件事。

RemoveOntologyAnnotation僅刪除本體本身上的注釋。

元素上的注釋使用公理表示,特別是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