Joey Pravato
Joey Pravato

Reputation: 73

Retrieve owl:restrictions using the OWL API

Good morning, I am working with the OWL API and I am trying to retrieve the data inside of an owl:Restriction. For instance, I am using the pizza ontology and I want to get the data for onProperty and someValuesFrom which is a part of

<owl:Class rdf:about="#American">
   <rdfs:label xml:lang="pt">Americana</rdfs:label>
   <rdfs:subClassOf>
     <owl:Restriction>
       <owl:onProperty rdf:resource="#hasTopping"/>
       <owl:someValuesFrom rdf:resource="#TomatoTopping"/>
     </owl:Restriction>
   </rdfs:subClassOf>
   ...
</owl:Class>

So if I have the American OWLClass, how can I get a list of the OwlRestrictions and the properties it applies to. Something like American -> subClassOf -> Restriction -> onProperty -> hasTopping. Is there a way to create a data structure that has all of these steps in it?

Upvotes: 2

Views: 823

Answers (1)

Artemis
Artemis

Reputation: 3301

I am not sure what exactly you mean by "steps", but I think you have a class and you need all the restrictions that applies to subclasses. However, what will happen if you also want restrictions applied to equivalent classes? Therefore, I thought to write a more general one. Here goes:

    PrefixManager pm= new DefaultPrefixManager("http://www.co-ode.org/ontologies/pizza/pizza.owl#");
    OWLClass american=factory.getOWLClass("American", pm);
    Set<OWLClassAxiom> tempAx=localOntology.getAxioms(american);
    for(OWLClassAxiom ax: tempAx){
        for(OWLClassExpression nce:ax.getNestedClassExpressions())
            if(nce.getClassExpressionType()!=ClassExpressionType.OWL_CLASS)
                System.out.println(ax);
    }

Upvotes: 3

Related Questions