use of com.sri.ai.expresso.api.ExpressionAndSyntacticContext 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;
}
use of com.sri.ai.expresso.api.ExpressionAndSyntacticContext in project aic-expresso by aic-sri-international.
the class AbstractQuantifiedExpression method makeAddressForIndexType.
private ExpressionAndSyntacticContext makeAddressForIndexType(int indexExpressionIndex, Expression type) {
SubExpressionAddress address = new IndexExpressionTypeSubExpressionAddress(indexExpressionIndex);
ExpressionAndSyntacticContext expressionAndSyntacticContext = new DefaultExpressionAndSyntacticContext(type, address);
return expressionAndSyntacticContext;
}
use of com.sri.ai.expresso.api.ExpressionAndSyntacticContext in project aic-expresso by aic-sri-international.
the class AbstractQuantifiedExpression method makeAddressForIndexArgument.
private ExpressionAndSyntacticContext makeAddressForIndexArgument(int indexExpressionIndex, Expression index, int argumentIndex) {
SubExpressionAddress address = new IndexExpressionArgumentSubExpressionAddress(indexExpressionIndex, argumentIndex);
ExpressionAndSyntacticContext expressionAndSyntacticContext = new DefaultExpressionAndSyntacticContext(index.get(argumentIndex), address);
return expressionAndSyntacticContext;
}
use of com.sri.ai.expresso.api.ExpressionAndSyntacticContext in project aic-expresso by aic-sri-international.
the class Expressions method freeVariables.
private static void freeVariables(Expression expression, Set<Expression> freeVariables, Set<Expression> quantifiedVariables, Predicate<Expression> isVariable) {
if (expression.getSyntacticFormType().equals(Symbol.SYNTACTIC_FORM_TYPE)) {
if (isVariable.apply(expression)) {
if (!quantifiedVariables.contains(expression)) {
freeVariables.add(expression);
}
}
} else {
Iterator<ExpressionAndSyntacticContext> subExpressionAndSyntacticContextsIterator = expression.getImmediateSubExpressionsAndContextsIterator();
Set<Expression> newLocalQuantifiedVariables = null;
while (subExpressionAndSyntacticContextsIterator.hasNext()) {
ExpressionAndSyntacticContext subExpressionAndSyntacticContext = subExpressionAndSyntacticContextsIterator.next();
// initialize newLocalQuantifiedVariables with an empty collection
if (newLocalQuantifiedVariables == null) {
// For efficiency, only instantiate once
newLocalQuantifiedVariables = new LinkedHashSet<Expression>();
} else {
newLocalQuantifiedVariables.clear();
}
for (Expression localVariable : subExpressionAndSyntacticContext.getIndices()) {
if (quantifiedVariables.add(localVariable)) {
newLocalQuantifiedVariables.add(localVariable);
}
}
freeVariables(subExpressionAndSyntacticContext.getExpression(), freeVariables, quantifiedVariables, isVariable);
// Backtrack to what quantifiedVariables was at the beginning of this call; perhaps it would be more efficient to keep this on a stack?
quantifiedVariables.removeAll(newLocalQuantifiedVariables);
}
}
return;
}
use of com.sri.ai.expresso.api.ExpressionAndSyntacticContext in project aic-expresso by aic-sri-international.
the class Expressions method freeVariables.
//
// PRIVATE METHODS
//
private static void freeVariables(Expression expression, Set<Expression> freeVariables, Set<Expression> quantifiedVariables, Registry registry) {
if (expression.getSyntacticFormType().equals(Symbol.SYNTACTIC_FORM_TYPE)) {
if (registry.isVariable(expression)) {
if (!quantifiedVariables.contains(expression)) {
freeVariables.add(expression);
}
}
} else {
Iterator<ExpressionAndSyntacticContext> subExpressionAndSyntacticContextsIterator = expression.getImmediateSubExpressionsAndContextsIterator();
Set<Expression> newLocalQuantifiedVariables = null;
while (subExpressionAndSyntacticContextsIterator.hasNext()) {
ExpressionAndSyntacticContext subExpressionAndSyntacticContext = subExpressionAndSyntacticContextsIterator.next();
// initialize newLocalQuantifiedVariables with an empty collection
if (newLocalQuantifiedVariables == null) {
// For efficiency, only instantiate once
newLocalQuantifiedVariables = new LinkedHashSet<Expression>();
} else {
newLocalQuantifiedVariables.clear();
}
for (Expression localVariable : subExpressionAndSyntacticContext.getIndices()) {
if (quantifiedVariables.add(localVariable)) {
newLocalQuantifiedVariables.add(localVariable);
}
}
freeVariables(subExpressionAndSyntacticContext.getExpression(), freeVariables, quantifiedVariables, registry);
// Backtrack to what quantifiedVariables was at the beginning of this call; perhaps it would be more efficient to keep this on a stack?
quantifiedVariables.removeAll(newLocalQuantifiedVariables);
}
}
return;
}
Aggregations