class nltk.AbstractLazySequence[source]

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


count(value) Return the number of times this list contains value.
index(value[, start, stop]) Return the index of the first occurrence of value in this list that is greater than or equal to start and less than stop.
iterate_from(start) Return an iterator that generates the tokens in the corpus file underlying this corpus view, starting at the token number start.
unicode_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.