Search code examples
owl-api

How Do I Get A Dataype's EquivalentClass in OWL API?


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:

  • rdfs:Datatype
    • owl:equivalentClass
      • rdfs:Datatype
        • owl:oneOf
          • rdf:Description
            • rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#List"

Solution

  • 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.