Search in sources :

Example 1 with FreshVarSubstitution

use of fr.lirmm.graphik.graal.core.FreshVarSubstitution in project graal by graphik-team.

the class DlgpListener method createAtomSet.

@Override
protected void createAtomSet(InMemoryAtomSet atomset) {
    FreshVarSubstitution s = new FreshVarSubstitution(DlgpParser.freeVarGen);
    CloseableIteratorWithoutException<Atom> it = atomset.iterator();
    while (it.hasNext()) {
        Atom a = it.next();
        this.set.write(s.createImageOf(a));
    }
}
Also used : FreshVarSubstitution(fr.lirmm.graphik.graal.core.FreshVarSubstitution) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 2 with FreshVarSubstitution

use of fr.lirmm.graphik.graal.core.FreshVarSubstitution in project graal by graphik-team.

the class UnifierUtils method getSafeCopy.

public static Rule getSafeCopy(Rule rule) {
    Substitution substitution = new FreshVarSubstitution(varGen);
    InMemoryAtomSet body = rule.getBody();
    InMemoryAtomSet head = rule.getHead();
    InMemoryAtomSet safeBody = new LinkedListAtomSet();
    InMemoryAtomSet safeHead = new LinkedListAtomSet();
    substitution.apply(body, safeBody);
    substitution.apply(head, safeHead);
    return DefaultRuleFactory.instance().create(safeBody, safeHead);
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) FreshVarSubstitution(fr.lirmm.graphik.graal.core.FreshVarSubstitution) FreshVarSubstitution(fr.lirmm.graphik.graal.core.FreshVarSubstitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)

Example 3 with FreshVarSubstitution

use of fr.lirmm.graphik.graal.core.FreshVarSubstitution in project graal by graphik-team.

the class FreeVarSubstitutionTest method test.

@Test
public void test() throws ParseException {
    final Term X = DefaultTermFactory.instance().createVariable("X");
    final Term Y = DefaultTermFactory.instance().createVariable("Y");
    final Term Z = DefaultTermFactory.instance().createVariable("Z");
    Rule rule = DlgpParser.parseRule("p(X,Y,Z) :- q(X,Y), q(Y,Z).");
    FreshVarSubstitution subtitution = new FreshVarSubstitution();
    Rule substitut = subtitution.createImageOf(rule);
    for (Variable t : substitut.getVariables()) {
        if (t.equals(X) || t.equals(Y) || t.equals(Z)) {
            Assert.assertFalse(true);
        }
    }
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) FreshVarSubstitution(fr.lirmm.graphik.graal.core.FreshVarSubstitution) Term(fr.lirmm.graphik.graal.api.core.Term) Rule(fr.lirmm.graphik.graal.api.core.Rule) Test(org.junit.Test)

Aggregations

FreshVarSubstitution (fr.lirmm.graphik.graal.core.FreshVarSubstitution)3 Atom (fr.lirmm.graphik.graal.api.core.Atom)1 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)1 Rule (fr.lirmm.graphik.graal.api.core.Rule)1 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)1 Term (fr.lirmm.graphik.graal.api.core.Term)1 Variable (fr.lirmm.graphik.graal.api.core.Variable)1 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)1 Test (org.junit.Test)1