Class ExpressionFunction

java.lang.Object
com.yahoo.searchlib.rankingexpression.ExpressionFunction

public class ExpressionFunction extends 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
  • Constructor Details

    • ExpressionFunction

      public ExpressionFunction(String name, RankingExpression body)
      Constructs a new function with no arguments
      Parameters:
      name - the name of this function
      body - the ranking expression that defines this function
    • ExpressionFunction

      public ExpressionFunction(String name, List<String> arguments, RankingExpression body)
      Constructs a new function
      Parameters:
      name - the name of this function
      arguments - its argument names
      body - the ranking expression that defines this function
    • ExpressionFunction

      public ExpressionFunction(String name, List<String> arguments, RankingExpression body, Map<String,com.yahoo.tensor.TensorType> argumentTypes, Optional<com.yahoo.tensor.TensorType> returnType)
  • Method Details

    • getName

      public String getName()
    • arguments

      public List<String> arguments()
      Returns an immutable list of the arguments of this
    • getBody

      public RankingExpression getBody()
    • argumentTypes

      public Map<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 Optional<com.yahoo.tensor.TensorType> returnType()
      Returns the return type of this, or empty if not specified
    • withName

      public ExpressionFunction withName(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(String argument)
      Returns a copy of this with the given argument added (if not already present)
    • withArgument

      public ExpressionFunction withArgument(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, List<ExpressionNode> argumentValues, Deque<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 this
      argumentValues - the arguments to instantiate on.
      path - the expansion path leading to this.
      Returns:
      the script function instance created.
    • toString

      public String toString()
      Overrides:
      toString in class Object