Reputation: 17
How can I determine the object properties restrictions for a class in Jena .
I have been trying to determinate if a class has a object restriction by using something like this:
if (essaClasse.isRestriction())
{
System.out.println( "Restriction on property " +
essaClasse.asRestriction().getOnProperty() );
}
else
{
System.out.println( "There is not restriction" );
}
but I got : "There is not restriction"
The owl file has a class (UserModel) which has the following restriction:
<owl:Class rdf:about="&geosim2;UserModel">
<rdfs:label xml:lang="en">UserModel</rdfs:label>
<rdfs:subClassOf rdf:resource="&geosim2;Model"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="&geosim2;hasPeople"/>
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="&geosim2;hasPhysicalPlace"/>
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:isDefinedBy rdf:datatype="&xsd;string">http://dit.upm.es/~perez/geosim/0.1.3/ns.owl#</rdfs:isDefinedBy>
<rdfs:comment xml:lang="en">An instance of this class models a user simulation model.</rdfs:comment>
</owl:Class>
Upvotes: 0
Views: 819
Reputation: 2823
If we look at the implementation of OntClass#isRestriction()
, we see that it requires the ability to find a specific triple in the underlying graph in order to identify that it is, indeed, on a restriction. Specifically, it looks for ?instance rdf:type ?obj
where ?obj
is specified by your profile.
Let us assume that you have an OWL profile in play. Then OWLProfile#RESTRICTION()
specifies that, in order to be interpreted as a Restriction
, the resource in question needs to of type owl:Restriction
.
You do have objects in your ontology that are of that type, but your code example does not expose whether or not you are referencing them. If, in your code example, your essaClasse
is referencing :&geosim2;UserModel
, then your code is doing exactly what it should. &geosim2;UserModel
is not a restriction, but it is rdfs:subClassOf
things which are.
TL;DR:
You need to list the super-classes of the class of interest (using OntClass#listSuperClasses()
, and then identify if those are restrictions. That will then give you the restrictions on your class.
In code that may not compile (written off the top of my head):
final ExtendedIterator<OntClass> superClass = esseClasse.listSuperClasses();
while( superClass.hasNext() ) {
final OntClass aParent = superClass.next();
if( aParent.isRestriction() ) {
// Do interesting things
}
else {
// Do other interesting things
}
}
Upvotes: 1