// ontology from the web:
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
OWLOntology ont = loadPizza(man);
// Create the walker. Pass in the pizza ontology - we need to put it
// into a set though, so we just create a singleton set in this case.
OWLOntologyWalker walker = new OWLOntologyWalker(singleton(ont));
// Now ask our walker to walk over the ontology. We specify a visitor
// who gets visited by the various objects as the walker encounters
// them. We need to create out visitor. This can be any ordinary
// visitor, but we will extend the OWLOntologyWalkerVisitor because it
// provides a convenience method to get the current axiom being visited
// as we go. Create an instance and override the
// visit(OWLObjectSomeValuesFrom) method, because we are interested in
// some values from restrictions.
OWLOntologyWalkerVisitorEx<Object> visitor = new OWLOntologyWalkerVisitorEx<Object>(
walker) {
@Override
public Object visit(OWLObjectSomeValuesFrom ce) {
// Print out the restriction
// System.out.println(desc);
// Print out the axiom where the restriction is used
// System.out.println(" " + getCurrentAxiom());
// We don't need to return anything here.
return "";
}
};
// Now ask the walker to walk over the ontology structure using our
// visitor instance.
walker.walkStructure(visitor);
}