use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.
the class AbstractMapper method map.
@Override
public InMemoryAtomSet map(InMemoryAtomSet atomset) {
InMemoryAtomSet mapped;
try {
mapped = atomset.getClass().newInstance();
} catch (InstantiationException e) {
mapped = new LinkedListAtomSet();
} catch (IllegalAccessException e) {
mapped = new LinkedListAtomSet();
}
CloseableIteratorWithoutException<Atom> it = atomset.iterator();
while (it.hasNext()) {
mapped.add(this.map(it.next()));
}
it.close();
return mapped;
}
use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.
the class AtomErasingChecker method isValidDependency.
// /////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean isValidDependency(Rule rule, InMemoryAtomSet query, Substitution s) {
InMemoryAtomSet b1 = s.createImageOf(rule.getBody());
InMemoryAtomSet b2 = s.createImageOf(query);
return !AtomSetUtils.contains(b1, b2);
}
use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.
the class UnifierUtils method extend.
// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
private static Collection<? extends QueryUnifier> extend(InMemoryAtomSet p, Partition<Term> unif, HashMap<Atom, LinkedList<Partition<Term>>> possibleUnification, ConjunctiveQuery q, Rule r) {
LinkedList<QueryUnifier> u = new LinkedList<QueryUnifier>();
// compute separating variable
LinkedList<Term> sep = AtomSetUtils.sep(p, q.getAtomSet());
// compute sticky variable
LinkedList<Term> sticky = TermPartitionUtils.getStickyVariable(unif, sep, r);
if (sticky.isEmpty()) {
u.add(new QueryUnifier(p, unif, r, q));
} else {
// compute Pext the atoms of Pbar linked to P by the sticky
// variables
InMemoryAtomSet pBar = AtomSetUtils.minus(q.getAtomSet(), p);
InMemoryAtomSet pExt = new LinkedListAtomSet();
InMemoryAtomSet toRemove = new LinkedListAtomSet();
for (Term t : sticky) {
pBar.removeAll(toRemove);
toRemove.clear();
CloseableIteratorWithoutException<Atom> ib = pBar.iterator();
while (ib.hasNext()) {
Atom b = ib.next();
if (b.getTerms().contains(t)) {
pExt.add(b);
toRemove.add(b);
}
}
}
Partition<Term> part;
for (Partition<Term> uExt : preUnifier(pExt, r, possibleUnification)) {
part = unif.join(uExt);
if (part != null && TermPartitionUtils.isAdmissible(part, r)) {
u.addAll(extend(AtomSetUtils.union(p, pExt), part, possibleUnification, q, r));
}
}
}
return u;
}
use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.
the class DefaultAtomSetFactory method create.
@Override
public InMemoryAtomSet create(AtomSet src) throws IteratorException {
InMemoryAtomSet atomset = this.create();
CloseableIterator<Atom> it = src.iterator();
while (it.hasNext()) {
Atom a = it.next();
atomset.add(a);
}
return atomset;
}
use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.
the class AbstractRulesCompilation method getIrredondant.
@Override
public InMemoryAtomSet getIrredondant(InMemoryAtomSet atomSet) {
InMemoryAtomSet irr = new LinkedListAtomSet(atomSet);
CloseableIteratorWithoutException<Atom> i = irr.iterator();
CloseableIteratorWithoutException<Atom> j;
InMemoryAtomSet toRemove = new LinkedListAtomSet();
Atom origin;
Atom target;
boolean isSubsumed;
while (i.hasNext()) {
target = i.next();
j = irr.iterator();
isSubsumed = false;
while (j.hasNext() && !isSubsumed) {
origin = j.next();
if (target != origin && !toRemove.contains(origin) && this.isImplied(target, origin)) {
isSubsumed = true;
toRemove.add(target);
}
}
}
irr.removeAll(toRemove);
return irr;
}
Aggregations