Search in sources :

Example 46 with InMemoryAtomSet

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;
}
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 47 with InMemoryAtomSet

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

Example 48 with InMemoryAtomSet

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;
}
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 49 with InMemoryAtomSet

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

Example 50 with InMemoryAtomSet

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;
}
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)

Aggregations

InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)122 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)40 Atom (fr.lirmm.graphik.graal.api.core.Atom)38 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)35 Test (org.junit.Test)35 Term (fr.lirmm.graphik.graal.api.core.Term)31 Rule (fr.lirmm.graphik.graal.api.core.Rule)25 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)23 LinkedList (java.util.LinkedList)22 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)21 Variable (fr.lirmm.graphik.graal.api.core.Variable)19 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)10 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)10 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)9 Theory (org.junit.experimental.theories.Theory)9 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)8 DefaultConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts)8 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)8 OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)7 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)6