类class
agentscope.ragWordParser
class WordParser(ParserBase)
源码Source
agentscope/rag/_parser/_word.py:288–502Word 解析器,把私有文档转化为可检索的知识。位于 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:
Sectioninstances holding a :class:DataBlockwith 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_types | list[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 True | bool | include 图像(类型 `bool`)。When `True`, embedded images are emitted as :class:`DataBlock` sections. Set to `False` to keep a text-only index. |
separate_table默认default False | bool | separate 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. |
- 可能抛出 `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.
list[str]
返回str列表。Returns a list of str.
源码Source
agentscope/rag/_parser/_word.py:308–310parse
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 |
|---|---|---|
file | bytes | str | 文件(类型 `bytes | str`)。Either the raw DOCX bytes, or a filesystem path to the DOCX file. |
filename | str | filename(类型 `str`)。The source filename, copied into each Section's :attr:`Section.source`. |
list[Section]
返回Section列表。`list[Section]`:
- 可能抛出 `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