modules.filters 模块帮助

本章节包含 modules.filters 包中常用「数据筛选与过滤」模块的使用说明和示例,例如:

  • 按条件筛选行(范围过滤、条件过滤等)

  • 按字段值过滤、去重等操作

TableSeriesSelector

模块简介与适用场景

  • TableSeriesSelectorTableDataTableCollection 中选择一列,输出 TableSeries

  • 典型适用场景:后续模块或绘图仅需某一字段(如深度、孔号),或从多表集合中按「表 + 字段」抽取一列;select_field 配置见「参数说明」。

端口说明

  • 输入端口 - InputTable:输入表数据(TableData)或表集合(TableCollection)。

  • 输出端口 - OutputTableSeries:选取到的一列(TableSeries);当输入为空/表为空/字段不存在时为 None

快速上手示例:从单表选择一列

from gdisdk.modules.filters import TableSeriesSelector

selector = TableSeriesSelector(mname="SelectSeries")
selector.select_field = "depth"   # 列名(也可以写列标题)
# selector.InputTable = table      # TableData
selector.execute()
series = selector.OutputTableSeries.data

快速上手示例:从多表集合选择一列

from gdisdk.modules.filters import TableSeriesSelector

selector = TableSeriesSelector(mname="SelectSeriesFromCollection")
selector.select_field = ("剖面数据表", "x_coordinate")  # (表名/表标题, 字段名/字段标题)
# selector.InputTable = tables     # TableCollection
selector.execute()
series = selector.OutputTableSeries.data

参数说明

TableSeriesSelector 参数一览

参数名

类型

默认值

说明

select_field

tuple[str, str] | str | None

None

选择的字段配置:当输入为 TableData 时填 str``(字段名/字段标题);当输入为 ``TableCollection 时填 (table, field) 二元组。

在 pipeline 中的使用方式

from gdisdk.pipeline import PipeLine
from gdisdk.modules.filters import TableSeriesSelector

pipe = PipeLine(app_name="SelectSeriesDemo", app_title="选择一列示例")

selector = TableSeriesSelector(mname="SelectSeries")
selector.select_field = "depth"
# links = upstream.OutputTable >> selector.InputTable
# pipe.add_links(links)
# pipe.run()
# series = selector.OutputTableSeries.data

更多信息

TableFieldsSelector

模块简介与适用场景

  • TableFieldsSelectorTableDataTableCollection 中**选择或删除若干列**,输出仍为 TableData``TableCollection``(结构与输入一致)。

  • 字段可用**列名**或**列标题**指定;select_fields 支持 list``(统一字段列表)或 ``dict``(按表分别配置),详见「参数说明」与「``select_fields 配置说明」。

  • 典型场景:GDIM 读入宽表后只保留绘图/统计所需列;从多表集合中批量裁剪各表字段;删除敏感或冗余列后再写入下游模块。

  • 注意operation='select' 且只保留一列时,输出仍是 TableData``(不是 ``TableSeries);若只需单列且后续要 TableSeries,请用 TableSeriesSelector

端口说明

  • 输入端口 - InputTable:输入表(TableData)或表集合(TableCollection)。

  • 输出端口 - OutputTable:字段操作后的表或表集合;当输入为空、表为空或 select_fieldsNone 时为 None

快速上手示例:从单表选择若干列

from gdisdk.modules.filters import TableFieldsSelector

selector = TableFieldsSelector(mname="PickColumns")
selector.operation = "select"
selector.select_fields = ["depth", "x_coordinate"]  # 列名或列标题
# selector.InputTable = table                      # TableData
selector.execute()
out_table = selector.OutputTable.data

快速上手示例:从单表删除若干列

from gdisdk.modules.filters import TableFieldsSelector

selector = TableFieldsSelector(mname="DropColumns")
selector.operation = "remove"
selector.select_fields = ["备注", "internal_id"]
# selector.InputTable = table
selector.execute()
out_table = selector.OutputTable.data

快速上手示例:从多表集合按表分别选列

from gdisdk.modules.filters import TableFieldsSelector

selector = TableFieldsSelector(mname="PickFieldsFromCollection")
selector.operation = "select"
selector.select_fields = {
    "剖面数据表": ["x_coordinate", "y_coordinate"],
    "钻孔表": ["孔号", "孔深"],
}  # 键为表名或表标题
# selector.InputTable = tables                     # TableCollection
selector.execute()
out_tables = selector.OutputTable.data

参数说明

TableFieldsSelector 参数一览

参数名

类型

默认值

说明

select_fields

list[str] | dict[str, list[str]] | None

None

要选取或删除的字段(列名/列标题)。listdict 在不同输入类型下的行为见「select_fields 配置说明」。

operation

Literal["select", "remove"]

"select"

"select" 仅保留解析到的列;"remove" 删除解析到的列。

rename_output

TableMetadata | dict | None

None

可选,重命名**输出**表或集合壳层的 name / title / description;接受 TableMetadata 或仅含上述键的 dict

rename_nested_table

dict[str, TableMetadata | dict] | None

None

仅当输入为 TableCollection 时有效;按键(嵌套表的 nametitle)分别重命名各子表。若 nametitle 同时作为键出现,两处的值必须一致。

``select_fields`` 配置说明

select_fields 与输入类型组合

输入类型

select_fields 形态

行为摘要

TableData

list[str]

operation='select':未知列名/标题会抛出 KeyError'remove' 会跳过未知标签。

TableData

dict[str, list[str]]

至少一个键须等于该表的 nametitleselect / remove 的未知字段规则同 list

TableCollection

list[str]

对**每个**嵌套表应用同一字段列表;未知标签在 selectremove 下均**跳过**。

TableCollection

dict[str, list[str]]

键为表 nametitle;命中的表按 operation 投影列,未出现在 dict 中的表**深拷贝**后原样保留。命中表:select 遇未知字段 KeyErrorremove 跳过未知字段。

在 pipeline 中的使用方式

from gdisdk.pipeline import PipeLine
from gdisdk.modules.filters import TableFieldsSelector

pipe = PipeLine(app_name="SelectFieldsDemo", app_title="选择/删除列示例")

selector = TableFieldsSelector(mname="PickColumns")
selector.operation = "select"
selector.select_fields = ["depth", "x_coordinate"]
# links = upstream.OutputTable >> selector.InputTable
# pipe.add_links(links)
# pipe.run()
# out_table = selector.OutputTable.data

更多信息

TableSelector

模块简介与适用场景

  • TableSelectorTableCollection 中选择一张表,输出 TableData

  • 典型适用场景:多表读取后只处理其中一张表;在 UI 中动态选择表(模块会根据输入集合生成可选项)。table_name / table_idx 见「参数说明」。

端口说明

  • 输入端口 - InputTables:输入表集合(TableCollection)。

  • 输出端口 - OutputTable:选中的表(TableData);当输入为空/未命中 table_name 且未设置 table_idx 时为 None

快速上手示例:按表名/表标题选择

from gdisdk.modules.filters import TableSelector

selector = TableSelector(mname="SelectTable")
selector.table_name = "剖面数据表"  # 表名或表标题;设置后会忽略 table_idx
# selector.InputTables = tables     # TableCollection
selector.execute()
table = selector.OutputTable.data

参数说明

TableSelector 参数一览

参数名

类型

默认值

说明

table_name

str | None

None

要选择的表名或表标题;若不为 None,则 table_idx 会被忽略。

table_idx

int | None

None

按索引选择(从 0 开始);仅在 table_nameNone 时生效。

在 pipeline 中的使用方式

from gdisdk.pipeline import PipeLine
from gdisdk.modules.filters import TableSelector

pipe = PipeLine(app_name="SelectTableDemo", app_title="选择表示例")

selector = TableSelector(mname="SelectTable")
selector.table_name = "剖面数据表"
# links = upstream.OutputTables >> selector.InputTables
# pipe.add_links(links)
# pipe.run()
# table = selector.OutputTable.data

更多信息

TableCollectionSelector

模块简介与适用场景

  • TableCollectionSelectorTableCollection 进行选取或剔除,输出新的 ``TableCollection``(保留主子表关系)。

  • 典型适用场景:从多表集合中只保留或排除指定表,避免后续模块误处理;operationtable_names 等见「参数说明」。

端口说明

  • 输入端口 - InputTables:输入表集合(TableCollection)。

  • 输出端口 - OutputTables:处理后的表集合(TableCollection),且保留了已有的主子表关系。

快速上手示例:只保留指定表

from gdisdk.modules.filters import TableCollectionSelector

selector = TableCollectionSelector(mname="PickTables")
selector.operation = "select"
selector.table_names = ["剖面数据表", "钻孔表"]  # 支持表名或表标题
# selector.InputTables = tables               # TableCollection
selector.execute()
out_tables = selector.OutputTables.data

快速上手示例:移除指定表

from gdisdk.modules.filters import TableCollectionSelector

selector = TableCollectionSelector(mname="RemoveTables")
selector.operation = "remove"
selector.table_names = ["不需要的表"]
# selector.InputTables = tables
selector.execute()
out_tables = selector.OutputTables.data

参数说明

TableCollectionSelector 参数一览

参数名

类型

默认值

说明

table_names

list[str] | None

None

要选取/移除的表名或表标题列表;若不为 None,会忽略 table_idxs;不存在的表会被忽略。

table_idxs

list[int] | None

None

要选取/移除的表索引列表;越界索引会被忽略。

operation

Literal["select","remove"]

"select"

"select" 表示只保留指定表;"remove" 表示从集合中移除指定表。

注意

  • table_namestable_idxs 都为 None 时:

    • operation="select":输出 None

    • operation="remove":直接返回**输入**的 TableCollection 引用。

在 pipeline 中的使用方式

from gdisdk.pipeline import PipeLine
from gdisdk.modules.filters import TableCollectionSelector

pipe = PipeLine(app_name="SelectTablesDemo", app_title="选择/移除表集合示例")

selector = TableCollectionSelector(mname="SelectTables")
selector.operation = "select"
selector.table_names = ["剖面数据表"]
# links = upstream.OutputTables >> selector.InputTables
# pipe.add_links(links)
# pipe.run()
# tables = selector.OutputTables.data

更多信息

TablesQuery

模块简介与适用场景

  • TablesQuery 使用 pandas DataFrame.query 风格表达式过滤 TableDataTableCollection,输出类型与输入一致。

  • 支持 query_template 模板变量(UI 动态改值)及主表/子表级联过滤;表达式语法见下文「查询模板语法说明」,参数见「参数说明」。

端口说明

  • 输入端口 - InputTables:输入表(TableData)或表集合(TableCollection)。

  • 输出端口 - OutputTables:过滤后的表(TableData)或表集合(TableCollection);当输入为空、query_template 为空、或模板变量校验失败(如变量值为 Nonenone_error_type 不为 "ignore")时为 None

快速上手示例:无模板变量(手写常量条件)

from gdisdk.modules.filters import TablesQuery

q = TablesQuery(mname="QueryTables")
q.query_template = "`年份` == 2007 and `国家` == 'US'"  # 字符串常量需要自己加引号
# q.InputTables = table_or_tables
q.execute()
out = q.OutputTables.data

快速上手示例:使用模板变量(UI 可改值)

from gdisdk.modules.filters import TablesQuery
from gdisdk.pipeline.pipeData import TemplateVariableConfig

q = TablesQuery(mname="QueryWithTpl")
q.query_template = "`年份` == {tpl_year} and `国家` == {tpl_country}"
q.template_variables = {
    "tpl_year": TemplateVariableConfig(
        title="年份",
        default=2007,
        value_type="int",
        schema_type="auto_select",
    ),
    "tpl_country": TemplateVariableConfig(
        title="国家",
        default="US",
        value_type="str",       # 字符串会自动加引号,无需写成 '{tpl_country}'
        schema_type="auto_select",
    ),
}
# q.InputTables = table_or_tables
q.tpl_country = "CN"  # 运行前可通过属性直接改模板变量
q.execute()
out = q.OutputTables.data

查询模板语法说明(常见写法速查)

  • query_template 基于 pandas 的 DataFrame.query 表达式语法(逻辑运算:and/or/not,比较:== != > >= < <=)。

  • 推荐把字段名/字段标题写在反引号里(例如 \`年份\`),可避免绝大多数 “字段名不是合法标识符” 导致的解析错误。

  • 字符串常量需要用引号包裹(例如 'US');但当你使用模板变量并设置 value_type="str" 时,字符串会**自动加引号**(无需写成 '{tpl_xxx}')。

常见模板示例

# 1) 数值等值 / 范围
"`年份` == 2007"
"`深度` >= 10 and `深度` < 30"

# 2) 字符串等值(手写常量时需要引号)
"`国家` == 'US'"

# 3) in / not in(列表常量)
"`类型` in ['A', 'B', 'C']"
"`类型` not in ['废弃', '删除']"

# 4) 空值判断(None/NaN)
"`备注` == ''"                # 空字符串
"`备注`.isnull()"             # 为空(None/NaN)
"`备注`.notnull()"            # 非空

# 5) 字符串包含/前后缀(pandas 字符串方法)
"`名称`.str.contains('岩', na=False)"
"`名称`.str.startswith('ZK', na=False)"
"`名称`.str.endswith('号', na=False)"

# 6) 多条件组合(括号控制优先级)
"(`状态` == '有效' and `深度` > 10) or (`状态` == '复核')"

什么时候需要使用反引号 ````…````(非常重要)

pandas 的 query 要求 “字段名像 Python 变量一样可解析”。当字段名不满足这个条件时,必须用反引号包裹字段名(即 \`列名\`)。以下情况**建议/需要**用反引号:

  • 字段名包含中文、空格、短横线等特殊字符(如 工程名称x coordinatex-coordinate)。

  • 字段名以数字开头或包含点号等(如 2020年a.b)。

  • 字段名与 Python 关键字冲突(如 classlambda)或包含不可作为标识符的字符。

  • 你在模板里使用的是 “字段标题” 而非字段名时(标题常包含中文/空格,强烈建议用反引号)。

为了减少踩坑,本文档的示例统一使用 \`字段名/字段标题\` 形式;这也是最推荐的写法。

参数说明

TablesQuery 参数一览

参数名

类型

默认值

说明

query_template

str | None

None

查询表达式模板(pandas 查询语法);支持 {tpl_xxx} 占位符;中文/带空格字段名建议用反引号包裹(如 \`年份\`)。

template_variables

dict[str, TemplateVariableConfig | UIAttributeSchema] | None

None

模板变量配置字典;所有变量名必须以 ``tpl_`` 开头,并可通过 q.tpl_xxx = ... 在运行前赋值。

main_table

str | None

None

级联过滤模式下的主表名/表标题;不填时会尝试从输入 TableCollection.main_table 自动获取。

related_tables

list[str] | None

None

级联过滤模式下要跟随过滤的子表列表;不填时会尝试从 TableCollection.sub_tables 自动获取。

join_key

str | None

None

主表与子表关联的键字段名/字段标题;不填时会尝试从 TableCollection.primary_key 自动获取。

cascade_to_children

bool

True

是否启用“主表过滤 → 按键值过滤子表”的级联逻辑;为 False 时对集合中每张表独立执行同一条 query。

debug_mode

bool

False

True 时输出更详细的查询评估错误信息(便于排查表达式问题)。

none_error_type

Literal["error","warning","gdi_warning","ignore"]

"warning"

当模板变量存在 None 值时的处理策略:报错、警告、GDIM 警告或忽略检查。

在 pipeline 中的使用方式

from gdisdk.pipeline import PipeLine
from gdisdk.modules.filters import TablesQuery

pipe = PipeLine(app_name="TablesQueryDemo", app_title="表格查询示例")

q = TablesQuery(mname="Query")
q.query_template = "`年份` >= 2020"
# links = upstream.OutputTables >> q.InputTables
# pipe.add_links(links)
# pipe.run()
# out = q.OutputTables.data

更多信息

DropDuplicateRows

模块简介与适用场景

  • DropDuplicateRowsTableData 按指定字段去重,输出 TableData

  • 典型适用场景:业务数据按编号去重,或在重复行中合并指定字符串列(join_string_columns);详见「参数说明」。

端口说明

  • 输入端口 - InputTable:输入表(TableData)。

  • 输出端口 - OutputTable:去重后的表(TableData);当输入为空时为 None

快速上手示例:按字段去重

from gdisdk.modules.filters import DropDuplicateRows

dropdup = DropDuplicateRows(mname="DropDuplicate")
dropdup.subset = ["bore_number"]   # 可写字段名或字段标题
# dropdup.InputTable = table        # TableData
dropdup.execute()
out_table = dropdup.OutputTable.data

快速上手示例:重复行合并字符串列(需要 subset)

from gdisdk.modules.filters import DropDuplicateRows

dropdup = DropDuplicateRows(mname="DropDuplicateMergeText")
dropdup.subset = ["bore_number"]
dropdup.join_string_columns = ["remark"]  # 需要合并的字符串列
dropdup.join_separator = "\n"
# dropdup.InputTable = table
dropdup.execute()
out_table = dropdup.OutputTable.data

参数说明

DropDuplicateRows 参数一览

参数名

类型

默认值

说明

subset

list[str] | None

None

用于识别重复行的列;为 None 时使用全部列;支持字段名或字段标题。

keep_empty_strings

bool

True

是否保留包含空字符串 "" 的行;为 False 时会在去重后删除包含空字符串的行。

keep_null_values

bool

True

是否保留包含 None/NaN 的行;为 False 时会在去重后删除包含空值的行。

join_string_columns

list[str] | None

None

当发现重复行(基于 subset)时,把这些列的字符串值进行拼接合并;仅当 ``subset`` 非空时生效

join_separator

str

"\\n"

合并字符串列时使用的分隔符。

在 pipeline 中的使用方式

from gdisdk.pipeline import PipeLine
from gdisdk.modules.filters import DropDuplicateRows

pipe = PipeLine(app_name="DropDuplicateDemo", app_title="去重示例")

dropdup = DropDuplicateRows(mname="DropDuplicate")
dropdup.subset = ["bore_number"]
# links = upstream.OutputTable >> dropdup.InputTable
# pipe.add_links(links)
# pipe.run()
# out_table = dropdup.OutputTable.data

更多信息

GdimAppDataSelector

模块简介与适用场景

  • GdimAppDataSelectorResultModel``(通常来自 :class:`~gdisdk.modules.readers.GdimAppDataReader` ``OutputResultModel)中**选取一个字段**,输出到端口 OutputData``(类型为 ``General,实际值可能是 TableData、标量等,取决于上游保存的内容)。

  • 模块根据你配置的 namemodule_name 自动拼接查找键,规则与 save_data_to_db() 落库时的键名一致:

    • name"Output" 开头 → 视为**输出端口名**,必须同时提供 module_name,键为 "{module_name}@{name}"

    • name 不以 "Output" 开头且提供了 module_name → 视为**模块参数**,键为 "{module_name}#{name}"

    • name 不以 "Output" 开头且 module_nameNone → 视为 Pipeline 本体属性,键为 "pipeline@{name}"``(须与 ``save_data_to_db(..., data_type="pipeline") 使用的属性名一致)。

  • 若键不存在,执行时会抛出 KeyError,并提示当前 ResultModel 中可用的键(便于核对上游配置)。

  • 典型适用场景:报告类 Pipeline 中,在 GdimAppDataReader 之后为每个下游模块分别接一个 GdimAppDataSelector,将表格、图片、参数等拆成独立连线。

端口说明

  • 输入端口 - InputResultModelGdimAppDataReader 产出的 ResultModel

  • 输出端口 - OutputData:选中字段的值;输入或 name 为空时为 None

快速上手示例:选取上游模块的输出表

from gdisdk.modules.filters import GdimAppDataSelector

sel = GdimAppDataSelector(mname="PickTable")
sel.module_name = "CorrosionCompute"
sel.name = "OutputTable"  # 端口名须以 Output 开头
# sel.InputResultModel = reader.OutputResultModel
sel.execute()
table = sel.OutputData.data

快速上手示例:选取 Pipeline 本体属性(如 workspace)

from gdisdk.modules.filters import GdimAppDataSelector

sel = GdimAppDataSelector(mname="PickWorkspace")
sel.module_name = None
sel.name = "workspace"
sel.execute()
value = sel.OutputData.data

参数说明

GdimAppDataSelector 参数一览

参数名

类型

默认值

说明

name

str | None

None

端口名(须以 Output 开头)、模块参数名、或 Pipeline 本体属性名;为 None 时输出 None

module_name

str | None

None

选取端口或模块参数时必填;选取 pipeline@... 时保持 None

在 pipeline 中的使用方式

from gdisdk.pipeline import PipeLine
from gdisdk.modules import GdimAppDataReader, GdimAppDataSelector

pipe = PipeLine(app_name="ReportFromSavedApp", app_title="读取上游结果写报告")

reader = GdimAppDataReader(mname="ReadApp")
reader.app_title = "水腐蚀性分析"

pick = GdimAppDataSelector(mname="PickResult")
pick.module_name = "AnalysisModule"
pick.name = "OutputTable"

links = reader.OutputResultModel >> pick.InputResultModel
pipe.add_links(links)
# pipe.run()
# table = pick.OutputData.data

更多信息

MarkdownSectionFilter

模块简介与适用场景

  • MarkdownSectionFilter 按 Markdown 标题层级(# / ## / ### …)解析章节树,并按规则筛选内容;输出过滤后的 Markdown(OutputMarkdown)及结构化 ResultModel``(``OutputResultModel)。

  • 若需写入文件,请在下游使用 writers 帮助 中的 TextWriter

  • 典型适用场景:长报告按章节裁剪供 LLM/RAG 使用,过滤目录等噪声,或控制表格长度;筛选与表格策略参数见「参数说明」。

端口说明

  • InputMarkdown:输入 Markdown 文本或文件路径;端口有值时覆盖 markdown 参数。

  • OutputMarkdown:过滤后的 Markdown 文本。

  • OutputResultModelMarkdownSectionFilterResult,含 filtered_markdown_key 命名的 Markdown 字段、章节元数据(selected_sections / dropped_sections)、字符/ token 统计及 filter_rules 摘要。多实例并行时建议设置不同的 ``filtered_markdown_key``(见「参数说明」)。

快速上手示例:按章节号筛选并压缩表格

from gdisdk.modules.filters import MarkdownSectionFilter

f = MarkdownSectionFilter(mname="FilterMarkdown")
f.markdown = "report.md"  # 也可以直接传入 markdown 字符串
f.include_number_prefixes = ["2", "4", "5"]  # 例如:场地条件/评价/结论
f.drop_toc = True
f.tables_mode = "truncate_rows"
f.table_truncate_rows = 5
f.execute()
out_md = f.OutputMarkdown.data

快速上手示例:自定义 ResultModel 中 Markdown 字段名(避免冲突)

from gdisdk.modules.filters import MarkdownSectionFilter

f = MarkdownSectionFilter(mname="FilterMarkdown")
f.filtered_markdown_key = "site_conditions_md"
f.markdown = "report.md"
f.execute()
out_md = f.OutputMarkdown.data
# out_md 与 f.OutputMarkdown.data 一致(过滤后的 Markdown 字符串)
# f.OutputResultModel.data.site_conditions_md 同为过滤后的 markdown
# 其它元数据:f.OutputResultModel.data.selected_sections 等

快速上手示例:按标题模式筛选(正则)并排除目录/图件

from gdisdk.modules.filters import MarkdownSectionFilter

f = MarkdownSectionFilter(mname="FilterByTitle")
f.markdown = "report.md"
f.include_title_patterns = ["场地.*地质条件", "地层岩性", "结论"]
f.exclude_title_patterns = ["图件", "目.*录"]
f.execute()
out_md = f.OutputMarkdown.data

参数说明

MarkdownSectionFilter 参数一览

参数名

类型

默认值

说明

markdown

str | Path | None

None

输入 Markdown 文本或文件路径;若 InputMarkdown 端口有值,会在执行时覆盖该属性。

filtered_markdown_key

str

"filtered_markdown"

OutputResultModel 上存放“过滤后 Markdown 文本”的**字段名**(ResultModel 属性);当多个 MarkdownSectionFilter 并行或下游合并多个结果时,建议为各模块设置不同字段名以避免冲突。

include_number_prefixes

list[str]

[]

需要包含的章节编号前缀(如 ["2", "4.6"]);会包含该前缀下所有子章节(如 "2" 会匹配 2.1/2.2.1 等)。

include_title_patterns

list[str]

[]

需要包含的标题模式(正则或子串);标题命中则包含对应章节。

exclude_number_prefixes

list[str]

[]

需要剔除的章节编号前缀(优先级高于 include)。

exclude_title_patterns

list[str]

[]

需要剔除的标题模式(正则)。

keep_parent_headings

bool

True

True 时,当命中某个子章节,会同时保留其父级标题作为上下文(仅标题,不含父级正文内容)。

drop_preamble

bool

True

是否丢弃第一个标题之前的 “前言/封面” 等非章节内容。

drop_toc

bool

True

是否尝试删除目录块(TOC)。

tables_mode

Literal["keep","drop","caption_only","truncate_rows"]

"keep"

表格处理策略:保留/删除/仅保留表题/截断行数(保留表头 + 前 N 行数据)。

table_truncate_rows

int

10

tables_mode="truncate_rows" 时,保留的数据行数(不含表头)。

在 pipeline 中的使用方式

from gdisdk.pipeline import PipeLine
from gdisdk.modules.filters import MarkdownSectionFilter

pipe = PipeLine(app_name="MarkdownFilterDemo", app_title="Markdown 章节过滤示例")

f = MarkdownSectionFilter(mname="MarkdownFilter")
f.include_number_prefixes = ["2", "4"]
f.drop_toc = True
# links = upstream.OutputMarkdown >> f.InputMarkdown
# pipe.add_links(links)
# pipe.run()
# out_md = f.OutputMarkdown.data
# meta = f.OutputResultModel.data
# 写文件可将 OutputMarkdown 接到 TextWriter 等模块

更多信息