Search in sources :

Example 1 with DependencyChecker

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

the class UnifierIterator method extendUnifier.

private Collection<Substitution> extendUnifier(Rule rule, Queue<Atom> atomset, Atom pieceElement, Unifier unifier) {
    atomset.remove(pieceElement);
    unifier.queryPiece.add(pieceElement);
    Collection<Substitution> unifierCollection = new LinkedList<Substitution>();
    Set<Variable> frontierVars = rule.getFrontier();
    Set<Variable> existentialVars = rule.getExistentials();
    CloseableIteratorWithoutException<Atom> it = rule.getHead().iterator();
    while (it.hasNext()) {
        Atom atom = it.next();
        Substitution u = unifier(unifier.s, pieceElement, atom, frontierVars, existentialVars);
        if (u != null) {
            unifier = new Unifier(unifier);
            unifier.ruleHeadPiece.add(atom);
            unifier.s = u;
            // look if there exist other element for the current piece
            Atom nextPieceElement = getNextPieceElementIfExist(u, atomset, existentialVars);
            if (nextPieceElement == null) {
                boolean check = true;
                for (DependencyChecker c : this.checkers) {
                    check &= c.isValidDependency(this.source, this.target, unifier.s);
                }
                if (check) {
                    unifierCollection.add(unifier.s);
                }
            } else {
                unifierCollection.addAll(extendUnifier(rule, new LinkedList<Atom>(atomset), nextPieceElement, unifier));
            }
        }
    }
    return unifierCollection;
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) DependencyChecker(fr.lirmm.graphik.graal.api.core.unifier.DependencyChecker) LinkedList(java.util.LinkedList) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Aggregations

Atom (fr.lirmm.graphik.graal.api.core.Atom)1 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)1 Variable (fr.lirmm.graphik.graal.api.core.Variable)1 DependencyChecker (fr.lirmm.graphik.graal.api.core.unifier.DependencyChecker)1 LinkedList (java.util.LinkedList)1