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;
}
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;
}
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;
}
}
}
}
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);
}
}
}
}
}
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));
}
}
}
}
}
}
Aggregations