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 using FeatStructReader. Otherwise, it should be a sequence of basic values and nested feature structures.

append(*args, **kwargs)

Append object to the end of the list. If self is frozen, raise ValueError.

extend(*args, **kwargs)

Extend list by appending elements from the iterable. If self is frozen, raise ValueError.

insert(*args, **kwargs)

Insert object before index. If self is frozen, raise ValueError.

pop(*args, **kwargs)

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)

Remove first occurrence of value.

Raises ValueError if the value is not present. If self is frozen, raise ValueError.

reverse(*args, **kwargs)

Reverse IN PLACE. If self is frozen, raise ValueError.

sort(*args, **kwargs)

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)

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
  • 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, then morefeatures provides additional features for the FeatDict constructor.

clear()

Remove all items from list.

copy(deep=True)

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.

cyclic()

Return True if this feature structure contains itself.

equal_values(other, check_reentrance=False)

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

check_reentrance – 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.

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.

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 copy() method.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

remove_variables()

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

Return type

FeatStruct

rename_variables(vars=None, used_vars=(), new_vars=None)
See

nltk.featstruct.rename_variables()

retract_bindings(bindings)
See

nltk.featstruct.retract_bindings()

substitute_bindings(bindings)
See

nltk.featstruct.substitute_bindings()

subsumes(other)

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

unify(other, bindings=None, trace=False, fail=None, rename_vars=True)
variables()
See

nltk.featstruct.find_variables()

walk()

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