Search in sources :

Example 1 with PredicatePosition

use of fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition in project graal by graphik-team.

the class AbstractAffectedPositionSet method affectInHead.

/**
 * @param rule
 * @param term
 */
protected boolean affectInHead(Rule rule, Term term) {
    int i;
    PredicatePosition predicatePosition;
    boolean addSomeAffectedPosition = false;
    CloseableIteratorWithoutException<Atom> it = rule.getHead().iterator();
    while (it.hasNext()) {
        Atom atom = it.next();
        i = -1;
        for (Term t : atom) {
            ++i;
            if (term.equals(t)) {
                predicatePosition = new PredicatePosition(atom.getPredicate(), i);
                if (!isAffected(predicatePosition)) {
                    this.affectedPosition.add(predicatePosition);
                    addSomeAffectedPosition = true;
                }
            }
        }
    }
    return addSomeAffectedPosition;
}
Also used : PredicatePosition(fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 2 with PredicatePosition

use of fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition in project graal by graphik-team.

the class GraphPositionDependencies method isWeaklyAcyclic.

public boolean isWeaklyAcyclic() {
    for (DefaultEdge e : this.graph.edgeSet()) {
        if (e instanceof SpecialEdge) {
            PredicatePosition head = this.graph.getEdgeTarget(e);
            PredicatePosition tail = this.graph.getEdgeSource(e);
            Set<PredicatePosition> markedVertex = new TreeSet<PredicatePosition>();
            markedVertex.add(head);
            markedVertex.add(tail);
            if (this.findSpecialCycle(head, markedVertex, tail)) {
                return false;
            }
        }
    }
    return true;
}
Also used : TreeSet(java.util.TreeSet) DefaultEdge(org.jgrapht.graph.DefaultEdge) PredicatePosition(fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition)

Example 3 with PredicatePosition

use of fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition in project graal by graphik-team.

the class MarkedVariableSet method mark.

private void mark(Term v, MarkedRule mrule) {
    if (!mrule.markedVars.contains(v)) {
        mrule.markedVars.add(v);
        CloseableIteratorWithoutException<Atom> it = mrule.rule.getBody().iterator();
        while (it.hasNext()) {
            Atom a = it.next();
            int i = 0;
            for (Term t : a) {
                if (v.equals(t)) {
                    this.markedPosition.add(new PredicatePosition(a.getPredicate(), i));
                }
                ++i;
            }
        }
    }
}
Also used : PredicatePosition(fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 4 with PredicatePosition

use of fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition in project graal by graphik-team.

the class AbstractAffectedPositionSet method step1.

/**
 * for each rule and for each existentially quantified variable occuring at
 * position p[i] in its head, p[i] is affected;
 */
protected void step1() {
    int i;
    Set<Variable> existentials;
    PredicatePosition predicatePosition;
    for (Rule rule : ruleSet) {
        existentials = rule.getExistentials();
        CloseableIteratorWithoutException<Atom> it = rule.getHead().iterator();
        while (it.hasNext()) {
            Atom atom = it.next();
            i = -1;
            for (Term t : atom) {
                ++i;
                if (existentials.contains(t)) {
                    predicatePosition = new PredicatePosition(atom.getPredicate(), i);
                    this.affectedPosition.add(predicatePosition);
                }
            }
        }
    }
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) PredicatePosition(fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition) Rule(fr.lirmm.graphik.graal.api.core.Rule) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 5 with PredicatePosition

use of fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition in project graal by graphik-team.

the class GraphPositionDependencies method init.

private void init() {
    int bodyTermIndex, headTermIndex;
    Set<Variable> existentials;
    for (Rule r : this.rules) {
        existentials = r.getExistentials();
        CloseableIteratorWithoutException<Atom> bodyIt = r.getBody().iterator();
        while (bodyIt.hasNext()) {
            Atom bodyAtom = bodyIt.next();
            bodyTermIndex = -1;
            for (Term bodyTerm : bodyAtom) {
                ++bodyTermIndex;
                if (r.getHead().getTerms().contains(bodyTerm)) {
                    CloseableIteratorWithoutException<Atom> headIt = r.getHead().iterator();
                    while (headIt.hasNext()) {
                        Atom headAtom = headIt.next();
                        headTermIndex = -1;
                        for (Term headTerm : headAtom) {
                            ++headTermIndex;
                            if (bodyTerm.equals(headTerm)) {
                                this.addEdge(new PredicatePosition(bodyAtom.getPredicate(), bodyTermIndex), new PredicatePosition(headAtom.getPredicate(), headTermIndex));
                            } else if (existentials.contains(headTerm)) {
                                this.addSpecialEdge(new PredicatePosition(bodyAtom.getPredicate(), bodyTermIndex), new PredicatePosition(headAtom.getPredicate(), headTermIndex));
                            }
                        }
                    }
                } else {
                    if (!this.graph.containsVertex(new PredicatePosition(bodyAtom.getPredicate(), bodyTermIndex))) {
                        this.graph.addVertex(new PredicatePosition(bodyAtom.getPredicate(), bodyTermIndex));
                    }
                }
            }
        }
    }
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) PredicatePosition(fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition) Rule(fr.lirmm.graphik.graal.api.core.Rule) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Aggregations

PredicatePosition (fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition)7 Atom (fr.lirmm.graphik.graal.api.core.Atom)5 Term (fr.lirmm.graphik.graal.api.core.Term)5 Rule (fr.lirmm.graphik.graal.api.core.Rule)2 Variable (fr.lirmm.graphik.graal.api.core.Variable)2 TreeSet (java.util.TreeSet)2 DefaultEdge (org.jgrapht.graph.DefaultEdge)2 Set (java.util.Set)1 StrongConnectivityInspector (org.jgrapht.alg.StrongConnectivityInspector)1