class documentation

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_values 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_variables Return the feature structure that is obtained by deleting any feature whose value is a Variable.
Method rename_variables No summary
Method retract_bindings No summary
Method substitute_bindings 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_hashvalue Return a hash value for this feature structure.
Method _equal Return True iff self and other have equal values.
Method _find_reentrances 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_ERROR 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
def __deepcopy__(self, memo): (source)
def __eq__(self, other): (source)

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()
def __hash__(self): (source)

If this feature structure is frozen, return its hash value; otherwise, raise TypeError.

def __lt__(self, other): (source)

Undocumented

def __ne__(self, other): (source)

Undocumented

def __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 the FeatList class.

Parameters
clsUndocumented
features

The initial feature values for this feature structure:

  • FeatStruct(string) -> FeatStructReader().read(string)
  • FeatStruct(mapping) -> FeatDict(mapping)
  • FeatStruct(sequence) -> FeatList(sequence)
  • FeatStruct() -> FeatDict()
**morefeaturesIf features is a mapping or None, then morefeatures provides additional features for the FeatDict constructor.
def __repr__(self): (source)

Display a single-line representation of this feature structure, suitable for embedding in other representations.

def copy(self, deep=True): (source)

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

Parameters
deepIf true, create a deep copy; if false, create a shallow copy.
def cyclic(self): (source)

Return True if this feature structure contains itself.

def equal_values(self, other, check_reentrance=False): (source)

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
otherUndocumented
check_reentranceIf 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.
def freeze(self): (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.

def frozen(self): (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 the copy() method.

def remove_variables(self): (source)

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

Returns
FeatStructUndocumented
def rename_variables(self, vars=None, used_vars=(), new_vars=None): (source)
See Also
nltk.featstruct.rename_variables()
def retract_bindings(self, bindings): (source)
See Also
nltk.featstruct.retract_bindings()
def substitute_bindings(self, bindings): (source)
See Also
nltk.featstruct.substitute_bindings()
def subsumes(self, other): (source)

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

def unify(self, other, bindings=None, trace=False, fail=None, rename_vars=True): (source)

Undocumented

def variables(self): (source)
See Also
nltk.featstruct.find_variables()
def walk(self): (source)

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

def _calculate_hashvalue(self, visited): (source)

Return a hash value for this feature structure.

Parameters
visitedA set containing the ids of all feature structures we've already visited while hashing.
Unknown Field: require
self must be frozen.
def _equal(self, other, check_reentrance, visited_self, visited_other, visited_pairs): (source)

Return True iff self and other have equal values.

Parameters
otherUndocumented
check_reentranceUndocumented
visited_selfA set containing the ids of all self feature structures we've already visited.
visited_otherA set containing the ids of all other feature structures we've already visited.
visited_pairsA set containing (selfid, otherid) pairs for all pairs of feature structures we've already visited.
def _find_reentrances(self, reentrances): (source)

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.

def _freeze(self, visited): (source)

Make this feature structure, and any feature structure it contains, immutable.

Parameters
visitedA set containing the ids of all feature structures we've already visited while freezing.
def _items(self): (source)

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.

def _keys(self): (source)

Return an iterable of the feature identifiers used by this FeatStruct.

def _repr(self, reentrances, reentrance_ids): (source)

Return a string representation of this feature structure.

Parameters
reentrancesA dictionary that maps from the id of each feature value in self, indicating whether that value is reentrant or not.
reentrance_idsA 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.
def _values(self): (source)

Return an iterable of the feature values directly defined by this FeatStruct.

def _walk(self, visited): (source)

Undocumented

_FROZEN_ERROR: str = (source)

Undocumented

Value
'Frozen FeatStructs may not be modified.'
_frozen: bool = (source)

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.

Undocumented