use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class IDConditionTest method homomorphismIssue35Test.
/**
* Given an IDCondition[(x,y) -> (x,y,x)] then homomorphism([u,v,w], [a,b])
* return (u->a, v->b, w->a)
*/
@Test
public void homomorphismIssue35Test() {
// Assume.assumeTrue(false); // FIXMEÂ #35
Term[] body = { X, Y };
Term[] head = { X, Y, X };
IDCondition cond = createCondition(body, head);
Term[] query = { U, V, W };
Term[] data = { A, B };
Substitution h = cond.homomorphism(Arrays.asList(query), Arrays.asList(data));
Assert.assertEquals(A, h.createImageOf(U));
Assert.assertEquals(B, h.createImageOf(V));
Assert.assertEquals(A, h.createImageOf(W));
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class IDConditionTest method homomorphismFailTest1.
/**
* Given an IDCondition[(x,y) -> (x,y)] then homomorphism([x,x], [a,b])
* return null
*/
@Test
public void homomorphismFailTest1() {
Term[] body = { X, Y };
Term[] head = { X, Y };
IDCondition cond = createCondition(body, head);
Term[] query = { U, U };
Term[] data = { A, B };
Substitution h = cond.homomorphism(Arrays.asList(query), Arrays.asList(data));
Assert.assertNull(h);
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class IDConditionTest method generateBodyTest5.
/**
* h(X,Y,X,Y) :- b(X,Y).
*
* generateBody([a,b,X,Y]) => [a, b].
*/
@Test
public void generateBodyTest5() {
Term[] body1 = { X, Y };
Term[] head1 = { X, Y, X, Y };
IDCondition cond = createCondition(body1, head1);
Term[] head = { A, B, X, Y };
Term[] expected = { A, B };
Pair<List<Term>, Substitution> ret = cond.generateBody(Arrays.asList(head));
List<Term> computed = ret.getLeft();
Substitution s = ret.getRight();
Assert.assertEquals(Arrays.asList(expected), computed);
Assert.assertEquals(A, s.createImageOf(X));
Assert.assertEquals(B, s.createImageOf(Y));
Assert.assertEquals(2, s.getTerms().size());
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class AbstractHomomorphism method exist.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean exist(T1 q, T2 a) throws HomomorphismException {
CloseableIterator<Substitution> results = this.execute(q, a);
boolean val;
try {
val = results.hasNext();
} catch (IteratorException e) {
throw new HomomorphismException(e);
}
results.close();
return val;
}
use of fr.lirmm.graphik.graal.api.core.Substitution in project graal by graphik-team.
the class FrontierRestrictedChaseHaltingConditionTest method test.
@Test
public void test() throws IteratorException, HomomorphismFactoryException, HomomorphismException {
InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create(DlgpParser.parseAtom("p(a,b)."));
Rule rule = DlgpParser.parseRule("p(X,Z):-p(X,Y).");
Variable x = DefaultTermFactory.instance().createVariable("X");
Variable y = DefaultTermFactory.instance().createVariable("Y");
Constant a = DefaultTermFactory.instance().createConstant("a");
Constant b = DefaultTermFactory.instance().createConstant("b");
Substitution s = DefaultSubstitutionFactory.instance().createSubstitution();
s.put(x, a);
s.put(y, b);
FrontierRestrictedChaseHaltingCondition condition = new FrontierRestrictedChaseHaltingCondition();
CloseableIterator<Atom> toAdd = condition.apply(rule, s, atomset);
Assert.assertTrue(toAdd.hasNext());
Atom atom1 = toAdd.next();
atomset.add(atom1);
Assert.assertFalse(toAdd.hasNext());
toAdd.close();
s = DefaultSubstitutionFactory.instance().createSubstitution();
s.put(x, a);
s.put(y, atom1.getTerm(1));
toAdd = condition.apply(rule, s, atomset);
Assert.assertFalse(toAdd.hasNext());
toAdd.close();
}
Aggregations