FilterOperation { public static void filter(OWLOntology ontology, Set<OWLObjectProperty> properties) { logger.debug("Filtering ontology for axioms with ObjectProperties " + properties); OWLOntologyManager manager = ontology.getOWLOntologyManager(); Set<OWLAxiom> axioms = ontology.getAxioms(); logger.debug("Ontology has {} axioms before filtering", axioms.size()); for (OWLAxiom axiom : axioms) { Set<OWLObjectProperty> ps = axiom.getObjectPropertiesInSignature(); ps.removeAll(properties); if (ps.size() > 0) { manager.removeAxiom(ontology, axiom); } } logger.debug("Ontology has {} axioms after filtering", ontology.getAxioms().size()); }  static void filter(OWLOntology ontology, Set<OWLObjectProperty> properties);  }
@Test public void testFilterNothing() throws IOException { Set<OWLObjectProperty> properties = new HashSet<>(); OWLOntology filtered = loadOntology("/simple.owl"); FilterOperation.filter(filtered, properties); assertIdentical("/simple.owl", filtered); }
@Test public void testRemoveParts() throws IOException { Set<OWLObjectProperty> properties = new HashSet<>(); OWLOntology filtered = loadOntology("/simple_parts.owl"); FilterOperation.filter(filtered, properties); assertIdentical("/simple.owl", filtered); }
@Test public void testKeepParts() throws IOException { OWLOntology simpleParts = loadOntology("/simple_parts.owl"); OWLOntologyManager manager = simpleParts.getOWLOntologyManager(); OWLDataFactory df = manager.getOWLDataFactory(); Set<OWLObjectProperty> properties = new HashSet<>(); properties.add(df.getOWLObjectProperty(IRI.create(base + "simple.owl#part_of"))); OWLOntology filtered = loadOntology("/simple_parts.owl"); FilterOperation.filter(filtered, properties); assertIdentical("/simple_parts.owl", filtered); }