Search in sources :

Example 1 with ListComparator

use of fr.lirmm.graphik.util.collections.ListComparator 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)

Aggregations

InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)1 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)1 Term (fr.lirmm.graphik.graal.api.core.Term)1 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)1 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)1 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)1 ListComparator (fr.lirmm.graphik.util.collections.ListComparator)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1