Search in sources :

Example 56 with AtomSetException

use of fr.lirmm.graphik.graal.api.core.AtomSetException 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 57 with AtomSetException

use of fr.lirmm.graphik.graal.api.core.AtomSetException 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 58 with AtomSetException

use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.

the class SimpleFC method checkForward.

@Override
public boolean checkForward(Var v, AtomSet g, Substitution initialSubstitution, Map<Variable, Integer> map, Var[] varData, RulesCompilation rc) throws BacktrackException {
    Profiler profiler = this.getProfiler();
    for (Atom atom : v.shared.postAtoms) {
        boolean contains = false;
        Atom im = BacktrackUtils.createImageOf(atom, initialSubstitution, map, varData);
        if (profiler != null) {
            profiler.incr("#selectOne", 1);
            profiler.start("selectOneTime");
        }
        for (Pair<Atom, Substitution> rew : rc.getRewritingOf(im)) {
            Atom a = rew.getLeft();
            CloseableIterator<Atom> matchIt = null;
            try {
                matchIt = g.match(a);
                if (matchIt.hasNext()) {
                    contains = true;
                    break;
                }
            } catch (IteratorException e) {
                throw new BacktrackException(e);
            } catch (AtomSetException e) {
                throw new BacktrackException(e);
            } finally {
                if (matchIt != null) {
                    matchIt.close();
                }
            }
        }
        if (profiler != null) {
            profiler.stop("selectOneTime");
        }
        if (!contains) {
            return false;
        }
    }
    return true;
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) Profiler(fr.lirmm.graphik.util.profiler.Profiler) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) Atom(fr.lirmm.graphik.graal.api.core.Atom) BacktrackException(fr.lirmm.graphik.graal.homomorphism.BacktrackException)

Example 59 with AtomSetException

use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.

the class SimpleFC 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;
    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) BacktrackException(fr.lirmm.graphik.graal.homomorphism.BacktrackException)

Example 60 with AtomSetException

use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.

the class NFC2 method checkForward.

// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean checkForward(Var v, AtomSet g, Substitution initialSubstitution, Map<Variable, Integer> map, Var[] varData, RulesCompilation rc) throws BacktrackException {
    // clear all computed candidats for post variables
    for (VarSharedData z : v.shared.postVars) {
        this.clear(v.shared, z);
    }
    Var varToAssign = null;
    for (Atom atom : v.shared.postAtoms) {
        boolean runCheck = true;
        if (checkMode) {
            int i = 0;
            for (Variable t : atom.getVariables()) {
                Integer idx = map.get(t);
                if (idx != null) {
                    Var z = varData[idx];
                    if (z.shared.level > v.shared.level) {
                        ++i;
                        varToAssign = z;
                        if (i > 1 || !this.data[z.shared.level].candidats[v.shared.level].init) {
                            runCheck = false;
                            break;
                        }
                    }
                }
            }
        }
        if (checkMode && runCheck) {
            try {
                if (!check(atom, v.shared, varToAssign.shared, g, initialSubstitution, map, varData, rc)) {
                    return false;
                }
            } catch (AtomSetException e) {
                throw new BacktrackException("An error occurs while checking current candidate");
            }
        } else {
            try {
                if (!select(atom, v, g, initialSubstitution, map, varData, rc)) {
                    return false;
                }
            } catch (IteratorException e) {
                throw new BacktrackException("An error occurs while selecting candidates for next steps ");
            } catch (AtomSetException e) {
                throw new BacktrackException("An error occurs while selecting candidates for next steps ");
            }
        }
    }
    return true;
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) Variable(fr.lirmm.graphik.graal.api.core.Variable) Var(fr.lirmm.graphik.graal.homomorphism.Var) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) VarSharedData(fr.lirmm.graphik.graal.homomorphism.VarSharedData) Atom(fr.lirmm.graphik.graal.api.core.Atom) BacktrackException(fr.lirmm.graphik.graal.homomorphism.BacktrackException)

Aggregations

AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)69 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)26 SQLException (java.sql.SQLException)26 Atom (fr.lirmm.graphik.graal.api.core.Atom)25 Term (fr.lirmm.graphik.graal.api.core.Term)23 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)12 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)11 Statement (java.sql.Statement)11 DBTable (fr.lirmm.graphik.graal.store.rdbms.util.DBTable)10 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)9 BacktrackException (fr.lirmm.graphik.graal.homomorphism.BacktrackException)9 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)7 TreeSet (java.util.TreeSet)7 SQLQuery (fr.lirmm.graphik.graal.store.rdbms.util.SQLQuery)6 CloseableIteratorAdapter (fr.lirmm.graphik.util.stream.CloseableIteratorAdapter)6 RuleApplicationException (fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException)5 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)5 TreeMap (java.util.TreeMap)5 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)4 Variable (fr.lirmm.graphik.graal.api.core.Variable)4