gatenlp.feature_bearer module

A “mixin” class to use for classes which should have features. This turns the class into something that can be used much like a dict in addition to original methods of the class. The inheriting class must implement _log_feature_change(command, feature=None, value=None) and must have an attribute changelog.

class gatenlp.feature_bearer.FeatureBearer(initialfeatures=None)[source]

Bases: object

Initialise any features, if necessary. :param initialfeatures: an iterable containing tuples of initial feature key/value pairs :return:

clear_features() → None[source]

Remove all features. :return:

copy() → Dict[source]

Return a shallow copy of the feature map. This is NOT a view and does not update when the features change! :return:

del_feature(featurename: str) → None[source]

Remove the feature with that name :param featurename: the feature to remove from the set :return:

feature_names() → Union[Set, KeysView][source]

Return an iterable with the feature names. This is NOT a view and does not update when the features change! :return:

feature_values() → List[source]

Return an iterable with the feature values. This is NOT a view and does not update when the features change! :return:

get_feature(key: str, default=None)[source]
has_feature(key: str) → bool[source]
num_features() → int[source]

Return the number of features. We do not use “len” for this, since the feature bearing object may have its own useful len implementation. :return: number of features

set_feature(key: str, value) → None[source]

Set feature to the given value :param key: feature name :param value: value :return:

update_features(*other, **kwargs)[source]

Update the features from another map or an iterable of key value pairs or from keyword arguments :param other: another dictionary or an iterable of key,value pairs :param kwargs: used to update the features :return:

class gatenlp.feature_bearer.FeatureViewer(features, changelog=None, logger=None)[source]

Bases: gatenlp.feature_bearer.FeatureBearer

Initialise any features, if necessary. :param initialfeatures: an iterable containing tuples of initial feature key/value pairs :return: