Search in sources :

Example 1 with IntPredicateInterpretation

use of at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.IntPredicateInterpretation in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testPositiveExternalLiteral.

@Test
public void testPositiveExternalLiteral() {
    externals.put("ext", new IntPredicateInterpretation(i -> i > 0));
    Rule<Head> rule = parser.parse("p(X) :- q(Y), &ext[Y](X).", externals).getRules().get(0);
    Literal literal = rule.getBody().stream().filter((lit) -> lit.getPredicate().getName().equals("ext")).findFirst().get();
    assertEquals(false, literal.isNegated());
    expectVariables(literal.getBindingVariables(), "X");
    expectVariables(literal.getNonBindingVariables(), "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) Head(at.ac.tuwien.kr.alpha.api.rules.heads.Head) 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 2 with IntPredicateInterpretation

use of at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.IntPredicateInterpretation 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)

Aggregations

PredicateInterpretation (at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation)2 ProgramParser (at.ac.tuwien.kr.alpha.api.programs.ProgramParser)2 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)2 Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)2 Rule (at.ac.tuwien.kr.alpha.api.rules.Rule)2 Head (at.ac.tuwien.kr.alpha.api.rules.heads.Head)2 VariableTerm (at.ac.tuwien.kr.alpha.api.terms.VariableTerm)2 ComparisonOperators (at.ac.tuwien.kr.alpha.commons.comparisons.ComparisonOperators)2 IntPredicateInterpretation (at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.IntPredicateInterpretation)2 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Disabled (org.junit.jupiter.api.Disabled)2 Test (org.junit.jupiter.api.Test)2