# Stage 一览表(当前实现 / 以 `src/stage_registry.py` 为准) 本项目采用 **“多入口 + 原子化小工具 + 可组合流水线”** 的 Unix 哲学: - **父进程主程序**(`src/main.py`)负责:用户态创建/管理/终止子进程、运行时选择通信方式(pipe/direct/indirect)、展示 `/proc` 进程信息、交互控制(stop/cont/term/kill)。 - **子进程 Stage**(`src/stage_*.py`)负责:**单一职责**的数据流变换/过滤/聚合/导出;默认 `stdin -> stdout`(日志写 `stderr`)。 - **业务目标**(当前默认预设):对 **英文单词**做词频统计(中文视为噪声不分词),并支持黑/白名单、长度过滤、延时 Stage(便于演示 stop/cont/term/kill)与文本报告输出。 ## 数据流类型约束(主程序会校验) - `lines`:文本行流(每行一条记录) - `tokens`:词元流(每行一个 token;默认预设为英文单词) - `counts`:计数流(TSV:`tokencount`) - `report`:报告输出(文本/文件路径提示等) ## Stage 一览表 > 说明:本表与代码保持同步;若文档与实现不一致,以 `src/stage_registry.py` 为准。 | ID(配置/主程序使用) | 实现(入口文件) | Stream API 对应 | 输入 | 输出 | 参数(常用) | 作用(原子职责) | |---|---|---|---|---|---|---| | `source.file` | `src/stage_source_file.py` | source(文件输入) | - | `lines` | `--path`(父进程从 `input.path` 注入) | 读取输入文件,输出行流 | | `tokenize.en_words` | `src/stage_tokenize_en_words.py` | flatMap | `lines` | `tokens` | - | 提取英文单词并小写化,输出 token 流 | | `token.len_range` | `src/stage_token_len_range.py` | filter | `tokens` | `tokens` | `--min-len` `--max-len`(推荐用 `stage_args` 配置) | 按 token 长度范围过滤(包含边界) | | `token.keep_list` | `src/stage_token_keep_list.py` | filter(集合包含) | `tokens` | `tokens` | `--file` | 按白名单保留 token(词表文件每行一个词) | | `token.drop_list` | `src/stage_token_drop_list.py` | filter(集合不包含) | `tokens` | `tokens` | `--file` | 按黑名单丢弃 token(词表文件每行一个词) | | `count.tokens` | `src/stage_count_tokens.py` | reduce/grouping | `tokens` | `counts` | - | 统计词频,输出 TSV:`tokencount` | | `report.text` | `src/stage_report_text.py` | terminal/sink | `counts` | `report` | `--title` `--topn` `--output`(父进程会注入 `--output`;未写 `--topn` 时用 `run.default_topn` 注入) | 生成文本报告(stdout 展示 + 落盘) | | `debug.delay` | `src/stage_debug_delay.py` | peek(side-effect) | `*` | `*` | `--seconds` | 透传并延时,便于演示 stop/cont/term/kill | ## 参数在配置文件中的写法(答辩推荐口径) - 流水线顺序:`pipeline.toml` 的 `[pipeline].stages`(线性数组,顺序即执行顺序)。 - Stage 参数: - 兼容写法:直接写在 `pipeline.stages` 的字符串里,例如 `"debug.delay --seconds 0.1"`。 - 推荐写法:使用结构化 `stage_args`(目前用于 `token.len_range`),例如: - `[stage_args.token.len_range]` - `min_len = 3` - `max_len = 12`