ChunkedTextList#

class scikitplot.corpus.ChunkedTextList(pairs, chunk_metadata_list)[source]#

A list subclass that carries per-chunk metadata alongside (int, str) pairs.

Returned by every ChunkerBridge subclass in place of a plain list. Behaves identically to list for all existing callers that unpack (char_start, chunk_text) pairs.

The extra chunk_metadata_list attribute lets _base.DocumentReader. get_documents read multilang metadata and populate CorpusDocument fields without breaking the existing (int, str) contract.

Parameters:
pairslist[tuple[int, str]]

The (char_start, chunk_text) tuples (standard contract).

chunk_metadata_listlist[dict]

One metadata dict per pair. Must have the same length as pairs. Each dict is chunk.metadata from the inner Chunk.

Parameters:

Notes

Developer note: Callers that only do for start, text in sub_chunks are unaffected — they never see chunk_metadata_list. Only _base.DocumentReader.get_documents inspects this attribute.

Idempotency: ChunkedTextList is constructed once per chunk() call and never mutated after construction.

Examples

>>> cl = ChunkedTextList([(0, "Hello")], [{"multilang": {"script": "latin"}}])
>>> for start, text in cl:
...     print(start, text)
0 Hello
>>> cl.chunk_metadata_list[0]["multilang"]["script"]
'latin'
append(object, /)#

Append object to the end of the list.

clear(/)#

Remove all items from list.

copy(/)#

Return a shallow copy of the list.

count(value, /)#

Return number of occurrences of value.

extend(iterable, /)#

Extend list by appending elements from the iterable.

index(value, start=0, stop=sys.maxsize, /)#

Return first index of value.

Raises ValueError if the value is not present.

insert(index, object, /)#

Insert object before index.

pop(index=-1, /)#

Remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(value, /)#

Remove first occurrence of value.

Raises ValueError if the value is not present.

reverse(/)#

Reverse IN PLACE.

sort(*, key=None, reverse=False)#

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.