// System.out.println("There are no unsatisfiable classes");
}
// Now we want to query the reasoner for all descendants of vegetarian.
// Vegetarians are defined in the ontology to be animals that don't eat
// animals or parts of animals.
OWLDataFactory fac = manager.getOWLDataFactory();
// Get a reference to the vegetarian class so that we can as the
// reasoner about it. The full IRI of this class happens to be:
// <http://owl.man.ac.uk/2005/07/sssw/people#vegetarian>
OWLClass vegPizza = fac.getOWLClass(IRI
.create("http://owl.man.ac.uk/2005/07/sssw/people#vegetarian"));
// Now use the reasoner to obtain the subclasses of vegetarian. We can
// ask for the direct subclasses of vegetarian or all of the (proper)
// subclasses of vegetarian. In this case we just want the direct ones
// (which we specify by the "true" flag).
NodeSet<OWLClass> subClses = reasoner.getSubClasses(vegPizza, true);
// The reasoner returns a NodeSet, which represents a set of Nodes. Each
// node in the set represents a subclass of vegetarian pizza. A node of
// classes contains classes, where each class in the node is equivalent.
// For example, if we asked for the subclasses of some class A and got
// back a NodeSet containing two nodes {B, C} and {D}, then A would have
// two proper subclasses. One of these subclasses would be equivalent to
// the class D, and the other would be the class that is equivalent to
// class B and class C. In this case, we don't particularly care about
// the equivalences, so we will flatten this set of sets and print the
// result
Set<OWLClass> clses = subClses.getFlattened();
// System.out.println("Subclasses of vegetarian: ");
// for (OWLClass cls : clses) {
// System.out.println(" " + cls);
// }
// In this case, we should find that the classes, cow, sheep and giraffe
// are vegetarian. Note that in this ontology only the class cow had
// been stated to be a subclass of vegetarian. The fact that sheep and
// giraffe are subclasses of vegetarian was implicit in the ontology
// (through other things we had said) and this illustrates why it is
// important to use a reasoner for querying an ontology. We can easily
// retrieve the instances of a class. In this example we'll obtain the
// instances of the class pet. This class has a full IRI of
// <http://owl.man.ac.uk/2005/07/sssw/people#pet> We need to obtain a
// reference to this class so that we can ask the reasoner about it.
OWLClass country = fac.getOWLClass(IRI
.create("http://owl.man.ac.uk/2005/07/sssw/people#pet"));
// Ask the reasoner for the instances of pet
NodeSet<OWLNamedIndividual> individualsNodeSet = reasoner.getInstances(
country, true);
// The reasoner returns a NodeSet again. This time the NodeSet contains
// individuals. Again, we just want the individuals, so get a flattened
// set.
Set<OWLNamedIndividual> individuals = individualsNodeSet.getFlattened();
// System.out.println("Instances of pet: ");
// for (OWLNamedIndividual ind : individuals) {
// System.out.println(" " + ind);
// }
// Again, it's worth noting that not all of the individuals that are
// returned were explicitly stated to be pets. Finally, we can ask for
// the property values (property assertions in OWL speak) for a given
// individual and property. Let's get the property values for the
// individual Mick, the full IRI of which is
// <http://owl.man.ac.uk/2005/07/sssw/people#Mick> Get a reference to
// the individual Mick
OWLNamedIndividual mick = fac.getOWLNamedIndividual(IRI
.create("http://owl.man.ac.uk/2005/07/sssw/people#Mick"));
// Let's get the pets of Mick Get hold of the has_pet property which has
// a full IRI of <http://owl.man.ac.uk/2005/07/sssw/people#has_pet>
OWLObjectProperty hasPet = fac.getOWLObjectProperty(IRI
.create("http://owl.man.ac.uk/2005/07/sssw/people#has_pet"));
// Now ask the reasoner for the has_pet property values for Mick
NodeSet<OWLNamedIndividual> petValuesNodeSet = reasoner
.getObjectPropertyValues(mick, hasPet);
Set<OWLNamedIndividual> values = petValuesNodeSet.getFlattened();