@Test public void redundantAxioms_areRemoved() throws Exception { OWLClass e = dataFactory.getOWLClass(IRI.create("http: OWLClass c = dataFactory.getOWLClass(IRI.create("http: OWLClassAxiom originalSubclass = dataFactory.getOWLSubClassOfAxiom(e, c); assertThat(ont.containsAxiom(originalSubclass), is(true)); util.removeRedundantAxioms(); assertThat(ont.containsAxiom(originalSubclass), is(false)); }
void removeRedundantAxioms() { final List<RemoveAxiom> changes = new ArrayList<RemoveAxiom>(); Set<OWLClass> allClasses = ont.getClassesInSignature(true); logger.info("Check classes for redundant super class axioms, all OWL classes count: " + allClasses.size()); for (OWLClass cls: allClasses) { final Set<OWLClass> directSuperClasses = reasoner.getSuperClasses(cls, true).getFlattened(); for (final OWLOntology importedOntology: ont.getImportsClosure()) { Set<OWLSubClassOfAxiom> subClassAxioms = importedOntology.getSubClassAxiomsForSubClass(cls); for (final OWLSubClassOfAxiom subClassAxiom : subClassAxioms) { subClassAxiom.getSuperClass().accept(new OWLClassExpressionVisitorAdapter(){ @Override public void visit(OWLClass desc) { if (directSuperClasses.contains(desc) == false) { changes.add(new RemoveAxiom(importedOntology, subClassAxiom)); } } }); } } } logger.info("Found redundant axioms: " + changes.size()); List<OWLOntologyChange> result = manager.applyChanges(changes); logger.info("Removed axioms: " + result.size()); }
ReasonerUtil { void removeRedundantAxioms() { final List<RemoveAxiom> changes = new ArrayList<RemoveAxiom>(); Set<OWLClass> allClasses = ont.getClassesInSignature(true); logger.info("Check classes for redundant super class axioms, all OWL classes count: " + allClasses.size()); for (OWLClass cls: allClasses) { final Set<OWLClass> directSuperClasses = reasoner.getSuperClasses(cls, true).getFlattened(); for (final OWLOntology importedOntology: ont.getImportsClosure()) { Set<OWLSubClassOfAxiom> subClassAxioms = importedOntology.getSubClassAxiomsForSubClass(cls); for (final OWLSubClassOfAxiom subClassAxiom : subClassAxioms) { subClassAxiom.getSuperClass().accept(new OWLClassExpressionVisitorAdapter(){ @Override public void visit(OWLClass desc) { if (directSuperClasses.contains(desc) == false) { changes.add(new RemoveAxiom(importedOntology, subClassAxiom)); } } }); } } } logger.info("Found redundant axioms: " + changes.size()); List<OWLOntologyChange> result = manager.applyChanges(changes); logger.info("Removed axioms: " + result.size()); } }
ReasonerUtil { void removeRedundantAxioms() { final List<RemoveAxiom> changes = new ArrayList<RemoveAxiom>(); Set<OWLClass> allClasses = ont.getClassesInSignature(true); logger.info("Check classes for redundant super class axioms, all OWL classes count: " + allClasses.size()); for (OWLClass cls: allClasses) { final Set<OWLClass> directSuperClasses = reasoner.getSuperClasses(cls, true).getFlattened(); for (final OWLOntology importedOntology: ont.getImportsClosure()) { Set<OWLSubClassOfAxiom> subClassAxioms = importedOntology.getSubClassAxiomsForSubClass(cls); for (final OWLSubClassOfAxiom subClassAxiom : subClassAxioms) { subClassAxiom.getSuperClass().accept(new OWLClassExpressionVisitorAdapter(){ @Override public void visit(OWLClass desc) { if (directSuperClasses.contains(desc) == false) { changes.add(new RemoveAxiom(importedOntology, subClassAxiom)); } } }); } } } logger.info("Found redundant axioms: " + changes.size()); List<OWLOntologyChange> result = manager.applyChanges(changes); logger.info("Removed axioms: " + result.size()); } @Inject  ReasonerUtil(ReasonerConfiguration reasonerConfig, OWLOntologyManager manager, OWLOntology ont); }
ReasonerUtil { void removeRedundantAxioms() { final List<RemoveAxiom> changes = new ArrayList<RemoveAxiom>(); Set<OWLClass> allClasses = ont.getClassesInSignature(true); logger.info("Check classes for redundant super class axioms, all OWL classes count: " + allClasses.size()); for (OWLClass cls: allClasses) { final Set<OWLClass> directSuperClasses = reasoner.getSuperClasses(cls, true).getFlattened(); for (final OWLOntology importedOntology: ont.getImportsClosure()) { Set<OWLSubClassOfAxiom> subClassAxioms = importedOntology.getSubClassAxiomsForSubClass(cls); for (final OWLSubClassOfAxiom subClassAxiom : subClassAxioms) { subClassAxiom.getSuperClass().accept(new OWLClassExpressionVisitorAdapter(){ @Override public void visit(OWLClass desc) { if (directSuperClasses.contains(desc) == false) { changes.add(new RemoveAxiom(importedOntology, subClassAxiom)); } } }); } } } logger.info("Found redundant axioms: " + changes.size()); List<OWLOntologyChange> result = manager.applyChanges(changes); logger.info("Removed axioms: " + result.size()); } @Inject  ReasonerUtil(ReasonerConfiguration reasonerConfig, OWLOntologyManager manager, OWLOntology ont); boolean reason(); }
ReasonerUtil { void removeRedundantAxioms() { final List<RemoveAxiom> changes = new ArrayList<RemoveAxiom>(); Set<OWLClass> allClasses = ont.getClassesInSignature(true); logger.info("Check classes for redundant super class axioms, all OWL classes count: " + allClasses.size()); for (OWLClass cls: allClasses) { final Set<OWLClass> directSuperClasses = reasoner.getSuperClasses(cls, true).getFlattened(); for (final OWLOntology importedOntology: ont.getImportsClosure()) { Set<OWLSubClassOfAxiom> subClassAxioms = importedOntology.getSubClassAxiomsForSubClass(cls); for (final OWLSubClassOfAxiom subClassAxiom : subClassAxioms) { subClassAxiom.getSuperClass().accept(new OWLClassExpressionVisitorAdapter(){ @Override public void visit(OWLClass desc) { if (directSuperClasses.contains(desc) == false) { changes.add(new RemoveAxiom(importedOntology, subClassAxiom)); } } }); } } } logger.info("Found redundant axioms: " + changes.size()); List<OWLOntologyChange> result = manager.applyChanges(changes); logger.info("Removed axioms: " + result.size()); } @Inject  ReasonerUtil(ReasonerConfiguration reasonerConfig, OWLOntologyManager manager, OWLOntology ont); boolean reason();  }