Package io.agentscope.core.rag.reader
Class WordReader
java.lang.Object
io.agentscope.core.rag.reader.AbstractChunkingReader
io.agentscope.core.rag.reader.WordReader
- All Implemented Interfaces:
Reader
Word document reader that extracts text, tables, and images from Word files.
This reader supports comprehensive extraction of content from Word documents (.docx), including:
- Text extraction from paragraphs
- Table extraction with Markdown or JSON formatting
- Image extraction with Base64 encoding
- Configurable chunking strategies
Dependencies: Requires Apache POI (poi-ooxml) to be available on the classpath.
Example usage:
WordReader reader = new WordReader(512, SplitStrategy.PARAGRAPH, 50,
true, false, TableFormat.MARKDOWN);
ReaderInput input = ReaderInput.fromString("path/to/document.docx");
List<Document> documents = reader.read(input).block();
-
Field Summary
Fields inherited from class io.agentscope.core.rag.reader.AbstractChunkingReader
chunkSize, overlapSize, splitStrategy -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new WordReader with default settings.WordReader(int chunkSize, SplitStrategy splitStrategy, int overlapSize, boolean includeImage, boolean separateTable, TableFormat tableFormat) Creates a new WordReader with full configuration. -
Method Summary
Modifier and TypeMethodDescriptionGets the list of file formats supported by this reader.Gets the table format.booleanChecks if image extraction is enabled.booleanChecks if tables are separated into individual chunks.reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>>read(ReaderInput input) Reads a document and returns a list of chunked Document objects.Methods inherited from class io.agentscope.core.rag.reader.AbstractChunkingReader
getChunkSize, getOverlapSize, getSplitStrategy, validateChunkingParameters
-
Constructor Details
-
WordReader
public WordReader(int chunkSize, SplitStrategy splitStrategy, int overlapSize, boolean includeImage, boolean separateTable, TableFormat tableFormat) Creates a new WordReader with full configuration.- Parameters:
chunkSize- the target size for each chunksplitStrategy- the strategy for splitting textoverlapSize- the number of characters to overlap between chunksincludeImage- whether to extract and include images from the documentseparateTable- whether to treat tables as separate chunkstableFormat- the format for extracted tables (MARKDOWN or JSON)- Throws:
IllegalArgumentException- if parameters are invalid
-
WordReader
public WordReader()Creates a new WordReader with default settings.Defaults:
- chunkSize = 512
- splitStrategy = PARAGRAPH
- overlapSize = 50
- includeImage = true
- separateTable = false
- tableFormat = MARKDOWN
-
-
Method Details
-
read
public reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>> read(ReaderInput input) Description copied from interface:ReaderReads a document and returns a list of chunked Document objects.Errors during reading are propagated through the Mono via
Mono.error().- Parameters:
input- the input to read (text, file path, URL, etc.)- Returns:
- a Mono that emits a list of Document objects, or an error signal on failure
-
getSupportedFormats
Description copied from interface:ReaderGets the list of file formats supported by this reader.- Returns:
- a list of supported file extensions (e.g., "txt", "md", "pdf")
-
isIncludeImage
public boolean isIncludeImage()Checks if image extraction is enabled.- Returns:
- true if images are extracted
-
isSeparateTable
public boolean isSeparateTable()Checks if tables are separated into individual chunks.- Returns:
- true if tables are separated
-
getTableFormat
Gets the table format.- Returns:
- the table format (MARKDOWN or JSON)
-