Search in sources :

Example 6 with CloseableIteratorAdapter

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;
}
Also used : AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) HomomorphismIteratorChecker(fr.lirmm.graphik.graal.homomorphism.utils.HomomorphismIteratorChecker) CloseableIteratorAdapter(fr.lirmm.graphik.util.stream.CloseableIteratorAdapter) BacktrackException(fr.lirmm.graphik.graal.homomorphism.BacktrackException)

Example 7 with CloseableIteratorAdapter

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;
}
Also used : AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) HomomorphismIteratorChecker(fr.lirmm.graphik.graal.homomorphism.utils.HomomorphismIteratorChecker) CloseableIteratorAdapter(fr.lirmm.graphik.util.stream.CloseableIteratorAdapter) BacktrackException(fr.lirmm.graphik.graal.homomorphism.BacktrackException)

Example 8 with CloseableIteratorAdapter

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;
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) Variable(fr.lirmm.graphik.graal.api.core.Variable) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) CloseableIteratorAdapter(fr.lirmm.graphik.util.stream.CloseableIteratorAdapter) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) ConjunctiveQueryWithFixedVariables(fr.lirmm.graphik.graal.core.ConjunctiveQueryWithFixedVariables) Atom(fr.lirmm.graphik.graal.api.core.Atom) BacktrackException(fr.lirmm.graphik.graal.homomorphism.BacktrackException)

Aggregations

CloseableIteratorAdapter (fr.lirmm.graphik.util.stream.CloseableIteratorAdapter)8 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)6 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)6 Term (fr.lirmm.graphik.graal.api.core.Term)5 BacktrackException (fr.lirmm.graphik.graal.homomorphism.BacktrackException)5 Atom (fr.lirmm.graphik.graal.api.core.Atom)4 TreeSet (java.util.TreeSet)3 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)2 Constant (fr.lirmm.graphik.graal.api.core.Constant)2 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)2 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)2 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)2 Variable (fr.lirmm.graphik.graal.api.core.Variable)2 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)2 ConjunctiveQueryWithFixedVariables (fr.lirmm.graphik.graal.core.ConjunctiveQueryWithFixedVariables)2 HomomorphismIteratorChecker (fr.lirmm.graphik.graal.homomorphism.utils.HomomorphismIteratorChecker)2 Store (fr.lirmm.graphik.graal.api.store.Store)1