use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.
the class Utils method rewrite.
/**
* Rewrite the fact q according to the unifier u.
*
* @param q
* the fact to rewrite
* @param u
* the unifier between q and r
* @return the rewrite of q according to the unifier u.
*/
public static ConjunctiveQuery rewrite(ConjunctiveQuery q, QueryUnifier u) {
InMemoryAtomSet ajout = u.getImageOf(u.getRule().getBody());
InMemoryAtomSet restant = u.getImageOf(AtomSetUtils.minus(q.getAtomSet(), u.getPiece()));
ConjunctiveQuery rew = null;
if (ajout != null && restant != null) {
// FIXME
InMemoryAtomSet res = AtomSetUtils.union(ajout, restant);
List<Term> ansVar = new LinkedList<Term>();
ansVar.addAll(q.getAnswerVariables());
rew = DefaultConjunctiveQueryFactory.instance().create(res, ansVar);
}
return rew;
}
use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.
the class Utils method rewriteWithMark.
/**
* Rewrite the marked fact q according to the unifier u between
*
* @param q
* the fact to rewrite must be a marked fact
* @param u
* the unifier between q and r
* @return the rewrite of q according to the unifier u.
*/
public static MarkedQuery rewriteWithMark(ConjunctiveQuery q, QueryUnifier u) {
InMemoryAtomSet ajout = u.getImageOf(u.getRule().getBody());
InMemoryAtomSet restant = u.getImageOf(AtomSetUtils.minus(q.getAtomSet(), u.getPiece()));
MarkedQuery rew = null;
InMemoryAtomSet res = AtomSetUtils.union(ajout, restant);
List<Term> ansVar = new LinkedList<Term>();
ansVar.addAll(q.getAnswerVariables());
rew = new MarkedQuery(res, ansVar);
ArrayList<Atom> markedAtoms = new ArrayList<Atom>();
CloseableIteratorWithoutException<Atom> it = ajout.iterator();
while (it.hasNext()) {
Atom a = it.next();
markedAtoms.add(a);
}
rew.setMarkedAtom(markedAtoms);
return rew;
}
use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.
the class Utils method getSafeCopy.
public static InMemoryAtomSet getSafeCopy(InMemoryAtomSet atomSet) {
Substitution substitution = new TreeMapSubstitution();
for (Variable t : atomSet.getVariables()) {
substitution.put(t, varGen.getFreshSymbol());
}
InMemoryAtomSet safe = new LinkedListAtomSet();
substitution.apply(atomSet, safe);
return safe;
}
use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.
the class Utils method computeCover.
/**
* Remove the fact that are not the most general (taking account of compiled
* rules) in the given facts
*
* @param comp
*/
public static void computeCover(Iterable<ConjunctiveQuery> set, RulesCompilation comp) {
Iterator<ConjunctiveQuery> beg = set.iterator();
Iterator<ConjunctiveQuery> end;
InMemoryAtomSet q;
InMemoryAtomSet o;
boolean finished;
while (beg.hasNext()) {
q = beg.next().getAtomSet();
finished = false;
end = set.iterator();
while (!finished && end.hasNext()) {
o = end.next().getAtomSet();
if (o != q && isMoreGeneralThan(o, q, comp)) {
finished = true;
beg.remove();
}
}
}
}
use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.
the class AbstractSubstitution method createImageOf.
@Override
public InMemoryAtomSet createImageOf(AtomSet src) throws AtomSetException {
InMemoryAtomSet dest = DefaultAtomSetFactory.instance().create();
this.apply(src, dest);
return dest;
}
Aggregations