Search in sources :

Example 26 with InMemoryAtomSet

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

Example 27 with InMemoryAtomSet

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

Example 28 with InMemoryAtomSet

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

Example 29 with InMemoryAtomSet

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

Example 30 with InMemoryAtomSet

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

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