Search in sources :

Example 1 with OWLDisjointClassesAxiom

use of org.semanticweb.owlapi.model.OWLDisjointClassesAxiom in project stanbol by apache.

the class HermitReasoningServiceTest method testClassify.

/**
     * We may want to test this method with more then 1 ontology. This is why the implementation is in
     * aprivate method. This method tests if all the logical axioms in testExpectedID ontology are inferences
     * of the testID ontology.
     * 
     * @param testID
     *            // The ID of the ontology to be the input (loaded in the TestData.manager)
     * @param testExpectedID
     *            // The ID of the ontology which contains logical axioms expected in the result
     */
private void testClassify(String testID, String testExpectedID) {
    log.info("Testing the CLASSIFY task");
    OWLOntologyManager manager = TestData.manager;
    // We prepare the input ontology
    try {
        OWLOntology testOntology = manager.createOntology();
        OWLOntologyID testOntologyID = testOntology.getOntologyID();
        log.debug("Created test ontology with ID: {}", testOntologyID);
        manager.applyChange(new AddImport(testOntology, TestData.factory.getOWLImportsDeclaration(IRI.create(testID))));
        // Maybe we want to see what is in before
        if (log.isDebugEnabled())
            TestUtils.debug(manager.getOntology(testOntologyID), log);
        // Now we test the method
        log.debug("Running HermiT");
        Set<OWLAxiom> inferred = this.theinstance.runTask(ReasoningService.Tasks.CLASSIFY, manager.getOntology(testOntologyID));
        // Maybe we want to see the inferred axiom list
        if (log.isDebugEnabled()) {
            TestUtils.debug(inferred, log);
        }
        Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(testExpectedID)).getLogicalAxioms();
        Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
        for (OWLAxiom expected : expectedAxioms) {
            if (!inferred.contains(expected)) {
                log.error("missing expected axiom: {}", expected);
                missing.add(expected);
            }
        }
        assertTrue(missing.isEmpty());
        // We want only Class related axioms in the result set
        for (OWLAxiom a : inferred) {
            assertTrue(a instanceof OWLClassAssertionAxiom || a instanceof OWLSubClassOfAxiom || a instanceof OWLEquivalentClassesAxiom || a instanceof OWLDisjointClassesAxiom);
        }
        // We want to remove the ontology from the manager
        manager.removeOntology(testOntology);
    } catch (OWLOntologyCreationException e) {
        log.error("An {} have been thrown while creating the input ontology for test", e.getClass());
        assertTrue(false);
    } catch (ReasoningServiceException e) {
        log.error("An {} have been thrown while executing the reasoning", e.getClass());
        assertTrue(false);
    } catch (InconsistentInputException e) {
        log.error("An {} have been thrown while executing the reasoning", e.getClass());
        assertTrue(false);
    } catch (UnsupportedTaskException e) {
        log.error("An {} have been thrown while executing the reasoning", e.getClass());
        assertTrue(false);
    }
}
Also used : OWLLogicalAxiom(org.semanticweb.owlapi.model.OWLLogicalAxiom) OWLDisjointClassesAxiom(org.semanticweb.owlapi.model.OWLDisjointClassesAxiom) InconsistentInputException(org.apache.stanbol.reasoners.servicesapi.InconsistentInputException) AddImport(org.semanticweb.owlapi.model.AddImport) UnsupportedTaskException(org.apache.stanbol.reasoners.servicesapi.UnsupportedTaskException) ReasoningServiceException(org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException) OWLSubClassOfAxiom(org.semanticweb.owlapi.model.OWLSubClassOfAxiom) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) OWLEquivalentClassesAxiom(org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 InconsistentInputException (org.apache.stanbol.reasoners.servicesapi.InconsistentInputException)1 ReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException)1 UnsupportedTaskException (org.apache.stanbol.reasoners.servicesapi.UnsupportedTaskException)1 AddImport (org.semanticweb.owlapi.model.AddImport)1 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)1 OWLClassAssertionAxiom (org.semanticweb.owlapi.model.OWLClassAssertionAxiom)1 OWLDisjointClassesAxiom (org.semanticweb.owlapi.model.OWLDisjointClassesAxiom)1 OWLEquivalentClassesAxiom (org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom)1 OWLLogicalAxiom (org.semanticweb.owlapi.model.OWLLogicalAxiom)1 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)1 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)1 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)1 OWLSubClassOfAxiom (org.semanticweb.owlapi.model.OWLSubClassOfAxiom)1