0
votes

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"
2
Do you mean for every DataProperty find the get the DataType? Because the set of valid values are defined in domain and ranges of the data properties. - Artemis
I want to know whether an OWLDatatype is an enumeration of values and, if it is, I want to do something with those values. - Jim L.
Can I have your ontology? - Artemis
I don't have permission to share it, so I would have to scrub it. It roughly looks like the bullet list in the question. The key is owl:equivalentClass and owl:oneOf with a funky RDF way of listing the values. - Jim L.
There problem is I am not sure how you define equivalent classes for dataTypes. I gave it a go, see what you think. - Artemis

2 Answers

1
votes

If understand correctly, you have a specific class "c" that has been defined as equivalent to oneOf many individuals, then I think this is one way to get those "allowed values":

    Set<OWLClassAxiom> allAx=localOntology.getAxioms(c);
    for(OWLClassAxiom ax: allAx){
        if(ax.getAxiomType()==AxiomType.EQUIVALENT_CLASSES)
            for(OWLClassExpression nce :ax.getNestedClassExpressions())
                if(nce.getClassExpressionType()==ClassExpressionType.OBJECT_ONE_OF)
                    for(OWLNamedIndividual temp: nce.getIndividualsInSignature())
                        System.out.println(temp);
    }
0
votes

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.