use of com.sri.ai.expresso.api.SyntaxTree in project aic-expresso by aic-sri-international.
the class IntersectionIntensionalSetsSimplifier method standardizeApartIntensionalSets.
public static IntensionalSet standardizeApartIntensionalSets(IntensionalSet intensionalSet, IntensionalSet fromOtherIntensionalSet, Context context) {
IntensionalSet result = intensionalSet;
IndexExpressionsSet intensionalSetIndexes = intensionalSet.getIndexExpressions();
IndexExpressionsSet fromOtherIntensionalSetIn = fromOtherIntensionalSet.getIndexExpressions();
List<Expression> overlappingIndexNames = new ArrayList<>();
for (Expression intensionalSetIndex : IndexExpressions.getIndices(intensionalSetIndexes)) {
if (IndexExpressions.indexExpressionsContainIndex(fromOtherIntensionalSetIn, intensionalSetIndex)) {
overlappingIndexNames.add(intensionalSetIndex);
}
}
if (overlappingIndexNames.size() > 0) {
Expression combinedExpression = And.make(intensionalSet, fromOtherIntensionalSet);
List<Expression> newIndexNames = new ArrayList<>();
for (Expression overlappingIndex : overlappingIndexNames) {
Expression newIndexName = Expressions.makeUniqueVariable(overlappingIndex.toString(), combinedExpression, context);
newIndexNames.add(newIndexName);
}
SyntaxTree resultSyntaxTree = result.getSyntaxTree();
for (int i = 0; i < newIndexNames.size(); i++) {
Expression replaced = overlappingIndexNames.get(i);
Expression replacement = newIndexNames.get(i);
resultSyntaxTree = resultSyntaxTree.replaceSubTreesAllOccurrences(replaced.getSyntaxTree(), replacement.getSyntaxTree());
}
result = (IntensionalSet) Expressions.makeFromSyntaxTree(resultSyntaxTree);
}
return result;
}
use of com.sri.ai.expresso.api.SyntaxTree in project aic-expresso by aic-sri-international.
the class IndexExpressions method addSubTreeWithIndexAndBasePathPlusArgumentIndex.
public static void addSubTreeWithIndexAndBasePathPlusArgumentIndex(Expression syntaxTree, int subTreeIndex, List<Integer> basePath, List<Pair<SyntaxTree, List<Integer>>> result) {
SyntaxTree subTree = syntaxTree.getSyntaxTree().getSubTree(subTreeIndex);
List<Integer> subExpressionPath = new LinkedList<Integer>(basePath);
subExpressionPath.add(subTreeIndex);
result.add(new Pair<SyntaxTree, List<Integer>>(subTree, subExpressionPath));
}
use of com.sri.ai.expresso.api.SyntaxTree in project aic-expresso by aic-sri-international.
the class AntlrGrinderParserTest method makeScopingSyntaxTree.
/**
* Makes a scoping expression out of a list of scoping variables.
*/
public static SyntaxTree makeScopingSyntaxTree(IndexExpressionsSet indexExpressions) {
List<Expression> indexExpressionsList = ((ExtensionalIndexExpressionsSet) indexExpressions).getList();
Expression kleeneListExpression = Expressions.makeKleeneListIfNeeded(indexExpressionsList);
SyntaxTree kleeneListSyntaxTree = kleeneListExpression.getSyntaxTree();
SyntaxTree result = SyntaxTrees.makeCompoundSyntaxTree(IntensionalSet.SCOPED_VARIABLES_LABEL, kleeneListSyntaxTree);
return result;
}
Aggregations