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 aFeatDict
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 aFeatStruct
, then its features are copied (shallow copy). Iffeatures
is a dict, then a feature is created for each item, mapping its key to its value. Iffeatures
is a string, then it is processed usingFeatStructReader
. Iffeatures
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
andmorefeatures
, then the value frommorefeatures
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
.
- pop(k[, d]) v, remove specified key and return the corresponding value. [source]¶
If key is not found, default is returned if given, otherwise KeyError is raised If self is frozen, raise ValueError.
- popitem(*args, **kwargs)[source]¶
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)[source]¶
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)[source]¶
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 theFeatList
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, thenmorefeatures
provides additional features for theFeatDict
constructor.
- copy(deep=True)[source]¶
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.
- equal_values(other, check_reentrance=False)[source]¶
Return True if
self
andother
assign the same value to to every feature. In particular, return true ifself[p]==other[p]
for every feature path p such thatself[p]
orother[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
andother
.- Note
the
==
is equivalent toequal_values()
withcheck_reentrance=True
.
- freeze()[source]¶
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()[source]¶
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 thecopy()
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()[source]¶
Return the feature structure that is obtained by deleting any feature whose value is a
Variable
.- Return type
- rename_variables(vars=None, used_vars=(), new_vars=None)[source]¶
- See
nltk.featstruct.rename_variables()
- subsumes(other)[source]¶
Return True if
self
subsumesother
. I.e., return true If unifyingself
withother
would result in a feature structure equal toother
.
- values() an object providing a view on D's values ¶