ParentChildChunker#
- class scikitplot.corpus.ParentChildChunker(config=None)[source]#
Large parents for context, small children for retrieval, linked.
- Parameters:
- configParentChildChunkerConfig or None, default=None
NoneisParentChildChunkerConfig().
- Parameters:
config (ParentChildChunkerConfig | None)
See also
RecursiveChunkerThe splitting rule used at both levels.
scikitplot.corpus.childrenTraverse the documents it produces.
Notes
User. Each parent is followed by its children. Every chunk’s metadata holds
chunk_role("parent"or"child") andparent_span; a child holdsparent_chunk, the position of its parent in the result. A document built from a child getsparent_doc_id(its parent’sdoc_id): retrieve children, then give the model the parent. Documents keepchunk_roleandparent_spanin their metadata, so withemit_parents=Falsea child still locates its parent’s region. Both levels report theRECURSIVEstrategy;chunk_roletells them apart. A parent no longer thanchild_sizehas one child with the same text: index children only.Examples
>>> text = "Alpha one. Beta two.\n\nGamma three. Delta four." >>> config = ParentChildChunkerConfig(parent_size=25, child_size=12) >>> result = ParentChildChunker(config).chunk(text) >>> [ ... (c.metadata["chunk_role"], c.text) for c in result.chunks ... ] [('parent', 'Alpha one. Beta two.'), ('child', 'Alpha one.'), ('child', 'Beta two.'), ('parent', 'Gamma three. Delta four.'), ('child', 'Gamma three.'), ('child', 'Delta four.')]
- chunk(text, doc_id=None, extra_metadata=None)[source]#
Split text into parents and the children inside each.
- Parameters:
- textstr
Raw document text.
- doc_idstr or None, default=None
Stored in each chunk’s metadata.
- extra_metadatadict or None, default=None
Merged into the result metadata.
- Returns:
- ChunkResult
Parents and children in source order (each parent first).
- Raises:
- TypeError
If text is not a
str.- ValueError
If text is empty or whitespace-only, or holds a NUL character or a lone surrogate.
- Parameters:
- Return type:
- chunk_batch(texts, doc_ids=None, extra_metadata=None)[source]#
Chunk a list of documents.
- Parameters:
- textslist of str
Input documents.
- doc_idslist of str or None, default=None
Parallel document identifiers.
- extra_metadatadict or None, default=None
Shared metadata for every result.
- Returns:
- list of ChunkResult
One result per document.
- Raises:
- TypeError
If texts is not a list.
- ValueError
If doc_ids length mismatches texts.
- Parameters:
- Return type:
- property config: ParentChildChunkerConfig#
The configuration (read-only).
- config_class[source]#
alias of
ParentChildChunkerConfig
- strategy: ClassVar[ChunkingStrategy] = 'recursive'[source]#
- text_is_source_slice = True#