Chunk#
- class scikitplot.corpus.Chunk(text, start_char, end_char, metadata=<factory>)[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 this chunk’s start in the source document. Set to
0when offsets are disabled.- end_charint
Zero-based exclusive character offset of this chunk’s end. 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.
- Parameters:
Notes
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).
- 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).