Search in sources :

Example 6 with PredicatePosition

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

the class GraphPositionDependencies method initFiniteRank.

public void initFiniteRank() {
    if (this.isFiniteRank == null) {
        this.isFiniteRank = new TreeSet<PredicatePosition>();
        StrongConnectivityInspector<PredicatePosition, DefaultEdge> sccInspector = new StrongConnectivityInspector<PredicatePosition, DefaultEdge>(graph);
        List<Set<PredicatePosition>> sccList = sccInspector.stronglyConnectedSets();
        for (Set<PredicatePosition> scc : sccList) {
            boolean componentIsFiniteRank = true;
            for (PredicatePosition p1 : scc) {
                for (PredicatePosition p2 : scc) {
                    for (DefaultEdge edge : graph.getAllEdges(p1, p2)) {
                        if (edge instanceof SpecialEdge) {
                            componentIsFiniteRank = false;
                        }
                    }
                }
            }
            // store information
            if (componentIsFiniteRank) {
                for (PredicatePosition p : scc) {
                    this.isFiniteRank.add(p);
                }
            }
        }
    }
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) StrongConnectivityInspector(org.jgrapht.alg.StrongConnectivityInspector) DefaultEdge(org.jgrapht.graph.DefaultEdge) PredicatePosition(fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition)

Example 7 with PredicatePosition

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

the class MarkedVariableSet method secondStep.

/**
 * apply until a fixpoint is reached: for each rule Ri, if a marked variable
 * v appears at position p[k] in its body, then for each rule Rj (including
 * i = j) and for each variable x appearing at position p[k] in the head of
 * Rj, mark each occurence of x in the body of Rj.
 */
private void secondStep() {
    LinkedList<MarkedRule> mrList;
    PredicatePosition mpos;
    Term v;
    while (!this.markedPosition.isEmpty()) {
        mpos = this.markedPosition.poll();
        mrList = this.map.get(mpos.predicate);
        if (mrList != null) {
            for (MarkedRule mr : mrList) {
                CloseableIteratorWithoutException<Atom> it = mr.rule.getHead().iterator();
                while (it.hasNext()) {
                    Atom a = it.next();
                    if (a.getPredicate().equals(mpos.predicate)) {
                        v = a.getTerm(mpos.position);
                        if (v.isVariable()) {
                            this.mark(v, mr);
                        }
                    }
                }
            }
        }
    }
}
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)

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