AS AgentScopeAPI 手册 / API Reference
类class agentscope.rag

WordParser

class WordParser(ParserBase)
源码Source agentscope/rag/_parser/_word.py:288–502

Word 解析器,把私有文档转化为可检索的知识。位于 agentscope.rag 包,继承自 ParserBase。核心成员包括 supported_extensions、parse。

Document order is preserved. Elements are visited sequentially and grouped into a minimum number of sections:

  • Paragraphs contribute to one running text section.
  • Tables are rendered as Markdown or JSON and, depending on separate_table, either merged into the running text or emitted as standalone text sections.
  • Images emit standalone :class:Section instances holding a :class:DataBlock with the base64-encoded image bytes.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(include_image: bool = True, separate_table: bool = False, table_format: Literal['markdown', 'json'] = 'mar…
初始化 `WordParser` 实例。
Initialize the Word parser.

属性摘要Attribute Summary

属性Attribute类型Type说明Description值Value
supported_media_typeslist[str]
`supported_media_types` 字段。
['application/vnd.openxmlformats-officedocument.wordprocessingml.document']

方法摘要Method Summary

方法Method说明Description
def supported_extensions() -> list[str]
返回 `supported_extensions` 结果。
Return ``[".docx"]`` — the only format ``python-docx`` reads.
async def parse(file: bytes | str, filename: str) -> list[Section]async
执行解析相关操作。
Parse a DOCX file into a list of :class:`Section` objects.

构造器详情Constructor Detail

WordParser

def __init__(include_image: bool = True, separate_table: bool = False, table_format: Literal['markdown', 'json'] = 'markdown') -> None

初始化 WordParser 实例。

Initialize the Word parser.

参数Parameters
名称Name类型Type说明Description
include_image默认default Trueboolinclude 图像(类型 `bool`)。When `True`, embedded images are emitted as :class:`DataBlock` sections. Set to `False` to keep a text-only index.
separate_table默认default Falseboolseparate table(类型 `bool`)。When `True`, each table becomes its own text section, never merged with surrounding paragraphs. table_format (`Literal["markdown", "json"]`, defaults to `"markdown"`): How to render tables. `"markdown"` uses pipe-table syntax, escaping pipes and rendering cell line breaks as ` `; `"json"` emits a JSON array prefixed with a ` ` marker and preserves extracted cell strings without Markdown rendering.
table_format默认default 'markdown'Literal['markdown', 'json']table 格式(类型 `Literal['markdown', 'json']`)。The table format.
异常Raises
  • 可能抛出 `Exception`。`ValueError`: If `table_format` is not one of
  • 可能抛出 `Exception`。`"markdown"` / `"json"`.
源码Source agentscope/rag/_parser/_word.py:312–347

属性详情Attribute Detail

supported_media_types

list[str] = ['application/vnd.openxmlformats-officedocument.wordprocessingml.document']

supported_media_types 字段。声明为 list[str]。

The supported media types field.

源码Source agentscope/rag/_parser/_word.py:302

方法详情Method Detail

supported_extensions

def supported_extensions() -> list[str]

返回 supported_extensions 结果。

Return [".docx"] — the only format python-docx reads.

返回Returns list[str]
返回str列表。Returns a list of str.
源码Source agentscope/rag/_parser/_word.py:308–310

parse

async def parse(file: bytes | str, filename: str) -> list[Section]
async

执行解析相关操作。

Parse a DOCX file into a list of :class:Section objects.

参数Parameters
名称Name类型Type说明Description
filebytes | str文件(类型 `bytes | str`)。Either the raw DOCX bytes, or a filesystem path to the DOCX file.
filenamestrfilename(类型 `str`)。The source filename, copied into each Section's :attr:`Section.source`.
返回Returns list[Section]
返回Section列表。`list[Section]`:
异常Raises
  • 可能抛出 `Exception`。`FileNotFoundError`: If `file` is a `str` pointing to
  • 可能抛出 `Exception`。a path that does not exist.
  • 可能抛出 `Exception`。`ImportError`: If :mod:`python-docx` is not installed.
  • 可能抛出 `Exception`。`ValueError`: If the bytes cannot be parsed.
源码Source agentscope/rag/_parser/_word.py:349–502
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.