class FeatDict(FeatStruct, dict): (source)
Known subclasses: nltk.grammar.FeatStructNonterminal
Constructor: FeatDict(features, **morefeatures)
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 Also | |
FeatStruct for information about feature paths, reentrance, cyclic feature structures, mutability, freezing, and hashing. |
Method | __contains__ |
Return true if a feature with the given name or path exists. |
Method | __deepcopy__ |
Undocumented |
Method | __delitem__ |
If the feature with the given name or path exists, delete its value; otherwise, raise KeyError. |
Method | __getitem__ |
If the feature with the given name or path exists, return its value; otherwise, raise KeyError. |
Method | __init__ |
Create a new feature dictionary, with the specified features. |
Method | __setitem__ |
Set the value for the feature with the given name or path to value. If name_or_path is an invalid path, raise KeyError. |
Method | __str__ |
Display a multi-line representation of this feature dictionary as an FVM (feature value matrix). |
Method | get |
If the feature with the given name or path exists, return its value; otherwise, return default. |
Method | has |
Return true if a feature with the given name or path exists. |
Method | update |
Undocumented |
Class Variable | clear |
Undocumented |
Class Variable | pop |
Undocumented |
Class Variable | popitem |
Undocumented |
Class Variable | setdefault |
Undocumented |
Method | _items |
Return an iterable of (fid,fval) pairs, where fid is a feature identifier and fval is the corresponding feature value, for all features defined by this FeatStruct. |
Method | _keys |
Return an iterable of the feature identifiers used by this FeatStruct. |
Method | _repr |
Return a string representation of this feature structure. |
Method | _str |
No summary |
Method | _values |
Return an iterable of the feature values directly defined by this FeatStruct. |
Constant | _INDEX |
Undocumented |
Inherited from FeatStruct
:
Method | __eq__ |
Return true if self and other are both feature structures, assign the same values to all features, and contain the same reentrances. I.e., return self.equal_values(other, check_reentrance=True). |
Method | __hash__ |
If this feature structure is frozen, return its hash value; otherwise, raise TypeError. |
Method | __lt__ |
Undocumented |
Method | __ne__ |
Undocumented |
Method | __new__ |
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. |
Method | __repr__ |
Display a single-line representation of this feature structure, suitable for embedding in other representations. |
Method | copy |
Return a new copy of self. The new copy will not be frozen. |
Method | cyclic |
Return True if this feature structure contains itself. |
Method | equal |
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). |
Method | 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. |
Method | 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 ... |
Method | remove |
Return the feature structure that is obtained by deleting any feature whose value is a Variable. |
Method | rename |
No summary |
Method | retract |
No summary |
Method | substitute |
No summary |
Method | subsumes |
Return True if self subsumes other. I.e., return true If unifying self with other would result in a feature structure equal to other. |
Method | unify |
Undocumented |
Method | variables |
No summary |
Method | walk |
Return an iterator that generates this feature structure, and each feature structure it contains. Each feature structure will be generated exactly once. |
Method | _calculate |
Return a hash value for this feature structure. |
Method | _equal |
Return True iff self and other have equal values. |
Method | _find |
Return a dictionary that maps from the id of each feature structure contained in self (including self) to a boolean value, indicating whether it is reentrant or not. |
Method | _freeze |
Make this feature structure, and any feature structure it contains, immutable. |
Method | _walk |
Undocumented |
Constant | _FROZEN |
Undocumented |
Instance Variable | _frozen |
frozen or not. Once this flag is set, it should never be un-set; and no further modification should be made to this feature structue. |
Instance Variable | _hash |
Undocumented |
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. |
Set the value for the feature with the given name or path to value. If name_or_path is an invalid path, raise KeyError.
nltk.featstruct.FeatStruct._items
Return an iterable of (fid,fval) pairs, where fid is a feature identifier and fval is the corresponding feature value, for all features defined by this FeatStruct.
nltk.featstruct.FeatStruct._keys
Return an iterable of the feature identifiers used by this FeatStruct.
nltk.featstruct.FeatStruct._repr
Return a string representation of this feature structure.
Parameters | |
reentrances | A dictionary that maps from the id of each feature value in self, indicating whether that value is reentrant or not. |
reentrance | A dictionary mapping from each id of a feature value to a unique identifier. This is modified by repr: the first time a reentrant feature value is displayed, an identifier is added to reentrance_ids for it. |
Parameters | |
reentrances | A dictionary that maps from the id of each feature value in self, indicating whether that value is reentrant or not. |
reentrance | A dictionary mapping from each id of a feature value to a unique identifier. This is modified by repr: the first time a reentrant feature value is displayed, an identifier is added to reentrance_ids for it. |
Returns | |
A list of lines composing a string representation of this feature dictionary. |
nltk.featstruct.FeatStruct._values
Return an iterable of the feature values directly defined by this FeatStruct.