nltk.featstruct.FeatDict

class nltk.featstruct.FeatDict[source]

Bases: FeatStruct, dict

A feature structure that acts like a Python dictionary. I.e., a mapping from feature identifiers to feature values, where a feature identifier can be a string or a Feature; and where a feature value can be either a basic value (such as a string or an integer), or a nested feature structure. A feature identifiers for a FeatDict is sometimes called a “feature name”.

Two feature dicts are considered equal if they assign the same values to all features, and have the same reentrances.

See

FeatStruct for information about feature paths, reentrance, cyclic feature structures, mutability, freezing, and hashing.

__init__(features=None, **morefeatures)[source]

Create a new feature dictionary, with the specified features.

Parameters
  • features – The initial value for this feature dictionary. If features is a FeatStruct, then its features are copied (shallow copy). If features is a dict, then a feature is created for each item, mapping its key to its value. If features is a string, then it is processed using FeatStructReader. If features is a list of tuples (name, val), then a feature is created for each tuple.

  • morefeatures – Additional features for the new feature dictionary. If a feature is listed under both features and morefeatures, then the value from morefeatures will be used.

get(name_or_path, default=None)[source]

If the feature with the given name or path exists, return its value; otherwise, return default.

has_key(name_or_path)[source]

Return true if a feature with the given name or path exists.

clear() None.  Remove all items from D.

If self is frozen, raise ValueError.

pop(k[, d]) v, remove specified key and return the corresponding value.

If key is not found, default is returned if given, otherwise KeyError is raised If self is frozen, raise ValueError.

popitem(*args, **kwargs)

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty. If self is frozen, raise ValueError.

setdefault(*args, **kwargs)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default. If self is frozen, raise ValueError.

update([E, ]**F) None.  Update D from dict/iterable E and F.[source]

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

static __new__(cls, features=None, **morefeatures)

Construct and return a new feature structure. If this constructor is called directly, then the returned feature structure will be an instance of either the FeatDict class or the FeatList class.

Parameters
  • features

    The initial feature values for this feature structure:

    • FeatStruct(string) -> FeatStructReader().read(string)

    • FeatStruct(mapping) -> FeatDict(mapping)

    • FeatStruct(sequence) -> FeatList(sequence)

    • FeatStruct() -> FeatDict()

  • morefeatures – If features is a mapping or None, then morefeatures provides additional features for the FeatDict constructor.

copy(deep=True)

Return a new copy of self. The new copy will not be frozen.

Parameters

deep – If true, create a deep copy; if false, create a shallow copy.

cyclic()

Return True if this feature structure contains itself.

equal_values(other, check_reentrance=False)

Return True if self and other assign the same value to to every feature. In particular, return true if self[p]==other[p] for every feature path p such that self[p] or other[p] is a base value (i.e., not a nested feature structure).

Parameters

check_reentrance – If True, then also return False if there is any difference between the reentrances of self and other.

Note

the == is equivalent to equal_values() with check_reentrance=True.

freeze()

Make this feature structure, and any feature structures it contains, immutable. Note: this method does not attempt to ‘freeze’ any feature value that is not a FeatStruct; it is recommended that you use only immutable feature values.

fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

frozen()

Return True if this feature structure is immutable. Feature structures can be made immutable with the freeze() method. Immutable feature structures may not be made mutable again, but new mutable copies can be produced with the copy() method.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
remove_variables()

Return the feature structure that is obtained by deleting any feature whose value is a Variable.

Return type

FeatStruct

rename_variables(vars=None, used_vars=(), new_vars=None)
See

nltk.featstruct.rename_variables()

retract_bindings(bindings)
See

nltk.featstruct.retract_bindings()

substitute_bindings(bindings)
See

nltk.featstruct.substitute_bindings()

subsumes(other)

Return True if self subsumes other. I.e., return true If unifying self with other would result in a feature structure equal to other.

unify(other, bindings=None, trace=False, fail=None, rename_vars=True)
values() an object providing a view on D's values
variables()
See

nltk.featstruct.find_variables()

walk()

Return an iterator that generates this feature structure, and each feature structure it contains. Each feature structure will be generated exactly once.