Using the pizza ontology, I want to be able to look up all the toppings for American
pizza.
If I open the ontology in Protégé, I can see that American
pizza has the following restrictions:
hasTopping some MozerellaTopping
hasTopping some TomatoTopping
How can I get the same information programatically through Jena?
Here's my solution. I've just printed out the strings you ask for, but hopefully you can see from this how to use the Jena OntAPI to traverse an ontology graph and pick out the things you're interested in.
Which produces the following output:
Now (with Apache-jena 3.x.x) there is one possible problem with org.apache.jena.ontology.OntModel and pizza.owl in that Jena-Ont-API supports OWL-1 only, while pizza is OWL-2 ontology. Though, for the example above it doesn't matter ('Existential Quantification' restrictions looks identically both for OWL1 and OWL2), in general case you can't use OntModel for processing ontology just as easily. As an option there is an OntModel-alternative called ru.avicomp.ontapi.jena.model.OntGraphModel from ont-api. It is based on the same principles as jena OntModel. Maybe it would be helpful for someone.
An example of usage (getting only object-some-values-from restrictions):
Out: