Class DocumentByParagraphSplitter
- All Implemented Interfaces:
DocumentSplitter
Document into paragraphs and attempts to fit as many paragraphs as possible
into a single TextSegment, adhering to the limit set by maxSegmentSize.
The maxSegmentSize can be defined in terms of characters (default) or tokens.
For token-based limit, a TokenCountEstimator must be provided.
Paragraph boundaries are detected by a minimum of two newline characters ("\n\n"). Any additional whitespaces before, between, or after are ignored. So, the following examples are all valid paragraph separators: "\n\n", "\n\n\n", "\n \n", " \n \n ", and so on.
If multiple paragraphs fit within maxSegmentSize, they are joined together using a double newline ("\n\n").
If a single paragraph is too long and exceeds maxSegmentSize,
the subSplitter (DocumentBySentenceSplitter by default) is used to split it into smaller parts and
place them into multiple segments.
Such segments contain only the parts of the split long paragraph.
Each TextSegment inherits all metadata from the Document and includes an "index" metadata key
representing its position within the document (starting from 0).
-
Field Summary
Fields inherited from class HierarchicalDocumentSplitter
maxOverlapSize, maxSegmentSize, subSplitter, tokenCountEstimator -
Constructor Summary
ConstructorsConstructorDescriptionDocumentByParagraphSplitter(int maxSegmentSizeInChars, int maxOverlapSizeInChars) DocumentByParagraphSplitter(int maxSegmentSizeInChars, int maxOverlapSizeInChars, DocumentSplitter subSplitter) DocumentByParagraphSplitter(int maxSegmentSizeInTokens, int maxOverlapSizeInTokens, TokenCountEstimator tokenCountEstimator) DocumentByParagraphSplitter(int maxSegmentSizeInTokens, int maxOverlapSizeInTokens, TokenCountEstimator tokenCountEstimator, DocumentSplitter subSplitter) -
Method Summary
Modifier and TypeMethodDescriptionprotected DocumentSplitterThe default sub-splitter to use when a single segment is too long.Delimiter string to use to re-join the parts.String[]Splits the provided text into parts.Methods inherited from class HierarchicalDocumentSplitter
splitMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DocumentSplitter
splitAll, splitAll
-
Constructor Details
-
DocumentByParagraphSplitter
public DocumentByParagraphSplitter(int maxSegmentSizeInChars, int maxOverlapSizeInChars) -
DocumentByParagraphSplitter
public DocumentByParagraphSplitter(int maxSegmentSizeInChars, int maxOverlapSizeInChars, DocumentSplitter subSplitter) -
DocumentByParagraphSplitter
public DocumentByParagraphSplitter(int maxSegmentSizeInTokens, int maxOverlapSizeInTokens, TokenCountEstimator tokenCountEstimator) -
DocumentByParagraphSplitter
public DocumentByParagraphSplitter(int maxSegmentSizeInTokens, int maxOverlapSizeInTokens, TokenCountEstimator tokenCountEstimator, DocumentSplitter subSplitter)
-
-
Method Details
-
split
Description copied from class:HierarchicalDocumentSplitterSplits the provided text into parts. Implementation API.- Specified by:
splitin classHierarchicalDocumentSplitter- Parameters:
text- The text to be split.- Returns:
- An array of parts.
-
joinDelimiter
Description copied from class:HierarchicalDocumentSplitterDelimiter string to use to re-join the parts.- Specified by:
joinDelimiterin classHierarchicalDocumentSplitter- Returns:
- The delimiter.
-
defaultSubSplitter
Description copied from class:HierarchicalDocumentSplitterThe default sub-splitter to use when a single segment is too long.- Specified by:
defaultSubSplitterin classHierarchicalDocumentSplitter- Returns:
- The default sub-splitter.
-