SelfReferenceInDefinition extends AbstractCheck { @Override public Collection<CheckWarning> check(OWLGraphWrapper graph, Collection<OWLObject> allOwlObjects) { OWLOntology ontology = graph.getSourceOntology(); List<CheckWarning> violations = new ArrayList<CheckWarning>(); for(OWLClass cls : ontology.getClassesInSignature()) { Set<OWLEquivalentClassesAxiom> equivalentClassesAxioms = ontology.getEquivalentClassesAxioms(cls); if (equivalentClassesAxioms != null && !equivalentClassesAxioms.isEmpty()) { for (OWLEquivalentClassesAxiom owlEquivalentClassesAxiom : equivalentClassesAxioms) { for (OWLClassExpression ex : owlEquivalentClassesAxiom.getClassExpressions()) { if (ex instanceof OWLClass) continue; Set<OWLClass> classesInSignature = ex.getClassesInSignature(); if (classesInSignature != null && classesInSignature.contains(cls)) { String id = graph.getIdentifier(cls); String message = "Class "+id+" has a self reference in its logical definition: "+owlEquivalentClassesAxiom; CheckWarning warning = new CheckWarning("Self_Reference_In_Definition", message , isFatal(), cls.getIRI()); violations.add(warning); } } } } } if (!violations.isEmpty()) { return violations; } return null; } SelfReferenceInDefinition(); @Override Collection<CheckWarning> check(OWLGraphWrapper graph, Collection<OWLObject> allOwlObjects); static final String SHORT_HAND; }
@Test public void testSelfReferences() 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 SelfReferenceInDefinition(); Collection<CheckWarning> warnings = check.check(graph, graph.getAllOWLObjects()); assertEquals(2, warnings.size()); for (CheckWarning warning : warnings) { boolean found = false; if (warning.getIris().contains(IRI.create("http: warning.getIris().contains(IRI.create("http: found = true; } assertTrue(found); } }