Labels are related to elements in OWL through the rdfs:label
property.
To verify this, we can start with a minimalistic model created through the following means:
final OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
final OntClass clazz = model.createClass("urn:ex:class");
clazz.addLabel("className1", "en");
clazz.addLabel("className2", "fr");
Writing out the model as N3, we get the following content:
<urn:ex:class>
a owl:Class ;
rdfs:label "className1"@en , "className2"@fr .
Now, because OntClass inherits listPropertyValues
from OntResource
, we can work with each declared label programmatically like this:
final NodeIterator labels = clazz.listPropertyValues(RDFS.label);
while( labels.hasNext() ) {
final RDFNode labelNode = labels.next();
final Literal label = labelNode.asLiteral();
System.out.println( label.getLanguage() );
}
For out example application, the following output should hopefully demonstrate that you can reflect on the language tag explicitly.
fr
en