ChunkedTextList#
- class scikitplot.corpus.ChunkedTextList(pairs, chunk_metadata_list)[source]#
A
listsubclass that carries per-chunk metadata alongside(int, str)pairs.Returned by every
ChunkerBridgesubclass in place of a plainlist. Behaves identically tolistfor all existing callers that unpack(char_start, chunk_text)pairs.The extra
chunk_metadata_listattribute lets_base.DocumentReader. get_documentsread multilang metadata and populateCorpusDocumentfields 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.metadatafrom the innerChunk.
- Parameters:
Notes
Developer note: Callers that only do
for start, text in sub_chunksare unaffected — they never seechunk_metadata_list. Only_base.DocumentReader.get_documentsinspects this attribute.Idempotency:
ChunkedTextListis constructed once perchunk()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.