OWLGraphManipulator { public OWLGraphWrapper getOwlGraphWrapper() { return this.owlGraphWrapper; } @SuppressWarnings("unused") private  OWLGraphManipulator();  OWLGraphManipulator(OWLOntology ont);  OWLGraphManipulator(OWLGraphWrapper owlGraphWrapper);  OWLGraphManipulator(OWLGraphWrapper owlGraphWrapper, boolean performDefaultModifs); void makeSimpleOntology(); void simplifies(Collection<String> classIdsToRemove, Collection<String> relIds, 
            Collection<String> toRemoveSubgraphRootIds,
            Collection<String> toFilterSubgraphRootIds,   
            Collection<String> subsetNames); int reduceRelations(); int reducePartOfIsARelations(); int removeClassAndPropagateEdges(String classToRemoveId); int mapRelationsToParent(Collection<String> parentRelations); int mapRelationsToParent(Collection<String> parentRelations, 
    		Collection<String> relsExcluded); Set<String> filterSubgraphs(Collection<String> allowedSubgraphRootIds); Set<String> removeSubgraphs(Collection<String> subgraphRootIds, 
            boolean keepSharedClasses); Set<String> removeSubgraphs(Collection<String> subgraphRootIds, 
            boolean keepSharedClasses, Collection<String> allowedSubgraphRootIds); int filterRelations(Collection<String> allowedRels, boolean allowSubRels); void removeUnrelatedRelations(Collection<String> allowedRels); int removeRelations(Collection<String> forbiddenRels, boolean forbidSubRels); int removeRelsToSubsets(Collection<String> subsets); int removeRelsToSubsets(Collection<String> subsets, 
	        Collection<String> classIdsExcluded); int removeDirectEdgesBetween(String sourceId, String targetId); boolean removeEdge(OWLGraphEdge edge); int removeEdges(Collection<OWLGraphEdge> edges); boolean addEdge(OWLGraphEdge edge); int addEdges(Set<OWLGraphEdge> edges); boolean removeClass(OWLClass classToDel); Set<OWLClass> removeClasses(Set<OWLClass> classesToDel); Set<OWLClass> filterClasses(Set<OWLClass> classesToKeep); boolean isASubClassOfEdge(OWLGraphEdge edge); boolean isAPartOfEdge(OWLGraphEdge edge); OWLGraphWrapper getOwlGraphWrapper();  }
@Test public void shouldTestDefaultOperations() throws OWLOntologyCreationException, OBOFormatParserException, IOException { log.debug("Loading ontology for testing default operations at instantiation..."); ParserWrapper parserWrapper = new ParserWrapper(); OWLOntology ont = parserWrapper.parse( this.getClass().getResource("/graph/manipulatorInstantiationTest.obo").getFile()); log.debug("Done loading the ontology."); log.debug("Loading the ontology into OWLGraphManipulator, testing default operations..."); this.graphManipulator = new OWLGraphManipulator(new OWLGraphWrapper(ont)); log.debug("Default operations done."); assertEquals("OWLEquivalentClassesAxioms not removed", 0, ont.getAxiomCount(AxiomType.EQUIVALENT_CLASSES)); for (OWLSubClassOfAxiom ax: ont.getAxioms(AxiomType.SUBCLASS_OF)) { for (OWLClassExpression ce: ax.getNestedClassExpressions()) { if (ce instanceof OWLObjectIntersectionOf || ce instanceof OWLObjectUnionOf) { throw new AssertionError("An OWLObjectIntersectionOf or " + "OWLObjectUnionOf was not removed: " + ax); } } } OWLDataFactory factory = ont.getOWLOntologyManager().getOWLDataFactory(); OWLGraphWrapper wrapper = this.graphManipulator.getOwlGraphWrapper(); OWLClass root = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0001"); OWLClass clsA = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0002"); OWLClass clsB = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0003"); OWLClass clsC = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0004"); OWLClass clsD = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0005"); OWLClass clsE = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0006"); OWLClass clsF = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0007"); OWLClass clsG = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0008"); OWLClass clsH = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0009"); OWLClass clsI = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0010"); OWLClass clsJ = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0011"); OWLClass clsImport = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0015"); OWLObjectProperty partOf = this.graphManipulator.getOwlGraphWrapper(). getOWLObjectPropertyByIdentifier("BFO:0000050"); Set<OWLAxiom> expectedAxioms = new HashSet<OWLAxiom>(); expectedAxioms.add(factory.getOWLSubClassOfAxiom(clsImport, clsC)); expectedAxioms.add(factory.getOWLSubClassOfAxiom(clsImport, factory.getOWLObjectSomeValuesFrom(partOf, root))); assertEquals("Axioms from import ontology incorrectly merged", expectedAxioms, ont.getAxioms(clsImport, Imports.EXCLUDED)); expectedAxioms = new HashSet<OWLAxiom>(); expectedAxioms.add(factory.getOWLSubClassOfAxiom(clsB, root)); expectedAxioms.add(factory.getOWLSubClassOfAxiom(clsB, factory.getOWLObjectSomeValuesFrom(partOf, clsA))); assertEquals("Incorrect axioms generated", expectedAxioms, ont.getAxioms(clsB, Imports.EXCLUDED)); expectedAxioms = new HashSet<OWLAxiom>(); expectedAxioms.add(factory.getOWLSubClassOfAxiom(clsC, factory.getOWLObjectSomeValuesFrom(partOf, clsA))); expectedAxioms.add(factory.getOWLSubClassOfAxiom(clsC, factory.getOWLObjectSomeValuesFrom(partOf, root))); assertEquals("Incorrect axioms generated", expectedAxioms, ont.getAxioms(clsC, Imports.EXCLUDED)); expectedAxioms = new HashSet<OWLAxiom>(); expectedAxioms.add(factory.getOWLSubClassOfAxiom(clsE, clsD)); assertEquals("Incorrect axioms generated", expectedAxioms, ont.getAxioms(clsE, Imports.EXCLUDED)); expectedAxioms = new HashSet<OWLAxiom>(); expectedAxioms.add(factory.getOWLSubClassOfAxiom(clsF, clsD)); assertEquals("Incorrect axioms generated", expectedAxioms, ont.getAxioms(clsF, Imports.EXCLUDED)); expectedAxioms = new HashSet<OWLAxiom>(); expectedAxioms.add(factory.getOWLSubClassOfAxiom(clsH, clsG)); assertEquals("Incorrect axioms generated", expectedAxioms, ont.getAxioms(clsH, Imports.EXCLUDED)); expectedAxioms = new HashSet<OWLAxiom>(); expectedAxioms.add(factory.getOWLSubClassOfAxiom(clsI, clsG)); assertEquals("Incorrect axioms generated", expectedAxioms, ont.getAxioms(clsI, Imports.EXCLUDED)); assertEquals("Incorrect axioms generated: " + ont.getAxioms(clsJ, Imports.EXCLUDED), 0, ont.getAxioms(clsJ, Imports.EXCLUDED).size()); assertEquals("Incorrect axioms generated: " + ont.getAxioms(clsG, Imports.EXCLUDED), 0, ont.getAxioms(clsG, Imports.EXCLUDED).size()); assertNotNull("Obsolete class incorrectly removed", wrapper.getOWLClassByIdentifier("FOO:0012")); assertNotNull("Obsolete class incorrectly removed", wrapper.getOWLClassByIdentifier("FOO:0013")); assertTrue("Outgoing edge of obsolete class not removed", wrapper.getOutgoingEdges( wrapper.getOWLClassByIdentifier("FOO:0012")).isEmpty()); assertTrue("Incoming edge of obsolete class not removed", wrapper.getIncomingEdges( wrapper.getOWLClassByIdentifier("FOO:0012")).isEmpty()); }
@Test public void regressionTestAxiomRelaxation() throws OWLOntologyCreationException, OBOFormatParserException, IOException { log.debug("Loading ontology for testing axiom relaxation at instantiation..."); ParserWrapper parserWrapper = new ParserWrapper(); OWLOntology ont = parserWrapper.parse( this.getClass().getResource("/graph/relaxAxiomsTest.owl").getFile()); log.debug("Done loading the ontology."); log.debug("Loading the ontology into OWLGraphManipulator, testing default operations..."); this.graphManipulator = new OWLGraphManipulator(new OWLGraphWrapper(ont)); log.debug("Default operations done."); assertEquals("Some EquivalentClassesAxioms were not removed", 0, ont.getAxiomCount(AxiomType.EQUIVALENT_CLASSES)); for (OWLSubClassOfAxiom ax: ont.getAxioms(AxiomType.SUBCLASS_OF)) { for (OWLClassExpression ce: ax.getNestedClassExpressions()) { if (ce instanceof OWLObjectIntersectionOf || ce instanceof OWLObjectUnionOf) { throw new AssertionError("An OWLObjectIntersectionOf or " + "OWLObjectUnionOf was not removed: " + ax); } } } OWLDataFactory factory = ont.getOWLOntologyManager().getOWLDataFactory(); OWLObjectProperty partOf = this.graphManipulator.getOwlGraphWrapper(). getOWLObjectPropertyByIdentifier("BFO:0000050"); OWLGraphWrapper wrapper = this.graphManipulator.getOwlGraphWrapper(); Set<OWLAxiom> expectedAxioms = new HashSet<OWLAxiom>(); expectedAxioms.add(factory.getOWLSubClassOfAxiom( wrapper.getOWLClass("http: factory.getOWLObjectSomeValuesFrom(partOf, wrapper.getOWLClass("http: expectedAxioms.add(factory.getOWLSubClassOfAxiom( wrapper.getOWLClass("http: factory.getOWLObjectSomeValuesFrom(partOf, wrapper.getOWLClass("http: expectedAxioms.add(factory.getOWLSubClassOfAxiom( wrapper.getOWLClass("http: wrapper.getOWLClass("http: expectedAxioms.add(factory.getOWLSubClassOfAxiom( wrapper.getOWLClass("http: wrapper.getOWLClass("http: assertEquals("Axioms from import ontology incorrectly merged", expectedAxioms, ont.getAxioms(wrapper.getOWLClass("http: }
@Test @Ignore("Disabling test due to lack of resources to debug") public void shouldGetOWLGraphEdgeSubRelsReflexive() { OWLOntology ont = this.graphManipulator.getOwlGraphWrapper().getSourceOntology(); OWLClass source = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0003"); OWLClass target = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0001"); OWLObjectProperty fakeRel1 = this.graphManipulator.getOwlGraphWrapper(). getOWLObjectPropertyByIdentifier("fake_rel1"); OWLGraphEdge testEdge = new OWLGraphEdge(source, target, fakeRel1, Quantifier.SOME, ont); int subRelRank = 0; for (OWLGraphEdge subRel: this.graphManipulator.getOwlGraphWrapper(). getOWLGraphEdgeSubRelsReflexive(testEdge)) { if (subRelRank == 0) { assertEquals("Incorrect order of sub-properties, 1st relation", "fake_rel1", this.graphManipulator.getOwlGraphWrapper().getIdentifier( subRel.getSingleQuantifiedProperty().getProperty())); } else if (subRelRank == 1) { assertEquals("Incorrect order of sub-properties, 2nd relation", "fake_rel2", this.graphManipulator.getOwlGraphWrapper().getIdentifier( subRel.getSingleQuantifiedProperty().getProperty())); } else if (subRelRank == 2 || subRelRank == 3) { assertTrue("Incorrect order of sub-properties, 3rd or 4th relation", ("fake_rel3".equals(this.graphManipulator.getOwlGraphWrapper().getIdentifier( subRel.getSingleQuantifiedProperty().getProperty())) || "fake_rel4".equals(this.graphManipulator.getOwlGraphWrapper().getIdentifier( subRel.getSingleQuantifiedProperty().getProperty())))); } else { throw new AssertionError("Incorrect number of sub-relations"); } subRelRank++; } assertEquals("Incorrect number of sub-relations", 4, subRelRank); }
@Test public void testOWLGraphEdgeHashCode() { OWLOntology ont = this.graphManipulator.getOwlGraphWrapper().getSourceOntology(); OWLObjectProperty partOf = this.graphManipulator.getOwlGraphWrapper(). getOWLObjectPropertyByIdentifier("BFO:0000050"); OWLClass source = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0003"); OWLClass target = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0001"); OWLGraphEdge edge1 = new OWLGraphEdge(source, target, partOf, Quantifier.SOME, ont); OWLGraphEdge edge2 = new OWLGraphEdge(source, target, partOf, Quantifier.SOME, ont); assertTrue("Two OWLGraphEdges are equal but have different hashcodes.", edge1.equals(edge2) && edge1.hashCode() == edge2.hashCode()); }
@Test public void testOWLOntologyChangeHashCode() { OWLOntology ont = this.graphManipulator.getOwlGraphWrapper().getSourceOntology(); OWLDataFactory factory = this.graphManipulator.getOwlGraphWrapper(). getManager().getOWLDataFactory(); OWLClass source = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0005"); OWLClass target = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0001"); OWLGraphEdge checkEdge = new OWLGraphEdge(source, target, ont); OWLAxiom axiom = factory.getOWLSubClassOfAxiom(source, (OWLClassExpression) this.graphManipulator.getOwlGraphWrapper(). edgeToTargetExpression(checkEdge)); OWLAxiomChange rm1 = new RemoveAxiom(ont, axiom); OWLGraphEdge checkEdge2 = new OWLGraphEdge(source, target, ont); OWLAxiom axiom2 = factory.getOWLSubClassOfAxiom(source, (OWLClassExpression) this.graphManipulator.getOwlGraphWrapper(). edgeToTargetExpression(checkEdge2)); OWLAxiomChange rm2 = new RemoveAxiom(ont, axiom2); assertTrue("The two OWLAxiomChange objects are equal", rm1.equals(rm2)); assertTrue("Two OWLAxiomChange are equal but have different hashcode", rm1.equals(rm2) && rm1.hashCode() == rm2.hashCode()); source = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0014"); target = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0001"); checkEdge = new OWLGraphEdge(source, target, ont); axiom = factory.getOWLSubClassOfAxiom(source, (OWLClassExpression) this.graphManipulator.getOwlGraphWrapper(). edgeToTargetExpression(checkEdge)); OWLAxiomChange rm3 = new RemoveAxiom(ont, axiom); assertFalse("Different OWLAxiomChange objects are equal", rm1.equals(rm3)); assertFalse("Different OWLAxiomChanges have same hashcode", rm1.hashCode() == rm3.hashCode()); }
@Test public void testOWLQuantifiedPropertyHashCode() { OWLObjectProperty prop1 = this.graphManipulator.getOwlGraphWrapper(). getOWLObjectPropertyByIdentifier("BFO:0000050"); OWLObjectProperty prop2 = this.graphManipulator.getOwlGraphWrapper(). getOWLObjectPropertyByIdentifier("BFO:0000050"); assertTrue("Two OWLQuantifiedProperty are equal but have different hashcodes.", prop1.equals(prop2) && prop1.hashCode() == prop2.hashCode()); OWLObjectProperty prop3 = this.graphManipulator.getOwlGraphWrapper(). getOWLObjectPropertyByIdentifier("RO:0002202"); assertFalse("Two different OWLQuantifiedProperty are equal", prop1.equals(prop3)); assertFalse("Two different OWLQuantifiedProperty have same hashcode", prop1.hashCode() == prop3.hashCode()); }