Search in sources :

Example 16 with Head

use of at.ac.tuwien.kr.alpha.api.rules.heads.Head in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testPositiveComparisonLiteral_EQ_RightAssigning.

@Test
public void testPositiveComparisonLiteral_EQ_RightAssigning() {
    Rule<Head> rule = parser.parse("p(X) :- q(X,Y), 5 = 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(), "Y");
    expectVariables(literal.getNonBindingVariables());
}
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)

Example 17 with Head

use of at.ac.tuwien.kr.alpha.api.rules.heads.Head in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testPositiveComparisonLiteral_NEQ_LeftAssigning.

@Test
public void testPositiveComparisonLiteral_NEQ_LeftAssigning() {
    Rule<Head> rule = parser.parse("p(X) :- q(X,Y), Y != 5.").getRules().get(0);
    Literal literal = rule.getBody().stream().filter((lit) -> lit.getPredicate() == ComparisonOperators.NE.toPredicate()).findFirst().get();
    assertEquals(false, literal.isNegated());
    expectVariables(literal.getBindingVariables());
    expectVariables(literal.getNonBindingVariables(), "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)

Example 18 with Head

use of at.ac.tuwien.kr.alpha.api.rules.heads.Head in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testPositiveComparisonLiteral_EQ_LeftAssigning.

@Test
public void testPositiveComparisonLiteral_EQ_LeftAssigning() {
    Rule<Head> rule = parser.parse("p(X) :- q(X,Y), Y = 5.").getRules().get(0);
    Literal literal = rule.getBody().stream().filter((lit) -> lit.getPredicate() == ComparisonOperators.EQ.toPredicate()).findFirst().get();
    assertEquals(false, literal.isNegated());
    expectVariables(literal.getBindingVariables(), "Y");
    expectVariables(literal.getNonBindingVariables());
}
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)

Example 19 with Head

use of at.ac.tuwien.kr.alpha.api.rules.heads.Head in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testNegativeComparisonLiteral_EQ_LeftAssigning.

@Test
public void testNegativeComparisonLiteral_EQ_LeftAssigning() {
    Rule<Head> rule = parser.parse("p(X) :- q(X,Y), not Y = 5.").getRules().get(0);
    Literal literal = rule.getNegativeBody().stream().findFirst().get();
    assertEquals(true, literal.isNegated());
    expectVariables(literal.getBindingVariables());
    expectVariables(literal.getNonBindingVariables(), "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)

Example 20 with Head

use of at.ac.tuwien.kr.alpha.api.rules.heads.Head in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testPositiveComparisonLiteral_NEQ_Bidirectional.

@Test
public void testPositiveComparisonLiteral_NEQ_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.NE.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)

Aggregations

Head (at.ac.tuwien.kr.alpha.api.rules.heads.Head)21 Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)12 Test (org.junit.jupiter.api.Test)12 Rule (at.ac.tuwien.kr.alpha.api.rules.Rule)6 BasicRule (at.ac.tuwien.kr.alpha.core.rules.BasicRule)6 ArrayList (java.util.ArrayList)6 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)5 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)4 NormalHead (at.ac.tuwien.kr.alpha.api.rules.heads.NormalHead)3 CompiledRule (at.ac.tuwien.kr.alpha.core.rules.CompiledRule)3 Substitution (at.ac.tuwien.kr.alpha.api.grounder.Substitution)2 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)2 BasicAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)2 AggregateLiteral (at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral)2 BasicLiteral (at.ac.tuwien.kr.alpha.api.programs.literals.BasicLiteral)2 Term (at.ac.tuwien.kr.alpha.api.terms.Term)2 VariableTerm (at.ac.tuwien.kr.alpha.api.terms.VariableTerm)2 BasicSubstitution (at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution)2 InlineDirectivesImpl (at.ac.tuwien.kr.alpha.core.parser.InlineDirectivesImpl)2 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)2