// relaxngDatatype.jar make sure these jars are on the classpath
OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
// Uncomment the line below reasonerFactory = new
// PelletReasonerFactory(); Load an example ontology - for the purposes
// of the example, we will just load the pizza ontology.
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
OWLOntology ont = loadPizza(man);
// Create the reasoner and classify the ontology
OWLReasoner reasoner = reasonerFactory.createNonBufferingReasoner(ont);
reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
// To generate an inferred ontology we use implementations of inferred
// axiom generators to generate the parts of the ontology we want (e.g.
// subclass axioms, equivalent classes axioms, class assertion axiom
// etc. - see the org.semanticweb.owlapi.util package for more
// implementations). Set up our list of inferred axiom generators
List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
gens.add(new InferredSubClassAxiomGenerator());
// Put the inferred axioms into a fresh empty ontology - note that there
// is nothing stopping us stuffing them back into the original asserted
// ontology if we wanted to do this.
OWLOntology infOnt = man.createOntology();
// Now get the inferred ontology generator to generate some inferred
// axioms for us (into our fresh ontology). We specify the reasoner that
// we want to use and the inferred axiom generators that we want to use.
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner,
gens);
iog.fillOntology(man.getOWLDataFactory(), infOnt);
// Save the inferred ontology. (Replace the URI with one that is
// appropriate for your setup)
man.saveOntology(infOnt, new StringDocumentTarget());
}