use of fr.lirmm.graphik.util.stream.CloseableIteratorAdapter in project graal by graphik-team.
the class AbstractNFC method getCandidatsIterator.
@Override
public CloseableIterator<Term> getCandidatsIterator(AtomSet g, Var var, Substitution initialSubstitution, Map<Variable, Integer> map, Var[] varData, RulesCompilation rc) throws BacktrackException {
HomomorphismIteratorChecker tmp;
if (this.data[var.shared.level].last.init) {
tmp = new HomomorphismIteratorChecker(var, new CloseableIteratorAdapter<Term>(this.data[var.shared.level].last.candidats.iterator()), this.data[var.shared.level].toCheckAfterAssignment, g, initialSubstitution, map, varData, rc);
} else {
try {
tmp = new HomomorphismIteratorChecker(var, g.termsIterator(), var.shared.preAtoms, g, initialSubstitution, map, varData, rc);
} catch (AtomSetException e) {
throw new BacktrackException(e);
}
}
tmp.setProfiler(this.getProfiler());
return tmp;
}
use of fr.lirmm.graphik.util.stream.CloseableIteratorAdapter in project graal by graphik-team.
the class NFC2WithLimit method getCandidatsIterator.
@Override
public CloseableIterator<Term> getCandidatsIterator(AtomSet g, Var var, Substitution initialSubstitution, Map<Variable, Integer> map, Var[] varData, RulesCompilation rc) throws BacktrackException {
HomomorphismIteratorChecker tmp;
if (this.data[var.shared.level].last.init) {
this.dataWithLimit[var.shared.level].atomsToCheck.addAll(this.data[var.shared.level].toCheckAfterAssignment);
tmp = new HomomorphismIteratorChecker(var, new CloseableIteratorAdapter<Term>(this.data[var.shared.level].last.candidats.iterator()), this.dataWithLimit[var.shared.level].atomsToCheck, g, initialSubstitution, map, varData, rc);
} else {
try {
tmp = new HomomorphismIteratorChecker(var, g.termsIterator(), var.shared.preAtoms, g, initialSubstitution, map, varData, rc);
} catch (AtomSetException e) {
throw new BacktrackException(e);
}
}
tmp.setProfiler(this.getProfiler());
return tmp;
}
use of fr.lirmm.graphik.util.stream.CloseableIteratorAdapter in project graal by graphik-team.
the class RestrictedChaseHaltingCondition method apply.
@Override
public CloseableIterator<Atom> apply(Rule rule, Substitution substitution, AtomSet data) throws HomomorphismFactoryException, HomomorphismException {
InMemoryAtomSet newFacts = substitution.createImageOf(rule.getHead());
ConjunctiveQuery query = new ConjunctiveQueryWithFixedVariables(newFacts, substitution.createImageOf(rule.getFrontier()));
try {
if (SmartHomomorphism.instance().execute(query, data).hasNext()) {
return new CloseableIteratorAdapter<Atom>(Collections.<Atom>emptyList().iterator());
}
} catch (IteratorException e) {
throw new HomomorphismException("An errors occurs while iterating results", e);
} catch (BacktrackException e) {
throw new HomomorphismException("An errors occurs while iterating results", e);
}
// replace variables by fresh symbol
for (Variable t : rule.getExistentials()) {
substitution.put(t, data.getFreshSymbolGenerator().getFreshSymbol());
}
CloseableIteratorWithoutException<Atom> it = substitution.createImageOf(rule.getHead()).iterator();
return it;
}
Aggregations