use of fr.lirmm.graphik.util.stream.filter.AndFilter in project graal by graphik-team.
the class AtomicQueryHomomorphismWithNegatedParts method execute.
// /////////////////////////////////////////////////////////////////////////
// HOMOMORPHISM METHODS
// /////////////////////////////////////////////////////////////////////////
public CloseableIterator<Substitution> execute(ConjunctiveQueryWithNegatedParts query, AtomSet data, RulesCompilation compilation) throws HomomorphismException {
try {
Atom atom = query.getPositivePart().iterator().next();
List<Term> ans = query.getAnswerVariables();
List<CloseableIterator<Substitution>> iteratorsList = new LinkedList<CloseableIterator<Substitution>>();
for (Pair<Atom, Substitution> im : compilation.getRewritingOf(atom)) {
iteratorsList.add(new ConverterCloseableIterator<Atom, Substitution>(data.match(im.getLeft()), new Atom2SubstitutionConverter(im.getLeft(), ans, im.getRight())));
}
CloseableIterator<Substitution> subIt = new CloseableIteratorAggregator<Substitution>(new CloseableIteratorAdapter<CloseableIterator<Substitution>>(iteratorsList.iterator()));
// manage negative parts
Set<Variable> variables = query.getPositivePart().getVariables();
@SuppressWarnings("rawtypes") Filter[] filters = new Filter[query.getNegatedParts().size()];
int i = 0;
for (InMemoryAtomSet negPart : query.getNegatedParts()) {
Set<Variable> frontier = SetUtils.intersection(variables, negPart.getVariables());
filters[i++] = new NegFilter(negPart, frontier, data, compilation);
}
@SuppressWarnings("unchecked") Filter<Substitution> filter = new AndFilter<Substitution>(filters);
return new FilterIterator<Substitution, Substitution>(subIt, filter);
} catch (AtomSetException e) {
throw new HomomorphismException(e);
}
}
Aggregations