use of fr.lirmm.graphik.graal.core.HashMapSubstitution in project graal by graphik-team.
the class RestrictedProductivityCheckerTest method testIsValidDependency.
/**
* Test method for {@link fr.lirmm.graphik.graal.core.unifier.checker.RestrictedProductivityChecker#isValidDependency(fr.lirmm.graphik.graal.api.core.Rule, fr.lirmm.graphik.graal.api.core.Rule, fr.lirmm.graphik.graal.api.core.Substitution)}.
* @throws ParseException
*/
@Test
public void testIsValidDependency() throws ParseException {
// given
Rule r1 = DlgpParser.parseRule("p(U,W) :- p(U,V), p(V,W).");
Rule r2 = DlgpParser.parseRule("p(X,Z) :- p(X,Y), p(Y,Z).");
Substitution s = new HashMapSubstitution();
s.put(TestUtils.X, TestUtils.U);
s.put(TestUtils.Y, TestUtils.W);
// when
boolean validDependency = RestrictedProductivityChecker.instance().isValidDependency(r1, r2, s);
// then
Assert.assertTrue(validDependency);
}
use of fr.lirmm.graphik.graal.core.HashMapSubstitution in project graal by graphik-team.
the class BacktrackIterator method solutionFound.
private Substitution solutionFound(List<Term> ans) {
Substitution s = new HashMapSubstitution();
for (Term t : ans) {
if (t instanceof Variable) {
Integer idx = this.data.index.get((Variable) t);
Var v = this.vars[idx];
s.put(v.shared.value, v.image);
}
}
return s;
}
use of fr.lirmm.graphik.graal.core.HashMapSubstitution in project graal by graphik-team.
the class RecursiveBacktrackHomomorphism method exist.
@Override
public boolean exist(ConjunctiveQuery query, AtomSet data) throws HomomorphismException {
try {
InMemoryAtomSet atomSet1 = query.getAtomSet();
List<Variable> orderedVars = order(atomSet1.getVariables());
Collection<Atom>[] queryAtomRanked = getAtomRank(atomSet1, orderedVars);
if (isHomomorphism(queryAtomRanked[0], data, new HashMapSubstitution())) {
return existHomomorphism(atomSet1, queryAtomRanked, data, new HashMapSubstitution(), orderedVars, 1);
} else {
return false;
}
} catch (Exception e) {
throw new HomomorphismException(e.getMessage(), e);
}
}
use of fr.lirmm.graphik.graal.core.HashMapSubstitution in project graal by graphik-team.
the class GRDTest method test.
@Test
public void test() throws ParseException {
Rule r1 = DlgpParser.parseRule("wf(X0,Y0), o(Y0) :- e(X0).");
Rule r2 = DlgpParser.parseRule("e(X1), wf(X1,Y1) :- o(Y1).");
Substitution s = new HashMapSubstitution();
s.put(DefaultTermFactory.instance().createVariable("Y1"), DefaultTermFactory.instance().createVariable("Y0"));
RestrictedProductivityChecker filter = RestrictedProductivityChecker.instance();
Assert.assertFalse(filter.isValidDependency(r1, r2, s));
}
Aggregations