Class WordReader

All Implemented Interfaces:
Reader

public class WordReader extends AbstractChunkingReader
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();
 
  • 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 chunk
      splitStrategy - the strategy for splitting text
      overlapSize - the number of characters to overlap between chunks
      includeImage - whether to extract and include images from the document
      separateTable - whether to treat tables as separate chunks
      tableFormat - 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: Reader
      Reads 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

      public List<String> getSupportedFormats()
      Description copied from interface: Reader
      Gets 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

      public TableFormat getTableFormat()
      Gets the table format.
      Returns:
      the table format (MARKDOWN or JSON)