use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class UnifierTest method example35MelanieThesis.
@Test
public void example35MelanieThesis() {
Rule rule = DefaultRuleFactory.instance().create();
rule.getBody().add(TestUtils.pXY);
rule.getHead().add(TestUtils.qXY);
InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
atomset.add(TestUtils.qUV);
atomset.add(TestUtils.pVW);
atomset.add(TestUtils.qTW);
CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
Assert.assertEquals(2, Iterators.count(unifiers));
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class UnifierTest method unificationExistentialWithFrontier.
@Test
public void unificationExistentialWithFrontier() {
Rule rule = DefaultRuleFactory.instance().create();
rule.getBody().add(TestUtils.sX);
rule.getHead().add(TestUtils.pXY);
InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
atomset.add(TestUtils.pUU);
CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
Assert.assertEquals(0, Iterators.count(unifiers));
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class UnifierTest method pieceUnifierTest2.
@Test
public void pieceUnifierTest2() {
Rule rule = DefaultRuleFactory.instance().create();
rule.getBody().add(TestUtils.sX);
rule.getHead().add(TestUtils.pXB);
InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
atomset.add(TestUtils.pAU);
CloseableIteratorWithoutException<Substitution> unifiers = DefaultUnifierAlgorithm.instance().computePieceUnifier(rule, atomset);
Assert.assertEquals(1, Iterators.count(unifiers));
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class IDCompilationTest method test3.
/**
* Given p(X,Y) -> q(X,Y,X,Y,X) <br>
* Then rew(q(U,V,A,B,V)) <br>
* Return q(U,V,A,B,V)-{}
*/
@Test
public void test3() {
Predicate predicateQ = new Predicate("q", 5);
Predicate predicateP = new Predicate("p", 2);
Atom body = new DefaultAtom(predicateP, X, Y);
Atom head = new DefaultAtom(predicateQ, X, Y, X, Y, X);
Atom query = new DefaultAtom(predicateQ, U, V, A, B, V);
RuleSet rules = new LinkedListRuleSet();
rules.add(DefaultRuleFactory.instance().create(body, head));
RulesCompilation comp = new IDCompilation();
comp.compile(rules.iterator());
Collection<Pair<Atom, Substitution>> rewritingOf = comp.getRewritingOf(query);
Assert.assertEquals(1, rewritingOf.size());
Pair<Atom, Substitution> p = rewritingOf.iterator().next();
Atom a = p.getLeft();
Substitution s = p.getRight();
Assert.assertEquals(predicateQ, a.getPredicate());
Assert.assertEquals(U, a.getTerm(0));
Assert.assertEquals(V, a.getTerm(1));
Assert.assertEquals(A, a.getTerm(2));
Assert.assertEquals(B, a.getTerm(3));
Assert.assertEquals(V, a.getTerm(4));
Assert.assertEquals(0, s.getTerms().size());
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class IDCompilationTest method test2.
/**
* Given p(X,Y) -> q(X,Y,X) <br>
* Then rew(q(U,U,U)) <br>
* Return q(U,U,U)-{} AND p(U,U)-{})
*/
@Test
public void test2() {
Predicate predicateQ = new Predicate("q", 3);
Predicate predicateP = new Predicate("p", 2);
Atom body = new DefaultAtom(predicateP, X, Y);
Atom head = new DefaultAtom(predicateQ, X, Y, X);
Atom query = new DefaultAtom(predicateQ, U, U, U);
RuleSet rules = new LinkedListRuleSet();
rules.add(DefaultRuleFactory.instance().create(body, head));
RulesCompilation comp = new IDCompilation();
comp.compile(rules.iterator());
Collection<Pair<Atom, Substitution>> rewritingOf = comp.getRewritingOf(query);
boolean rew1 = false;
boolean rew2 = false;
for (Pair<Atom, Substitution> p : rewritingOf) {
Atom a = p.getLeft();
Substitution s = p.getRight();
if (a.getPredicate().equals(predicateQ)) {
rew1 = true;
Assert.assertEquals(U, a.getTerm(0));
Assert.assertEquals(U, a.getTerm(1));
Assert.assertEquals(U, a.getTerm(2));
Assert.assertEquals(0, s.getTerms().size());
} else {
rew2 = true;
Assert.assertEquals(predicateP, a.getPredicate());
Assert.assertEquals(U, a.getTerm(0));
Assert.assertEquals(U, a.getTerm(1));
Assert.assertEquals(0, s.getTerms().size());
}
}
Assert.assertTrue(rew1 && rew2);
Assert.assertEquals(2, rewritingOf.size());
}
Aggregations