class documentation

An abstract base class for read-only sequences whose values are computed as needed. Lazy sequences act like tuples -- they can be indexed, sliced, and iterated over; but they may not be modified.

The most common application of lazy sequences in NLTK is for corpus view objects, which provide access to the contents of a corpus without loading the entire corpus into memory, by loading pieces of the corpus from disk as needed.

The result of modifying a mutable element of a lazy sequence is undefined. In particular, the modifications made to the element may or may not persist, depending on whether and when the lazy sequence caches that element's value or reconstructs it from scratch.

Subclasses are required to define two methods: __len__() and iterate_from().

Method __add__ Return a list concatenating self with other.
Method __contains__ Return true if this list contains value.
Method __eq__ Undocumented
Method __getitem__ Return the i th token in the corpus file underlying this corpus view. Negative indices and spans are both supported.
Method __hash__ No summary
Method __iter__ Return an iterator that generates the tokens in the corpus file underlying this corpus view.
Method __len__ Return the number of tokens in the corpus file underlying this corpus view.
Method __lt__ Undocumented
Method __mul__ Return a list concatenating self with itself count times.
Method __ne__ Undocumented
Method __radd__ Return a list concatenating other with self.
Method __repr__ Return a string representation for this corpus view that is similar to a list's representation; but if it would be more than 60 characters long, it is truncated.
Method __rmul__ Return a list concatenating self with itself count times.
Method count Return the number of times this list contains value.
Method index Return the index of the first occurrence of value in this list that is greater than or equal to start and less than stop. Negative start and stop values are treated like negative slice bounds -- i.e., they count from the end of the list.
Method iterate_from Return an iterator that generates the tokens in the corpus file underlying this corpus view, starting at the token number start. If start>=len(self), then this iterator will generate no tokens.
Constant _MAX_REPR_SIZE Undocumented
def __add__(self, other): (source)

Return a list concatenating self with other.

def __contains__(self, value): (source)

Return true if this list contains value.

def __eq__(self, other): (source)

Undocumented

def __getitem__(self, i): (source)

Return the i th token in the corpus file underlying this corpus view. Negative indices and spans are both supported.

def __hash__(self): (source)
Raises
ValueErrorCorpus view objects are unhashable.
def __iter__(self): (source)

Return an iterator that generates the tokens in the corpus file underlying this corpus view.

def __len__(self): (source)

Return the number of tokens in the corpus file underlying this corpus view.

def __lt__(self, other): (source)

Undocumented

def __mul__(self, count): (source)

Return a list concatenating self with itself count times.

def __ne__(self, other): (source)

Undocumented

def __radd__(self, other): (source)

Return a list concatenating other with self.

def __repr__(self): (source)

Return a string representation for this corpus view that is similar to a list's representation; but if it would be more than 60 characters long, it is truncated.

def __rmul__(self, count): (source)

Return a list concatenating self with itself count times.

def count(self, value): (source)

Return the number of times this list contains value.

def index(self, value, start=None, stop=None): (source)

Return the index of the first occurrence of value in this list that is greater than or equal to start and less than stop. Negative start and stop values are treated like negative slice bounds -- i.e., they count from the end of the list.

def iterate_from(self, start): (source)

Return an iterator that generates the tokens in the corpus file underlying this corpus view, starting at the token number start. If start>=len(self), then this iterator will generate no tokens.

_MAX_REPR_SIZE: int = (source)

Undocumented

Value
60