Package org.apache.tika.inference
Class MarkdownChunker
java.lang.Object
org.apache.tika.inference.MarkdownChunker
- All Implemented Interfaces:
Initializable,TextChunker
Splits markdown text into chunks that respect structural boundaries.
The chunker first splits on markdown heading boundaries (# ...).
If a section exceeds the maximum chunk size, it is further split on
paragraph boundaries (double newlines). As a last resort, oversized
paragraphs are split at the character limit.
Consecutive chunks can overlap by a configurable number of characters to avoid losing context at boundaries.
-
Constructor Summary
ConstructorsConstructorDescriptionThe binding form:{"markdown-chunker": {"maxChunkChars": .., "overlapChars": ..}}.MarkdownChunker(int maxChunkChars, int overlapChars) -
Method Summary
Modifier and TypeMethodDescriptionChunk the given markdown text.intintvoidCalled after all properties have been set to allow for validation and initialization that depends on multiple properties.voidsetMaxChunkChars(int maxChunkChars) voidsetOverlapChars(int overlapChars) List<int[]> Half-open[start, end)character ranges of the chunks, in document order.
-
Constructor Details
-
MarkdownChunker
public MarkdownChunker()The binding form:{"markdown-chunker": {"maxChunkChars": .., "overlapChars": ..}}. -
MarkdownChunker
public MarkdownChunker(int maxChunkChars, int overlapChars)
-
-
Method Details
-
initialize
Description copied from interface:InitializableCalled after all properties have been set to allow for validation and initialization that depends on multiple properties.- Specified by:
initializein interfaceInitializable- Throws:
TikaConfigException- if there is a problem with the configuration
-
getMaxChunkChars
public int getMaxChunkChars() -
setMaxChunkChars
public void setMaxChunkChars(int maxChunkChars) -
getOverlapChars
public int getOverlapChars() -
setOverlapChars
public void setOverlapChars(int overlapChars) -
spans
Description copied from interface:TextChunkerHalf-open[start, end)character ranges of the chunks, in document order.- Specified by:
spansin interfaceTextChunker
-
chunk
Chunk the given markdown text.- Parameters:
text- the full markdown content- Returns:
- ordered list of chunks with offsets relative to
text
-