Search in sources :

Example 31 with Substitution

use of at.ac.tuwien.kr.alpha.api.grounder.Substitution in project Alpha by alpha-asp.

the class SubstitutionTest method groundAndPrintRule.

@Test
public void groundAndPrintRule() {
    Rule<Head> rule = PARSER.parse("x :- p(X,Y), not q(X,Y).").getRules().get(0);
    CompiledRule nonGroundRule = InternalRule.fromNormalRule(NormalRuleImpl.fromBasicRule(rule));
    Substitution substitution1 = BasicSubstitution.specializeSubstitution(PX, PA, BasicSubstitution.EMPTY_SUBSTITUTION);
    Substitution substitution2 = BasicSubstitution.specializeSubstitution(PY, PB, substitution1);
    String printedString = SubstitutionTestUtil.groundAndPrintRule(nonGroundRule, substitution2);
    assertEquals("x :- p(a, b), not q(a, b).", printedString);
}
Also used : Head(at.ac.tuwien.kr.alpha.api.rules.heads.Head) Substitution(at.ac.tuwien.kr.alpha.api.grounder.Substitution) BasicSubstitution(at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution) CompiledRule(at.ac.tuwien.kr.alpha.core.rules.CompiledRule) Test(org.junit.jupiter.api.Test)

Example 32 with Substitution

use of at.ac.tuwien.kr.alpha.api.grounder.Substitution in project Alpha by alpha-asp.

the class SubstitutionTest method substituteBasicAtomLiteral.

private void substituteBasicAtomLiteral(boolean negated) {
    Predicate p = Predicates.getPredicate("p", 2);
    BasicAtom atom = Atoms.newBasicAtom(p, Arrays.asList(X, Y));
    Literal literal = Literals.fromAtom(atom, !negated);
    Substitution substitution = new BasicSubstitution();
    substitution.put(X, A);
    substitution.put(Y, B);
    literal = literal.substitute(substitution);
    assertEquals(p, literal.getPredicate());
    assertEquals(A, literal.getTerms().get(0));
    assertEquals(B, literal.getTerms().get(1));
    assertEquals(negated, literal.isNegated());
}
Also used : Substitution(at.ac.tuwien.kr.alpha.api.grounder.Substitution) BasicSubstitution(at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution) BasicSubstitution(at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) BasicAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom) Predicate(at.ac.tuwien.kr.alpha.api.programs.Predicate)

Example 33 with Substitution

use of at.ac.tuwien.kr.alpha.api.grounder.Substitution in project Alpha by alpha-asp.

the class SubstitutionTest method putSimpleBinding.

@Test
public void putSimpleBinding() {
    Substitution substitution = new BasicSubstitution();
    substitution.put(Y, A);
    assertEquals(A, substitution.eval(Y));
}
Also used : Substitution(at.ac.tuwien.kr.alpha.api.grounder.Substitution) BasicSubstitution(at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution) BasicSubstitution(at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution) Test(org.junit.jupiter.api.Test)

Example 34 with Substitution

use of at.ac.tuwien.kr.alpha.api.grounder.Substitution in project Alpha by alpha-asp.

the class SubstitutionTest method specializeTermsSimpleBinding.

@Test
public void specializeTermsSimpleBinding() {
    Substitution substitution = BasicSubstitution.specializeSubstitution(PY, PA, BasicSubstitution.EMPTY_SUBSTITUTION);
    assertEquals(A, substitution.eval(Y));
}
Also used : Substitution(at.ac.tuwien.kr.alpha.api.grounder.Substitution) BasicSubstitution(at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution) Test(org.junit.jupiter.api.Test)

Aggregations

Substitution (at.ac.tuwien.kr.alpha.api.grounder.Substitution)34 BasicSubstitution (at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution)33 Test (org.junit.jupiter.api.Test)19 Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)13 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)10 BasicAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)8 Instance (at.ac.tuwien.kr.alpha.commons.substitutions.Instance)8 CompiledRule (at.ac.tuwien.kr.alpha.core.rules.CompiledRule)8 VariableTerm (at.ac.tuwien.kr.alpha.api.terms.VariableTerm)7 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)7 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)7 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)6 EnumerationLiteral (at.ac.tuwien.kr.alpha.core.atoms.EnumerationLiteral)6 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)6 NoGood (at.ac.tuwien.kr.alpha.core.common.NoGood)6 WorkingMemory (at.ac.tuwien.kr.alpha.core.grounder.WorkingMemory)6 ArrayList (java.util.ArrayList)6 BindingResult (at.ac.tuwien.kr.alpha.core.grounder.instantiation.BindingResult)5 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)4 NormalProgram (at.ac.tuwien.kr.alpha.api.programs.NormalProgram)4