use of at.ac.tuwien.kr.alpha.commons.substitutions.Unifier in project Alpha by alpha-asp.
the class Terms method renameVariables.
/**
* Renames variables in given set of terms.
* @param varNamePrefix
* @return
*/
public static Substitution renameVariables(Set<VariableTerm> terms, String varNamePrefix) {
Unifier renamingSubstitution = new Unifier();
int counter = 0;
for (VariableTerm variable : terms) {
renamingSubstitution.put(variable, Terms.newVariable(varNamePrefix + counter++));
}
return renamingSubstitution;
}
use of at.ac.tuwien.kr.alpha.commons.substitutions.Unifier in project Alpha by alpha-asp.
the class UnificationTest method nonunificationWithArithmeticTermsNested.
@Test
public void nonunificationWithArithmeticTermsNested() {
Atom left = partsParser.parseLiteral("a(X + 7)").getAtom();
Atom right = partsParser.parseLiteral("a(Y + (Z - 2))").getAtom();
Unifier unifier = Unification.unifyAtoms(left, right);
assertNull(unifier);
}
use of at.ac.tuwien.kr.alpha.commons.substitutions.Unifier in project Alpha by alpha-asp.
the class UnificationTest method unificationWithArithmeticTerms.
@Test
public void unificationWithArithmeticTerms() {
Atom left = partsParser.parseLiteral("a(X - (3 * Y))").getAtom();
Atom right = partsParser.parseLiteral("a(15 - Z)").getAtom();
Unifier unifier = Unification.unifyAtoms(left, right);
assertNotNull(unifier);
assertEquals(3, unifier.getMappedVariables().size());
assertEquals(left.substitute(unifier).toString(), right.substitute(unifier).toString());
}
use of at.ac.tuwien.kr.alpha.commons.substitutions.Unifier in project Alpha by alpha-asp.
the class UnificationTest method nonunificationWithArithmeticTerms.
@Test
public void nonunificationWithArithmeticTerms() {
Atom left = partsParser.parseLiteral("a(X + 4)").getAtom();
Atom right = partsParser.parseLiteral("a(Y - 4)").getAtom();
Unifier unifier = Unification.unifyAtoms(left, right);
assertNull(unifier);
}
use of at.ac.tuwien.kr.alpha.commons.substitutions.Unifier in project Alpha by alpha-asp.
the class UnificationTest method unificationNonGround.
@Test
public void unificationNonGround() {
Atom left = partsParser.parseLiteral("p(X, 13)").getAtom();
Atom right = partsParser.parseLiteral("p(Z, Y)").getAtom();
Unifier unifier = Unification.unifyAtoms(left, right);
assertNotNull(unifier);
assertEquals(3, unifier.getMappedVariables().size());
assertEquals("13", unifier.eval(Terms.newVariable("Y")).toString());
// Check that the unifier sets X=Z by either mapping X -> Z or Z -> X.
if (unifier.eval(Terms.newVariable("X")) != null) {
// X is mapped, it must map to Z now.
assertEquals("Z", unifier.eval(Terms.newVariable("X")).toString());
} else {
// X is not mapped, so Z must map to X.
assertEquals("X", unifier.eval(Terms.newVariable("Z")).toString());
}
}
Aggregations