nltk.featstruct.FeatList¶
- class nltk.featstruct.FeatList[source]¶
Bases:
FeatStruct
,list
A list of feature values, where each feature value is either a basic value (such as a string or an integer), or a nested feature structure.
Feature lists may contain reentrant feature values. A “reentrant feature value” is a single feature value that can be accessed via multiple feature paths. Feature lists may also be cyclic.
Two feature lists 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=())[source]¶
Create a new feature list, with the specified features.
- Parameters
features – The initial list of features for this feature list. If
features
is a string, then it is paresd usingFeatStructReader
. Otherwise, it should be a sequence of basic values and nested feature structures.
- append(*args, **kwargs)[source]¶
Append object to the end of the list. If self is frozen, raise ValueError.
- extend(*args, **kwargs)[source]¶
Extend list by appending elements from the iterable. If self is frozen, raise ValueError.
- pop(*args, **kwargs)[source]¶
Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range. If self is frozen, raise ValueError.
- remove(*args, **kwargs)[source]¶
Remove first occurrence of value.
Raises ValueError if the value is not present. If self is frozen, raise ValueError.
- sort(*args, **kwargs)[source]¶
Sort the list in ascending order and return None.
The sort is in-place (i.e. the list itself is modified) and stable (i.e. the order of two equal elements is maintained).
If a key function is given, apply it once to each list item and sort them, ascending or descending, according to their function values.
The reverse flag can be set to sort in descending order. If self is frozen, raise ValueError.
- 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.
- clear()¶
Remove all items from list.
- 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.
- count(value, /)¶
Return number of occurrences of value.
- 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.
- 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.
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- 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()