Is there any way to get all individuals of a specific class using reasoner? Reasoner because i want to get all the inferred and assereted individuals of that class. I am using JFact reasoner, and i am trying for loops and if statement. And i want to find the individuals of class e.g "person". But i am unable to see the individuals. Any idea about below code or is there any method for this purpose?
for (OWLClass c : myPizza.getClassesInSignature()) {
NodeSet<OWLNamedIndividual> instances = reasoner.getInstances(c, true);
System.out.println(c.getIRI().getFragment());
if (c.getIRI().getFragment().equals("Person")){
for (OWLNamedIndividual i : instances.getFlattened()) {
System.out.println(i.getIRI().getFragment());
}
}
else {
continue;
}
break;
}
Thanks
Try out this method. You can get all individuals for a particular class using below method.
Calling
reasoner.getInstances(c, true);
will only give you the /direct/ instances of c; if the individuals you are after are instances of subclasses of c, they will be skipped. Switch toreasoner.getInstances(c, false);
to include instances of subclasses.You are also calling
break;
after the first iteration. Ifperson
is not the first class in the signature, you'll never look for instances ofperson
.You could slightly change your code to do less reasoning work:
Edit: Note from comments, if you expect to see SWRL inferred individuals you need to use a reasoner that supports SWRL, like Pellet or HermiT. JFact does not support SWRL rules.