use of fr.lirmm.graphik.graal.api.core.RulesCompilation in project graal by graphik-team.
the class ConjunctiveQueryWithCompilation method test2.
@Theory
public void test2(Homomorphism<ConjunctiveQuery, AtomSet> hh, RulesCompilationFactory factory, AtomSet store) throws Exception {
Assume.assumeTrue(hh instanceof HomomorphismWithCompilation);
HomomorphismWithCompilation<ConjunctiveQuery, AtomSet> h = (HomomorphismWithCompilation<ConjunctiveQuery, AtomSet>) hh;
store.add(DlgpParser.parseAtom("<P>(a,b)."));
RuleSet rules = new LinkedListRuleSet();
rules.add(DlgpParser.parseRule("<Q>(X,Y) :- <P>(Y,X)."));
RulesCompilation comp = factory.create();
comp.compile(rules.iterator());
StaticChase.executeChase(store, rules);
CloseableIterator<Substitution> results = h.execute(DlgpParser.parseQuery("?(X,Y) :- <Q>(X,Y)."), store, comp);
Assert.assertTrue(results.hasNext());
Substitution next = results.next();
Assert.assertEquals(DefaultTermFactory.instance().createConstant("a"), next.createImageOf(DefaultTermFactory.instance().createVariable("Y")));
Assert.assertEquals(DefaultTermFactory.instance().createConstant("b"), next.createImageOf(DefaultTermFactory.instance().createVariable("X")));
Assert.assertFalse(results.hasNext());
results.close();
}
use of fr.lirmm.graphik.graal.api.core.RulesCompilation in project graal by graphik-team.
the class ConjunctiveQueryWithCompilation method issue34.
@Theory
public void issue34(Homomorphism<ConjunctiveQuery, AtomSet> hh, RulesCompilationFactory factory, AtomSet store) throws Exception {
Assume.assumeTrue(hh instanceof HomomorphismWithCompilation);
HomomorphismWithCompilation<ConjunctiveQuery, AtomSet> h = (HomomorphismWithCompilation<ConjunctiveQuery, AtomSet>) hh;
store.add(DlgpParser.parseAtom("<Q>(a,b)."));
RuleSet rules = new LinkedListRuleSet();
rules.add(DlgpParser.parseRule("<P>(X,Y) :- <Q>(Y,X)."));
RulesCompilation comp = factory.create();
comp.compile(rules.iterator());
StaticChase.executeChase(store, rules);
InMemoryAtomSet query1 = new LinkedListAtomSet();
query1.add(DlgpParser.parseAtom("<P>(a,Y)."));
CloseableIterator<Substitution> results = h.execute(new DefaultConjunctiveQuery(query1), store, comp);
Assert.assertFalse(results.hasNext());
results.close();
}
use of fr.lirmm.graphik.graal.api.core.RulesCompilation in project graal by graphik-team.
the class ConjunctiveQueryWithCompilation method issue35.
@Theory
public void issue35(Homomorphism<ConjunctiveQuery, AtomSet> hh, RulesCompilationFactory factory, AtomSet store) throws Exception {
Assume.assumeFalse(store instanceof TripleStore);
Assume.assumeTrue(hh instanceof HomomorphismWithCompilation);
HomomorphismWithCompilation<ConjunctiveQuery, AtomSet> h = (HomomorphismWithCompilation<ConjunctiveQuery, AtomSet>) hh;
store.addAll(DlgpParser.parseAtomSet("<P>(a,a), <R>(a,b,b)."));
RuleSet rules = new LinkedListRuleSet();
rules.add(DlgpParser.parseRule("<Q>(X,Y,X) :- <P>(X,Y)."));
ConjunctiveQuery query = DlgpParser.parseQuery("? :- <Q>(X,Y,Y), <R>(X,Y,Z).");
RulesCompilation comp = factory.create();
comp.compile(rules.iterator());
StaticChase.executeChase(store, rules);
CloseableIterator<Substitution> results = h.execute(new DefaultConjunctiveQuery(query), store, comp);
Assert.assertFalse(results.hasNext());
results.close();
}
Aggregations