Search in sources :

Example 1 with IDCompilation

use of fr.lirmm.graphik.graal.core.compilation.IDCompilation in project graal by graphik-team.

the class PureHomomorphismTest method issue34.

@Theory
public void issue34(ExistentialHomomorphismWithCompilation<InMemoryAtomSet, AtomSet> h) throws HomomorphismException, IteratorException, ParseException {
    InMemoryAtomSet query1 = new LinkedListAtomSet();
    query1.add(DlgpParser.parseAtom("p(a,Y)."));
    InMemoryAtomSet facts = new LinkedListAtomSet();
    facts.add(DlgpParser.parseAtom("q(a,b)."));
    RuleSet rules = new LinkedListRuleSet();
    rules.add(DlgpParser.parseRule("p(X,Y) :- q(Y,X)."));
    RulesCompilation comp = new IDCompilation();
    comp.compile(rules.iterator());
    Assert.assertFalse(h.exist(query1, facts, comp));
}
Also used : RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) IDCompilation(fr.lirmm.graphik.graal.core.compilation.IDCompilation) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) RulesCompilation(fr.lirmm.graphik.graal.api.core.RulesCompilation) Theory(org.junit.experimental.theories.Theory)

Example 2 with IDCompilation

use of fr.lirmm.graphik.graal.core.compilation.IDCompilation in project graal by graphik-team.

the class HomomorphismTest method test6Compilation.

@Test
public void test6Compilation() throws HomomorphismException, IteratorException, AtomSetException {
    InMemoryAtomSet data = new DefaultInMemoryGraphStore();
    RuleSet rules = new LinkedListRuleSet();
    rules.add(DlgpParser.parseRule("r(X,Y) :- s(X,Y)."));
    RulesCompilation comp = new IDCompilation();
    comp.compile(rules.iterator());
    data.addAll(DlgpParser.parseAtomSet("p(a,b), q(b), p(a,c), s(a,d), q(d), s(a,e)."));
    Variable y = DefaultTermFactory.instance().createVariable("Y");
    Variable z = DefaultTermFactory.instance().createVariable("Z");
    InMemoryAtomSet positivePart = new LinkedListAtomSet();
    positivePart.addAll(DlgpParser.parseAtomSet("p(X,Y),r(X,Z)."));
    CloseableIteratorWithoutException<Atom> it = positivePart.iterator();
    it.next().setTerm(1, y);
    it.next().setTerm(1, z);
    LinkedList<InMemoryAtomSet> parts = new LinkedList<InMemoryAtomSet>();
    InMemoryAtomSet negatedPart = new LinkedListAtomSet();
    negatedPart.addAll(DlgpParser.parseAtomSet("q(Y)."));
    negatedPart.iterator().next().setTerm(0, y);
    parts.add(negatedPart);
    negatedPart = new LinkedListAtomSet();
    negatedPart.addAll(DlgpParser.parseAtomSet("q(Z)."));
    negatedPart.iterator().next().setTerm(0, z);
    parts.add(negatedPart);
    DefaultConjunctiveQueryWithNegatedParts query = new DefaultConjunctiveQueryWithNegatedParts(positivePart, parts);
    BacktrackHomomorphismWithNegatedParts h = new BacktrackHomomorphismWithNegatedParts();
    CloseableIterator<Substitution> res = h.execute(query, data, comp);
    Assert.assertTrue(res.hasNext());
    res.next();
    Assert.assertFalse(res.hasNext());
    res.close();
}
Also used : RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) Variable(fr.lirmm.graphik.graal.api.core.Variable) IDCompilation(fr.lirmm.graphik.graal.core.compilation.IDCompilation) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) Atom(fr.lirmm.graphik.graal.api.core.Atom) LinkedList(java.util.LinkedList) DefaultConjunctiveQueryWithNegatedParts(fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) RulesCompilation(fr.lirmm.graphik.graal.api.core.RulesCompilation) Test(org.junit.Test)

Example 3 with IDCompilation

use of fr.lirmm.graphik.graal.core.compilation.IDCompilation in project graal by graphik-team.

the class PureRewriter method execute.

// /////////////////////////////////////////////////////////////////////////
// METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public CloseableIteratorWithoutException<ConjunctiveQuery> execute(ConjunctiveQuery query, Iterable<Rule> rules) {
    RuleSet newRulSet = new LinkedListRuleSet(rules);
    RulesCompilation compilation = new IDCompilation();
    compilation.compile(newRulSet.iterator());
    RewritinCloseableIterator it = new RewritinCloseableIterator(true, query, newRulSet, compilation, this.operator);
    it.setProfiler(this.getProfiler());
    return it;
}
Also used : RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) IDCompilation(fr.lirmm.graphik.graal.core.compilation.IDCompilation) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) RulesCompilation(fr.lirmm.graphik.graal.api.core.RulesCompilation)

Example 4 with IDCompilation

use of fr.lirmm.graphik.graal.core.compilation.IDCompilation in project graal by graphik-team.

the class DefaultKnowledgeBase method compileRule.

protected void compileRule() {
    if (!this.isCompiled) {
        this.ruleCompilation = new IDCompilation();
        this.ruleCompilation.compile(this.getFUSRuleSet().iterator());
        this.isCompiled = true;
    }
}
Also used : IDCompilation(fr.lirmm.graphik.graal.core.compilation.IDCompilation)

Aggregations

IDCompilation (fr.lirmm.graphik.graal.core.compilation.IDCompilation)4 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)3 RulesCompilation (fr.lirmm.graphik.graal.api.core.RulesCompilation)3 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)3 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)2 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)2 Atom (fr.lirmm.graphik.graal.api.core.Atom)1 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)1 Variable (fr.lirmm.graphik.graal.api.core.Variable)1 DefaultConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts)1 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 Theory (org.junit.experimental.theories.Theory)1