use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class SubstitutionTest method specializeTermsFunctionTermBinding.
@Test
public void specializeTermsFunctionTermBinding() {
Substitution substitution = new BasicSubstitution();
substitution.put(Y, A);
FunctionTerm groundFunctionTerm = Terms.newFunctionTerm("f", B, C);
Instance qfBC = new Instance(groundFunctionTerm);
Term nongroundFunctionTerm = Terms.newFunctionTerm("f", B, X);
BasicAtom qfBX = Atoms.newBasicAtom(Predicates.getPredicate("q", 1), nongroundFunctionTerm);
Substitution substitution1 = BasicSubstitution.specializeSubstitution(qfBX, qfBC, substitution);
assertEquals(C, substitution1.eval(X));
assertEquals(A, substitution1.eval(Y));
}
use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class UnifierTest method mergeUnifierIntoLeft.
@Test
public void mergeUnifierIntoLeft() {
VariableTerm varX = Terms.newVariable("X");
VariableTerm varY = Terms.newVariable("Y");
VariableTerm varZ = Terms.newVariable("Z");
Term constA = Terms.newConstant("a");
Unifier left = new Unifier();
left.put(varX, varY);
left.put(varZ, varY);
Unifier right = new Unifier();
right.put(varX, constA);
Unifier merged = Unifier.mergeIntoLeft(left, right);
assertEquals(constA, merged.eval(varY));
assertEquals(constA, merged.eval(varZ));
}
use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class ParseTreeVisitor method visitTerm_interval.
@Override
public IntervalTerm visitTerm_interval(ASPCore2Parser.Term_intervalContext ctx) {
// interval : lower = (NUMBER | VARIABLE) DOT DOT upper = (NUMBER | VARIABLE);
ASPCore2Parser.IntervalContext ictx = ctx.interval();
String lowerText = ictx.lower.getText();
String upperText = ictx.upper.getText();
Term lower = ictx.lower.getType() == ASPCore2Lexer.NUMBER ? Terms.newConstant(Integer.parseInt(lowerText)) : Terms.newVariable(lowerText);
Term upper = ictx.upper.getType() == ASPCore2Lexer.NUMBER ? Terms.newConstant(Integer.parseInt(upperText)) : Terms.newVariable(upperText);
return IntervalTerm.getInstance(lower, upper);
}
use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class ParseTreeVisitor method visitAggregate.
@Override
public AggregateLiteral visitAggregate(ASPCore2Parser.AggregateContext ctx) {
// aggregate : NAF? (lt=term lop=binop)? aggregate_function CURLY_OPEN aggregate_elements CURLY_CLOSE (uop=binop ut=term)?;
boolean isPositive = ctx.NAF() == null;
Term lt = null;
ComparisonOperator lop = null;
Term ut = null;
ComparisonOperator uop = null;
if (ctx.lt != null) {
lt = (Term) visit(ctx.lt);
lop = visitBinop(ctx.lop);
}
if (ctx.ut != null) {
ut = (Term) visit(ctx.ut);
uop = visitBinop(ctx.uop);
}
AggregateAtom.AggregateFunctionSymbol aggregateFunction = visitAggregate_function(ctx.aggregate_function());
List<AggregateAtom.AggregateElement> aggregateElements = visitAggregate_elements(ctx.aggregate_elements());
return Atoms.newAggregateAtom(lop, lt, uop, ut, aggregateFunction, aggregateElements).toLiteral(isPositive);
}
use of at.ac.tuwien.kr.alpha.api.terms.Term in project Alpha by alpha-asp.
the class ParseTreeVisitor method visitExternal_atom.
@Override
public ExternalAtom visitExternal_atom(ASPCore2Parser.External_atomContext ctx) {
if (ctx.MINUS() != null) {
throw notSupported(ctx);
}
final String predicateName = ctx.ID().getText();
final PredicateInterpretation interpretation = externals.get(predicateName);
if (interpretation == null) {
throw new IllegalArgumentException("Unknown interpretation name encountered: " + predicateName);
}
List<Term> outputTerms = visitTerms(ctx.output);
return Atoms.newExternalAtom(Predicates.getPredicate(predicateName, outputTerms.size()), interpretation, visitTerms(ctx.input), outputTerms);
}
Aggregations