use of fr.lirmm.graphik.graal.homomorphism.utils.EqualityHandlerConverter in project graal by graphik-team.
the class RecursiveBacktrackHomomorphism method execute.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public CloseableIterator<Substitution> execute(ConjunctiveQuery query, AtomSet facts) throws HomomorphismException {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(query.toString());
}
if (profiler != null) {
profiler.start("preprocessing time");
}
Pair<ConjunctiveQuery, Substitution> pair = EqualityUtils.processEquality(query);
List<Variable> orderedVars = order(pair.getLeft().getAtomSet().getVariables());
Collection<Atom>[] queryAtomRanked = getAtomRank(pair.getLeft().getAtomSet(), orderedVars);
if (profiler != null) {
profiler.stop("preprocessing time");
}
try {
this.domain = facts.getTerms();
if (profiler != null) {
profiler.start("backtracking time");
}
CloseableIterator<Substitution> results;
if (isHomomorphism(queryAtomRanked[0], facts, new HashMapSubstitution())) {
results = new CloseableIteratorAdapter<Substitution>(homomorphism(pair.getLeft(), queryAtomRanked, facts, new HashMapSubstitution(), orderedVars, 1).iterator());
} else {
// return false
results = new CloseableIteratorAdapter<Substitution>(Collections.<Substitution>emptyList().iterator());
}
if (profiler != null) {
profiler.stop("backtracking time");
}
if (!pair.getRight().getTerms().isEmpty()) {
results = new ConverterCloseableIterator<Substitution, Substitution>(results, new EqualityHandlerConverter(pair.getRight()));
}
return results;
} catch (Exception e) {
throw new HomomorphismException(e.getMessage(), e);
}
}
Aggregations