Search in sources :

Example 1 with OWLLogicalAxiom

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

the class HermitReasoningServiceTest method testRun.

private void testRun(String testID, String expectedID) {
    log.info("Testing the run() method");
    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);
        AddImport addImport = new AddImport(testOntology, TestData.factory.getOWLImportsDeclaration(IRI.create(testID)));
        manager.applyChange(addImport);
        // We just test class assertions
        List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
        gens.add(new InferredClassAssertionAxiomGenerator());
        // 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.run(manager.getOntology(testOntologyID), gens);
        // Maybe we want to see the inferred axiom list
        if (log.isDebugEnabled()) {
            TestUtils.debug(inferred, log);
        }
        // These are the set of expected axioms
        Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(expectedID)).getLogicalAxioms();
        Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
        for (OWLAxiom expected : expectedAxioms) {
            if (!inferred.contains(expected)) {
                log.error("missing expected axiom: {}", expected);
                missing.add(expected);
            }
        }
        log.info("Are all expected axioms in the result (true)? {}", missing.isEmpty());
        assertTrue(missing.isEmpty());
        // 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 (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException e) {
        log.error("An {} have been thrown while executing the reasoning", e.getClass());
        assertTrue(false);
    } catch (org.apache.stanbol.reasoners.servicesapi.InconsistentInputException e) {
        log.error("An {} have been thrown while executing the reasoning", e.getClass());
        assertTrue(false);
    }
}
Also used : OWLLogicalAxiom(org.semanticweb.owlapi.model.OWLLogicalAxiom) InferredAxiomGenerator(org.semanticweb.owlapi.util.InferredAxiomGenerator) ArrayList(java.util.ArrayList) AddImport(org.semanticweb.owlapi.model.AddImport) ReasoningServiceException(org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) InconsistentInputException(org.apache.stanbol.reasoners.servicesapi.InconsistentInputException) InferredClassAssertionAxiomGenerator(org.semanticweb.owlapi.util.InferredClassAssertionAxiomGenerator) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) HashSet(java.util.HashSet)

Example 2 with OWLLogicalAxiom

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

the class HermitReasoningServiceTest method testClassifyWithRules.

private void testClassifyWithRules(String testID, String rulesID, String testExpectedID) {
    log.info("Testing the task CLASSIFY with rules");
    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);
        OWLImportsDeclaration importTest = TestData.factory.getOWLImportsDeclaration(IRI.create(testID));
        manager.applyChange(new AddImport(testOntology, importTest));
        Set<SWRLRule> rules = manager.getOntology(IRI.create(rulesID)).getAxioms(AxiomType.SWRL_RULE);
        // Maybe we want to see the list of rules
        if (log.isDebugEnabled()) {
            log.debug("List of {} rules: ", rules.size());
            TestUtils.debug(rules, log);
        }
        log.debug("We add the rules to the ontology");
        manager.addAxioms(manager.getOntology(testOntologyID), rules);
        // Maybe we want to see what is in before
        if (log.isDebugEnabled())
            log.debug("Content of the input is:");
        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()) {
            log.debug("{} inferred axioms:", inferred.size());
            TestUtils.debug(inferred, log);
        }
        Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(testExpectedID)).getLogicalAxioms();
        Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
        for (OWLAxiom expected : expectedAxioms) {
            // We consider here only two kind of axioms
            if (expected instanceof OWLSubClassOfAxiom || expected instanceof OWLClassAssertionAxiom) {
                if (!inferred.contains(expected)) {
                    log.error("missing expected axiom: {}", expected);
                    missing.add(expected);
                }
            }
        }
        assertTrue(missing.isEmpty());
        // 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) OWLImportsDeclaration(org.semanticweb.owlapi.model.OWLImportsDeclaration) 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) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) HashSet(java.util.HashSet)

Example 3 with OWLLogicalAxiom

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

the class HermitReasoningServiceTest method testEnrichWithRules.

private void testEnrichWithRules(String testID, String rulesID, String testExpectedID) {
    log.info("Testing the task ENRICH with rules");
    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);
        OWLImportsDeclaration importTest = TestData.factory.getOWLImportsDeclaration(IRI.create(testID));
        manager.applyChange(new AddImport(testOntology, importTest));
        Set<SWRLRule> rules = manager.getOntology(IRI.create(rulesID)).getAxioms(AxiomType.SWRL_RULE);
        // Maybe we want to see the list of rules
        if (log.isDebugEnabled()) {
            log.debug("List of {} rules: ", rules.size());
            TestUtils.debug(rules, log);
        }
        log.debug("We add the rules to the ontology");
        manager.addAxioms(manager.getOntology(testOntologyID), rules);
        // Maybe we want to see what is in before
        if (log.isDebugEnabled())
            log.debug("Content of the input is:");
        TestUtils.debug(manager.getOntology(testOntologyID), log);
        // Now we test the method
        log.debug("Running HermiT");
        Set<OWLAxiom> inferred = this.theinstance.runTask(ReasoningService.Tasks.ENRICH, manager.getOntology(testOntologyID));
        // Maybe we want to see the inferred axiom list
        if (log.isDebugEnabled()) {
            log.debug("{} inferred axioms:", inferred.size());
            TestUtils.debug(inferred, log);
        }
        Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(testExpectedID)).getLogicalAxioms();
        Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
        for (OWLAxiom expected : expectedAxioms) {
            // We consider here all kind of axioms
            if (!inferred.contains(expected)) {
                log.error("missing expected axiom: {}", expected);
                missing.add(expected);
            }
        }
        assertTrue(missing.isEmpty());
        // 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) OWLImportsDeclaration(org.semanticweb.owlapi.model.OWLImportsDeclaration) 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) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) HashSet(java.util.HashSet)

Example 4 with OWLLogicalAxiom

use of org.semanticweb.owlapi.model.OWLLogicalAxiom 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)

Example 5 with OWLLogicalAxiom

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

the class HermitReasoningServiceTest method testEnrich.

/**
     * 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.
     * 
     * TODO: This method is the same as testClassify(String,String), with the only difference - the task
     * called. We may want to have this procedure isolated.
     * 
     * @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 testEnrich(String testID, String testExpectedID) {
    log.info("Testing the ENRICH 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);
        OWLImportsDeclaration importTest = TestData.factory.getOWLImportsDeclaration(IRI.create(testID));
        manager.applyChange(new AddImport(testOntology, importTest));
        // 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.ENRICH, 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 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) OWLImportsDeclaration(org.semanticweb.owlapi.model.OWLImportsDeclaration) 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) 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) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)5 InconsistentInputException (org.apache.stanbol.reasoners.servicesapi.InconsistentInputException)5 ReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException)5 AddImport (org.semanticweb.owlapi.model.AddImport)5 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)5 OWLLogicalAxiom (org.semanticweb.owlapi.model.OWLLogicalAxiom)5 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)5 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)5 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)5 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)5 UnsupportedTaskException (org.apache.stanbol.reasoners.servicesapi.UnsupportedTaskException)4 OWLImportsDeclaration (org.semanticweb.owlapi.model.OWLImportsDeclaration)3 OWLClassAssertionAxiom (org.semanticweb.owlapi.model.OWLClassAssertionAxiom)2 OWLSubClassOfAxiom (org.semanticweb.owlapi.model.OWLSubClassOfAxiom)2 SWRLRule (org.semanticweb.owlapi.model.SWRLRule)2 ArrayList (java.util.ArrayList)1 OWLDisjointClassesAxiom (org.semanticweb.owlapi.model.OWLDisjointClassesAxiom)1 OWLEquivalentClassesAxiom (org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom)1 InferredAxiomGenerator (org.semanticweb.owlapi.util.InferredAxiomGenerator)1 InferredClassAssertionAxiomGenerator (org.semanticweb.owlapi.util.InferredClassAssertionAxiomGenerator)1