java.lang.Object
com.yahoo.searchlib.rankingexpression.evaluation.Context
All Implemented Interfaces:
com.yahoo.tensor.evaluation.EvaluationContext<Reference>, com.yahoo.tensor.evaluation.TypeContext<Reference>
Direct Known Subclasses:
AbstractArrayContext, MapContext

public abstract class Context extends Object implements com.yahoo.tensor.evaluation.EvaluationContext<Reference>
The context providing value bindings for an expression evaluation.
Author:
bratseth
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    get(int index)
    Lookup by index rather than name.
    abstract Value
    get(String name)
    Returns the value of a simple variable name.
    get(String name, Arguments arguments, String output)
    Returns the value of a structured variable on the form name(argument*)(.output)?, where argument is any string.
    double
    getDouble(int index)
    Lookup by index rather than name directly to a double.
    com.yahoo.tensor.Tensor
    Returns a variable as a tensor
    com.yahoo.tensor.TensorType
    getType(String reference)
     
    Returns all the names available in this, or throws an UnsupportedOperationException if this operation is not supported.
    final void
    put(String name, double value)
    Same as put(name,DoubleValue.frozen(value))
    void
    put(String name, Value value)
    Sets a value to this, or throws an UnsupportedOperationException if this is not supported.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.yahoo.tensor.evaluation.TypeContext

    getType
  • Constructor Details

    • Context

      public Context()
  • Method Details

    • get

      public abstract Value get(String name)
      Returns the value of a simple variable name.
      Parameters:
      name - the name of the variable whose value to return.
      Returns:
      the value of the named variable.
    • getType

      public com.yahoo.tensor.TensorType getType(String reference)
      Specified by:
      getType in interface com.yahoo.tensor.evaluation.TypeContext<Reference>
    • getTensor

      public com.yahoo.tensor.Tensor getTensor(String name)
      Returns a variable as a tensor
      Specified by:
      getTensor in interface com.yahoo.tensor.evaluation.EvaluationContext<Reference>
    • get

      public Value get(String name, Arguments arguments, String output)

      Returns the value of a structured variable on the form name(argument*)(.output)?, where argument is any string. This may be used to implement more advanced variables whose values are calculated at runtime from arguments. Supporting this in a context is optional.

      This default implementation generates a name on the form name(argument1, argument2, ...argumentN).output. If there are no arguments the parenthesis are omitted. If there is no output, the dot is omitted.

      Parameters:
      name - the name of this variable.
      arguments - the parsed arguments as given in the textual expression.
      output - the name of the value to output (to enable one named calculation to output several), or null to output the "main" (or only) value.
    • get

      public Value get(int index)

      Lookup by index rather than name. This is supported by some optimized context subclasses. This default implementation throws UnsupportedOperationException.

      Parameters:
      index - the index of the variable whose value to return.
      Returns:
      the value of the indexed variable.
    • getDouble

      public double getDouble(int index)
      Lookup by index rather than name directly to a double. This is supported by some optimized context subclasses. This default implementation throws UnsupportedOperationException.
      Parameters:
      index - the index of the variable whose value to return.
      Returns:
      the value of the indexed variable.
    • put

      public final void put(String name, double value)
      Same as put(name,DoubleValue.frozen(value))
    • put

      public void put(String name, Value value)
      Sets a value to this, or throws an UnsupportedOperationException if this is not supported. This default implementation does the latter.
      Parameters:
      name - the name of the variable to set.
      value - the value to set. Ownership of this value is transferred to this - if it is mutable (not frozen) it may be modified during execution
    • names

      public Set<String> names()
      Returns all the names available in this, or throws an UnsupportedOperationException if this operation is not supported. This default implementation does the latter.
      Returns:
      the set of all variable names.