use of org.openrdf.repository.sail.SailGraphQuery in project incubator-rya by apache.
the class SailExecutionStrategy method executeConstructRule.
/**
* Executes a CONSTRUCT query through the SAIL and inserts the results into
* the DAO.
* @param rule A construct query; not null.
* @param metadata Metadata to add to any inferred triples; not null.
* @return The number of inferred triples.
* @throws ForwardChainException if query execution or data insert fails.
*/
@Override
public long executeConstructRule(AbstractConstructRule rule, StatementMetadata metadata) throws ForwardChainException {
Preconditions.checkNotNull(rule);
Preconditions.checkNotNull(metadata);
if (!initialized) {
initialize();
}
ParsedGraphQuery graphQuery = rule.getQuery();
long statementsAdded = 0;
logger.info("Applying inference rule " + rule + "...");
for (String line : graphQuery.getTupleExpr().toString().split("\n")) {
logger.debug("\t" + line);
}
InferredStatementHandler<?> handler = new InferredStatementHandler<>(dao, metadata);
try {
GraphQuery executableQuery = new SailGraphQuery(graphQuery, conn) {
};
executableQuery.evaluate(handler);
statementsAdded = handler.getNumStatementsAdded();
logger.info("Added " + statementsAdded + " inferred statements.");
return statementsAdded;
} catch (QueryEvaluationException e) {
throw new ForwardChainException("Error evaluating query portion of construct rule", e);
} catch (RDFHandlerException e) {
throw new ForwardChainException("Error processing results of construct rule", e);
}
}
Aggregations