CycleCheck extends AbstractCheck { @Override public Collection<CheckWarning> check(OWLGraphWrapper graph, Collection<OWLObject> allOwlObjects) { Collection<CheckWarning> out = new ArrayList<CheckWarning>(); Tarjan<OWLClass> tarjan = new MappingTarjan<OWLClass>(true); List<List<OWLClass>> scc = tarjan.executeTarjan(new OWLClassAdjacency(graph, allOwlObjects)); for (List<OWLClass> component : scc) { StringBuilder sb = new StringBuilder("Cycle detected with the following classes: "); List<IRI> iris = new ArrayList<IRI>(component.size()); for (OWLClass owlClass : component) { if (!iris.isEmpty()) { sb.append(", "); } final IRI iri = owlClass.getIRI(); iris.add(iri); sb.append(graph.getIdentifier(iri)); final String label = graph.getLabel(owlClass); if (label != null) { sb.append(" ("); sb.append(label); sb.append(")"); } } CheckWarning warning = new CheckWarning(getID(), sb.toString(), isFatal(), iris, null); out.add(warning); } return out; } CycleCheck(); @Override Collection<CheckWarning> check(OWLGraphWrapper graph, Collection<OWLObject> allOwlObjects); static final String SHORT_HAND; }
@Test public void testNonCycle3() throws Exception { ParserWrapper parser = new ParserWrapper(); IRI iri = IRI.create(getResource("verification/self_references.obo").getAbsoluteFile()) ; OWLGraphWrapper graph = parser.parseToOWLGraph(iri.toString()); OntologyCheck check = new CycleCheck(); Collection<CheckWarning> warnings = check.check(graph, graph.getAllOWLObjects()); assertTrue(warnings.isEmpty()); }
@Test public void testCycle1() throws Exception { ParserWrapper parser = new ParserWrapper(); IRI iri = IRI.create(getResource("verification/cycle.obo").getAbsoluteFile()) ; OWLGraphWrapper graph = parser.parseToOWLGraph(iri.toString()); OntologyCheck check = new CycleCheck(); Collection<CheckWarning> warnings = check.check(graph, graph.getAllOWLObjects()); assertEquals(1, warnings.size()); CheckWarning warning = warnings.iterator().next(); List<IRI> iris = warning.getIris(); assertEquals(3, iris.size()); }
@Test public void testNonCycle1() throws Exception { ParserWrapper parser = new ParserWrapper(); IRI iri = IRI.create(getResource("verification/dangling_references.obo").getAbsoluteFile()) ; OWLGraphWrapper graph = parser.parseToOWLGraph(iri.toString()); OntologyCheck check = new CycleCheck(); Collection<CheckWarning> warnings = check.check(graph, graph.getAllOWLObjects()); assertTrue(warnings.isEmpty()); }
@Test public void testNonCycle2() throws Exception { ParserWrapper parser = new ParserWrapper(); IRI iri = IRI.create(getResource("verification/name_redundancy.obo").getAbsoluteFile()) ; OWLGraphWrapper graph = parser.parseToOWLGraph(iri.toString()); OntologyCheck check = new CycleCheck(); Collection<CheckWarning> warnings = check.check(graph, graph.getAllOWLObjects()); assertTrue(warnings.isEmpty()); }