use of fr.lirmm.graphik.graal.api.core.RuleSet 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.api.core.RuleSet in project graal by graphik-team.
the class RdbmsStoreTest method SQLRuleApplierTest.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Theory
public void SQLRuleApplierTest(RdbmsStore store) throws AtomSetException, IteratorException, ParseException {
RuleSet ruleSet = new LinkedListRuleSet();
ruleSet.add(DlgpParser.parseRule("<Q>(X,Y) :- <P>(X)."));
ruleSet.add(DlgpParser.parseRule("<R>(Y) :- <Q>(X,Y)."));
Atom a = DlgpParser.parseAtom("<P>(a).");
store.add(a);
Chase chase = new BasicChase<RdbmsStore>(ruleSet, store, new SQLRuleApplier(SqlHomomorphism.instance()));
try {
chase.execute();
} catch (ChaseException e) {
Assert.fail(e.getMessage());
}
CloseableIterator<Atom> it = store.iterator();
int count = Iterators.count(it);
Assert.assertEquals(3, count);
}
use of fr.lirmm.graphik.graal.api.core.RuleSet in project graal by graphik-team.
the class ChaseTest method test2.
// @Theory
// public void coreChaseTest(AtomSet atomSet) throws AtomSetException,
// HomomorphismFactoryException,
// HomomorphismException, ChaseException {
// atomSet.addAll(DlgpParser.parseAtomSet("e(X,Y), e(Y,X)."));
//
// LinkedList<Rule> ruleSet = new LinkedList<Rule>();
// ruleSet.add(DlgpParser.parseRule("e(Z,Z) :- e(X,Y), e(Y,X)."));
// ruleSet.add(DlgpParser.parseRule("e(X,Z), e(Z,Y) :- e(X,Y)."));
//
// Chase chase = new DefaultChase(ruleSet, atomSet,
// RecursiveBacktrackHomomorphism.instance(),
// new CoreChaseStopCondition());
// chase.execute();
//
// int size = 0;
// for (Iterator<Atom> it = atomSet.iterator(); it.hasNext(); it.next()) {
// if (++size > 3)
// Assert.assertFalse(true);
// }
//
// Assert.assertTrue(true);
// }
//
// @Theory
// public void coreChaseTest2(AtomSet atomSet) throws AtomSetException,
// HomomorphismFactoryException,
// HomomorphismException, ChaseException {
// atomSet.addAll(DlgpParser.parseAtomSet("e(X,Y), e(Y,Z)."));
//
// LinkedList<Rule> ruleSet = new LinkedList<Rule>();
// ruleSet.add(DlgpParser.parseRule("e(X,Z) :- e(X,Y), e(Y,Z)."));
//
// Chase chase = new DefaultChase(ruleSet, atomSet,
// RecursiveBacktrackHomomorphism.instance(),
// new CoreChaseStopCondition());
// chase.execute();
//
// ConjunctiveQuery query = DlgpParser.parseQuery("? :-
// e(X,Y),e(Y,Z),e(X,Z).");
// Assert.assertTrue(StaticHomomorphism.instance().execute(query,
// atomSet).hasNext());
// }
@Theory
public void test2(InMemoryAtomSet atomSet) throws ChaseException, HomomorphismFactoryException, HomomorphismException, IteratorException, ParseException {
// add assertions into this atom set
atomSet.add(DlgpParser.parseAtom("<P>(a,a)."));
atomSet.add(DlgpParser.parseAtom("<P>(c,c)."));
atomSet.add(DlgpParser.parseAtom("<Q>(b,b)."));
atomSet.add(DlgpParser.parseAtom("<Q>(c,c)."));
atomSet.add(DlgpParser.parseAtom("<S>(z,z)."));
// /////////////////////////////////////////////////////////////////////
// create a rule set
RuleSet ruleSet = new LinkedListRuleSet();
// add a rule into this rule set
ruleSet.add(DlgpParser.parseRule("<R>(X,X) :- <P>(X,X), <Q>(X,X)."));
ruleSet.add(DlgpParser.parseRule("<S>(X, Y) :- <P>(X,X), <Q>(Y,Y)."));
// /////////////////////////////////////////////////////////////////////
// run saturation
StaticChase.executeChase(atomSet, ruleSet);
// /////////////////////////////////////////////////////////////////////
// execute query
ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y) :- <S>(X, Y), <P>(X,X), <Q>(Y,Y).");
CloseableIterator<Substitution> subReader = SmartHomomorphism.instance().execute(query, atomSet);
Assert.assertTrue(subReader.hasNext());
}
use of fr.lirmm.graphik.graal.api.core.RuleSet in project graal by graphik-team.
the class ConjunctiveQueryWithCompilation method backtrackHomomorphismBootstrapperTest2.
@Theory
public void backtrackHomomorphismBootstrapperTest2(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>(b,a)."));
RuleSet rules = new LinkedListRuleSet();
rules.add(DlgpParser.parseRule("<Q>(X,Y) :- <P>(X,Y)."));
RulesCompilation comp = factory.create();
comp.compile(rules.iterator());
StaticChase.executeChase(store, rules);
ConjunctiveQuery query = DlgpParser.parseQuery("?(X) :- <Q>(X,a).");
CloseableIterator<Substitution> subReader;
Substitution sub;
subReader = h.execute(query, store, comp);
Assert.assertTrue(subReader.hasNext());
sub = subReader.next();
Assert.assertEquals(DefaultTermFactory.instance().createConstant("b"), sub.createImageOf(DefaultTermFactory.instance().createVariable("X")));
Assert.assertFalse(subReader.hasNext());
subReader.close();
}
use of fr.lirmm.graphik.graal.api.core.RuleSet in project graal by graphik-team.
the class ConjunctiveQueryWithCompilation method backtrackHomomorphismBootstrapperTest1.
@Theory
public void backtrackHomomorphismBootstrapperTest1(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>(b,a)."));
RuleSet rules = new LinkedListRuleSet();
rules.add(DlgpParser.parseRule("<Q>(X,Y) :- <P>(X,Y)."));
RulesCompilation comp = factory.create();
comp.compile(rules.iterator());
StaticChase.executeChase(store, rules);
ConjunctiveQuery query = DlgpParser.parseQuery("?(X) :- <Q>(b,X).");
CloseableIterator<Substitution> subReader;
Substitution sub;
subReader = h.execute(query, store, comp);
Assert.assertTrue(subReader.hasNext());
sub = subReader.next();
Assert.assertEquals(DefaultTermFactory.instance().createConstant("a"), sub.createImageOf(DefaultTermFactory.instance().createVariable("X")));
Assert.assertFalse(subReader.hasNext());
subReader.close();
}
Aggregations