use of org.apache.stanbol.reasoners.owlapi.OWLApiReasoningService in project stanbol by apache.
the class ReasoningServiceExecutor method execute.
/**
* General method for execution, delegates to specific implementations.
*
* @param task
* @param service
* @param targetGraphID
* @param parameters
* @return
* @throws ReasoningServiceException
* @throws UnsupportedTaskException
* @throws InconsistentInputException
*/
private ReasoningServiceResult<?> execute(String task, ReasoningService<?, ?, ?> service, String targetGraphID, Map<String, List<String>> parameters) throws ReasoningServiceException, UnsupportedTaskException, InconsistentInputException {
long start = System.currentTimeMillis();
if (log.isDebugEnabled()) {
log.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
log.debug("[start] Execution: {}", service.getClass().getCanonicalName());
log.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
log.debug("-----------------------------------------------------");
log.debug("execute()");
log.debug(" > task: {}", task);
log.debug(" > service: {}", service.getClass().getCanonicalName());
log.debug(" > target: {}", targetGraphID);
log.debug(" > parameters:");
for (Entry<String, List<String>> e : parameters.entrySet()) {
log.debug(" >> {}: {}", e.getKey());
for (String v : e.getValue()) {
log.debug(" >>> value: {}", v);
}
}
log.debug(" > input providers:");
for (ReasoningServiceInputProvider p : inmgr.getProviders()) {
log.debug(" >> {}", p.getClass().getCanonicalName());
}
log.debug("-----------------------------------------------------");
}
ReasoningServiceResult<?> result = null;
/**
* TODO Switch this into the ReasoningService implementation
*/
if (service instanceof JenaReasoningService) {
Model input = ModelFactory.createDefaultModel();
synchronized (inmgr) {
Iterator<Statement> statements = inmgr.getInputData(Statement.class);
while (statements.hasNext()) {
input.add(statements.next());
}
}
List<Rule> rules = null;
synchronized (inmgr) {
Iterator<Rule> rulesI = inmgr.getInputData(Rule.class);
while (rulesI.hasNext()) {
Rule o = rulesI.next();
log.debug("Rule: {}", o);
if (rules == null) {
rules = new ArrayList<Rule>();
}
rules.add(o);
}
}
if (log.isDebugEnabled()) {
log.debug("Input size is {} statements", input.listStatements().toSet().size());
}
result = executeJenaReasoningService(task, (JenaReasoningService) service, input, rules, targetGraphID, true, parameters);
} else if (service instanceof OWLApiReasoningService) {
OWLOntology input;
try {
input = OWLManager.createOWLOntologyManager().createOntology();
} catch (OWLOntologyCreationException e) {
throw new ReasoningServiceException(e);
}
synchronized (inmgr) {
Iterator<OWLAxiom> statements = inmgr.getInputData(OWLAxiom.class);
while (statements.hasNext()) {
input.getOWLOntologyManager().addAxiom(input, statements.next());
}
}
// FIXME Please check if this is really necessary!!!
input = input.getOWLOntologyManager().getOntology(input.getOntologyID());
List<SWRLRule> rules = null;
synchronized (inmgr) {
Iterator<SWRLRule> rulesI = inmgr.getInputData(SWRLRule.class);
while (rulesI.hasNext()) {
if (rules == null) {
rules = new ArrayList<SWRLRule>();
}
rules.add(rulesI.next());
}
}
if (log.isDebugEnabled()) {
log.debug("Input size is {} statements", input.getAxiomCount());
}
result = executeOWLApiReasoningService(task, (OWLApiReasoningService) service, input, rules, targetGraphID, true, parameters);
} else
throw new UnsupportedOperationException("Service implementation not supported!");
if (log.isDebugEnabled()) {
log.debug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
long end = System.currentTimeMillis();
log.debug("[end] In time: {}ms", (end - start));
log.debug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
}
return result;
}
use of org.apache.stanbol.reasoners.owlapi.OWLApiReasoningService in project stanbol by apache.
the class ReasoningServiceTaskResource method prepare.
public void prepare(String serviceID, String taskIDstr, String jobFlag) {
this.taskID = taskIDstr;
log.debug("Called service {} to perform task {}", serviceID, taskID);
// Parameters for customized reasoning services
this.parameters = prepareParameters();
// Retrieve the service
try {
service = getService(serviceID);
} catch (UnboundReasoningServiceException e) {
log.error("Service not found: {}", serviceID);
throw new WebApplicationException(e, Response.Status.NOT_FOUND);
}
log.debug("Service retrieved");
// Check if the task is allowed
if (this.service.supportsTask(taskID) || taskID.equals(ReasoningServiceExecutor.TASK_CHECK)) {
// Ok
} else {
log.error("Unsupported task (not found): {}", taskID);
throw new WebApplicationException(new Exception("Unsupported task (not found): " + taskID), Response.Status.NOT_FOUND);
}
// Check for the job parameter
if (!jobFlag.equals("")) {
log.debug("Job param is {}", job);
if (jobFlag.equals("/job")) {
log.debug("Ask for background job");
this.job = true;
} else {
log.error("Malformed request");
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
}
// Now we check if the service implementation is supported
if (getCurrentService() instanceof JenaReasoningService) {
} else if (getCurrentService() instanceof OWLApiReasoningService) {
} else {
log.error("This implementation of ReasoningService is not supported: {}", getCurrentService().getClass());
throw new WebApplicationException(new Exception("This implementation of ReasoningService is not supported: " + getCurrentService().getClass()), Response.Status.INTERNAL_SERVER_ERROR);
}
log.debug("Implementation is supported");
}
Aggregations