Class ExpressionFunction
- java.lang.Object
-
- com.yahoo.searchlib.rankingexpression.ExpressionFunction
-
public class ExpressionFunction extends java.lang.Object
A function defined by a ranking expression, optionally containing type information for inputs and outputs. Immutable, but note that ranking expressions are *not* immutable.- Author:
- Simon Thoresen Hult, bratseth
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ExpressionFunction.Instance
An instance of a serialization of this function, using a particular serialization context (byexpand(com.yahoo.searchlib.rankingexpression.rule.SerializationContext, java.util.List<com.yahoo.searchlib.rankingexpression.rule.ExpressionNode>, java.util.Deque<java.lang.String>)
)
-
Constructor Summary
Constructors Constructor Description ExpressionFunction(java.lang.String name, RankingExpression body)
Constructs a new function with no argumentsExpressionFunction(java.lang.String name, java.util.List<java.lang.String> arguments, RankingExpression body)
Constructs a new functionExpressionFunction(java.lang.String name, java.util.List<java.lang.String> arguments, RankingExpression body, java.util.Map<java.lang.String,com.yahoo.tensor.TensorType> argumentTypes, java.util.Optional<com.yahoo.tensor.TensorType> returnType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<java.lang.String>
arguments()
Returns an immutable list of the arguments of thisjava.util.Map<java.lang.String,com.yahoo.tensor.TensorType>
argumentTypes()
Returns the types of the arguments of this, if specified.ExpressionFunction.Instance
expand(SerializationContext context, java.util.List<ExpressionNode> argumentValues, java.util.Deque<java.lang.String> path)
Creates and returns an instance of this function based on the given arguments.RankingExpression
getBody()
java.lang.String
getName()
java.util.Optional<com.yahoo.tensor.TensorType>
returnType()
Returns the return type of this, or empty if not specifiedjava.lang.String
toString()
ExpressionFunction
withArgument(java.lang.String argument)
Returns a copy of this with the given argument added (if not already present)ExpressionFunction
withArgument(java.lang.String argument, com.yahoo.tensor.TensorType type)
Returns a copy of this with the given argument (if not present) and argument type addedExpressionFunction
withBody(RankingExpression body)
Returns a copy of this with the body changed to the given valueExpressionFunction
withName(java.lang.String name)
ExpressionFunction
withReturnType(com.yahoo.tensor.TensorType returnType)
-
-
-
Constructor Detail
-
ExpressionFunction
public ExpressionFunction(java.lang.String name, RankingExpression body)
Constructs a new function with no arguments- Parameters:
name
- the name of this functionbody
- the ranking expression that defines this function
-
ExpressionFunction
public ExpressionFunction(java.lang.String name, java.util.List<java.lang.String> arguments, RankingExpression body)
Constructs a new function- Parameters:
name
- the name of this functionarguments
- its argument namesbody
- the ranking expression that defines this function
-
ExpressionFunction
public ExpressionFunction(java.lang.String name, java.util.List<java.lang.String> arguments, RankingExpression body, java.util.Map<java.lang.String,com.yahoo.tensor.TensorType> argumentTypes, java.util.Optional<com.yahoo.tensor.TensorType> returnType)
-
-
Method Detail
-
getName
public java.lang.String getName()
-
arguments
public java.util.List<java.lang.String> arguments()
Returns an immutable list of the arguments of this
-
getBody
public RankingExpression getBody()
-
argumentTypes
public java.util.Map<java.lang.String,com.yahoo.tensor.TensorType> argumentTypes()
Returns the types of the arguments of this, if specified. The keys of this may be any subset of the arguments
-
returnType
public java.util.Optional<com.yahoo.tensor.TensorType> returnType()
Returns the return type of this, or empty if not specified
-
withName
public ExpressionFunction withName(java.lang.String name)
-
withBody
public ExpressionFunction withBody(RankingExpression body)
Returns a copy of this with the body changed to the given value
-
withReturnType
public ExpressionFunction withReturnType(com.yahoo.tensor.TensorType returnType)
-
withArgument
public ExpressionFunction withArgument(java.lang.String argument)
Returns a copy of this with the given argument added (if not already present)
-
withArgument
public ExpressionFunction withArgument(java.lang.String argument, com.yahoo.tensor.TensorType type)
Returns a copy of this with the given argument (if not present) and argument type added
-
expand
public ExpressionFunction.Instance expand(SerializationContext context, java.util.List<ExpressionNode> argumentValues, java.util.Deque<java.lang.String> path)
Creates and returns an instance of this function based on the given arguments. If function calls are nested, this call may produce additional functions.- Parameters:
context
- the context used to expand thisargumentValues
- the arguments to instantiate on.path
- the expansion path leading to this.- Returns:
- the script function instance created.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-