On 22/12/15 11:06, Dibyanshu Jaiswal wrote:
I am using the following function to get a list of all the equivalent
classes of a given class.
*Inputs* :
1. myModel: is my jena OntModel.
2. classURI : URI of the class for which I want to fetch the equivalent
classes.
*Output* : List<String> containing the URIs of the equivalent classes.
*Function* :
public static List<String> getEquivalentClasses(String classURI, OntModel
myModel){
List<String> list = new ArrayList<String>();
OntClass oc = myModel.getOntClass(classURI);
ExtendedIterator<OntClass> InstIt = oc.listEquivalentClasses();
while (InstIt.hasNext())
{
oc=InstIt.next();
if(oc.getURI()!=null)
list.add(oc.getURI());
}
return list;
}
I use the same logic to fetch a list of subclasses of a given class, which
works fine.
But it doesn't works for Equivalent classes.
I have tried this on the Pizza
<http://protege.stanford.edu/ontologies/pizza/pizza.owl> ontology, for
class Pizza and CheesyPizza. It has many equivalent classes when opened in
protege, but unable to list any via the OntClass.listEquivalentClasses()
API of Jena.
There are lots of owl:equivalentClass statements in that ontology but
none of them are between pairs of named classes. In all cases the
equivalent class is a bNode with no URI and so is excluded by your
"if(oc.getURI()!=null)" test.
Note also that protege may be using inference to deduce additional
equivalent class relationships. You would need to use an equivalent
inference set up in your OntModel to see those deduced equivalences.
To my observation, the for example class CheeseyPizza is an equivalent to
Pizza class and further has some property restriction as "hasTopping some
CheeseTopping" , is this got something to do with it?
No. That owl:equivalentClass statement is saying that a #CheeseyPizza is
equivalent to the intersection of Pizza and those restriction, it is not
directly equivalent to #Pizza. Paraphrasing in Turtle it has:
<#CheeseyPizza> a owl:Class;
owl:equivalentClass [
a owl:Class;
owl:intersectionOf (
<#Pizza>
[ a owl:Restriction;
owl:onProperty <#hasToppy>;
owl:someValuesFrom <#CheeseToppy>
]
)
]
So the object of the owl:equivalentClass statement on #CheeseyPizza is a
bNode:
[
a owl:Class;
owl:intersectionOf (
<#Pizza>
[ a owl:Restriction;
owl:onProperty <#hasToppy>;
owl:someValuesFrom <#CheeseToppy>
]
)
]
and has no URI.
Dave