Advanced document partitioning and processing toolset
Project description
Triclick Doc Toolset
一个基于管道架构的文档处理工具集
项目架构理念
核心设计原则
本项目采用管道-策略-命令三层架构模式,实现了高度可配置、可扩展的文档处理框架:
1. 管道架构 (Pipeline Architecture)
- 声明式配置:通过YAML配置文件定义处理流程,实现业务逻辑与代码分离
- 流式处理:数据在管道中流转,每个阶段都对上下文进行增量处理
- 可组合性:不同的管道配置可以组合出不同的处理流程
2. 策略模式 (Strategy Pattern)
- 执行策略:支持顺序执行(sequential)和并行执行(parallel)两种模式
- 优先级控制:通过数值优先级控制策略和命令的执行顺序
- 条件执行:支持基于上下文条件的动态命令执行
3. 命令模式 (Command Pattern)
- 统一接口:所有处理逻辑封装为Command,提供统一的执行接口
- 自动注册:通过CommandRegistry实现命令的自动发现和注册
- 条件判断:每个命令都有is_satisfied和check_condition机制
架构层次
Pipeline (管道层)
├── Strategy (策略层)
│ ├── ExecMode: sequential/parallel
│ ├── Priority: 数值优先级
│ └── Commands: 命令列表
└── Command (命令层)
├── is_satisfied(): 前置条件检查
├── check_condition(): 运行时条件检查
└── execute(): 核心执行逻辑
数据流转
项目采用Context上下文对象作为数据载体,在管道中流转:
Context {
doc_type: 文档类型识别结果
document_uri: 输入文档路径
sections: 解析出的文档段落结构
metadata: 元数据字典
errors: 错误信息收集
generated_files: 生成的文件列表
}
配置驱动
管道配置示例
pipeline:
strategies:
- name: detect_file_type
exec_mode: sequential
priority: 1
commands:
- type: FileTypeIdentificationCommand
name: detect_file_type
priority: 1
- name: parse_by_type
exec_mode: sequential
priority: 2
commands:
- type: DocxFileParseCommand
condition: "doc_type == 'docx'"
priority: 1
扩展性设计
1. 命令扩展
- 继承
Command基类 - 实现
is_satisfied()和execute()方法 - 通过
CommandRegistry.register()注册
2. 策略扩展
- 新增执行模式枚举值
- 在
Strategy.apply()中实现对应逻辑
3. 管道扩展
- 创建新的YAML配置文件
- 定义策略组合和执行顺序
领域特化
项目针对文档处理领域进行了特化设计:
文档解析层
- 多格式支持:DOCX、RTF等格式的统一处理接口
- 结构化解析:标题、表格、脚注的结构化提取
- 元数据保留:段落索引、样式信息的完整保留
业务规则层
- 模式匹配:基于正则表达式的标题和脚注模式识别
- 引用解析:"Same as Table X.Y"等业务规则的自动处理
- 文件命名:基于内容标签的智能文件命名
输出管理层
- 路径去重:自动处理文件名冲突
- 样式保留:完整保留原文档的格式和样式
- 批量处理:支持单文件和文件夹的批量处理
工程实践
缓存机制
- 管道缓存:基于配置文件修改时间的智能缓存
- 线程安全:使用锁机制保证并发安全
错误处理
- 优雅降级:单个命令失败不影响整体流程
- 错误收集:统一的错误信息收集和报告机制
资源管理
- 路径解析:支持打包后的资源文件访问
- 内存优化:流式处理避免大文件内存占用
使用方式
基础用法
from triclick_doc_toolset import run_generation, run_review
# 运行生成流水线
result = run_generation("input.docx", "output/")
# 运行评审流水线
result = run_review("input.docx", "output/")
自定义管道
from triclick_doc_toolset import run_pipeline
result = run_pipeline("custom_pipeline.yaml", "input.docx", "output/")
项目结构
triclick-doc-toolset/
├── pipelines/ # 管道配置文件
│ ├── generation.yaml # 生成流水线
│ ├── review.yaml # 评审流水线
│ └── title_table_footnote_patterns.yaml # 模式配置
├── src/triclick_doc_toolset/
│ ├── framework/ # 核心框架
│ │ ├── pipeline.py # 管道实现
│ │ ├── strategy.py # 策略实现
│ │ ├── command.py # 命令基类
│ │ ├── context.py # 上下文对象
│ │ └── command_registry.py # 命令注册表
│ ├── commands/ # 具体命令实现
│ ├── common/ # 通用组件
│ │ ├── models/ # 数据模型
│ │ ├── utils/ # 工具函数
│ │ ├── rules/ # 业务规则
│ │ └── word/ # Word文档处理
│ └── service.py # 服务入口
└── tests/ # 测试用例
这种架构设计使得项目具备了良好的可维护性、可扩展性和可测试性,能够灵活应对不同的文档处理需求。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file triclick_doc_toolset-1.2.1.tar.gz.
File metadata
- Download URL: triclick_doc_toolset-1.2.1.tar.gz
- Upload date:
- Size: 66.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f22f273a9386c973f4ecf20acc553d388d634ac2cf4b142b3023a9f38312c74
|
|
| MD5 |
0f4a3a8e17cce53aaa4bb8278f89c34f
|
|
| BLAKE2b-256 |
c958ea353f496807ceb5952ae211a8b07098bf75b6c425d271d4cd1f19b1e073
|
File details
Details for the file triclick_doc_toolset-1.2.1-py3-none-any.whl.
File metadata
- Download URL: triclick_doc_toolset-1.2.1-py3-none-any.whl
- Upload date:
- Size: 42.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c044d0d4009f86ad7784997f960016a4f5e8aee6db31761a11e5e0e9916aa8cb
|
|
| MD5 |
858304fa37eb23947f140bfa6e2ac7d0
|
|
| BLAKE2b-256 |
863d64c3cbc2f17495e27c9b0d85e90b2c357913e61bcddf925786c85d9ead12
|