Search in sources :

Example 46 with LinkedListAtomSet

use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.

the class UnifierUtils method preUnifier.

private static LinkedList<Partition<Term>> preUnifier(InMemoryAtomSet p, Rule r, HashMap<Atom, LinkedList<Partition<Term>>> possibleUnification) {
    LinkedList<Partition<Term>> res = new LinkedList<Partition<Term>>();
    CloseableIteratorWithoutException<Atom> it = p.iterator();
    while (it.hasNext()) {
        Atom a = it.next();
        if (possibleUnification.get(a) != null)
            for (Partition<Term> ua : possibleUnification.get(a)) {
                InMemoryAtomSet fa = new LinkedListAtomSet();
                fa.add(a);
                InMemoryAtomSet aBar = null;
                aBar = AtomSetUtils.minus(p, fa);
                if (!aBar.iterator().hasNext())
                    res.add(ua);
                else {
                    Partition<Term> part;
                    for (Partition<Term> u : preUnifier(aBar, r, possibleUnification)) {
                        part = ua.join(u);
                        if (part != null && TermPartitionUtils.isAdmissible(part, r)) {
                            res.add(part);
                        }
                    }
                }
            }
        else
            return res;
    }
    return res;
}
Also used : Partition(fr.lirmm.graphik.util.Partition) 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 47 with LinkedListAtomSet

use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.

the class IDCompilation method getSaturation.

// /////////////////////////////////////////////////////////////////////////
// METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public Iterable<Rule> getSaturation() {
    LinkedListRuleSet saturation = new LinkedListRuleSet();
    Map<Predicate, TreeMap<List<Integer>, InMemoryAtomSet>> newMap = new TreeMap<Predicate, TreeMap<List<Integer>, InMemoryAtomSet>>();
    // p -> q
    Predicate p, q;
    for (Map.Entry<Predicate, TreeMap<Predicate, LinkedList<IDCondition>>> e : this.conditions.entrySet()) {
        q = e.getKey();
        for (Map.Entry<Predicate, LinkedList<IDCondition>> map : e.getValue().entrySet()) {
            p = map.getKey();
            TreeMap<List<Integer>, InMemoryAtomSet> head = newMap.get(p);
            if (head == null) {
                head = new TreeMap<List<Integer>, InMemoryAtomSet>(new ListComparator<Integer>());
                newMap.put(p, head);
            }
            for (IDCondition conditionPQ : map.getValue()) {
                InMemoryAtomSet atomSet = head.get(conditionPQ.getBody());
                if (atomSet == null) {
                    atomSet = new LinkedListAtomSet();
                    head.put(conditionPQ.getBody(), atomSet);
                }
                atomSet.add(new DefaultAtom(q, conditionPQ.generateHead()));
            }
        }
    }
    for (Map.Entry<Predicate, TreeMap<List<Integer>, InMemoryAtomSet>> e1 : newMap.entrySet()) {
        p = e1.getKey();
        for (Map.Entry<List<Integer>, InMemoryAtomSet> e2 : e1.getValue().entrySet()) {
            List<Term> terms = new LinkedList<Term>();
            for (Integer i : e2.getKey()) {
                terms.add(DefaultTermFactory.instance().createVariable("X" + i));
            }
            InMemoryAtomSet body = new LinkedListAtomSet();
            body.add(new DefaultAtom(p, terms));
            saturation.add(DefaultRuleFactory.instance().create(body, e2.getValue()));
        }
    }
    return saturation;
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) ListComparator(fr.lirmm.graphik.util.collections.ListComparator) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) Term(fr.lirmm.graphik.graal.api.core.Term) TreeMap(java.util.TreeMap) LinkedList(java.util.LinkedList) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 48 with LinkedListAtomSet

use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.

the class DefaultConjunctiveQueryFactory method create.

@Override
public ConjunctiveQuery create(Atom atom) {
    LinkedList<Atom> list = new LinkedList<Atom>();
    list.add(atom);
    return new DefaultConjunctiveQuery(new LinkedListAtomSet(list));
}
Also used : DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) Atom(fr.lirmm.graphik.graal.api.core.Atom) LinkedList(java.util.LinkedList)

Example 49 with LinkedListAtomSet

use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.

the class AbstractMapper method unmap.

@Override
public InMemoryAtomSet unmap(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.unmap(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 50 with LinkedListAtomSet

use of fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet in project graal by graphik-team.

the class RestrictedProductivityChecker method isValidDependency.

// /////////////////////////////////////////////////////////////////////////
// 
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean isValidDependency(Rule r1, Rule r2, Substitution s) {
    InMemoryAtomSet b1 = s.createImageOf(r1.getBody());
    InMemoryAtomSet h1 = s.createImageOf(r1.getHead());
    InMemoryAtomSet b2 = s.createImageOf(r2.getBody());
    InMemoryAtomSet h2 = s.createImageOf(r2.getHead());
    InMemoryAtomSet f = new LinkedListAtomSet();
    f.addAll(b1.iterator());
    f.addAll(h1.iterator());
    f.addAll(b2.iterator());
    Set<Variable> fixedVariables = h2.getVariables();
    fixedVariables.retainAll(b2.getVariables());
    try {
        ConjunctiveQueryWithFixedVariables query = new ConjunctiveQueryWithFixedVariables(h2, fixedVariables);
        return !PureHomomorphism.instance().exist(query.getAtomSet(), f);
    } catch (HomomorphismException e) {
        // TODO treat this exception
        e.printStackTrace();
        throw new Error("Untreated exception");
    }
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) ConjunctiveQueryWithFixedVariables(fr.lirmm.graphik.graal.core.ConjunctiveQueryWithFixedVariables)

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