blob: bcc8b81764135cd11360aa4b2927270e855ddd58 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.rankingexpression.transform;
import com.yahoo.searchlib.rankingexpression.RankingExpression;
import com.yahoo.searchlib.rankingexpression.rule.CompositeNode;
import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode;
import java.util.ArrayList;
import java.util.List;
/**
* Superclass of expression transformers
*
* @author bratseth
*/
public abstract class ExpressionTransformer {
public RankingExpression transform(RankingExpression expression) {
return new RankingExpression(expression.getName(), transform(expression.getRoot()));
}
/** Transforms an expression node and returns the transformed node */
public abstract ExpressionNode transform(ExpressionNode node);
/**
* Utility method which calls transform on each child of the given node and return the resulting transformed
* composite
*/
protected CompositeNode transformChildren(CompositeNode node) {
List<ExpressionNode> children = node.children();
List<ExpressionNode> transformedChildren = new ArrayList<>(children.size());
for (ExpressionNode child : children)
transformedChildren.add(transform(child));
return node.setChildren(transformedChildren);
}
}
|