Class Context
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
-
Method Summary
Modifier and TypeMethodDescriptionget
(int index) Lookup by index rather than name.abstract Value
Returns the value of a simple variable name.Returns the value of a structured variable on the formname(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 tensorcom.yahoo.tensor.TensorType
names()
Returns all the names available in this, or throws an UnsupportedOperationException if this operation is not supported.final void
Same as put(name,DoubleValue.frozen(value))void
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
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
- Specified by:
getType
in interfacecom.yahoo.tensor.evaluation.TypeContext<Reference>
-
getTensor
Returns a variable as a tensor- Specified by:
getTensor
in interfacecom.yahoo.tensor.evaluation.EvaluationContext<Reference>
-
get
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
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
Same as put(name,DoubleValue.frozen(value)) -
put
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
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.
-