feat: excel清理优化
This commit is contained in:
1 parent
87ac58c394
commit
ca5782b6cd
16 files changed
+132
-27
No files matched your search
@@ -17,7 +17,9 @@ OWN_KWS = ["责任", "负责人", "部门", "岗位"]
|
||||
|
||||
# 列数较多时,Markdown 表格可读性较差,改为字段键值的行文本。
|
||||
WIDE_TABLE_COLS = 8
|
||||
DEFAULT_SEGMENT_MAX_CHARS = 480
|
||||
# 仅 Excel/CSV 表格分段使用:按字符累计完整原始行,防止 Dify 在单行中间二次截断。
|
||||
# 取 1000 左右可让专利类宽表通常容纳约 3~4 条数据行,减少 top-k=10 的覆盖损失。
|
||||
DEFAULT_TABLE_SEGMENT_MAX_CHARS = 1000
|
||||
|
||||
|
||||
def _find_col(headers: list[str], kws: list[str]) -> int | None:
|
||||
@@ -29,12 +31,12 @@ def _find_col(headers: list[str], kws: list[str]) -> int | None:
|
||||
return None
|
||||
|
||||
|
||||
def _normalize_segment_max_chars(value: int | None) -> int:
|
||||
"""归一化 Excel 段字符上限,避免非法配置导致清洗任务失败。"""
|
||||
def _normalize_table_segment_max_chars(value: int | None) -> int:
|
||||
"""归一化表格专用段字符上限,避免非法配置导致 Excel/CSV 清洗任务失败。"""
|
||||
try:
|
||||
return max(100, int(value or DEFAULT_SEGMENT_MAX_CHARS))
|
||||
return max(100, int(value or DEFAULT_TABLE_SEGMENT_MAX_CHARS))
|
||||
except (TypeError, ValueError):
|
||||
return DEFAULT_SEGMENT_MAX_CHARS
|
||||
return DEFAULT_TABLE_SEGMENT_MAX_CHARS
|
||||
|
||||
|
||||
def _pack_atomic_rows(
|
||||
@@ -125,7 +127,7 @@ def _condition_action_row_lines(
|
||||
def run(
|
||||
input_data: list[dict] | dict,
|
||||
context: Context,
|
||||
segment_max_chars: int = DEFAULT_SEGMENT_MAX_CHARS,
|
||||
table_segment_max_chars: int = DEFAULT_TABLE_SEGMENT_MAX_CHARS,
|
||||
) -> str:
|
||||
"""
|
||||
将 Excel/CSV 表格线性化为“多完整行一个段”的 Markdown。
|
||||
@@ -136,13 +138,14 @@ def run(
|
||||
Args:
|
||||
input_data: loader 输出的单表或多表结构,包含 sheet、headers、rows。
|
||||
context: 当前清洗上下文,保留统一 skill 调用签名。
|
||||
segment_max_chars: 单个 Dify 段的最大字符数;不会切断超过上限的单条原始行。
|
||||
table_segment_max_chars: 仅表格使用的单个 Dify 段最大字符数;超过上限时在
|
||||
上一完整原始行结束,单条行本身超限时仍完整保留。
|
||||
|
||||
Returns:
|
||||
str: 供 clean/export 和 Dify custom segmentation 使用的 Markdown 文本。
|
||||
"""
|
||||
del context # 当前阶段不修改上下文,保留 skill 标准入参。
|
||||
max_chars = _normalize_segment_max_chars(segment_max_chars)
|
||||
max_chars = _normalize_table_segment_max_chars(table_segment_max_chars)
|
||||
tables = input_data if isinstance(input_data, list) else [input_data]
|
||||
segments: list[str] = []
|
||||
|
||||
|
||||
Reference in new issue
Block a user