In the OWL API, I am unable to find a way to retrieve the equivalent class for a datatype that defines an enumeration of valid values. When I have an OWLDatatype in hand, how do I get a set of allowed values?
[I tried pasting RDF/XML as a code block here, but it doesn't work. I even looked at the markdown help. Please tell me how to do that.]
The ontology is using the following construct:
Here's what I came up with:
for (OWLDatatype dt : o.getDatatypesInSignature(Imports.INCLUDED)) {
logger.info("found datatype {} labeled '{}'", dt, getOWLEntityLabel(dt));
Set<OWLDatatypeDefinitionAxiom> datatypeDefinitions = o.getDatatypeDefinitions(dt);
for (OWLDatatypeDefinitionAxiom definitionAxiom : datatypeDefinitions) {
logger.info("found datatype definition '{}'", definitionAxiom);
OWLDataRange dataRange = definitionAxiom.getDataRange();
if ( ! dataRange.isDatatype()) {
logger.info("looks like an enumeration");
OWLDataOneOf owlDataOneOf = (OWLDataOneOf) dataRange;
Set<OWLLiteral> values = owlDataOneOf.getValues();
for (OWLLiteral value : values) {
logger.info("Found literal value '{}'", value.getLiteral());
}
}
}
}
I really don't like the cast to OWLDataOneOf
. There must be a better way.