corneto.data.Sample#

class corneto.data.Sample(features=<factory>)#

Bases: object

Represents a sample as a collection of features. Each feature is stored as a value. If a feature needs metadata, it should be represented as a dict with a mandatory “value” key.

Parameters:

features (Dict[str, Any])

__init__(features=<factory>)#
Parameters:

features (Dict[str, Any])

Return type:

None

Methods

__init__([features])

add_feature(name, value)

Adds a feature to this sample.

filter(predicate)

Filters the features and returns a new dict containing only those that satisfy the predicate.

filter_by(key, value)

Returns features that have metadata matching the given key and value.

filter_values(predicate[, value_key])

Filters the features and returns a new dict containing only those that satisfy the predicate.

filter_values_by(key, value[, value_key])

Returns features that have metadata matching the given key and value.

get_value(feature_name[, key])

Returns the value of a specific feature.

get_values([key])

Returns a dictionary of feature names and their values.

Attributes

features: Dict[str, Any]#
add_feature(name, value)#

Adds a feature to this sample. Raises an error if the feature already exists.

Parameters:
Return type:

None

get_values(key='value')#

Returns a dictionary of feature names and their values.

Parameters:

key (str)

Return type:

Dict[str, Any]

filter_values(predicate, value_key='value')#

Filters the features and returns a new dict containing only those that satisfy the predicate.

Parameters:
Return type:

Dict[str, Any]

filter_values_by(key, value, value_key='value')#

Returns features that have metadata matching the given key and value.

Parameters:
Return type:

Dict[str, Any]

get_value(feature_name, key='value')#

Returns the value of a specific feature.

Parameters:
  • feature_name (str)

  • key (str)

Return type:

Any

filter(predicate)#

Filters the features and returns a new dict containing only those that satisfy the predicate.

Parameters:

predicate (Callable[[str, Any], bool])

Return type:

Dict[str, Any]

filter_by(key, value)#

Returns features that have metadata matching the given key and value.

Parameters:
Return type:

Dict[str, Any]