0

我正在为一个项目编辑JAVA本体org.semanticweb.owlapi.model.OWLOntology。我需要找到一个关于向 owl 类添加多个标签的解决方案。

对于来自 OWL-API 的任何类c,我可以通过c.getIRI(). 但是如何将第二个标签添加到此类?

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLOntologyManager;
    private static void addMultipleLabel() {
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLDataFactory factory = manager.getOWLDataFactory();

    IRI iri_1 = IRI.create("my_first_label");
    IRI iri_2 = IRI.create("my_second_label");
    OWLClass myClass = factory.getOWLClass(iri_1);
    // how to assign also iri_2 to myClass

}

我在 SKOS 中发现,可以为一个类添加多个标签。但是,使用SKOS:altLabel要求我将我的 owl 类定义为一个 SKOS 概念,这让我面临更改项目中所有使用的模型的挑战。

有什么线索吗,如何为 OWL-API 类添加多个标签

提前感谢您的建议和帮助。

4

1 回答 1

0

感谢 Ignazio,
所以我这样更正它:

    private static void addMultipleLabel() throws OWLOntologyCreationException {
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLDataFactory factory = manager.getOWLDataFactory();
    OWLOntology myOnt = manager.createOntology(IRI.create("C:\\LOCAL_FOLDER_\\ontName.owl"));

    IRI iri_1 = IRI.create("my_first_label");
    IRI iri_2 = IRI.create("my_second_label");
    OWLClass myClass = factory.getOWLClass(iri_1);

    OWLAnnotationProperty labels = factory.getRDFSLabel();

    OWLAnnotation pA1 = factory.getOWLAnnotation(labels, iri_1);
    OWLAnnotationAssertionAxiom myAxiom1 = factory.getOWLAnnotationAssertionAxiom(myClass.getIRI(), pA1);
    manager.addAxiom(myOnt, myAxiom1);

    OWLAnnotation pA2 = factory.getOWLAnnotation(labels, iri_2);
    OWLAnnotationAssertionAxiom myAxiom2 = factory.getOWLAnnotationAssertionAxiom(myClass.getIRI(), pA2);
    manager.addAxiom(myOnt, myAxiom2);

}
于 2020-01-11T15:10:04.477 回答