Search in sources :

Example 71 with Literal

use of at.ac.tuwien.kr.alpha.api.programs.literals.Literal in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testPositiveComparisonLiteral_EQ_Bidirectional.

@Test
@Disabled("Literals of this kind are compiled away by VariableEqualityRemoval")
public void testPositiveComparisonLiteral_EQ_Bidirectional() {
    Rule<Head> rule = parser.parse("p(X) :- q(X,Y), X = Y.").getRules().get(0);
    Literal literal = rule.getBody().stream().filter((lit) -> lit.getPredicate() == ComparisonOperators.EQ.toPredicate()).findFirst().get();
    assertEquals(false, literal.isNegated());
    expectVariables(literal.getBindingVariables());
    expectVariables(literal.getNonBindingVariables(), "X", "Y");
}
Also used : Head(at.ac.tuwien.kr.alpha.api.rules.heads.Head) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 72 with Literal

use of at.ac.tuwien.kr.alpha.api.programs.literals.Literal 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 73 with Literal

use of at.ac.tuwien.kr.alpha.api.programs.literals.Literal in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testNegativeExternalLiteral.

@Test
public void testNegativeExternalLiteral() {
    externals.put("ext", new IntPredicateInterpretation(i -> i > 0));
    Literal literal = parser.parse("p(X) :- q(Y), not &ext[Y](X).", externals).getRules().get(0).getNegativeBody().stream().findFirst().get();
    assertEquals(true, literal.isNegated());
    expectVariables(literal.getBindingVariables());
    expectVariables(literal.getNonBindingVariables(), "X", "Y");
}
Also used : Arrays(java.util.Arrays) Rule(at.ac.tuwien.kr.alpha.api.rules.Rule) ProgramParser(at.ac.tuwien.kr.alpha.api.programs.ProgramParser) Collection(java.util.Collection) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Set(java.util.Set) HashMap(java.util.HashMap) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) Disabled(org.junit.jupiter.api.Disabled) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Head(at.ac.tuwien.kr.alpha.api.rules.heads.Head) VariableTerm(at.ac.tuwien.kr.alpha.api.terms.VariableTerm) IntPredicateInterpretation(at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.IntPredicateInterpretation) PredicateInterpretation(at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ComparisonOperators(at.ac.tuwien.kr.alpha.commons.comparisons.ComparisonOperators) IntPredicateInterpretation(at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.IntPredicateInterpretation) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) Test(org.junit.jupiter.api.Test)

Example 74 with Literal

use of at.ac.tuwien.kr.alpha.api.programs.literals.Literal in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testPositiveBasicLiteral.

@Test
public void testPositiveBasicLiteral() {
    Literal literal = parser.parse("p(X,Y) :- q(X,Y).").getRules().get(0).getBody().stream().findFirst().get();
    assertEquals(false, literal.isNegated());
    expectVariables(literal.getBindingVariables(), "X", "Y");
    expectVariables(literal.getNonBindingVariables());
}
Also used : Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) Test(org.junit.jupiter.api.Test)

Example 75 with Literal

use of at.ac.tuwien.kr.alpha.api.programs.literals.Literal in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testNegativeComparisonLiteral_NEQ_LeftAssigning.

@Test
public void testNegativeComparisonLiteral_NEQ_LeftAssigning() {
    Literal literal = parser.parse("p(X) :- q(X,Y), not Y != 5.").getRules().get(0).getNegativeBody().stream().findFirst().get();
    assertEquals(true, literal.isNegated());
    expectVariables(literal.getBindingVariables(), "Y");
    expectVariables(literal.getNonBindingVariables());
}
Also used : Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) Test(org.junit.jupiter.api.Test)

Aggregations

Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)82 Test (org.junit.jupiter.api.Test)42 VariableTerm (at.ac.tuwien.kr.alpha.api.terms.VariableTerm)20 ArrayList (java.util.ArrayList)20 AggregateLiteral (at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral)17 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)16 Substitution (at.ac.tuwien.kr.alpha.api.grounder.Substitution)14 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)14 BasicAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)14 BasicSubstitution (at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution)13 Map (java.util.Map)12 Head (at.ac.tuwien.kr.alpha.api.rules.heads.Head)11 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)11 CompiledRule (at.ac.tuwien.kr.alpha.core.rules.CompiledRule)10 HashSet (java.util.HashSet)10 ComparisonLiteral (at.ac.tuwien.kr.alpha.api.programs.literals.ComparisonLiteral)9 Instance (at.ac.tuwien.kr.alpha.commons.substitutions.Instance)9 LinkedHashSet (java.util.LinkedHashSet)8 List (java.util.List)8 Term (at.ac.tuwien.kr.alpha.api.terms.Term)7