ReasonerHelper { public static void validate(OWLReasoner reasoner) throws IncoherentTBoxException, InconsistentOntologyException, IncoherentRBoxException { validate(reasoner, null, null); }  static void validate(OWLReasoner reasoner); static void validate(OWLReasoner reasoner, String unsatisfiableModulePath); static void validate(
      OWLReasoner reasoner, String unsatisfiableModulePath, IOHelper ioHelper); static OWLOntology createIncoherentModule(OWLReasoner reasoner, IRI outputIRI); static List<InferredAxiomGenerator<? extends OWLAxiom>> getInferredAxiomGenerators(
      List<String> axGenerators, boolean direct); static List<InferredAxiomGenerator<? extends OWLAxiom>> getInferredAxiomGenerators(
      List<String> axGenerators); static InferredAxiomGenerator<? extends OWLAxiom> getInferredAxiomGenerator(
      String axGenerator); static InferredAxiomGenerator<? extends OWLAxiom> getInferredAxiomGenerator(
      String axGenerator, boolean direct);  }
@Test public void testIncoherentRBox() throws IOException, IncoherentTBoxException, InconsistentOntologyException { OWLOntology ontology = loadOntology("/incoherent-rbox.owl"); OWLReasonerFactory reasonerFactory = new org.semanticweb.elk.owlapi.ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ontology); boolean isCaughtException = false; try { ReasonerHelper.validate(reasoner); } catch (IncoherentRBoxException e) { isCaughtException = true; } assertTrue(isCaughtException); }
@Test public void testIncoherentTBox() throws IOException, InconsistentOntologyException, IncoherentRBoxException { OWLOntology ontology = loadOntology("/incoherent-tbox.owl"); OWLReasonerFactory reasonerFactory = new org.semanticweb.elk.owlapi.ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ontology); boolean isCaughtException = false; try { ReasonerHelper.validate(reasoner); } catch (IncoherentTBoxException e) { isCaughtException = true; } assertTrue(isCaughtException); }
@Test public void testCreateUnsatisfiableModule() throws Exception { OWLOntology ontologyMain = loadOntology("/incoherent-tbox.owl"); IRI iri = ontologyMain.getOntologyID().getOntologyIRI().orNull(); if (iri == null) { throw new Exception("Ontology 'incoherent-tbox.owl' does not have an IRI"); } OWLOntology ontology = ontologyMain.getOWLOntologyManager().createOntology(); OWLDataFactory factory = ontology.getOWLOntologyManager().getOWLDataFactory(); AddImport ai = new AddImport(ontology, factory.getOWLImportsDeclaration(iri)); ontology.getOWLOntologyManager().applyChange(ai); OWLReasonerFactory reasonerFactory = new org.semanticweb.elk.owlapi.ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ontology); boolean isCaughtException = false; IOHelper ioHelper = new IOHelper(); String PATH = "target/unsat.owl"; try { ReasonerHelper.validate(reasoner, PATH, ioHelper); } catch (IncoherentTBoxException e) { isCaughtException = true; IOHelper ioh = new IOHelper(); OWLOntology unsatisfiableOntology = ioh.loadOntology(PATH); Set<OWLSubClassOfAxiom> scas = unsatisfiableOntology.getAxioms(AxiomType.SUBCLASS_OF); for (OWLSubClassOfAxiom sca : scas) { assertEquals(1, sca.getAnnotations().size()); OWLAnnotation ann = sca.getAnnotations().iterator().next(); assertEquals(factory.getRDFSIsDefinedBy(), ann.getProperty()); OWLLiteral v = ann.getValue().asLiteral().orNull(); if (v == null) { throw new Exception(String.format("OWLAnnotation '%s' has no value.", ann.toString())); } String val = v.getLiteral(); String originalOntIdVal = ontologyMain.getOntologyID().toString(); assertEquals(originalOntIdVal, val); } assertEquals(2, scas.size()); } assertTrue(isCaughtException); }
@Test public void testInconsistentOntology() throws IOException, IncoherentTBoxException, IncoherentRBoxException { OWLOntology ontology = loadOntology("/inconsistent.owl"); OWLReasonerFactory reasonerFactory = new org.semanticweb.elk.owlapi.ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ontology); boolean isCaughtException = false; try { ReasonerHelper.validate(reasoner); } catch (InconsistentOntologyException e) { isCaughtException = true; } assertTrue(isCaughtException); }
@Test public void testNoFalsePositives() throws IOException, IncoherentTBoxException, InconsistentOntologyException, IncoherentRBoxException { OWLOntology ontology = loadOntology("/simple.owl"); OWLReasonerFactory reasonerFactory = new org.semanticweb.elk.owlapi.ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ontology); ReasonerHelper.validate(reasoner); assertTrue(true); }