use of com.sri.ai.expresso.api.SyntaxTree in project aic-expresso by aic-sri-international.
the class IntersectionIntensionalSetsSimplifier method standardizeApartIntensionalSets.
@SuppressWarnings("deprecation")
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 AbstractExpression method equals.
@Override
public boolean equals(Object another) {
if (this == another) {
return true;
}
SyntaxTree anotherSyntaxTree;
if (another instanceof SyntaxTree) {
anotherSyntaxTree = (SyntaxTree) another;
} else if (another instanceof Expression) {
anotherSyntaxTree = ((Expression) another).getSyntaxTree();
} else {
anotherSyntaxTree = SyntaxTrees.makeSyntaxLeaf(another);
}
boolean result = getSyntaxTree().equals(anotherSyntaxTree);
return result;
}
use of com.sri.ai.expresso.api.SyntaxTree in project aic-expresso by aic-sri-international.
the class AbstractIntensionalSet method makeSyntaxTree.
private SyntaxTree makeSyntaxTree() {
IndexExpressionsSet indexExpressions = getIndexExpressions();
SyntaxTree parametersSyntaxTree = indexExpressions.getSubSyntaxTree();
SyntaxTree scopingSyntaxTree = new DefaultCompoundSyntaxTree(IntensionalSet.SCOPED_VARIABLES_LABEL, parametersSyntaxTree);
SyntaxTree headSyntaxTree = getHead().getSyntaxTree();
SyntaxTree conditionSyntaxTree = (getCondition() == null || getCondition().equals("true")) ? null : SyntaxTrees.makeCompoundSyntaxTree(IntensionalSet.CONDITION_LABEL, condition.getSyntaxTree());
cachedSyntaxTree = makeCompoundSyntaxTree(getSyntaxTreeLabel(), scopingSyntaxTree, headSyntaxTree, conditionSyntaxTree);
return cachedSyntaxTree;
}
use of com.sri.ai.expresso.api.SyntaxTree in project aic-expresso by aic-sri-international.
the class AbstractQuantifiedExpressionWithABody method makeSyntaxTree.
private SyntaxTree makeSyntaxTree() {
IndexExpressionsSet indexExpressions = getIndexExpressions();
List<Expression> indexExpressionsList = ((ExtensionalIndexExpressionsSet) indexExpressions).getList();
List<SyntaxTree> indexExpressionsSyntaxTrees = mapIntoArrayList(indexExpressionsList, Expression::getSyntaxTree);
SyntaxTree parameterList = SyntaxTrees.makeKleeneListIfNeeded(indexExpressionsSyntaxTrees);
SyntaxTree result = makeCompoundSyntaxTree(getSyntaxTreeLabel(), parameterList, getBody().getSyntaxTree());
return result;
}
use of com.sri.ai.expresso.api.SyntaxTree in project aic-expresso by aic-sri-international.
the class DefaultCompoundSyntaxTree method equals.
@Override
public boolean equals(Object anotherObject) {
boolean result;
if (anotherObject instanceof CompoundSyntaxTree) {
CompoundSyntaxTree anotherCompoundSyntaxTree = (CompoundSyntaxTree) anotherObject;
if (this.hashCode() == anotherCompoundSyntaxTree.hashCode()) {
List<SyntaxTree> anotherSubTrees = anotherCompoundSyntaxTree.getImmediateSubTrees();
result = this.getRootTree().equals(anotherCompoundSyntaxTree.getRootTree()) && this.getImmediateSubTrees().equals(anotherSubTrees);
} else {
result = false;
}
} else {
result = false;
}
return result;
}
Aggregations