Search in sources :

Example 1 with Unifier

use of at.ac.tuwien.kr.alpha.commons.substitutions.Unifier in project Alpha by alpha-asp.

the class UnificationTest method unificationWithFunctionTerms.

@Test
public void unificationWithFunctionTerms() {
    Atom left = partsParser.parseLiteral("a(b, f(X, 13), g(Z), d)").getAtom();
    Atom right = partsParser.parseLiteral("a(b, A, g(e), d)").getAtom();
    Unifier unifier = Unification.unifyAtoms(left, right);
    assertNotNull(unifier);
    assertEquals(3, unifier.getMappedVariables().size());
    assertEquals(left.substitute(unifier).toString(), right.substitute(unifier).toString());
}
Also used : Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Unifier(at.ac.tuwien.kr.alpha.commons.substitutions.Unifier) Test(org.junit.jupiter.api.Test)

Example 2 with Unifier

use of at.ac.tuwien.kr.alpha.commons.substitutions.Unifier in project Alpha by alpha-asp.

the class UnificationTest method nonunificationSimple.

@Test
public void nonunificationSimple() {
    Atom left = partsParser.parseLiteral("a(b,X)").getAtom();
    Atom right = partsParser.parseLiteral("a(c,Y)").getAtom();
    Unifier unifier = Unification.unifyAtoms(left, right);
    assertNull(unifier);
}
Also used : Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Unifier(at.ac.tuwien.kr.alpha.commons.substitutions.Unifier) Test(org.junit.jupiter.api.Test)

Example 3 with Unifier

use of at.ac.tuwien.kr.alpha.commons.substitutions.Unifier in project Alpha by alpha-asp.

the class UnificationTest method unificationBothSides.

@Test
public void unificationBothSides() {
    Atom left = partsParser.parseLiteral("p(X, 1)").getAtom();
    Atom right = partsParser.parseLiteral("p(d, Y)").getAtom();
    Unifier unifier = Unification.unifyAtoms(left, right);
    assertNotNull(unifier);
    assertEquals(2, unifier.getMappedVariables().size());
    assertEquals("d", unifier.eval(Terms.newVariable("X")).toString());
    assertEquals("1", unifier.eval(Terms.newVariable("Y")).toString());
}
Also used : Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Unifier(at.ac.tuwien.kr.alpha.commons.substitutions.Unifier) Test(org.junit.jupiter.api.Test)

Example 4 with Unifier

use of at.ac.tuwien.kr.alpha.commons.substitutions.Unifier in project Alpha by alpha-asp.

the class UnificationTest method nonunificationNested.

@Test
public void nonunificationNested() {
    Atom left = partsParser.parseLiteral("a(f(X,a))").getAtom();
    Atom right = partsParser.parseLiteral("a(f(a,b))").getAtom();
    Unifier unifier = Unification.unifyAtoms(left, right);
    assertNull(unifier);
}
Also used : Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Unifier(at.ac.tuwien.kr.alpha.commons.substitutions.Unifier) Test(org.junit.jupiter.api.Test)

Example 5 with Unifier

use of at.ac.tuwien.kr.alpha.commons.substitutions.Unifier in project Alpha by alpha-asp.

the class UnificationTest method simpleGroundUnification.

@Test
public void simpleGroundUnification() {
    Atom pX = partsParser.parseLiteral("p(X)").getAtom();
    Atom pa = partsParser.parseLiteral("p(abc)").getAtom();
    Unifier unifier = Unification.unifyAtoms(pa, pX);
    assertNotNull(unifier);
    assertEquals(1, unifier.getMappedVariables().size());
    assertEquals("abc", unifier.eval(Terms.newVariable("X")).toString());
}
Also used : Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Unifier(at.ac.tuwien.kr.alpha.commons.substitutions.Unifier) Test(org.junit.jupiter.api.Test)

Aggregations

Unifier (at.ac.tuwien.kr.alpha.commons.substitutions.Unifier)20 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)15 Test (org.junit.jupiter.api.Test)11 VariableTerm (at.ac.tuwien.kr.alpha.api.terms.VariableTerm)6 BasicAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)5 Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)5 ArrayList (java.util.ArrayList)5 ComparisonLiteral (at.ac.tuwien.kr.alpha.api.programs.literals.ComparisonLiteral)4 LinkedHashSet (java.util.LinkedHashSet)4 Term (at.ac.tuwien.kr.alpha.api.terms.Term)3 HashSet (java.util.HashSet)3 Set (java.util.Set)2 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)1 VariableNormalizableAtom (at.ac.tuwien.kr.alpha.api.programs.VariableNormalizableAtom)1 AggregateLiteral (at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral)1 DisjunctiveHead (at.ac.tuwien.kr.alpha.api.rules.heads.DisjunctiveHead)1 NormalHead (at.ac.tuwien.kr.alpha.api.rules.heads.NormalHead)1 ArithmeticTerm (at.ac.tuwien.kr.alpha.api.terms.ArithmeticTerm)1 FunctionTerm (at.ac.tuwien.kr.alpha.api.terms.FunctionTerm)1 Instance (at.ac.tuwien.kr.alpha.commons.substitutions.Instance)1