Chunk#
- class scikitplot.corpus.Chunk(text, start_char, end_char, metadata=<factory>, context_start=None, context_end=None)[source]#
A single unit of text produced by a chunker.
- Parameters:
- textstr
The chunk’s text content (possibly including overlap context).
- start_charint
Zero-based character offset of the chunk’s anchor in the source: the region the chunk stands for (a sentence, without the sentences repeated before it as overlap). Set to
0when offsets are disabled.- end_charint
Zero-based exclusive end of the anchor. Set to
0when offsets are disabled.- metadataMetadataDict
Arbitrary per-chunk key/value pairs (e.g.
chunk_index,doc_id,backend,tokens). Always a dict — neverNone.- context_startint or None, optional
Start of the context span: the source region
textis taken from, which covers the anchor (overlap context included).Nonemeans the anchor start.- context_endint or None, optional
Exclusive end of the context span;
Nonemeans the anchor end.
- Parameters:
Notes
Span invariant (R3-3). For every built-in chunker whose
text_is_source_sliceisTrue(all butWordChunker, whose text is a token transformation),text == source[context_start: context_end]when offsets are enabled, and the context span covers the anchor:context_start <= start_char <= end_char <= context_end.textmust be a non-empty string. Validation is the chunker’s responsibility;Chunkitself does not re-validate to keep it a pure value object.metadatais stored as-is. Callers must not mutate the dict after construction (frozen dataclass contract).
- property anchor_span: tuple[int, int]#
the region this chunk stands for.
- Type:
(start_char, end_char)
- char_length()[source]#
Return the character span length of this chunk.
- Returns:
- int
end_char - start_char. Returns0when offsets are disabled (both fields are0).
- Return type:
- content_hash()[source]#
Return a stable SHA-256 hex digest of
text.Useful as a deduplication key in storage backends.
- Returns:
- str
64-character lowercase hex string.
- Return type:
- with_metadata(**kwargs)[source]#
Return a new
Chunkwith additional metadata keys.- Parameters:
- **kwargs
Key/value pairs to merge into a copy of
metadata.
- Returns:
- Chunk
New frozen instance with merged metadata.
- Parameters:
kwargs (Any)
- Return type:
Notes
Uses
dataclasses.replaceso any new fields added toChunkare automatically preserved without editing this method (CRITICAL-04 / LOW-02 fix).