Search in sources :

Example 21 with LinkedListAtomSet

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;
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) Term(fr.lirmm.graphik.graal.api.core.Term) LinkedList(java.util.LinkedList) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 22 with LinkedListAtomSet

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;
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 23 with LinkedListAtomSet

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);
    }
}
Also used : HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) SqlHomomorphism(fr.lirmm.graphik.graal.store.rdbms.homomorphism.SqlHomomorphism) SubstitutionIterator2AtomIterator(fr.lirmm.graphik.graal.core.stream.SubstitutionIterator2AtomIterator) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)

Example 24 with LinkedListAtomSet

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);
    }
}
Also used : HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) SqlHomomorphism(fr.lirmm.graphik.graal.store.rdbms.homomorphism.SqlHomomorphism) Term(fr.lirmm.graphik.graal.api.core.Term) SubstitutionIterator2AtomIterator(fr.lirmm.graphik.graal.core.stream.SubstitutionIterator2AtomIterator) LinkedList(java.util.LinkedList) Atom(fr.lirmm.graphik.graal.api.core.Atom) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)

Example 25 with LinkedListAtomSet

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();
}
Also used : RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) RulesCompilation(fr.lirmm.graphik.graal.api.core.RulesCompilation) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) HomomorphismWithCompilation(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismWithCompilation) Theory(org.junit.experimental.theories.Theory)

Aggregations

LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)52 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)35 Atom (fr.lirmm.graphik.graal.api.core.Atom)28 LinkedList (java.util.LinkedList)19 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)18 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)17 Term (fr.lirmm.graphik.graal.api.core.Term)17 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)11 Theory (org.junit.experimental.theories.Theory)11 DefaultConjunctiveQuery (fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery)9 Test (org.junit.Test)9 Variable (fr.lirmm.graphik.graal.api.core.Variable)8 DefaultConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts)8 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)7 Rule (fr.lirmm.graphik.graal.api.core.Rule)6 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)5 SubstitutionIterator2AtomIterator (fr.lirmm.graphik.graal.core.stream.SubstitutionIterator2AtomIterator)5 SqlHomomorphism (fr.lirmm.graphik.graal.store.rdbms.homomorphism.SqlHomomorphism)5 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)4 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)4