Search in sources :

Example 1 with Predicate

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

the class HierarchicalCompilation method computeIndex.

private void computeIndex(Iterable<Rule> ruleset) {
    for (Rule rule : ruleset) {
        // count the number of new pred in r
        CloseableIteratorWithoutException<Predicate> it = rule.getBody().predicatesIterator();
        while (it.hasNext()) {
            this.addPredicate(it.next());
        }
        it = rule.getHead().predicatesIterator();
        while (it.hasNext()) {
            this.addPredicate(it.next());
        }
    }
    int nbPred = this.indexPredicate.size();
    Atom father, son;
    this.order = new byte[nbPred][nbPred];
    for (Rule ru : ruleset) {
        father = ru.getHead().iterator().next();
        son = ru.getBody().iterator().next();
        this.addRule(father, son);
    }
    // reflexivity
    for (int i = 0; i < this.order.length; ++i) {
        this.order[i][i] = 1;
    }
}
Also used : Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 2 with Predicate

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

the class HierarchicalCompilation method isImplied.

@Override
public boolean isImplied(Atom father, Atom son) {
    Predicate predFather = father.getPredicate();
    Predicate predSon = son.getPredicate();
    Integer f = predicateIndex.get(predFather);
    Integer s = predicateIndex.get(predSon);
    if (f != null && s != null && TermValueComparator.instance().compare(father.getTerms(), son.getTerms()) == 0)
        return order[f][s] == 1;
    else
        return false;
}
Also used : Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 3 with Predicate

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

the class HierarchicalCompilation method addRule.

private void addRule(Atom father, Atom son) {
    Predicate predFather = father.getPredicate();
    Predicate predSon = son.getPredicate();
    Integer f = predicateIndex.get(predFather);
    Integer s = predicateIndex.get(predSon);
    order[f][s] = 1;
    computeTransitiveClosure(f, s);
}
Also used : Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 4 with Predicate

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

the class IDCompilation method getUnification.

@Override
public LinkedList<Partition<Term>> getUnification(Atom father, Atom son) {
    LinkedList<Partition<Term>> res = new LinkedList<Partition<Term>>();
    Predicate predB = son.getPredicate();
    Predicate predH = father.getPredicate();
    List<IDCondition> conds = getConditions(predB, predH);
    for (IDCondition cond : conds) {
        Partition<Term> unif = cond.generateUnification(son.getTerms(), father.getTerms());
        if (unif != null) {
            res.add(unif);
        }
    }
    return res;
}
Also used : Partition(fr.lirmm.graphik.util.Partition) Term(fr.lirmm.graphik.graal.api.core.Term) LinkedList(java.util.LinkedList) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 5 with Predicate

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

the class IDCompilation method homomorphism.

@Override
public LinkedList<Substitution> homomorphism(Atom father, Atom son) {
    LinkedList<Substitution> res = new LinkedList<Substitution>();
    Predicate predB = son.getPredicate();
    Predicate predH = father.getPredicate();
    List<IDCondition> conds = getConditions(predB, predH);
    for (IDCondition cond : conds) {
        if (cond.checkBody(son.getTerms())) {
            Substitution homo = cond.homomorphism(father.getTerms(), son.getTerms());
            if (homo != null) {
                res.add(new TreeMapSubstitution(homo));
            }
        }
    }
    return res;
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) TreeMapSubstitution(fr.lirmm.graphik.graal.core.TreeMapSubstitution) LinkedList(java.util.LinkedList) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) TreeMapSubstitution(fr.lirmm.graphik.graal.core.TreeMapSubstitution)

Aggregations

Predicate (fr.lirmm.graphik.graal.api.core.Predicate)77 Atom (fr.lirmm.graphik.graal.api.core.Atom)35 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)28 Term (fr.lirmm.graphik.graal.api.core.Term)27 Test (org.junit.Test)25 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)16 LinkedList (java.util.LinkedList)16 Theory (org.junit.experimental.theories.Theory)14 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)9 Rule (fr.lirmm.graphik.graal.api.core.Rule)9 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)9 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)7 DefaultURI (fr.lirmm.graphik.util.DefaultURI)7 TreeSet (java.util.TreeSet)7 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)6 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)6 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)6 Variable (fr.lirmm.graphik.graal.api.core.Variable)6 ConversionException (fr.lirmm.graphik.util.stream.converter.ConversionException)6 Pair (org.apache.commons.lang3.tuple.Pair)6