Class FeatureData

java.lang.Object
com.yahoo.search.result.FeatureData
All Implemented Interfaces:
com.yahoo.data.access.Inspectable, com.yahoo.data.JsonProducer

public class FeatureData extends Object implements com.yahoo.data.access.Inspectable, com.yahoo.data.JsonProducer
A wrapper for structured data representing feature values: A map of floats and tensors. This class is immutable but not thread safe.
Author:
bratseth
  • Constructor Summary

    Constructors
    Constructor
    Description
    FeatureData(com.yahoo.data.access.Inspector encodedValues)
     
    FeatureData(Map<String,com.yahoo.tensor.Tensor> values)
    Creates a feature data from a map of values.
  • Method Summary

    Modifier and Type
    Method
    Description
     
    boolean
    equals(Object other)
     
    Returns the names of the features available in this
    getDouble(String featureName)
    Returns the value of a scalar feature, or null if it is not present.
    com.yahoo.tensor.Tensor
    getTensor(String featureName)
    Returns the value of a tensor feature, or null if it is not present.
    int
     
    com.yahoo.data.access.Inspector
    Returns the fields of this as an inspector, where tensors are represented as binary data which can be decoded using com.yahoo.tensor.serialization.TypedBinaryFormat.decode(Optional.empty(), GrowableByteBuffer.wrap(featureValue.asData()))
    boolean
     
    void
    set(String featureName, double value)
    Sets a new or modified value in this.
    void
    set(String featureName, com.yahoo.tensor.Tensor value)
    Sets a new or modified value in this.
     
    toJson(boolean tensorShortForm)
     
    toJson(boolean tensorShortForm, boolean tensorDirectValues)
     
    toJson(com.yahoo.tensor.serialization.JsonFormat.EncodeOptions tensorOptions)
     
     
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • FeatureData

      public FeatureData(com.yahoo.data.access.Inspector encodedValues)
    • FeatureData

      public FeatureData(Map<String,com.yahoo.tensor.Tensor> values)
      Creates a feature data from a map of values.
  • Method Details

    • empty

      public static FeatureData empty()
    • inspect

      public com.yahoo.data.access.Inspector inspect()
      Returns the fields of this as an inspector, where tensors are represented as binary data which can be decoded using com.yahoo.tensor.serialization.TypedBinaryFormat.decode(Optional.empty(), GrowableByteBuffer.wrap(featureValue.asData()))
      Specified by:
      inspect in interface com.yahoo.data.access.Inspectable
    • toJson

      public String toJson()
      Specified by:
      toJson in interface com.yahoo.data.JsonProducer
    • toJson

      public String toJson(boolean tensorShortForm)
    • toJson

      public String toJson(boolean tensorShortForm, boolean tensorDirectValues)
    • toJson

      public String toJson(com.yahoo.tensor.serialization.JsonFormat.EncodeOptions tensorOptions)
    • writeJson

      public StringBuilder writeJson(StringBuilder target)
      Specified by:
      writeJson in interface com.yahoo.data.JsonProducer
    • getDouble

      public Double getDouble(String featureName)
      Returns the value of a scalar feature, or null if it is not present.
      Throws:
      IllegalArgumentException - if the value exists but isn't a scalar (that is, if it is a tensor with nonzero rank)
    • getTensor

      public com.yahoo.tensor.Tensor getTensor(String featureName)
      Returns the value of a tensor feature, or null if it is not present. This will return any feature value: Scalars are returned as a rank 0 tensor.
    • set

      public void set(String featureName, com.yahoo.tensor.Tensor value)
      Sets a new or modified value in this.
    • set

      public void set(String featureName, double value)
      Sets a new or modified value in this.
    • isEmpty

      public boolean isEmpty()
    • featureNames

      public Set<String> featureNames()
      Returns the names of the features available in this
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object