RedundantInferences { public static Map<OWLClass, Set<RedundantAxiom>> removeRedundantSubClassAxioms(OWLOntology ontology, OWLReasoner reasoner) { Iterable<OWLClass> classes = ontology.getClassesInSignature(); Map<OWLClass, Set<RedundantAxiom>> axioms = findRedundantSubClassAxioms(classes, ontology, reasoner); if (!axioms.isEmpty()) { Set<OWLSubClassOfAxiom> allAxioms = new THashSet<OWLSubClassOfAxiom>(); for(OWLClass cls : axioms.keySet()) { for(RedundantAxiom redundantAxiom : axioms.get(cls)) { allAxioms.add(redundantAxiom.getAxiom()); } } OWLOntologyManager manager = ontology.getOWLOntologyManager(); manager.removeAxioms(ontology, allAxioms); LOG.info("Removed "+axioms.size()+" redundant axioms."); } return axioms; } private  RedundantInferences(); static Map<OWLClass, Set<RedundantAxiom>> findRedundantSubClassAxioms(Iterable<OWLClass> classes, OWLOntology ontology, OWLReasoner reasoner); static Map<OWLClass, Set<RedundantAxiom>> removeRedundantSubClassAxioms(OWLOntology ontology, OWLReasoner reasoner);  }
@Test public void test() throws Exception { Map<OWLClass, Set<RedundantAxiom>> redundantAxiomMap = RedundantInferences.removeRedundantSubClassAxioms(graph.getSourceOntology(), reasoner); assertNotNull(redundantAxiomMap); assertEquals(1, redundantAxiomMap.size()); OWLClass test1Sub = graph.getOWLClassByIdentifier("FOO:0004"); OWLClass test1Super = graph.getOWLClassByIdentifier("FOO:0002"); Set<RedundantAxiom> redundantAxioms = redundantAxiomMap.get(test1Sub); assertEquals(1, redundantAxioms.size()); RedundantAxiom redundantAxiom = redundantAxioms.iterator().next(); OWLSubClassOfAxiom owlAxiom = redundantAxiom.getAxiom(); assertTrue(AxiomAnnotationTools.isMarkedAsInferredAxiom(owlAxiom)); assertEquals(test1Super, owlAxiom.getSuperClass()); Set<OWLClass> moreSpecific = redundantAxiom.getMoreSpecific(); assertEquals(1, moreSpecific.size()); OWLClass moreSpecificClass = moreSpecific.iterator().next(); assertEquals(graph.getOWLClassByIdentifier("FOO:0003"), moreSpecificClass); }