feat(tsl-syntax-reference): harden retrieval and restructure pages

- flag weak candidates (no intent/heading/identifier/tag hit) and exit 2
  when every candidate is weak: mis-hits used to be indistinguishable
  from real hits, so the retry-with-better-terms loop never fired
- accept multiple ids per --section for batch fetch, failing atomically
  on any unknown id so a partial fetch cannot pass as complete
- move query synonyms and page intent aliases to data/lexicon.json and
  enforce alias/page correspondence in --check; curation data no longer
  lives in the engine
- document the weak-hit rule, batch fetch and prelude-once guidance in
  SKILL.md, with curation discipline in data/README.md
- drop 11_pitfalls.md, renumber the trailing pages and spread retrieval
  tags across topics; lexicon keys are page filenames, so the renumbering
  and the new --check rule cannot land in separate commits
This commit is contained in:
csh
2026-07-29 15:45:47 +08:00
parent 37a3bf4b0c
commit 40a9885eb4
28 changed files with 1048 additions and 773 deletions
@@ -0,0 +1,33 @@
# 检索词表(lexicon.json
`lexicon.json``scripts/lookup.py` 的策展检索数据,与引擎逻辑分离维护。
两张表都只影响检索,不是事实正文。
## query_synonyms —— 口语同义词
中文口语词 → TSL 术语的展开(如「打印」→ 输出 / writeLn)。策展纪律:
- 同义词必须落在**目标章节已有的词面**上,否则不产生区分度。用户说的词在
参考页正文里出现 0 次时,页级 alias 只能把整页抬起来,页内仍需要词法
信号才能选中正确章节——节级词汇桥(如「交集」→ `intersect`)补的就是
这一层。
- 不要展开成泛化的中文概念词(如「集合运算」会命中别页交叉引用小节标题)。
## page_intent_aliases —— 页级意图短语
整句口语短语 → 参考页文件名的路由(命中一条 +80 分,是页级路由的唯一强
信号)。约束:
- 键必须与 `references/` 下的文件名完全一致;每个参考页至少一条短语。
键写错或参考页改名后 `_intent_score` 会静默返回 0 分,该页失去自然语言
入口——`lookup.py --check` 和回归测试会拦住这两种漂移。
## 改动后的校验
```bash
python scripts/lookup.py --check
python -m unittest test.test_tsl_syntax_lookup_recall # 在仓库根目录运行
```
新增参考页时,除补词表外还须在回归测试里补一条真实问法
`test/test_tsl_syntax_lookup_recall.py``RECALL_CASES`)。
@@ -0,0 +1,77 @@
{
"query_synonyms": {
"打印": ["输出", "writeLn"],
"打出来": ["输出", "writeLn"],
"左连接": ["左联接", "left join", "TS-SQL"],
"左外连接": ["左联接", "left join", "TS-SQL"],
"left outer join": ["left join", "左联接", "TS-SQL"],
"列表": ["数组"],
"复用文件": ["tsf", "unit"],
"多个文件": ["unit", "uses", "作用域"],
"跳出去": ["break", "控制流"],
"程序慢": ["性能分析", "计时", "profiler"],
"瓶颈": ["性能分析", "profiler"],
"debug": ["调试", "性能分析"],
"program": ["脚本"],
"tinysoft": ["天软", "TSL"],
"字符串转整数": ["类型转换", "strToInt"],
"高性能矩阵": ["FMArray"],
"交集": ["intersect"],
"并集": ["union2"],
"差集": ["minus"],
"对称差": ["outersect"],
"中括号": ["operator", "下标"],
"方括号": ["operator", "下标"],
"按引用传": ["varByRef", "var"],
"引用传递": ["varByRef", "var"],
"计时": ["mtic", "mtoc"]
},
"page_intent_aliases": {
"01_quickstart.md": ["最简单能跑", "最简单的脚本", "天软脚本", "tinysoft"],
"02_core_model.md": ["脚本和可复用", "可复用函数文件", "声明函数后面写代码"],
"03_values_and_literals.md": ["字符串和数组下标", "下标从几开始", "下标起点"],
"04_variables_and_constants.md": ["常量怎么声明", "变量能不能直接赋值"],
"05_functions_and_calls.md": ["默认参数", "函数怎么带"],
"06_expressions_and_operators.md": ["赋值和相等比较"],
"07_control_flow.md": [
"跳出去",
"循环里满足条件",
"跳过这一次",
"跳过本次",
"捕获异常",
"抛异常"
],
"08_objects_and_classes.md": ["定义类", "创建对象"],
"09_units_and_scope.md": ["多个文件", "复用一组函数"],
"10_runtime_context_and_with.md": ["临时切换系统参数"],
"11_matrix_and_collections.md": ["某行存在", "二维数组怎么判断"],
"12_resultset_and_filters.md": ["保留匹配行", "按某一列"],
"13_ts_sql.md": ["左连接", "左外连接", "左联接", "数据库", "分组排序", "聚合排序"],
"14_debug_and_profiler.md": [
"程序慢",
"计时找瓶颈",
"性能瓶颈",
"性能问题",
"执行了多久",
"执行时间",
"耗时",
"debug"
],
"15_lexical_structure_and_compile_options.md": ["变量名区分大小写", "注释怎么写"],
"16_types_and_conversions.md": ["字符串转整数", "类型转换"],
"17_external_calls_and_threads.md": ["调用 dll", "dll", "动态库", "开线程"],
"18_namespace_libpath_and_unit_runtime.md": ["找不到 tsf", "搜索路径"],
"19_object_runtime_and_introspection.md": ["查看对象属于哪个类", "运行时对象"],
"20_builtin_runtime_objects.md": ["内存流"],
"21_matrix_deep_dive.md": ["矩阵求逆", "矩阵转置", "求逆和转置"],
"22_fmarray.md": ["高性能矩阵", "fmarray"],
"23_object_overloads_and_iteration.md": [
"自定义对象支持下标",
"中括号",
"方括号",
"运算符重载",
"算符重载",
"for in"
]
}
}