class FeatStruct(SubstituteBindingsI): (source)
Known subclasses: nltk.featstruct.FeatDict
, nltk.featstruct.FeatList
Constructor: FeatStruct(features, **morefeatures)
A mapping from feature identifiers to feature values, where each feature value is either a basic value (such as a string or an integer), or a nested feature structure. There are two types of feature structure:
- feature dictionaries, implemented by FeatDict, act like Python dictionaries. Feature identifiers may be strings or instances of the Feature class.
- feature lists, implemented by FeatList, act like Python lists. Feature identifiers are integers.
Feature structures may be indexed using either simple feature identifiers or 'feature paths.' A feature path is a sequence of feature identifiers that stand for a corresponding sequence of indexing operations. In particular, fstruct[(f1,f2,...,fn)] is equivalent to fstruct[f1][f2]...[fn].
Feature structures may contain reentrant feature structures. A "reentrant feature structure" is a single feature structure object that can be accessed via multiple feature paths. Feature structures may also be cyclic. A feature structure is "cyclic" if there is any feature path from the feature structure to itself.
Two feature structures are considered equal if they assign the same values to all features, and have the same reentrancies.
By default, feature structures are mutable. They may be made immutable with the freeze() method. Once they have been frozen, they may be hashed, and thus used as dictionary keys.
Method | __deepcopy__ |
Undocumented |
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 | _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 | _values |
Return an iterable of the feature values directly defined by this FeatStruct. |
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 |
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).
See Also | |
equal_values() |
nltk.grammar.FeatStructNonterminal
If this feature structure is frozen, return its hash value; otherwise, raise TypeError.
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 | |
cls | Undocumented |
features | The initial feature values for this feature structure:
|
**morefeatures | If features is a mapping or None, then morefeatures provides additional features for the FeatDict constructor. |
Display a single-line representation of this feature structure, suitable for embedding in other representations.
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. |
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 | |
other | Undocumented |
check | 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. |
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.
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.
Return the feature structure that is obtained by deleting any feature whose value is a Variable.
Returns | |
FeatStruct | Undocumented |
Return True if self subsumes other. I.e., return true If unifying self with other would result in a feature structure equal to other.
Return an iterator that generates this feature structure, and each feature structure it contains. Each feature structure will be generated exactly once.
Return a hash value for this feature structure.
Parameters | |
visited | A set containing the ids of all feature structures we've already visited while hashing. |
Unknown Field: require | |
self must be frozen. |
Return True iff self and other have equal values.
Parameters | |
other | Undocumented |
check | Undocumented |
visited | A set containing the ids of all self feature structures we've already visited. |
visited | A set containing the ids of all other feature structures we've already visited. |
visited | A set containing (selfid, otherid) pairs for all pairs of feature structures we've already visited. |
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.
Make this feature structure, and any feature structure it contains, immutable.
Parameters | |
visited | A set containing the ids of all feature structures we've already visited while freezing. |
nltk.featstruct.FeatDict
, nltk.featstruct.FeatList
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.FeatDict
, nltk.featstruct.FeatList
Return an iterable of the feature identifiers used by this FeatStruct.
nltk.featstruct.FeatDict
, nltk.featstruct.FeatList
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. |
nltk.featstruct.FeatDict
, nltk.featstruct.FeatList
Return an iterable of the feature values directly defined by this FeatStruct.