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));
}
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();
}
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;
}
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;
}
}
Aggregations