Search in sources :

Example 91 with InMemoryAtomSet

use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.

the class UnifierUtils method getSafeCopy.

public static Rule getSafeCopy(Rule rule) {
    Substitution substitution = new FreshVarSubstitution(varGen);
    InMemoryAtomSet body = rule.getBody();
    InMemoryAtomSet head = rule.getHead();
    InMemoryAtomSet safeBody = new LinkedListAtomSet();
    InMemoryAtomSet safeHead = new LinkedListAtomSet();
    substitution.apply(body, safeBody);
    substitution.apply(head, safeHead);
    return DefaultRuleFactory.instance().create(safeBody, safeHead);
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) FreshVarSubstitution(fr.lirmm.graphik.graal.core.FreshVarSubstitution) FreshVarSubstitution(fr.lirmm.graphik.graal.core.FreshVarSubstitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)

Example 92 with InMemoryAtomSet

use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet 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 93 with InMemoryAtomSet

use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet 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 94 with InMemoryAtomSet

use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.

the class DefaultRuleFactory method create.

@Override
public Rule create(Atom[] body, Atom[] head) {
    InMemoryAtomSet bodySet = DefaultAtomSetFactory.instance().create(body);
    InMemoryAtomSet headSet = DefaultAtomSetFactory.instance().create(head);
    return new DefaultRule(bodySet, headSet);
}
Also used : DefaultRule(fr.lirmm.graphik.graal.core.DefaultRule) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)

Example 95 with InMemoryAtomSet

use of fr.lirmm.graphik.graal.api.core.InMemoryAtomSet in project graal by graphik-team.

the class DefaultRuleFactory method create.

@Override
public Rule create(Atom body, Atom head) {
    InMemoryAtomSet bodySet = DefaultAtomSetFactory.instance().create(body);
    InMemoryAtomSet headSet = DefaultAtomSetFactory.instance().create(head);
    return new DefaultRule(bodySet, headSet);
}
Also used : DefaultRule(fr.lirmm.graphik.graal.core.DefaultRule) 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