跳到内容

Docling 文档

这是DoclingDocument类型的自动生成API参考。

文档

用于定义文档类型的模型的包。

类:

Docling文档

基础: BaseModel

Docling文档。

方法:

属性:

主体

body: GroupItem = GroupItem(
    name="_root_", self_ref="#/body"
)

表单项目

form_items: List[FormItem] = []

家具

furniture: Annotated[GroupItem, Field(deprecated=True)] = (
    GroupItem(
        name="_root_",
        self_ref="#/furniture",
        content_layer=FURNITURE,
    )
)

groups: List[GroupItem] = []

键值项

key_value_items: List[KeyValueItem] = []

名称

name: str

origin: Optional[DocumentOrigin] = None

页面

pages: Dict[int, PageItem] = {}

图片

pictures: List[PictureItem] = []

schema_name

schema_name: Literal['DoclingDocument'] = 'DoclingDocument'

tables: List[TableItem] = []

文本

texts: List[
    Union[SectionHeaderItem, ListItem, TextItem, CodeItem]
] = []

版本

version: Annotated[
    str,
    StringConstraints(pattern=VERSION_PATTERN, strict=True),
] = CURRENT_VERSION

添加代码

add_code(
    text: str,
    code_language: Optional[CodeLanguageLabel] = None,
    orig: Optional[str] = None,
    caption: Optional[Union[TextItem, RefItem]] = None,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
    content_layer: Optional[ContentLayer] = None,
)

添加代码。

参数:

  • text (str) –

    字符串:

  • code_language (可选[代码语言标签], 默认: ) –

    可选[str]: (默认值 = 无)

  • orig (可选[str], 默认: None ) –

    可选[str]: (默认值 = None)

  • caption (可选[联合[TextItem, RefItem]], 默认: None ) –

    可选[联合[TextItem:

  • RefItem]]

    (默认值 = None)

  • prov (可选[ProvenanceItem], 默认: ) –

    可选[ProvenanceItem]: (默认值 = 无)

  • parent (可选[NodeItem], 默认: None ) –

    可选[NodeItem]: (默认值 = None)

add_form

add_form(
    graph: GraphData,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
)

添加表单。

参数:

  • graph (GraphData) –

    图形数据:

  • prov (可选[ProvenanceItem], 默认: ) –

    可选[ProvenanceItem]: (默认值 = 无)

  • parent (可选[NodeItem], 默认: None ) –

    可选[NodeItem]: (默认值 = None)

添加组

add_group(
    label: Optional[GroupLabel] = None,
    name: Optional[str] = None,
    parent: Optional[NodeItem] = None,
    content_layer: Optional[ContentLayer] = None,
) -> GroupItem

添加组。

参数:

  • label (可选[GroupLabel], 默认: None ) –

    可选[GroupLabel]: (默认值 = None)

  • name (可选[str], 默认: ) –

    可选[str]: (默认值 = 无)

  • parent (可选[NodeItem], 默认: None ) –

    可选[NodeItem]: (默认值 = None)

添加标题

add_heading(
    text: str,
    orig: Optional[str] = None,
    level: LevelNumber = 1,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
    content_layer: Optional[ContentLayer] = None,
)

添加标题。

参数:

  • label

    文档项目标签:

  • text (str) –

    字符串:

  • orig (可选[str], 默认: None ) –

    可选[str]: (默认值 = None)

  • level (LevelNumber, 默认: 1 ) –

    LevelNumber: (默认值 = 1)

  • prov (可选[ProvenanceItem], 默认: None ) –

    可选[ProvenanceItem]: (默认值 = None)

  • parent (可选[NodeItem], 默认: None ) –

    可选[NodeItem]: (默认值 = None)

添加键值对

add_key_values(
    graph: GraphData,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
)

添加键值对.

参数:

  • graph (GraphData) –

    图形数据:

  • prov (可选[ProvenanceItem], 默认: ) –

    可选[ProvenanceItem]: (默认值 = 无)

  • parent (可选[NodeItem], 默认: None ) –

    可选[NodeItem]: (默认值 = None)

添加列表项

add_list_item(
    text: str,
    enumerated: bool = False,
    marker: Optional[str] = None,
    orig: Optional[str] = None,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
    content_layer: Optional[ContentLayer] = None,
)

添加列表项。

参数:

  • label

    字符串:

  • text (str) –

    字符串:

  • orig (可选[str], 默认: None ) –

    可选[str]: (默认值 = None)

  • prov (可选[ProvenanceItem], 默认: ) –

    可选[ProvenanceItem]: (默认值 = 无)

  • parent (可选[NodeItem], 默认: None ) –

    可选[NodeItem]: (默认值 = None)

add_page

add_page(
    page_no: int,
    size: Size,
    image: Optional[ImageRef] = None,
) -> PageItem

添加页面。

参数:

  • page_no (int) –

    整数:

  • size (Size) –

    大小:

添加图片

add_picture(
    annotations: List[PictureDataType] = [],
    image: Optional[ImageRef] = None,
    caption: Optional[Union[TextItem, RefItem]] = None,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
    content_layer: Optional[ContentLayer] = None,
)

添加图片。

参数:

  • data

    列表[PictureData]: (默认值 = [])

  • caption (可选[联合[TextItem, RefItem]], 默认: None ) –

    可选[联合[TextItem:

  • RefItem]]

    (默认值 = None)

  • prov (可选[ProvenanceItem], 默认: ) –

    可选[ProvenanceItem]: (默认值 = 无)

  • parent (可选[NodeItem], 默认: None ) –

    可选[NodeItem]: (默认值 = None)

add_table

add_table(
    data: TableData,
    caption: Optional[Union[TextItem, RefItem]] = None,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
    label: DocItemLabel = TABLE,
    content_layer: Optional[ContentLayer] = None,
)

添加表格。

参数:

  • data (TableData) –

    表格数据:

  • caption (可选[并联合[TextItem, RefItem]], 默认: None ) –

    可选[并联合[TextItem, RefItem]]: (默认值 = None)

  • prov (可选[ProvenanceItem], 默认: ) –

    可选[ProvenanceItem]: (默认值 = 无)

  • parent (可选[NodeItem], 默认: None ) –

    可选[NodeItem]: (默认值 = None)

  • label (DocItemLabel, 默认: TABLE ) –

    DocItemLabel: (默认值 = DocItemLabel.TABLE)

添加文本

add_text(
    label: DocItemLabel,
    text: str,
    orig: Optional[str] = None,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
    content_layer: Optional[ContentLayer] = None,
)

添加文本。

参数:

  • label (DocItemLabel) –

    字符串:

  • text (str) –

    字符串:

  • orig (可选[str], 默认: None ) –

    可选[str]: (默认值 = None)

  • prov (可选[ProvenanceItem], 默认: ) –

    可选[ProvenanceItem]: (默认值 = 无)

  • parent (可选[NodeItem], 默认: None ) –

    可选[NodeItem]: (默认值 = None)

添加标题

add_title(
    text: str,
    orig: Optional[str] = None,
    prov: Optional[ProvenanceItem] = None,
    parent: Optional[NodeItem] = None,
    content_layer: Optional[ContentLayer] = None,
)

添加标题。

参数:

  • text (str) –

    字符串:

  • orig (可选[str], 默认: None ) –

    可选[str]: (默认值 = None)

  • prov (可选[ProvenanceItem], 默认: ) –

    可选[ProvenanceItem]: (默认值 = 无)

  • parent (可选[NodeItem], 默认: None ) –

    可选[NodeItem]: (默认值 = None)

check_version_is_compatible

check_version_is_compatible(v: str) -> str

检查该文档版本是否与当前版本兼容。

export_to_dict

export_to_dict(
    mode: str = "json",
    by_alias: bool = True,
    exclude_none: bool = True,
) -> Dict

导出为字典。

导出到文档令牌

export_to_document_tokens(
    delim: str = "",
    from_element: int = 0,
    to_element: int = maxsize,
    labels: set[
        DocItemLabel
    ] = DOCUMENT_TOKENS_EXPORT_LABELS,
    xsize: int = 500,
    ysize: int = 500,
    add_location: bool = True,
    add_content: bool = True,
    add_page_index: bool = True,
    add_table_cell_location: bool = False,
    add_table_cell_text: bool = True,
) -> str

将文档内容导出为DocumentToken格式。

对文档主体的一个片段进行操作,该片段是通过参数 from_element 和 to_element 定义的;默认为整个 main_text。

参数:

  • delim (str, 默认: '' ) –

    str: (默认值 = "")

  • from_element (int, default: 0 ) –

    int: (默认值 = 0)

  • to_element (int, 默认: maxsize ) –

    可选[int]: (默认值 = None)

  • labels (set[DocItemLabel], 默认: DOCUMENT_TOKENS_EXPORT_LABELS ) –

    set[DocItemLabel]

  • xsize (int, 默认: 500 ) –

    int: (默认值 = 500)

  • ysize (int, 默认: 500 ) –

    int: (默认值 = 500)

  • add_location (bool, 默认: True ) –

    bool: (默认值 = True)

  • add_content (bool, default: True ) –

    bool: (默认值 = True)

  • add_page_index (bool, default: True ) –

    bool: (默认值 = True)

  • add_table_cell_text (bool, 默认值: True ) –

    bool: (默认值 = True)

返回:

  • str

    文档的内容格式化为DocTags字符串。

导出到元素树

export_to_element_tree() -> str

导出到元素树。

导出为html

export_to_html(
    from_element: int = 0,
    to_element: int = maxsize,
    labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
    image_mode: ImageRefMode = PLACEHOLDER,
    formula_to_mathml: bool = True,
    page_no: Optional[int] = None,
    html_lang: str = "en",
    html_head: str = _HTML_DEFAULT_HEAD,
    included_content_layers: set[
        ContentLayer
    ] = DEFAULT_CONTENT_LAYERS,
) -> str

序列化为HTML。

导出到Markdown

export_to_markdown(
    delim: str = "\n",
    from_element: int = 0,
    to_element: int = maxsize,
    labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
    strict_text: bool = False,
    escaping_underscores: bool = True,
    image_placeholder: str = "<!-- image -->",
    image_mode: ImageRefMode = PLACEHOLDER,
    indent: int = 4,
    text_width: int = -1,
    page_no: Optional[int] = None,
    included_content_layers: set[
        ContentLayer
    ] = DEFAULT_CONTENT_LAYERS,
) -> str

序列化为Markdown。

对文档主体的一部分进行操作,该部分通过参数 from_element 和 to_element 定义;默认为整个文档。

参数:

  • delim (str, default: '\n' ) –

    合并各种Markdown部分时使用的分隔符。(默认值 = "\n")。

  • from_element (int, default: 0 ) –

    主体切片起始索引(包含)。(默认值 = 0)。

  • to_element (int, default: maxsize ) –

    主体切片停止索引(不包括该索引)。 (默认值 = maxint)。

  • labels (set[DocItemLabel], default: DEFAULT_EXPORT_LABELS ) –

    要包含在导出中的文档标签集合。

  • strict_text (bool, default: False ) –

    bool: 是否仅包含文档的文本内容。 (默认值 = False)。

  • escaping_underscores (bool, default: True ) –

    bool: 是否在文档的文本内容中转义下划线。(默认值 = True)。

  • image_placeholder (str, default: '' ) –

    用于在markdown中定位图像的占位符。(默认值 = "\"。)

  • image_mode (ImageRefMode, 默认: PLACEHOLDER ) –

    在markdown中包含图像时使用的模式。(默认值 = ImageRefMode.PLACEHOLDER)。

  • indent (int, 默认: 4 ) –

    嵌套列表的空格缩进。 (默认值 = 4)。

返回:

  • str

    导出的Markdown表示。

export_to_text

export_to_text(
    delim: str = "\n\n",
    from_element: int = 0,
    to_element: int = 1000000,
    labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
) -> str

导出为文本。

iterate_items

iterate_items(
    root: Optional[NodeItem] = None,
    with_groups: bool = False,
    traverse_pictures: bool = False,
    page_no: Optional[int] = None,
    included_content_layers: set[
        ContentLayer
    ] = DEFAULT_CONTENT_LAYERS,
    _level: int = 0,
) -> Iterable[Tuple[NodeItem, int]]

迭代元素。

参数:

  • root (可选[NodeItem], 默认: None ) –

    可选[NodeItem]: (默认值 = None)

  • with_groups (bool, 默认: False ) –

    bool: (默认值 = False)

  • traverse_pictures (bool, 默认: False ) –

    bool: (默认值 = False)

  • page_no (可选[int], 默认: None ) –

    可选[int]: (默认值 = None)

  • _level (int, 默认: 0 ) –

    (默认值 = 0)

从JSON加载

load_from_json(filename: Path) -> DoclingDocument

从json加载.

参数:

  • filename (Path) –

    要加载保存的 DoclingDocument 的 .json 文件名。

返回:

  • DoclingDocument

    加载的 DoclingDocument。

num_pages

num_pages()

num_pages.

打印元素树

print_element_tree()

打印元素树。

save_as_document_tokens

save_as_document_tokens(
    filename: Path,
    delim: str = "",
    from_element: int = 0,
    to_element: int = maxsize,
    labels: set[
        DocItemLabel
    ] = DOCUMENT_TOKENS_EXPORT_LABELS,
    xsize: int = 500,
    ysize: int = 500,
    add_location: bool = True,
    add_content: bool = True,
    add_page_index: bool = True,
    add_table_cell_location: bool = False,
    add_table_cell_text: bool = True,
)

将文档内容保存为DocumentToken格式。

保存为html

save_as_html(
    filename: Path,
    artifacts_dir: Optional[Path] = None,
    from_element: int = 0,
    to_element: int = maxsize,
    labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
    image_mode: ImageRefMode = PLACEHOLDER,
    formula_to_mathml: bool = True,
    page_no: Optional[int] = None,
    html_lang: str = "en",
    html_head: str = _HTML_DEFAULT_HEAD,
    included_content_layers: set[
        ContentLayer
    ] = DEFAULT_CONTENT_LAYERS,
)

保存为HTML。

保存为JSON

save_as_json(
    filename: Path,
    artifacts_dir: Optional[Path] = None,
    image_mode: ImageRefMode = EMBEDDED,
    indent: int = 2,
)

另存为json。

另存为Markdown

save_as_markdown(
    filename: Path,
    artifacts_dir: Optional[Path] = None,
    delim: str = "\n",
    from_element: int = 0,
    to_element: int = maxsize,
    labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS,
    strict_text: bool = False,
    escaping_underscores: bool = True,
    image_placeholder: str = "<!-- image -->",
    image_mode: ImageRefMode = PLACEHOLDER,
    indent: int = 4,
    text_width: int = -1,
    page_no: Optional[int] = None,
    included_content_layers: set[
        ContentLayer
    ] = DEFAULT_CONTENT_LAYERS,
)

保存为 markdown。

保存为_yaml

save_as_yaml(
    filename: Path,
    artifacts_dir: Optional[Path] = None,
    image_mode: ImageRefMode = EMBEDDED,
    default_flow_style: bool = False,
)

另存为yaml。

transform_to_content_layer

transform_to_content_layer(data: dict) -> dict

转换为内容层.

验证文档

validate_document(d: DoclingDocument)

验证文档。

validate_tree

validate_tree(root) -> bool

验证树.

文档来源

基础: BaseModel

文件源。

方法:

属性:

二进制哈希

binary_hash: Uint64

文件名

filename: str

文件类型

mimetype: str

uri

uri: Optional[AnyUrl] = None

解析十六进制字符串

parse_hex_string(value)

解析十六进制字符串。

验证 MIME 类型

validate_mimetype(v)

验证媒体类型。

文档项

基础: NodeItem

文档项。

方法:

属性:

子项

children: List[RefItem] = []

内容层

content_layer: ContentLayer = BODY

标签

label: DocItemLabel

模型配置

model_config = ConfigDict(extra='forbid')

父级

parent: Optional[RefItem] = None

提供

prov: List[ProvenanceItem] = []

自引用

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

获取图像

get_image(doc: DoclingDocument) -> Optional[Image]

返回此 DocItem 的图像。

如果此 DocItem 没有有效的来源,或者在 doc 中没有可用的包含此 DocItem 的页面有效图像,则该函数返回 None。

获取位置令牌

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 500,
    ysize: int = 500,
) -> str

获取BaseCell的位置字符串。

获取引用

get_ref()

get_ref.

文档项标签

基类: str, Enum

文档项目标签.

方法:

  • get_color

    返回与给定标签相关联的 RGB 颜色。

属性:

说明

CAPTION = 'caption'

选中的复选框

CHECKBOX_SELECTED = 'checkbox_selected'

未选中的复选框

CHECKBOX_UNSELECTED = 'checkbox_unselected'

代码

CODE = 'code'

文档索引

DOCUMENT_INDEX = 'document_index'

脚注

FOOTNOTE = 'footnote'

表格

FORM = 'form'

公式

FORMULA = 'formula'

键值区域

KEY_VALUE_REGION = 'key_value_region'

列表项

LIST_ITEM = 'list_item'
PAGE_FOOTER = 'page_footer'

页面标题

PAGE_HEADER = 'page_header'

段落

PARAGRAPH = 'paragraph'

图片

PICTURE = 'picture'

参考文献

REFERENCE = 'reference'

章节标题

SECTION_HEADER = 'section_header'

TABLE = 'table'

文本

TEXT = 'text'

标题

TITLE = 'title'

获取颜色

get_color(label: DocItemLabel) -> Tuple[int, int, int]

返回与给定标签相关联的RGB颜色。

来源项

基础: BaseModel

来源项。

属性:

边界框

字符跨度

charspan: Tuple[int, int]

页码

page_no: int

组项

基础: NodeItem

组项目。

方法:

属性:

子项

children: List[RefItem] = []

内容层

content_layer: ContentLayer = BODY

标签

模型配置

model_config = ConfigDict(extra='forbid')

名称

name: str = 'group'

父级

parent: Optional[RefItem] = None

自引用

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

获取引用

get_ref()

get_ref.

组标签

基类: str, Enum

组标签。

属性:

章节

CHAPTER = 'chapter'

评论部分

COMMENT_SECTION = 'comment_section'

表单区域

FORM_AREA = 'form_area'

键值区域

KEY_VALUE_AREA = 'key_value_area'

列表

LIST = 'list'

有序列表

ORDERED_LIST = 'ordered_list'

章节

SECTION = 'section'

工作表

SHEET = 'sheet'

幻灯片

SLIDE = 'slide'

未指定

UNSPECIFIED = 'unspecified'

节点项

基础: BaseModel

节点项。

方法:

属性:

子项

children: List[RefItem] = []

内容层

content_layer: ContentLayer = BODY

模型配置

model_config = ConfigDict(extra='forbid')

父级

parent: Optional[RefItem] = None

自引用

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

获取引用

get_ref()

get_ref.

页面项

基础: BaseModel

页面项。

属性:

图像

image: Optional[ImageRef] = None

页码

page_no: int

大小

size: Size

浮动项

基类: DocItem

浮动项。

方法:

属性:

标题

captions: List[RefItem] = []

子项

children: List[RefItem] = []

内容层

content_layer: ContentLayer = BODY

脚注

footnotes: List[RefItem] = []

图像

image: Optional[ImageRef] = None

标签

label: DocItemLabel

模型配置

model_config = ConfigDict(extra='forbid')

父级

parent: Optional[RefItem] = None

提供

prov: List[ProvenanceItem] = []

参考文献

references: List[RefItem] = []

自引用

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

标题文本

caption_text(doc: DoclingDocument) -> str

将标题计算为单一文本。

获取图像

get_image(doc: DoclingDocument) -> Optional[Image]

返回与此 FloatingItem 相对应的图像。

如果可用,该函数返回来自 self.image 的 PIL 图像。否则,它使用 DocItem.get_image 获取此 FloatingItem 的图像。

特别是,当 self.image 为 None 时,如果这个 FloatingItem 没有有效的来源或文档不包含所需页面的有效图像,函数将返回 None。

获取位置令牌

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 500,
    ysize: int = 500,
) -> str

获取BaseCell的位置字符串。

获取引用

get_ref()

get_ref.

文本项

基类: DocItem

文本项。

方法:

属性:

子项

children: List[RefItem] = []

内容层

content_layer: ContentLayer = BODY

模型配置

model_config = ConfigDict(extra='forbid')

原始

orig: str

父级

parent: Optional[RefItem] = None

提供

prov: List[ProvenanceItem] = []

自引用

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

文本

text: str

导出到文档令牌

export_to_document_tokens(
    doc: DoclingDocument,
    new_line: str = "",
    xsize: int = 500,
    ysize: int = 500,
    add_location: bool = True,
    add_content: bool = True,
)

将文本元素导出为文档令牌格式。

参数:

  • doc (DoclingDocument) –

    "DoclingDocument":

  • new_line (str, 默认: '' ) –

    str (默认值 = "")

  • xsize (int, 默认: 500 ) –

    int: (默认值 = 500)

  • ysize (int, 默认: 500 ) –

    int: (默认值 = 500)

  • add_location (bool, 默认: True ) –

    bool: (默认值 = True)

  • add_content (bool, default: True ) –

    bool: (默认值 = True)

获取图像

get_image(doc: DoclingDocument) -> Optional[Image]

返回此 DocItem 的图像。

如果此 DocItem 没有有效的来源,或者在 doc 中没有可用的包含此 DocItem 的页面有效图像,则该函数返回 None。

获取位置令牌

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 500,
    ysize: int = 500,
) -> str

获取BaseCell的位置字符串。

获取引用

get_ref()

get_ref.

表项

基类: FloatingItem

表项。

方法:

属性:

标题

captions: List[RefItem] = []

子项

children: List[RefItem] = []

内容层

content_layer: ContentLayer = BODY

数据

data: TableData

脚注

footnotes: List[RefItem] = []

图像

image: Optional[ImageRef] = None

标签

label: Literal[DOCUMENT_INDEX, TABLE] = TABLE

模型配置

model_config = ConfigDict(extra='forbid')

父级

parent: Optional[RefItem] = None

提供

prov: List[ProvenanceItem] = []

参考文献

references: List[RefItem] = []

自引用

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

标题文本

caption_text(doc: DoclingDocument) -> str

将标题计算为单一文本。

export_to_dataframe

export_to_dataframe() -> DataFrame

将表格导出为 Pandas DataFrame。

导出到文档令牌

export_to_document_tokens(
    doc: DoclingDocument,
    new_line: str = "",
    xsize: int = 500,
    ysize: int = 500,
    add_location: bool = True,
    add_cell_location: bool = True,
    add_cell_text: bool = True,
    add_caption: bool = True,
)

将表格导出为文档令牌格式。

参数:

  • doc (DoclingDocument) –

    "DoclingDocument":

  • new_line (str, 默认: '' ) –

    str(默认值 = "")

  • xsize (int, 默认: 500 ) –

    int: (默认值 = 500)

  • ysize (int, 默认: 500 ) –

    int: (默认值 = 500)

  • add_location (bool, 默认: True ) –

    bool: (默认值 = True)

  • add_cell_location (bool, 默认: True ) –

    bool: (默认值 = True)

  • add_cell_text (bool, 默认: True ) –

    bool: (默认值 = True)

  • add_caption (bool, 默认: True ) –

    bool: (默认值 = True)

导出为html

export_to_html(
    doc: Optional[DoclingDocument] = None,
    add_caption: bool = True,
) -> str

将表格导出为html。

导出到Markdown

export_to_markdown() -> str

将表格导出为markdown。

导出到_otsl

export_to_otsl(
    doc: DoclingDocument,
    add_cell_location: bool = True,
    add_cell_text: bool = True,
    xsize: int = 500,
    ysize: int = 500,
) -> str

将表格导出为OTSL。

获取图像

get_image(doc: DoclingDocument) -> Optional[Image]

返回与此 FloatingItem 相对应的图像。

如果可用,该函数返回来自 self.image 的 PIL 图像。否则,它使用 DocItem.get_image 获取此 FloatingItem 的图像。

特别是,当 self.image 为 None 时,如果这个 FloatingItem 没有有效的来源或文档不包含所需页面的有效图像,函数将返回 None。

获取位置令牌

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 500,
    ysize: int = 500,
) -> str

获取BaseCell的位置字符串。

获取引用

get_ref()

get_ref.

表格单元格

基础: BaseModel

单元格。

方法:

属性:

边界框

bbox: Optional[BoundingBox] = None

列跨度

col_span: int = 1

列头

column_header: bool = False

结束列偏移索引

end_col_offset_idx: int

终止行偏移索引

end_row_offset_idx: int

行标题

row_header: bool = False

行_部分

row_section: bool = False

行跨度

row_span: int = 1

start_col_offset_idx

start_col_offset_idx: int

起始行偏移索引

start_row_offset_idx: int

文本

text: str

从字典格式

from_dict_format(data: Any) -> Any

从字典格式。

表格数据

基础: BaseModel

基础表数据。

属性:

网格

grid: List[List[TableCell]]

网格。

num_cols

num_cols: int = 0

num_rows

num_rows: int = 0

表格单元格

table_cells: List[TableCell] = []

表格单元格标签

基类: str, Enum

单元格标签.

属性:

主体

BODY = 'body'

列标题

COLUMN_HEADER = 'col_header'

行标题

ROW_HEADER = 'row_header'

行_部分

ROW_SECTION = 'row_section'

键值项

基类: FloatingItem

键值项。

方法:

属性:

标题

captions: List[RefItem] = []

子项

children: List[RefItem] = []

内容层

content_layer: ContentLayer = BODY

脚注

footnotes: List[RefItem] = []

图形

graph: GraphData

图像

image: Optional[ImageRef] = None

标签

模型配置

model_config = ConfigDict(extra='forbid')

父级

parent: Optional[RefItem] = None

提供

prov: List[ProvenanceItem] = []

参考文献

references: List[RefItem] = []

自引用

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

标题文本

caption_text(doc: DoclingDocument) -> str

将标题计算为单一文本。

获取图像

get_image(doc: DoclingDocument) -> Optional[Image]

返回与此 FloatingItem 相对应的图像。

如果可用,该函数返回来自 self.image 的 PIL 图像。否则,它使用 DocItem.get_image 获取此 FloatingItem 的图像。

特别是,当 self.image 为 None 时,如果这个 FloatingItem 没有有效的来源或文档不包含所需页面的有效图像,函数将返回 None。

获取位置令牌

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 500,
    ysize: int = 500,
) -> str

获取BaseCell的位置字符串。

获取引用

get_ref()

get_ref.

节标题项

基类: TextItem

章节项。

方法:

属性:

子项

children: List[RefItem] = []

内容层

content_layer: ContentLayer = BODY

标签

label: Literal[SECTION_HEADER] = SECTION_HEADER

级别

level: LevelNumber = 1

模型配置

model_config = ConfigDict(extra='forbid')

原始

orig: str

父级

parent: Optional[RefItem] = None

提供

prov: List[ProvenanceItem] = []

自引用

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

文本

text: str

导出到文档令牌

export_to_document_tokens(
    doc: DoclingDocument,
    new_line: str = "",
    xsize: int = 500,
    ysize: int = 500,
    add_location: bool = True,
    add_content: bool = True,
)

将文本元素导出为文档令牌格式。

参数:

  • doc (DoclingDocument) –

    "DoclingDocument":

  • new_line (str, 默认: '' ) –

    str(默认值 = "")

  • xsize (int, 默认: 500 ) –

    int: (默认值 = 500)

  • ysize (int, 默认: 500 ) –

    int: (默认值 = 500)

  • add_location (bool, 默认: True ) –

    bool: (默认值 = True)

  • add_content (bool, default: True ) –

    bool: (默认值 = True)

获取图像

get_image(doc: DoclingDocument) -> Optional[Image]

返回此 DocItem 的图像。

如果此 DocItem 没有有效的来源,或者在 doc 中没有可用的包含此 DocItem 的页面有效图像,则该函数返回 None。

获取位置令牌

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 500,
    ysize: int = 500,
) -> str

获取BaseCell的位置字符串。

获取引用

get_ref()

get_ref.

图片项目

基类: FloatingItem

图片项。

方法:

属性:

注释

annotations: List[PictureDataType] = []

标题

captions: List[RefItem] = []

子项

children: List[RefItem] = []

内容层

content_layer: ContentLayer = BODY

脚注

footnotes: List[RefItem] = []

图像

image: Optional[ImageRef] = None

标签

label: Literal[PICTURE] = PICTURE

模型配置

model_config = ConfigDict(extra='forbid')

父级

parent: Optional[RefItem] = None

提供

prov: List[ProvenanceItem] = []

参考文献

references: List[RefItem] = []

自引用

self_ref: str = Field(pattern=_JSON_POINTER_REGEX)

标题文本

caption_text(doc: DoclingDocument) -> str

将标题计算为单一文本。

导出到文档令牌

export_to_document_tokens(
    doc: DoclingDocument,
    new_line: str = "",
    xsize: int = 500,
    ysize: int = 500,
    add_location: bool = True,
    add_caption: bool = True,
    add_content: bool = True,
)

将图片导出为文档令牌格式。

参数:

  • doc (DoclingDocument) –

    "DoclingDocument":

  • new_line (str, 默认: '' ) –

    str(默认值 = "")

  • xsize (int, 默认: 500 ) –

    int: (默认值 = 500)

  • ysize (int, 默认: 500 ) –

    int: (默认值 = 500)

  • add_location (bool, 默认: True ) –

    bool: (默认值 = True)

  • add_caption (bool, 默认: True ) –

    bool: (默认值 = True)

  • add_content (bool, default: True ) –

    bool: (默认值 = True)

导出为html

export_to_html(
    doc: DoclingDocument,
    add_caption: bool = True,
    image_mode: ImageRefMode = PLACEHOLDER,
) -> str

将图片导出为HTML格式。

导出到Markdown

export_to_markdown(
    doc: DoclingDocument,
    add_caption: bool = True,
    image_mode: ImageRefMode = EMBEDDED,
    image_placeholder: str = "<!-- image -->",
) -> str

将图片导出为Markdown格式。

获取图像

get_image(doc: DoclingDocument) -> Optional[Image]

返回与此 FloatingItem 相对应的图像。

如果可用,该函数返回来自 self.image 的 PIL 图像。否则,它使用 DocItem.get_image 获取此 FloatingItem 的图像。

特别是,当 self.image 为 None 时,如果这个 FloatingItem 没有有效的来源或文档不包含所需页面的有效图像,函数将返回 None。

获取位置令牌

get_location_tokens(
    doc: DoclingDocument,
    new_line: str,
    xsize: int = 500,
    ysize: int = 500,
) -> str

获取BaseCell的位置字符串。

获取引用

get_ref()

get_ref.

图像引用

基础: BaseModel

图像引用。

方法:

属性:

点每英寸

dpi: int

文件类型

mimetype: str

pil_image

pil_image: Optional[Image]

返回PIL图像。

大小

size: Size

uri

uri: Union[AnyUrl, Path] = Field(union_mode="left_to_right")

from_pil

from_pil(image: Image, dpi: int) -> Self

从PIL图像构造ImageRef。

验证 MIME 类型

validate_mimetype(v)

验证媒体类型。

图像分类类

基础: BaseModel

图片分类数据。

属性:

类名

class_name: str

置信度

confidence: float

图片分类数据

基类: BasePictureData

图片分类数据。

属性:

种类

kind: Literal['classification'] = 'classification'

预测的类别

predicted_classes: List[PictureClassificationClass]

来源

provenance: str

参考项

基础: BaseModel

参考项。

方法:

属性:

参考

cref: str = Field(alias="$ref", pattern=_JSON_POINTER_REGEX)

模型配置

model_config = ConfigDict(populate_by_name=True)

获取引用

get_ref()

get_ref.

解决

resolve(doc: DoclingDocument)

解决。

边界框

基础: BaseModel

边界框。

方法:

属性:

b

b: float

坐标原点

coord_origin: CoordOrigin = TOPLEFT

高度

height

高度。

l

l: float

r

r: float

t

t: float

宽度

width

宽度。

区域

area() -> float

区域。

作为元组

as_tuple() -> Tuple[float, float, float, float]

作为元组。

围绕边界框

enclosing_bbox(boxes: List[BoundingBox]) -> BoundingBox

创建一个包含所有给定框的边界框。

按比例展开

expand_by_scale(
    x_scale: float, y_scale: float
) -> BoundingBox

扩展至指定大小。

from_tuple

from_tuple(coord: Tuple[float, ...], origin: CoordOrigin)

从元组。

参数:

  • coord (Tuple[float, ...]) –

    元组[浮点数:

  • ...]
  • origin (CoordOrigin) –

    坐标原点:

与的交集面积

intersection_area_with(other: BoundingBox) -> float

计算与另一个包围盒的交集区域。

intersection_over_self

intersection_over_self(
    other: BoundingBox, eps: float = 1e-06
) -> float

自交.

交并比

intersection_over_union(
    other: BoundingBox, eps: float = 1e-06
) -> float

交并比。

is_above

is_above(other: BoundingBox) -> bool

is_above.

是水平连接的

is_horizontally_connected(
    elem_i: BoundingBox, elem_j: BoundingBox
) -> bool

is_horizontally_connected.

在左边

is_left_of(other: BoundingBox) -> bool

在左侧。

高于严格

is_strictly_above(
    other: BoundingBox, eps: float = 0.001
) -> bool

is_strictly_above.

is_strictly_left_of

is_strictly_left_of(
    other: BoundingBox, eps: float = 0.001
) -> bool

严格在左侧。

归一化

normalized(page_size: Size)

归一化。

重叠

overlaps(other: BoundingBox) -> bool

重叠。

水平重叠

overlaps_horizontally(other: BoundingBox) -> bool

检查两个边界框是否在水平方向上重叠。

垂直重叠

overlaps_vertically(other: BoundingBox) -> bool

检查两个边界框是否垂直重叠。

与 iou 垂直重叠

overlaps_vertically_with_iou(
    other: BoundingBox, iou: float
) -> bool

与iou重叠。

按比例调整大小

resize_by_scale(x_scale: float, y_scale: float)

按比例调整大小。

scale_to_size

scale_to_size(old_size: Size, new_size: Size)

缩放到大小.

缩放

scaled(scale: float)

缩放。

到左下原点

to_bottom_left_origin(page_height: float) -> BoundingBox

到底左下原点。

参数:

  • page_height (float) –
    页面高度

到左上角原点

to_top_left_origin(page_height: float) -> BoundingBox

到左上角原点。

参数:

  • page_height (float) –

坐标原点

基类: str, Enum

坐标原点。

属性:

左下角

BOTTOMLEFT = 'BOTTOMLEFT'

左上角

TOPLEFT = 'TOPLEFT'

图像引用模式

基类: str, Enum

图像引用模式。

属性:

嵌入式

EMBEDDED = 'embedded'

占位符

PLACEHOLDER = 'placeholder'

引用的

REFERENCED = 'referenced'

大小

基础: BaseModel

大小。

方法:

属性:

高度

height: float = 0.0

宽度

width: float = 0.0

作为元组

as_tuple()

作为元组。