diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-09-28 17:42:55 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-09-28 17:42:55 +0200 |
commit | bcbb2009c44380055b2670e7cdefcad232f9ece4 (patch) | |
tree | b1f1716e6dcb7cb79dcb9871af21758cf6c0a5c2 /searchlib | |
parent | 3d49f155fccfa4fc08882b01e7a6e3a982c55212 (diff) |
Drop 'arithmetic' from name
Diffstat (limited to 'searchlib')
8 files changed, 83 insertions, 75 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTForestOptimizer.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTForestOptimizer.java index 6ab483800a7..78acd2e5af1 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTForestOptimizer.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTForestOptimizer.java @@ -5,8 +5,8 @@ import com.yahoo.searchlib.rankingexpression.RankingExpression; import com.yahoo.searchlib.rankingexpression.evaluation.ContextIndex; import com.yahoo.searchlib.rankingexpression.evaluation.OptimizationReport; import com.yahoo.searchlib.rankingexpression.evaluation.Optimizer; -import com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode; -import com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator; +import com.yahoo.searchlib.rankingexpression.rule.OperationNode; +import com.yahoo.searchlib.rankingexpression.rule.Operator; import com.yahoo.searchlib.rankingexpression.rule.CompositeNode; import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode; @@ -84,12 +84,12 @@ public class GBDTForestOptimizer extends Optimizer { currentTreesOptimized++; return true; } - if (!(node instanceof ArithmeticNode)) { + if (!(node instanceof OperationNode)) { return false; } - ArithmeticNode aNode = (ArithmeticNode)node; - for (ArithmeticOperator op : aNode.operators()) { - if (op != ArithmeticOperator.PLUS) { + OperationNode aNode = (OperationNode)node; + for (Operator op : aNode.operators()) { + if (op != Operator.PLUS) { return false; } } diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTOptimizer.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTOptimizer.java index cf4c35d94af..b3cbe252dfc 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTOptimizer.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTOptimizer.java @@ -61,13 +61,13 @@ public class GBDTOptimizer extends Optimizer { * @return the optimized expression */ private ExpressionNode optimize(ExpressionNode node, ContextIndex context) { - if (node instanceof ArithmeticNode) { - Iterator<ExpressionNode> childIt = ((ArithmeticNode)node).children().iterator(); + if (node instanceof OperationNode) { + Iterator<ExpressionNode> childIt = ((OperationNode)node).children().iterator(); ExpressionNode ret = optimize(childIt.next(), context); - Iterator<ArithmeticOperator> operIt = ((ArithmeticNode)node).operators().iterator(); + Iterator<Operator> operIt = ((OperationNode)node).operators().iterator(); while (childIt.hasNext() && operIt.hasNext()) { - ret = ArithmeticNode.resolve(ret, operIt.next(), optimize(childIt.next(), context)); + ret = OperationNode.resolve(ret, operIt.next(), optimize(childIt.next(), context)); } return ret; } @@ -115,10 +115,10 @@ public class GBDTOptimizer extends Optimizer { /** Consumes the if condition and return the size of the values resulting, for convenience */ private int consumeIfCondition(ExpressionNode condition, List<Double> values, ContextIndex context) { if (isBinaryComparison(condition)) { - ArithmeticNode comparison = (ArithmeticNode)condition; - if (comparison.operators().get(0) == ArithmeticOperator.LESS) + OperationNode comparison = (OperationNode)condition; + if (comparison.operators().get(0) == Operator.LESS) values.add(GBDTNode.MAX_LEAF_VALUE + GBDTNode.MAX_VARIABLES*0 + getVariableIndex(comparison.children().get(0), context)); - else if (comparison.operators().get(0) == ArithmeticOperator.EQUAL) + else if (comparison.operators().get(0) == Operator.EQUAL) values.add(GBDTNode.MAX_LEAF_VALUE + GBDTNode.MAX_VARIABLES*1 + getVariableIndex(comparison.children().get(0), context)); else throw new IllegalArgumentException("Cannot optimize other conditions than < and ==, encountered: " + comparison.operators().get(0)); @@ -134,8 +134,8 @@ public class GBDTOptimizer extends Optimizer { else if (condition instanceof NotNode notNode) { // handle if inversion: !(a >= b) if (notNode.children().size() == 1 && notNode.children().get(0) instanceof EmbracedNode embracedNode) { if (embracedNode.children().size() == 1 && isBinaryComparison(embracedNode.children().get(0))) { - ArithmeticNode comparison = (ArithmeticNode)embracedNode.children().get(0); - if (comparison.operators().get(0) == ArithmeticOperator.GREATEREQUAL) + OperationNode comparison = (OperationNode)embracedNode.children().get(0); + if (comparison.operators().get(0) == Operator.GREATEREQUAL) values.add(GBDTNode.MAX_LEAF_VALUE + GBDTNode.MAX_VARIABLES*3 + getVariableIndex(comparison.children().get(0), context)); else throw new IllegalArgumentException("Cannot optimize other conditions than >=, encountered: " + comparison.operators().get(0)); @@ -151,15 +151,15 @@ public class GBDTOptimizer extends Optimizer { } private boolean isBinaryComparison(ExpressionNode condition) { - if ( ! (condition instanceof ArithmeticNode binaryNode)) return false; + if ( ! (condition instanceof OperationNode binaryNode)) return false; if (binaryNode.operators().size() != 1) return false; - if (binaryNode.operators().get(0) == ArithmeticOperator.GREATEREQUAL) return true; - if (binaryNode.operators().get(0) == ArithmeticOperator.GREATER) return true; - if (binaryNode.operators().get(0) == ArithmeticOperator.LESSEQUAL) return true; - if (binaryNode.operators().get(0) == ArithmeticOperator.LESS) return true; - if (binaryNode.operators().get(0) == ArithmeticOperator.APPROX) return true; - if (binaryNode.operators().get(0) == ArithmeticOperator.NOTEQUAL) return true; - if (binaryNode.operators().get(0) == ArithmeticOperator.EQUAL) return true; + if (binaryNode.operators().get(0) == Operator.GREATEREQUAL) return true; + if (binaryNode.operators().get(0) == Operator.GREATER) return true; + if (binaryNode.operators().get(0) == Operator.LESSEQUAL) return true; + if (binaryNode.operators().get(0) == Operator.LESS) return true; + if (binaryNode.operators().get(0) == Operator.APPROX) return true; + if (binaryNode.operators().get(0) == Operator.NOTEQUAL) return true; + if (binaryNode.operators().get(0) == Operator.EQUAL) return true; return false; } diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/LambdaFunctionNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/LambdaFunctionNode.java index 9f07f146264..3c7f48aa38c 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/LambdaFunctionNode.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/LambdaFunctionNode.java @@ -106,10 +106,10 @@ public class LambdaFunctionNode extends CompositeNode { } private Optional<DoubleBinaryOperator> getDirectEvaluator() { - if ( ! (functionExpression instanceof ArithmeticNode)) { + if ( ! (functionExpression instanceof OperationNode)) { return Optional.empty(); } - ArithmeticNode node = (ArithmeticNode) functionExpression; + OperationNode node = (OperationNode) functionExpression; if ( ! (node.children().get(0) instanceof ReferenceNode) || ! (node.children().get(1) instanceof ReferenceNode)) { return Optional.empty(); } @@ -121,7 +121,7 @@ public class LambdaFunctionNode extends CompositeNode { if (node.operators().size() != 1) { return Optional.empty(); } - ArithmeticOperator operator = node.operators().get(0); + Operator operator = node.operators().get(0); switch (operator) { case OR: return asFunctionExpression((left, right) -> ((left != 0.0) || (right != 0.0)) ? 1.0 : 0.0); case AND: return asFunctionExpression((left, right) -> ((left != 0.0) && (right != 0.0)) ? 1.0 : 0.0); diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/OperationNode.java index c3e39197316..392f42f6cbe 100755 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticNode.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/OperationNode.java @@ -16,26 +16,26 @@ import java.util.List; import java.util.Objects; /** - * A binary mathematical operation + * A sequence of binary operations. * * @author bratseth */ -public final class ArithmeticNode extends CompositeNode { +public final class OperationNode extends CompositeNode { private final List<ExpressionNode> children; - private final List<ArithmeticOperator> operators; + private final List<Operator> operators; - public ArithmeticNode(List<ExpressionNode> children, List<ArithmeticOperator> operators) { + public OperationNode(List<ExpressionNode> children, List<Operator> operators) { this.children = List.copyOf(children); this.operators = List.copyOf(operators); } - public ArithmeticNode(ExpressionNode leftExpression, ArithmeticOperator operator, ExpressionNode rightExpression) { + public OperationNode(ExpressionNode leftExpression, Operator operator, ExpressionNode rightExpression) { this.children = List.of(leftExpression, rightExpression); this.operators = List.of(operator); } - public List<ArithmeticOperator> operators() { return operators; } + public List<Operator> operators() { return operators; } @Override public List<ExpressionNode> children() { return children; } @@ -50,7 +50,7 @@ public final class ArithmeticNode extends CompositeNode { child.next().toString(string, context, path, this); if (child.hasNext()) string.append(" "); - for (Iterator<ArithmeticOperator> op = operators.iterator(); op.hasNext() && child.hasNext();) { + for (Iterator<Operator> op = operators.iterator(); op.hasNext() && child.hasNext();) { string.append(op.next().toString()).append(" "); child.next().toString(string, context, path, this); if (op.hasNext()) @@ -68,7 +68,7 @@ public final class ArithmeticNode extends CompositeNode { */ private boolean nonDefaultPrecedence(CompositeNode parent) { if ( parent == null) return false; - if ( ! (parent instanceof ArithmeticNode arithmeticParent)) return false; + if ( ! (parent instanceof OperationNode arithmeticParent)) return false; // The line below can only be correct in both only have one operator. // Getting this correct is impossible without more work. @@ -96,8 +96,8 @@ public final class ArithmeticNode extends CompositeNode { // Apply in precedence order: Deque<ValueItem> stack = new ArrayDeque<>(); stack.push(new ValueItem(null, child.next().evaluate(context))); - for (Iterator<ArithmeticOperator> it = operators.iterator(); it.hasNext() && child.hasNext();) { - ArithmeticOperator op = it.next(); + for (Iterator<Operator> it = operators.iterator(); it.hasNext() && child.hasNext();) { + Operator op = it.next(); if ( ! stack.isEmpty()) { while (stack.size() > 1 && ! op.hasPrecedenceOver(stack.peek().op)) { popStack(stack); @@ -121,30 +121,38 @@ public final class ArithmeticNode extends CompositeNode { public CompositeNode setChildren(List<ExpressionNode> newChildren) { if (children.size() != newChildren.size()) throw new IllegalArgumentException("Expected " + children.size() + " children but got " + newChildren.size()); - return new ArithmeticNode(newChildren, operators); + return new OperationNode(newChildren, operators); } @Override public int hashCode() { return Objects.hash(children, operators); } - public static ArithmeticNode resolve(ExpressionNode left, ArithmeticOperator op, ExpressionNode right) { - if ( ! (left instanceof ArithmeticNode leftArithmetic)) return new ArithmeticNode(left, op, right); + @Override + public boolean equals(Object o) { + if ( ! (o instanceof OperationNode other)) return false; + if ( ! this.children().equals(other.children())) return false; + if ( ! this.operators().equals(other.operators())) return false; + return true; + } + + public static OperationNode resolve(ExpressionNode left, Operator op, ExpressionNode right) { + if ( ! (left instanceof OperationNode leftArithmetic)) return new OperationNode(left, op, right); List<ExpressionNode> newChildren = new ArrayList<>(leftArithmetic.children()); newChildren.add(right); - List<ArithmeticOperator> newOperators = new ArrayList<>(leftArithmetic.operators()); + List<Operator> newOperators = new ArrayList<>(leftArithmetic.operators()); newOperators.add(op); - return new ArithmeticNode(newChildren, newOperators); + return new OperationNode(newChildren, newOperators); } private static class ValueItem { - final ArithmeticOperator op; + final Operator op; Value value; - public ValueItem(ArithmeticOperator op, Value value) { + public ValueItem(Operator op, Value value) { this.op = op; this.value = value; } diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticOperator.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/Operator.java index 435c92ff7da..4ddbfa4ea9f 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticOperator.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/Operator.java @@ -12,7 +12,7 @@ import java.util.function.BiFunction; * * @author bratseth */ -public enum ArithmeticOperator { +public enum Operator { // In order from lowest to highest precedence OR("||", (x, y) -> x.or(y)), @@ -31,25 +31,25 @@ public enum ArithmeticOperator { MODULO("%", (x, y) -> x.modulo(y)), POWER("^", true, (x, y) -> x.power(y)); - /** A list of all the operators in this in order of decreasing precedence */ - public static final List<ArithmeticOperator> operatorsByPrecedence = Arrays.stream(ArithmeticOperator.values()).toList(); + /** A list of all the operators in this in order of increasing precedence */ + public static final List<Operator> operatorsByPrecedence = Arrays.stream(Operator.values()).toList(); private final String image; private final boolean bindsRight; // TODO: Implement private final BiFunction<Value, Value, Value> function; - ArithmeticOperator(String image, BiFunction<Value, Value, Value> function) { + Operator(String image, BiFunction<Value, Value, Value> function) { this(image, false, function); } - ArithmeticOperator(String image, boolean bindsRight, BiFunction<Value, Value, Value> function) { + Operator(String image, boolean bindsRight, BiFunction<Value, Value, Value> function) { this.image = image; this.bindsRight = bindsRight; this.function = function; } /** Returns true if this operator has precedence over the given operator */ - public boolean hasPrecedenceOver(ArithmeticOperator op) { + public boolean hasPrecedenceOver(Operator op) { return operatorsByPrecedence.indexOf(this) > operatorsByPrecedence.indexOf(op); } diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/Simplifier.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/Simplifier.java index 7a34f5b7b03..04728966bc1 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/Simplifier.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/Simplifier.java @@ -4,8 +4,8 @@ package com.yahoo.searchlib.rankingexpression.transform; import com.yahoo.searchlib.rankingexpression.evaluation.DoubleCompatibleValue; import com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue; import com.yahoo.searchlib.rankingexpression.evaluation.Value; -import com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode; -import com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator; +import com.yahoo.searchlib.rankingexpression.rule.OperationNode; +import com.yahoo.searchlib.rankingexpression.rule.Operator; import com.yahoo.searchlib.rankingexpression.rule.CompositeNode; import com.yahoo.searchlib.rankingexpression.rule.ConstantNode; import com.yahoo.searchlib.rankingexpression.rule.EmbracedNode; @@ -33,8 +33,8 @@ public class Simplifier extends ExpressionTransformer<TransformContext> { node = transformIf((IfNode) node); if (node instanceof EmbracedNode e && hasSingleUndividableChild(e)) node = e.children().get(0); - if (node instanceof ArithmeticNode) - node = transformArithmetic((ArithmeticNode) node); + if (node instanceof OperationNode) + node = transformArithmetic((OperationNode) node); if (node instanceof NegativeNode) node = transformNegativeNode((NegativeNode) node); return node; @@ -42,18 +42,18 @@ public class Simplifier extends ExpressionTransformer<TransformContext> { private boolean hasSingleUndividableChild(EmbracedNode node) { if (node.children().size() > 1) return false; - if (node.children().get(0) instanceof ArithmeticNode) return false; + if (node.children().get(0) instanceof OperationNode) return false; return true; } - private ExpressionNode transformArithmetic(ArithmeticNode node) { + private ExpressionNode transformArithmetic(OperationNode node) { // Fold the subset of expressions that are constant (such that in "1 + 2 + var") if (node.children().size() > 1) { List<ExpressionNode> children = new ArrayList<>(node.children()); - List<ArithmeticOperator> operators = new ArrayList<>(node.operators()); - for (ArithmeticOperator operator : ArithmeticOperator.operatorsByPrecedence) + List<Operator> operators = new ArrayList<>(node.operators()); + for (Operator operator : Operator.operatorsByPrecedence) transform(operator, children, operators); - node = new ArithmeticNode(children, operators); + node = new OperationNode(children, operators); } if (isConstant(node) && ! node.evaluate(null).isNaN()) @@ -64,8 +64,8 @@ public class Simplifier extends ExpressionTransformer<TransformContext> { return node; } - private void transform(ArithmeticOperator operatorToTransform, - List<ExpressionNode> children, List<ArithmeticOperator> operators) { + private void transform(Operator operatorToTransform, + List<ExpressionNode> children, List<Operator> operators) { int i = 0; while (i < children.size()-1) { boolean transformed = false; @@ -73,7 +73,7 @@ public class Simplifier extends ExpressionTransformer<TransformContext> { ExpressionNode child1 = children.get(i); ExpressionNode child2 = children.get(i + 1); if (isConstant(child1) && isConstant(child2) && hasPrecedence(operators, i)) { - Value evaluated = new ArithmeticNode(child1, operators.get(i), child2).evaluate(null); + Value evaluated = new OperationNode(child1, operators.get(i), child2).evaluate(null); if ( ! evaluated.isNaN()) { // Don't replace by NaN operators.remove(i); children.set(i, new ConstantNode(evaluated.freeze())); @@ -92,7 +92,7 @@ public class Simplifier extends ExpressionTransformer<TransformContext> { * This check works because we simplify by decreasing precedence, so neighbours will either be single constant values * or a more complex expression that can't be simplified and hence also prevents the simplification in question here. */ - private boolean hasPrecedence(List<ArithmeticOperator> operators, int i) { + private boolean hasPrecedence(List<Operator> operators, int i) { if (i > 0 && operators.get(i-1).hasPrecedenceOver(operators.get(i))) return false; if (i < operators.size()-1 && operators.get(i+1).hasPrecedenceOver(operators.get(i))) return false; return true; @@ -114,14 +114,14 @@ public class Simplifier extends ExpressionTransformer<TransformContext> { return new ConstantNode(constant.getValue().negate() ); } - private boolean allMultiplicationOrDivision(ArithmeticNode node) { - for (ArithmeticOperator o : node.operators()) - if (o != ArithmeticOperator.MULTIPLY && o != ArithmeticOperator.DIVIDE) + private boolean allMultiplicationOrDivision(OperationNode node) { + for (Operator o : node.operators()) + if (o != Operator.MULTIPLY && o != Operator.DIVIDE) return false; return true; } - private boolean hasZero(ArithmeticNode node) { + private boolean hasZero(OperationNode node) { for (ExpressionNode child : node.children()) { if (isZero(child)) return true; @@ -129,9 +129,9 @@ public class Simplifier extends ExpressionTransformer<TransformContext> { return false; } - private boolean hasDivisionByZero(ArithmeticNode node) { + private boolean hasDivisionByZero(OperationNode node) { for (int i = 1; i < node.children().size(); i++) { - if ( node.operators().get(i - 1) == ArithmeticOperator.DIVIDE && isZero(node.children().get(i))) + if (node.operators().get(i - 1) == Operator.DIVIDE && isZero(node.children().get(i))) return true; } return false; diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/RankingExpressionTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/RankingExpressionTestCase.java index 1ab9ee11252..83de8e04a7d 100755 --- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/RankingExpressionTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/RankingExpressionTestCase.java @@ -2,8 +2,8 @@ package com.yahoo.searchlib.rankingexpression; import com.yahoo.searchlib.rankingexpression.parser.ParseException; -import com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode; -import com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator; +import com.yahoo.searchlib.rankingexpression.rule.OperationNode; +import com.yahoo.searchlib.rankingexpression.rule.Operator; import com.yahoo.searchlib.rankingexpression.rule.CompositeNode; import com.yahoo.searchlib.rankingexpression.rule.IfNode; import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode; @@ -66,7 +66,7 @@ public class RankingExpressionTestCase { public void testProgrammaticBuilding() throws ParseException { ReferenceNode input = new ReferenceNode("input"); ReferenceNode constant = new ReferenceNode("constant"); - ArithmeticNode product = new ArithmeticNode(input, ArithmeticOperator.MULTIPLY, constant); + OperationNode product = new OperationNode(input, Operator.MULTIPLY, constant); Reduce<Reference> sum = new Reduce<>(new TensorFunctionNode.ExpressionTensorFunction(product), Reduce.Aggregator.sum); RankingExpression expression = new RankingExpression(new TensorFunctionNode(sum)); diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/EvaluationTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/EvaluationTestCase.java index b1ac4b9e3ca..019f76521e9 100644 --- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/EvaluationTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/EvaluationTestCase.java @@ -5,8 +5,8 @@ import com.yahoo.javacc.UnicodeUtilities; import com.yahoo.searchlib.rankingexpression.RankingExpression; import com.yahoo.searchlib.rankingexpression.parser.ParseException; import com.yahoo.searchlib.rankingexpression.rule.Arguments; -import com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode; -import com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator; +import com.yahoo.searchlib.rankingexpression.rule.OperationNode; +import com.yahoo.searchlib.rankingexpression.rule.Operator; import com.yahoo.searchlib.rankingexpression.rule.ConstantNode; import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode; import com.yahoo.searchlib.rankingexpression.rule.IfNode; @@ -779,8 +779,8 @@ public class EvaluationTestCase { @Test public void testProgrammaticBuildingAndPrecedence() { - RankingExpression standardPrecedence = new RankingExpression(new ArithmeticNode(constant(2), ArithmeticOperator.PLUS, new ArithmeticNode(constant(3), ArithmeticOperator.MULTIPLY, constant(4)))); - RankingExpression oppositePrecedence = new RankingExpression(new ArithmeticNode(new ArithmeticNode(constant(2), ArithmeticOperator.PLUS, constant(3)), ArithmeticOperator.MULTIPLY, constant(4))); + RankingExpression standardPrecedence = new RankingExpression(new OperationNode(constant(2), Operator.PLUS, new OperationNode(constant(3), Operator.MULTIPLY, constant(4)))); + RankingExpression oppositePrecedence = new RankingExpression(new OperationNode(new OperationNode(constant(2), Operator.PLUS, constant(3)), Operator.MULTIPLY, constant(4))); assertEquals(14.0, standardPrecedence.evaluate(null).asDouble(), tolerance); assertEquals(20.0, oppositePrecedence.evaluate(null).asDouble(), tolerance); assertEquals("2.0 + 3.0 * 4.0", standardPrecedence.toString()); |