use of org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException in project stanbol by apache.
the class JenaReasoningServiceTest method testClassify.
/**
* Tests the classify() method
*/
private void testClassify(JenaReasoningService reasoningService) {
// Clean data
TestData.alexdma.removeProperties();
// Prepare data
TestData.alexdma.addProperty(RDF.type, TestData.foaf_Person);
// Setup input for the reasoner
Model input = ModelFactory.createUnion(TestData.foaf, TestData.alexdma.getModel());
// Run the method
Set<Statement> inferred;
try {
inferred = reasoningService.runTask(ReasoningService.Tasks.CLASSIFY, input);
boolean foafAgentExists = false;
log.info("Check for statements to be rdf:type only");
for (Statement stat : inferred) {
// Here we want only rdf:type statements
if (!stat.getPredicate().equals(RDF.type)) {
log.error("This statement is not rdf:type: {}", stat);
}
assertTrue(stat.getPredicate().equals(RDF.type));
if (stat.getObject().isResource()) {
if (stat.getObject().asResource().equals(TestData.foaf_Agent)) {
foafAgentExists = true;
}
}
}
log.info("Does the statement: example:me rdf:type foaf:Agent exists (true)? {}", foafAgentExists);
assertTrue(foafAgentExists);
} catch (ReasoningServiceException e) {
log.error("Error thrown: {}", e);
assertTrue(false);
} catch (InconsistentInputException e) {
log.error("Error thrown: {}", e);
assertTrue(false);
} catch (UnsupportedTaskException e) {
log.error("Error thrown: {}", e);
assertTrue(false);
}
// Clean data
TestData.alexdma.removeProperties();
}
use of org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException in project stanbol by apache.
the class JenaOWLReasoningServiceTest method isNotConsistent.
public void isNotConsistent() {
// Clean data
TestData.alexdma.removeProperties();
// Prepare data
TestData.alexdma.addProperty(RDF.type, TestData.foaf_Person);
TestData.alexdma.addProperty(RDF.type, TestData.foaf_Organization);
// Setup input for the reasoner
Model input = ModelFactory.createUnion(TestData.foaf, TestData.alexdma.getModel());
try {
assertFalse(reasoningService.isConsistent(input));
} catch (ReasoningServiceException e) {
log.error("Error thrown: {}", e);
}
// Clean data
TestData.alexdma.removeProperties();
}
use of org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException 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);
}
}
use of org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException in project stanbol by apache.
the class HermitReasoningServiceTest method testIsConsistent.
/**
* Check whether the ontology is consistent
*
* @param testID
* // The ID of the ontology to test
* @param expected
* // If it is expected to be consistent or not
*/
private void testIsConsistent(String testID, boolean expected) {
log.info("Testing the isConsistent 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);
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");
try {
assertTrue(this.theinstance.isConsistent(testOntology) == expected);
} catch (ReasoningServiceException e) {
log.error("Error while testing the isConsistent method. Message was: {}", e.getLocalizedMessage());
assertTrue(false);
}
// 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);
}
}
use of org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException 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);
}
}
Aggregations