Adding multiple labels to an OWL class (similar to SKOS:altLabel)

352 Views Asked by At

I am editing ontologies for a project in JAVA with org.semanticweb.owlapi.model.OWLOntology. I need to find a solution about adding multiple labels to an owl class.

For any class c from OWL-API, I can get its label via c.getIRI(). But how can I add the second label to this class?

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

}

I found in SKOS, there is a possibility to add several labels for a class. But, using SKOS:altLabel requires that I define my owl class as a SKOS concept, which it put me in a challenge to change all my used models in the project.

Is there any clue, how can I add multiple labels for an OWL-API Class?

Thanks in advance for your suggestion and help.

1

There are 1 best solutions below

2
Sami On

Thanks to Ignazio,
so I correct it like this:

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

}