Search in sources :

Example 6 with HashMapSubstitution

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);
}
Also used : HashMapSubstitution(fr.lirmm.graphik.graal.core.HashMapSubstitution) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) Rule(fr.lirmm.graphik.graal.api.core.Rule) HashMapSubstitution(fr.lirmm.graphik.graal.core.HashMapSubstitution) Test(org.junit.Test)

Example 7 with HashMapSubstitution

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;
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) HashMapSubstitution(fr.lirmm.graphik.graal.core.HashMapSubstitution) Term(fr.lirmm.graphik.graal.api.core.Term) HashMapSubstitution(fr.lirmm.graphik.graal.core.HashMapSubstitution)

Example 8 with HashMapSubstitution

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);
    }
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Collection(java.util.Collection) HashMapSubstitution(fr.lirmm.graphik.graal.core.HashMapSubstitution) CloseableIteratorWithoutException(fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException) CloseableIterableWithoutException(fr.lirmm.graphik.util.stream.CloseableIterableWithoutException) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)

Example 9 with HashMapSubstitution

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));
}
Also used : HashMapSubstitution(fr.lirmm.graphik.graal.core.HashMapSubstitution) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) RestrictedProductivityChecker(fr.lirmm.graphik.graal.core.unifier.checker.RestrictedProductivityChecker) Rule(fr.lirmm.graphik.graal.api.core.Rule) HashMapSubstitution(fr.lirmm.graphik.graal.core.HashMapSubstitution) Test(org.junit.Test)

Aggregations

HashMapSubstitution (fr.lirmm.graphik.graal.core.HashMapSubstitution)9 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)8 Rule (fr.lirmm.graphik.graal.api.core.Rule)4 Variable (fr.lirmm.graphik.graal.api.core.Variable)4 Test (org.junit.Test)4 Term (fr.lirmm.graphik.graal.api.core.Term)3 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)2 RestrictedProductivityChecker (fr.lirmm.graphik.graal.core.unifier.checker.RestrictedProductivityChecker)2 CloseableIterableWithoutException (fr.lirmm.graphik.util.stream.CloseableIterableWithoutException)2 CloseableIteratorWithoutException (fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException)2 Collection (java.util.Collection)2 LinkedList (java.util.LinkedList)2 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)1 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)1 AtomErasingChecker (fr.lirmm.graphik.graal.core.unifier.checker.AtomErasingChecker)1 EqualityHandlerConverter (fr.lirmm.graphik.graal.homomorphism.utils.EqualityHandlerConverter)1