use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class AbstractQuantifiedExpressionWithABody method replaceSymbol.
@Override
public Expression replaceSymbol(Expression symbol, Expression newSymbol, Registry registry) {
AbstractQuantifiedExpression result = this;
Function<Expression, Expression> renameSymbol = e -> IndexExpressions.renameSymbol(e, symbol, newSymbol, registry);
List<Expression> indexExpressionsList = ((ExtensionalIndexExpressionsSet) getIndexExpressions()).getList();
IndexExpressionsSet newIndexExpressions = new ExtensionalIndexExpressionsSet(replaceElementsNonDestructively(indexExpressionsList, renameSymbol));
Expression newBody = getBody().replaceSymbol(symbol, newSymbol, registry);
result = replaceIfNeeded(newIndexExpressions, newBody);
return result;
}
use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class DefaultIntensionalMultiSet method intensionalMultiSet.
/**
* Creates an intensional multi-set on a single index, obtaining its type from the context
* (so it must be registered there).
* @param index
* @param body
* @param condition
* @param context
* @return an intensional multi-set expression.
*/
public static Expression intensionalMultiSet(Expression index, Expression body, Expression condition, Context context) {
Expression type = context.getMandatoryTypeExpressionOfRegisteredSymbol(index);
Expression indexExpression = apply(FunctorConstants.IN, index, type);
IndexExpressionsSet indexExpressions = new ExtensionalIndexExpressionsSet(indexExpression);
Expression set = new DefaultIntensionalMultiSet(indexExpressions, body, condition);
return set;
}
use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class Expressions method makeDefaultIntensionalMultiSetFromLabelAndSubTrees.
private static Expression makeDefaultIntensionalMultiSetFromLabelAndSubTrees(Object label, Object[] subTreeObjects) {
if (subTreeObjects.length == 1 && subTreeObjects[0] instanceof Collection) {
subTreeObjects = ((Collection) subTreeObjects[0]).toArray();
}
ArrayList<Expression> subTreeExpressions = Util.mapIntoArrayList(subTreeObjects, Expressions::makeFromObject);
if (subTreeExpressions.size() == 1) {
subTreeExpressions = new ArrayList<Expression>(Expressions.ensureListFromKleeneList(subTreeExpressions.get(0)));
}
Expression scopingExpression = subTreeExpressions.get(0);
IndexExpressionsSet indexExpressions = new ExtensionalIndexExpressionsSet((scopingExpression == null || scopingExpression.numberOfArguments() == 0) ? Util.list() : new ArrayList<Expression>(Expressions.ensureListFromKleeneList(scopingExpression.get(0))));
Expression conditioningSyntaxTree = subTreeExpressions.get(2);
Expression condition = conditioningSyntaxTree == null ? Expressions.TRUE : conditioningSyntaxTree.get(0);
Expression result = new DefaultIntensionalMultiSet(indexExpressions, subTreeExpressions.get(1), condition);
return result;
}
use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class Expressions method makeDefaultLambdaExpressionFromLabelAndSubTrees.
private static Expression makeDefaultLambdaExpressionFromLabelAndSubTrees(Object label, Object[] subTreeObjects) {
ArrayList<Expression> subTreeExpressions = Util.mapIntoArrayList(subTreeObjects, Expressions::makeFromObject);
Expression indexExpressionsKleeneList = subTreeExpressions.get(0);
IndexExpressionsSet indexExpressions = new ExtensionalIndexExpressionsSet(ensureListFromKleeneList(indexExpressionsKleeneList));
Expression body = subTreeExpressions.get(1);
Expression result = new DefaultLambdaExpression(indexExpressions, body);
return result;
}
use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class Expressions method freeSymbols.
private static void freeSymbols(Expression expression, Set<Expression> freeSymbols, Stack<Expression> quantifiedSymbols, Registry registry) {
if (expression.getSyntacticFormType().equals(Symbol.SYNTACTIC_FORM_TYPE)) {
if (!quantifiedSymbols.contains(expression)) {
freeSymbols.add(expression);
}
} else {
Iterator<ExpressionAndSyntacticContext> subExpressionAndSyntacticContextsIterator = expression.getImmediateSubExpressionsAndContextsIterator();
while (subExpressionAndSyntacticContextsIterator.hasNext()) {
ExpressionAndSyntacticContext subExpressionAndSyntacticContext = subExpressionAndSyntacticContextsIterator.next();
IndexExpressionsSet indexExpressions = subExpressionAndSyntacticContext.getIndexExpressions();
List<Expression> indexExpressionsList = ((ExtensionalIndexExpressionsSet) indexExpressions).getList();
List<Expression> newQuantifiedSymbols = Util.mapIntoList(indexExpressionsList, IndexExpressions.GET_INDEX);
int numberOfPushed = Util.pushAll(quantifiedSymbols, newQuantifiedSymbols);
freeSymbols(subExpressionAndSyntacticContext.getExpression(), freeSymbols, quantifiedSymbols, registry);
Util.popAll(quantifiedSymbols, numberOfPushed);
}
}
return;
}
Aggregations