use of org.apache.stanbol.reasoners.servicesapi.InconsistentInputException in project stanbol by apache.
the class JenaReasoningServiceTest method testEnrich2.
/**
* Tests the enrich(Model data,boolean filtered) method
*
* @param service
*/
private void testEnrich2(JenaReasoningService service) {
// 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());
try {
// Run the method
Set<Statement> inferred = service.runTask(ReasoningService.Tasks.ENRICH, input, null, false, null);
// Prepare the input statements to check the output with
Set<Statement> inputStatements = input.listStatements().toSet();
log.info("All the input statements must be in the inferred output");
Set<Statement> notInOutput = new HashSet<Statement>();
for (Statement stat : inputStatements) {
if (!inferred.contains(stat)) {
notInOutput.add(stat);
}
}
log.info("Are all input statements in the inferred set (true)? {}", notInOutput.isEmpty());
if (!notInOutput.isEmpty()) {
for (Statement bad : notInOutput) {
log.error("Found a statement not included in output: {}", bad);
}
}
assertTrue(notInOutput.isEmpty());
} 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.InconsistentInputException in project stanbol by apache.
the class AbstractOWLApiReasoningService method run.
/**
* Generic method for running the reasoner
*
* @param input
* @param generators
* @return
*/
@Override
public Set<OWLAxiom> run(OWLOntology input, List<InferredAxiomGenerator<? extends OWLAxiom>> generators) throws ReasoningServiceException, InconsistentInputException {
log.debug("run(OWLOntology input, List<InferredAxiomGenerator<? extends OWLAxiom>> generators)");
try {
// Get the manager
OWLOntologyManager manager = createOWLOntologyManager();
// Get the reasoner
OWLReasoner reasoner = getReasoner(input);
log.info("Running {} reasoner on {} ", reasoner.getClass(), input.getOntologyID());
// To generate inferred axioms
InferredOntologyGenerator inferred = new InferredOntologyGenerator(reasoner, generators);
// We fill an anonymous ontology with the result, the return the
// axiom set
Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
try {
OWLOntology output = manager.createOntology();
log.debug("Created output ontology: {}", output);
try {
inferred.fillOntology(manager, output);
} catch (InconsistentOntologyException i) {
throw i;
} catch (Throwable t) {
log.error("Some problem occurred:\n {}", t.getStackTrace());
throw new ReasoningServiceException();
}
log.debug("Filled ontology: {}", output);
log.debug("Temporary ID is {}", output.getOntologyID());
axioms = manager.getOntology(output.getOntologyID()).getAxioms();
// IMPORTANT We remove the ontology from the manager
manager.removeOntology(output);
} catch (OWLOntologyCreationException e) {
log.error("An exception have been thrown when instantiating the ontology");
throw new ReasoningServiceException();
}
return axioms;
} catch (InconsistentOntologyException inconsistent) {
/**
* TODO Add report. Why it is inconsistent?
*/
throw new InconsistentInputException();
} catch (Exception exception) {
log.error("An exception have been thrown while executing method run()", exception);
throw new ReasoningServiceException();
}
}
Aggregations