use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet 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.core.atomset.LinkedListAtomSet 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;
}
use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.
the class AdHocRdbmsStore method match.
@Override
public CloseableIterator<Atom> match(Atom atom) throws AtomSetException {
ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(new LinkedListAtomSet(atom));
SqlHomomorphism solver = SqlHomomorphism.instance();
try {
return new SubstitutionIterator2AtomIterator(atom, solver.execute(query, this));
} catch (HomomorphismException e) {
throw new AtomSetException(e);
}
}
use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.
the class AdHocRdbmsStore method atomsByPredicate.
@Override
public CloseableIterator<Atom> atomsByPredicate(Predicate p) throws AtomSetException {
List<Term> terms = new LinkedList<Term>();
for (int i = 0; i < p.getArity(); ++i) {
terms.add(DefaultTermFactory.instance().createVariable("X" + i));
}
Atom atom = DefaultAtomFactory.instance().create(p, terms);
ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(new LinkedListAtomSet(atom));
SqlHomomorphism solver = SqlHomomorphism.instance();
try {
return new SubstitutionIterator2AtomIterator(atom, solver.execute(query, this));
} catch (HomomorphismException e) {
throw new AtomSetException(e);
}
}
use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.
the class ConjunctiveQueryWithCompilation method issue34.
@Theory
public void issue34(Homomorphism<ConjunctiveQuery, AtomSet> hh, RulesCompilationFactory factory, AtomSet store) throws Exception {
Assume.assumeTrue(hh instanceof HomomorphismWithCompilation);
HomomorphismWithCompilation<ConjunctiveQuery, AtomSet> h = (HomomorphismWithCompilation<ConjunctiveQuery, AtomSet>) hh;
store.add(DlgpParser.parseAtom("<Q>(a,b)."));
RuleSet rules = new LinkedListRuleSet();
rules.add(DlgpParser.parseRule("<P>(X,Y) :- <Q>(Y,X)."));
RulesCompilation comp = factory.create();
comp.compile(rules.iterator());
StaticChase.executeChase(store, rules);
InMemoryAtomSet query1 = new LinkedListAtomSet();
query1.add(DlgpParser.parseAtom("<P>(a,Y)."));
CloseableIterator<Substitution> results = h.execute(new DefaultConjunctiveQuery(query1), store, comp);
Assert.assertFalse(results.hasNext());
results.close();
}
Aggregations