// objects from a data factory that represent class A and class B
OWLClass clsA = factory.getOWLClass(IRI.create(ontologyIRI + "#A"));
OWLClass clsB = factory.getOWLClass(IRI.create(ontologyIRI + "#B"));
SWRLVariable var = factory.getSWRLVariable(IRI.create(ontologyIRI
+ "#x"));
SWRLRule rule = factory.getSWRLRule(
singleton(factory.getSWRLClassAtom(clsA, var)),
singleton(factory.getSWRLClassAtom(clsB, var)));
manager.applyChange(new AddAxiom(ontology, rule));
OWLObjectProperty prop = factory.getOWLObjectProperty(IRI
.create(ontologyIRI + "#propA"));
OWLObjectProperty propB = factory.getOWLObjectProperty(IRI
.create(ontologyIRI + "#propB"));
SWRLObjectPropertyAtom propAtom = factory.getSWRLObjectPropertyAtom(
prop, var, var);
SWRLObjectPropertyAtom propAtom2 = factory.getSWRLObjectPropertyAtom(
propB, var, var);
Set<SWRLAtom> antecedent = new HashSet<SWRLAtom>();
antecedent.add(propAtom);
antecedent.add(propAtom2);
SWRLRule rule2 = factory.getSWRLRule(antecedent,
Collections.singleton(propAtom));
manager.applyChange(new AddAxiom(ontology, rule2));
// Now save the ontology. The ontology will be saved to the location
// where we loaded it from, in the default ontology format
manager.saveOntology(ontology);