use of fr.lirmm.graphik.graal.api.core.Predicate in project graal by graphik-team.
the class HierarchicalCompilation method computeIndex.
private void computeIndex(Iterable<Rule> ruleset) {
for (Rule rule : ruleset) {
// count the number of new pred in r
CloseableIteratorWithoutException<Predicate> it = rule.getBody().predicatesIterator();
while (it.hasNext()) {
this.addPredicate(it.next());
}
it = rule.getHead().predicatesIterator();
while (it.hasNext()) {
this.addPredicate(it.next());
}
}
int nbPred = this.indexPredicate.size();
Atom father, son;
this.order = new byte[nbPred][nbPred];
for (Rule ru : ruleset) {
father = ru.getHead().iterator().next();
son = ru.getBody().iterator().next();
this.addRule(father, son);
}
// reflexivity
for (int i = 0; i < this.order.length; ++i) {
this.order[i][i] = 1;
}
}
use of fr.lirmm.graphik.graal.api.core.Predicate in project graal by graphik-team.
the class HierarchicalCompilation method isImplied.
@Override
public boolean isImplied(Atom father, Atom son) {
Predicate predFather = father.getPredicate();
Predicate predSon = son.getPredicate();
Integer f = predicateIndex.get(predFather);
Integer s = predicateIndex.get(predSon);
if (f != null && s != null && TermValueComparator.instance().compare(father.getTerms(), son.getTerms()) == 0)
return order[f][s] == 1;
else
return false;
}
use of fr.lirmm.graphik.graal.api.core.Predicate in project graal by graphik-team.
the class HierarchicalCompilation method addRule.
private void addRule(Atom father, Atom son) {
Predicate predFather = father.getPredicate();
Predicate predSon = son.getPredicate();
Integer f = predicateIndex.get(predFather);
Integer s = predicateIndex.get(predSon);
order[f][s] = 1;
computeTransitiveClosure(f, s);
}
use of fr.lirmm.graphik.graal.api.core.Predicate in project graal by graphik-team.
the class IDCompilation method getUnification.
@Override
public LinkedList<Partition<Term>> getUnification(Atom father, Atom son) {
LinkedList<Partition<Term>> res = new LinkedList<Partition<Term>>();
Predicate predB = son.getPredicate();
Predicate predH = father.getPredicate();
List<IDCondition> conds = getConditions(predB, predH);
for (IDCondition cond : conds) {
Partition<Term> unif = cond.generateUnification(son.getTerms(), father.getTerms());
if (unif != null) {
res.add(unif);
}
}
return res;
}
use of fr.lirmm.graphik.graal.api.core.Predicate in project graal by graphik-team.
the class IDCompilation method homomorphism.
@Override
public LinkedList<Substitution> homomorphism(Atom father, Atom son) {
LinkedList<Substitution> res = new LinkedList<Substitution>();
Predicate predB = son.getPredicate();
Predicate predH = father.getPredicate();
List<IDCondition> conds = getConditions(predB, predH);
for (IDCondition cond : conds) {
if (cond.checkBody(son.getTerms())) {
Substitution homo = cond.homomorphism(father.getTerms(), son.getTerms());
if (homo != null) {
res.add(new TreeMapSubstitution(homo));
}
}
}
return res;
}
Aggregations