Map<GdlVariable, ? extends GdlTerm> assignment) {
if (gdl instanceof GdlProposition) {
return gdl;
} else if (gdl instanceof GdlRelation) {
GdlRelation relation = (GdlRelation) gdl;
GdlConstant name = relation.getName();
List<GdlTerm> newBody = new ArrayList<GdlTerm>(relation.arity());
for(GdlTerm term : relation.getBody()) {
newBody.add(replaceVariables(term, assignment));
}
return GdlPool.getRelation(name, newBody);
} else if (gdl instanceof GdlConstant) {
return gdl;
} else if (gdl instanceof GdlVariable) {
if(assignment.containsKey(gdl))
return assignment.get(gdl);
else
return gdl;
} else if (gdl instanceof GdlFunction) {
GdlFunction function = (GdlFunction) gdl;
GdlConstant name = function.getName();
List<GdlTerm> newBody = new ArrayList<GdlTerm>(function.arity());
for (GdlTerm term : function.getBody()) {
newBody.add(replaceVariables(term, assignment));
}
return GdlPool.getFunction(name, newBody);