use of com.yahoo.searchlib.rankingexpression.rule.CompositeNode in project vespa by vespa-engine.
the class SimplifierTestCase method testParenthesisPreservation.
@Test
public void testParenthesisPreservation() throws ParseException {
Simplifier s = new Simplifier();
TransformContext c = new TransformContext(Collections.emptyMap());
CompositeNode transformed = (CompositeNode) s.transform(new RankingExpression("a + (b + c) / 100000000.0"), c).getRoot();
assertEquals("a + (b + c) / 100000000.0", transformed.toString());
}
use of com.yahoo.searchlib.rankingexpression.rule.CompositeNode in project vespa by vespa-engine.
the class GBDTForestOptimizer method findAndOptimize.
/**
* Recursively descend and optimize gbdt forest nodes.
*
* @return the resulting node, which may be the input node if no optimizations were found
*/
private ExpressionNode findAndOptimize(ExpressionNode node) {
ExpressionNode newNode = optimize(node);
//
if (!(newNode instanceof CompositeNode))
return newNode;
CompositeNode newComposite = (CompositeNode) newNode;
List<ExpressionNode> newChildren = new ArrayList<>();
for (ExpressionNode child : newComposite.children()) {
newChildren.add(findAndOptimize(child));
}
return newComposite.setChildren(newChildren);
}
use of com.yahoo.searchlib.rankingexpression.rule.CompositeNode in project vespa by vespa-engine.
the class TensorFlowFeatureConverter method reduceBatchDimensionsAtInput.
private ExpressionNode reduceBatchDimensionsAtInput(ExpressionNode node, TensorFlowModel model, TypeContext<Reference> typeContext) {
if (node instanceof TensorFunctionNode) {
TensorFunction tensorFunction = ((TensorFunctionNode) node).function();
if (tensorFunction instanceof Rename) {
List<ExpressionNode> children = ((TensorFunctionNode) node).children();
if (children.size() == 1 && children.get(0) instanceof ReferenceNode) {
ReferenceNode referenceNode = (ReferenceNode) children.get(0);
if (model.requiredMacros().containsKey(referenceNode.getName())) {
return reduceBatchDimensionExpression(tensorFunction, typeContext);
}
}
}
}
if (node instanceof ReferenceNode) {
ReferenceNode referenceNode = (ReferenceNode) node;
if (model.requiredMacros().containsKey(referenceNode.getName())) {
return reduceBatchDimensionExpression(TensorFunctionNode.wrapArgument(node), typeContext);
}
}
if (node instanceof CompositeNode) {
List<ExpressionNode> children = ((CompositeNode) node).children();
List<ExpressionNode> transformedChildren = new ArrayList<>(children.size());
for (ExpressionNode child : children) {
transformedChildren.add(reduceBatchDimensionsAtInput(child, model, typeContext));
}
return ((CompositeNode) node).setChildren(transformedChildren);
}
return node;
}
use of com.yahoo.searchlib.rankingexpression.rule.CompositeNode in project vespa by vespa-engine.
the class RankingExpressionTestCase method testIsNan.
@Test
public void testIsNan() throws ParseException {
String strExpr = "if (isNan(attribute(foo)) == 1.0, 1.0, attribute(foo))";
RankingExpression expr = new RankingExpression(strExpr);
CompositeNode root = (CompositeNode) expr.getRoot();
CompositeNode comparison = (CompositeNode) root.children().get(0);
ExpressionNode isNan = comparison.children().get(0);
assertTrue(isNan instanceof FunctionNode);
assertEquals("isNan(attribute(foo))", isNan.toString());
}
use of com.yahoo.searchlib.rankingexpression.rule.CompositeNode in project vespa by vespa-engine.
the class AbstractArrayContext method extractVariables.
private void extractVariables(ExpressionNode node, Set<String> variables) {
if (node instanceof ReferenceNode) {
ReferenceNode fNode = (ReferenceNode) node;
if (fNode.getArguments().expressions().size() > 0)
throw new UnsupportedOperationException("Array lookup is not supported with features having arguments)");
variables.add(fNode.toString());
} else if (node instanceof CompositeNode) {
CompositeNode cNode = (CompositeNode) node;
for (ExpressionNode child : cNode.children()) extractVariables(child, variables);
}
}
Aggregations