@dazitech/cli 3.0.9 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +1 -1
  2. package/dist/clis/dazi-app.js +2 -2
  3. package/dist/clis/dazi-flow.js +2 -2
  4. package/dist/clis/dazi-onto.js +324 -41
  5. package/dist/clis/dazi.js +407 -185
  6. package/dist/docs/flow/flow-project-guide.md +1 -1
  7. package/dist/docs/guides/cli-reference.md +16 -3
  8. package/dist/docs/guides/troubleshooting.md +3 -3
  9. package/dist/docs/index.json +3 -15
  10. package/dist/docs/onto/dazi_script_sdk_reference.md +246 -244
  11. package/dist/docs/onto/dazi_script_seed_data_guide.md +1 -1
  12. package/dist/docs/onto/function-guide.md +123 -123
  13. package/dist/docs/onto//346/234/254/344/275/223/345/210/206/347/261/273/350/247/204/345/210/222/344/270/216SDK/346/211/251/345/261/225/346/226/271/346/241/210.md +169 -168
  14. package/dist/docs/onto//346/234/254/344/275/223/345/221/275/345/220/215/350/247/204/350/214/203_/347/211/251/347/220/206/350/241/250Cube/344/270/216/345/257/271/350/261/241.md +403 -402
  15. package/dist/docs/onto//346/234/254/344/275/223/345/274/200/345/217/221/344/274/230/345/214/226/346/200/273/347/273/223.md +257 -0
  16. package/dist/docs/onto//346/234/254/344/275/223/350/204/232/346/234/254/347/274/226/345/206/231/346/214/207/345/215/227.md +339 -311
  17. package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +305 -281
  18. package/dist/docs/onto//350/204/232/346/234/254/350/277/220/350/241/214/345/270/270/350/247/201/351/224/231/350/257/257/345/244/204/347/220/206.md +297 -0
  19. package/dist/examples/index.json +222 -6
  20. package/dist/examples/onto/README.md +34 -36
  21. package/dist/examples/onto/_templates/onto_preflight.ps1 +84 -0
  22. package/dist/examples/onto/index.json +53 -0
  23. package/dist/examples/onto/index.yaml +29 -0
  24. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/README.md +23 -0
  25. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/save_test_arguments.ps1 +12 -11
  26. package/dist/{docs/onto → examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/plans}//350/247/204/345/210/222/347/244/272/344/276/213_/345/210/251/346/266/246/345/210/206/346/236/220/346/234/254/344/275/223/346/226/271/346/241/210.md +37 -35
  27. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_category_mount.py +85 -0
  28. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +3 -66
  29. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/README.md +24 -0
  30. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_availability_analysis.py +84 -0
  31. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_downtime_breakdown.py +119 -0
  32. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_energy_intensity.py +98 -0
  33. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_get_summary.py +125 -0
  34. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_maintenance_compliance.py +77 -0
  35. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_mom_analysis.py +118 -0
  36. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_oee_analysis.py +126 -0
  37. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_plan_vs_actual.py +105 -0
  38. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_top_fault_equipment.py +104 -0
  39. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_unit_comparison.py +120 -0
  40. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/equip_ops_fn_yoy_analysis.py +115 -0
  41. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/save_test_arguments.ps1 +42 -0
  42. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.availability_analysis.json +7 -0
  43. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.downtime_breakdown.json +8 -0
  44. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.energy_intensity.json +8 -0
  45. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.get_summary.json +7 -0
  46. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.maintenance_compliance.json +7 -0
  47. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.mom_analysis.json +8 -0
  48. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.oee_analysis.json +8 -0
  49. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.plan_vs_actual.json +8 -0
  50. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.top_fault_equipment.json +8 -0
  51. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.unit_comparison.json +8 -0
  52. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/functions/test_arguments/equip_ops.fn.yoy_analysis.json +8 -0
  53. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/plans//345/214/226/345/267/245/350/256/276/345/244/207/350/277/220/350/220/245/345/210/206/346/236/220/346/234/254/344/275/223/346/226/271/346/241/210.md +735 -0
  54. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/setup/equip_ops_category_mount.py +106 -0
  55. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/setup/equip_ops_ontology_init.py +1077 -0
  56. package/dist/examples/onto//350/256/276/345/244/207/350/277/220/350/220/245/setup/equip_ops_seed_data.py +552 -0
  57. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/README.md +23 -0
  58. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +13 -12
  59. package/dist/{docs/onto → examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/plans}//350/247/204/345/210/222/347/244/272/344/276/213_/344/272/247/345/223/201/351/224/200/345/224/256/346/234/254/344/275/223/350/247/204/345/210/222/346/226/271/346/241/210.md +34 -34
  60. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_category_mount.py +82 -0
  61. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +3 -54
  62. package/dist/prompts/index.json +8 -1
  63. package/dist/prompts/onto/function-design.md +73 -73
  64. package/dist/prompts/onto/planning-design.md +226 -0
  65. package/dist/prompts/onto/script-publish-run.md +231 -208
  66. package/package.json +1 -1
  67. package/dist/docs/onto//350/204/232/346/234/254/350/277/220/350/241/214/347/272/240/351/224/231_/345/225/206/345/212/241/346/210/220/346/234/254/346/226/271/346/241/210/345/274/200/345/217/221/350/277/207/347/250/213.md +0 -213
@@ -1,123 +1,123 @@
1
- # 本体函数开发指南
2
-
3
- **文档 ID**: `onto/function-guide`
4
-
5
- > **执行脚本前必读**:[`脚本运行纠错_商务成本方案开发过程.md`](./脚本运行纠错_商务成本方案开发过程.md)(CLI、SQL、`output.print_json` 等常见误用)。
6
-
7
- ## 函数生命周期
8
-
9
- ```
10
- 编写 .py → publish-preview(可选)→ publish(--register-function-id 入库)
11
- → function run 验证 save-test-arguments(写入 test_arguments,侧栏预填)
12
- → 后续改代码:update-code
13
- ```
14
-
15
- 工作路径:`项目/<业务名>/本体/ontos/<实现名>/functions/`;本地 JSON:`functions/test_arguments/<function_id>.json`。
16
-
17
- ## 新建函数
18
-
19
- **推荐**:复制 `资源/examples/onto/_templates/ontology_function_template.py` 或 `销售示例/functions/sales_fn_*.py`,再改业务逻辑。
20
-
21
- ```bash
22
- # 发布新函数(路径指向本体实现单元 functions/ 目录)
23
- dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/functions/my_func.py \
24
- --space <space-id> \
25
- --register-function-id domain.fn.my_analysis
26
- ```
27
-
28
- `<space-id>` 取自 **`项目/<业务名>/本体/ontos/<实现名>/README.md`**。
29
-
30
- ## 更新已有函数代码
31
-
32
- ```bash
33
- dazi onto function update-code <function-id> \
34
- --space <space-id> \
35
- --stem my_func
36
- ```
37
-
38
- `--stem` 为脚本文件名(不含扩展名),须与 `functions/` 下文件一致。
39
-
40
- ## 运行函数
41
-
42
- ```bash
43
- dazi onto function run <function-id> \
44
- --space <space-id> \
45
- --params '{}'
46
- ```
47
-
48
- > **`function run` 不支持 `--arguments-json-file`**。详见 [脚本运行纠错](./脚本运行纠错_商务成本方案开发过程.md#4-cli-参数认知错误)。
49
-
50
- PowerShell 下复杂 JSON 建议用环境变量 `DAZI_PARAMS` 或侧栏运行(使用已保存的 `test_arguments`)。详见 [本体脚本编写指南](./本体脚本编写指南.md#函数测试参数test_arguments发布后必做)。
51
-
52
- ## 保存测试参数(test_arguments)
53
-
54
- 函数 **`run` 验证通过后**,须将默认入参写入函数定义,侧栏 **Onto → 运行函数** 才会预填。
55
-
56
- **本地文件**:`functions/test_arguments/<function_id>.json`(格式见 [本体脚本编写指南](./本体脚本编写指南.md))。
57
-
58
- ```bash
59
- dazi onto function save-test-arguments <ofn_internal_id> \
60
- --space <space-id> \
61
- --arguments-json-file 项目/<业务名>/本体/ontos/<实现名>/functions/test_arguments/<function_id>.json
62
- ```
63
-
64
- > **注意**:须用平台**内部 id** `ofn_xxx`(`dazi onto function list` 返回),不是 `function_id` 字符串。
65
-
66
- ## 函数脚本结构(标准模板)
67
-
68
- 本体函数与 setup/seed 脚本不同:**`main()` 无参**,平台注入 `ctx`、`space`、`onto`;**必须 return** `function_result`,**禁止** `output.print_json()`。
69
-
70
- ```python
71
- TEST_ARGUMENTS = {
72
- "v": 1,
73
- "arguments": {"start_date": "2025-01-01", "end_date": "2026-06-30"},
74
- "object_type_code": "SalesAnalysis",
75
- }
76
-
77
-
78
- def _ontology_fn_body(p):
79
- params = dict(p.get_params() or {})
80
- start_date = params.get("start_date", "")
81
- end_date = params.get("end_date", "")
82
-
83
- rows = p.sql.query(f"SELECT sum(amount) AS total FROM fact WHERE date >= '{start_date}'")
84
- row = rows[0] if rows else {}
85
- total = float(row.get("total", 0) or 0)
86
-
87
- return p.function_result(
88
- columns=["total"],
89
- data=[{"total": total}],
90
- row_count=1,
91
- )
92
-
93
-
94
- def main():
95
- s = space.get(ctx.space_id or "")
96
- _Ports = type(
97
- "_Ports",
98
- (),
99
- {
100
- "get_params": lambda self: dict(ctx.params or {}),
101
- "function_result": lambda self, **kw: onto.function_result(**kw),
102
- },
103
- )
104
- p = _Ports()
105
- p.sql = s.sql
106
- return _ontology_fn_body(p)
107
- ```
108
-
109
- | 要点 | 说明 |
110
- | ---- | ---- |
111
- | 入口 | **`def main():`**(无 `params` 形参) |
112
- | 入参 | `ctx.params` → `p.get_params()` |
113
- | 空间 / SQL | `s = space.get(ctx.space_id)` → `p.sql = s.sql` |
114
- | 出参 | **`return p.function_result(columns=..., data=..., row_count=...)`** |
115
- | 禁止 | `output.print_json`、`main(params: dict)`、裸 `return {"k": v}` |
116
-
117
- 可复制模板:`资源/examples/onto/_templates/ontology_function_template.py` · 参考实现:`销售示例/functions/sales_fn_get_summary.py`。
118
-
119
- ## 相关文档
120
-
121
- - [脚本运行纠错(商务成本方案实录)](./脚本运行纠错_商务成本方案开发过程.md)
122
- - [本体脚本编写指南](./本体脚本编写指南.md)
123
- - [DaziScript SDK 参考](./dazi_script_sdk_reference.md)
1
+ # 本体函数开发指南
2
+
3
+ **文档 ID**: `onto/function-guide`
4
+
5
+ > **执行脚本前必读**:[`脚本运行常见错误处理.md`](./脚本运行常见错误处理.md)(CLI、SQL、`output.print_json` 等常见误用)。
6
+
7
+ ## 函数生命周期
8
+
9
+ ```
10
+ 编写 .py → publish-preview(本地静态预检)→ publish(--register-function-id 入库)
11
+ → function run 验证(无参回退 TEST_ARGUMENTS)→ save-test-arguments(写入 test_arguments,侧栏预填)
12
+ → 后续改代码:update-code
13
+ ```
14
+
15
+ 工作路径:`项目/<业务名>/本体/ontos/<实现名>/functions/`;本地 JSON:`functions/test_arguments/<function_id>.json`。
16
+
17
+ ## 新建函数
18
+
19
+ **推荐**:复制 `资源/examples/onto/_templates/ontology_function_template.py` 或 `销售示例/functions/sales_fn_*.py`,再改业务逻辑。
20
+
21
+ ```bash
22
+ # 发布新函数(路径指向本体实现单元 functions/ 目录)
23
+ dazi onto script publish 项目/<业务名>/本体/ontos/<实现名>/functions/my_func.py \
24
+ --space <space-id> \
25
+ --register-function-id domain.fn.my_analysis
26
+ ```
27
+
28
+ `<space-id>` 取自 **`项目/<业务名>/本体/ontos/<实现名>/README.md`**。
29
+
30
+ ## 更新已有函数代码
31
+
32
+ ```bash
33
+ dazi onto function update-code <function-id> \
34
+ --space <space-id> \
35
+ --stem my_func
36
+ ```
37
+
38
+ `--stem` 为脚本文件名(不含扩展名),须与 `functions/` 下文件一致。
39
+
40
+ ## 运行函数
41
+
42
+ ```bash
43
+ dazi onto function run <function-id> \
44
+ --space <space-id> \
45
+ --params '{}'
46
+ ```
47
+
48
+ > **`function run` 不支持 `--arguments-json-file`**。详见 [脚本运行常见错误处理](./脚本运行常见错误处理.md#4-cli-参数误用)。
49
+
50
+ PowerShell 下复杂 JSON 建议用环境变量 `DAZI_PARAMS` 或侧栏运行(使用已保存的 `test_arguments`)。详见 [本体脚本编写指南](./本体脚本编写指南.md#函数测试参数test_arguments发布后必做)。
51
+
52
+ ## 保存测试参数(test_arguments)
53
+
54
+ 函数 **`run` 验证通过后**,须将默认入参写入函数定义,侧栏 **Onto → 运行函数** 才会预填。
55
+
56
+ **本地文件**:`functions/test_arguments/<function_id>.json`(格式见 [本体脚本编写指南](./本体脚本编写指南.md))。
57
+
58
+ ```bash
59
+ dazi onto function save-test-arguments --function-id domain.fn.my_analysis \
60
+ --space <space-id> \
61
+ --arguments-json-file 项目/<业务名>/本体/ontos/<实现名>/functions/test_arguments/<function_id>.json
62
+ ```
63
+
64
+ > **注意**:亦可用平台**内部 id** `ofn_xxx`(`dazi onto function list --json` 返回);推荐 `--function-id` 别名。
65
+
66
+ ## 函数脚本结构(标准模板)
67
+
68
+ 本体函数与 setup/seed 脚本不同:**`main()` 无参**,平台注入 `ctx`、`space`、`onto`;**必须 return** `function_result`,**禁止** `output.print_json()`。
69
+
70
+ ```python
71
+ TEST_ARGUMENTS = {
72
+ "v": 1,
73
+ "arguments": {"start_date": "2025-01-01", "end_date": "2026-06-30"},
74
+ "object_type_code": "SalesAnalysis",
75
+ }
76
+
77
+
78
+ def _ontology_fn_body(p):
79
+ params = dict(p.get_params() or {})
80
+ start_date = params.get("start_date", "")
81
+ end_date = params.get("end_date", "")
82
+
83
+ rows = p.sql.query(f"SELECT sum(amount) AS total FROM fact WHERE date >= '{start_date}'")
84
+ row = rows[0] if rows else {}
85
+ total = float(row.get("total", 0) or 0)
86
+
87
+ return p.function_result(
88
+ columns=["total"],
89
+ data=[{"total": total}],
90
+ row_count=1,
91
+ )
92
+
93
+
94
+ def main():
95
+ s = space.get(ctx.space_id or "")
96
+ _Ports = type(
97
+ "_Ports",
98
+ (),
99
+ {
100
+ "get_params": lambda self: dict(ctx.params or {}),
101
+ "function_result": lambda self, **kw: onto.function_result(**kw),
102
+ },
103
+ )
104
+ p = _Ports()
105
+ p.sql = s.sql
106
+ return _ontology_fn_body(p)
107
+ ```
108
+
109
+ | 要点 | 说明 |
110
+ | ---- | ---- |
111
+ | 入口 | **`def main():`**(无 `params` 形参) |
112
+ | 入参 | `ctx.params` → `p.get_params()` |
113
+ | 空间 / SQL | `s = space.get(ctx.space_id)` → `p.sql = s.sql` |
114
+ | 出参 | **`return p.function_result(columns=..., data=..., row_count=...)`** |
115
+ | 禁止 | `output.print_json`、`main(params: dict)`、裸 `return {"k": v}` |
116
+
117
+ 可复制模板:`资源/examples/onto/_templates/ontology_function_template.py` · 参考实现:`销售示例/functions/sales_fn_get_summary.py`。
118
+
119
+ ## 相关文档
120
+
121
+ - [脚本运行常见错误处理](./脚本运行常见错误处理.md)
122
+ - [本体脚本编写指南](./本体脚本编写指南.md)
123
+ - [DaziScript SDK 参考](./dazi_script_sdk_reference.md)
@@ -1,168 +1,169 @@
1
- # 349 · 本体分类规划与 SDK 扩展方案
2
-
3
- **文档 ID**:`onto/category-taxonomy-sdk`
4
-
5
- > **文档编号**:349
6
- > **类型**:规范 + 实施方案(对齐 §347 · `ads_categories` 平台分类)
7
- > **同步路径**:`dazi docs sync` → `资源/docs/onto/本体分类规划与SDK扩展方案.md`
8
- > **前置依据**:[本体命名规范 §347](./本体命名规范_物理表Cube与对象.md)、[本体规划指南](./本体规划指南.md)
9
-
10
- ---
11
-
12
- ## 1. 目标
13
-
14
- 将 **347 语义分类**(规划表「类别/分类」列)与 **`ads_categories` 平台分类**(侧栏分组、桥表挂载)打通,支持 init 脚本幂等注册。
15
-
16
- **约束**:本体规划阶段分类 **全部平级**(挂空间默认根下,不建多层树)。
17
-
18
- ---
19
-
20
- ## 2. 两类分类,一套语言
21
-
22
- | 维度 | 347 语义分类 | ads_categories 平台分类 |
23
- |------|-------------|------------------------|
24
- | 作用 | 规划自检、命名约束 | 侧栏展示、资源分组 |
25
- | 对齐 | 平台 `category_name` **=** 347 标准中文名 | 禁止自定义别名 |
26
-
27
- ---
28
-
29
- ## 3. 347 标准分类字典(6 类资源)
30
-
31
- ### 3.1 物理表(`category_kind=dataspace_table`)
32
-
33
- | 347 类别 | 前缀 | 平台分类名 |
34
- |----------|------|------------|
35
- | 时间维 | `dim_date` | 时间维 |
36
- | 维度表 | `dim_` | 维度表 |
37
- | 事实表 | `fact_` | 事实表 |
38
- | 桥表 | `bridge_` | 桥表 |
39
- | 映射表 | `map_` | 映射表 |
40
- | 配置表 | `cfg_` | 配置表 |
41
- | 汇总表 | `agg_` | 汇总表 |
42
- | 临时表 | `tmp_` | 临时表 |
43
-
44
- ### 3.2 Cube(`category_kind=cube`)
45
-
46
- | 347 类别 | 平台分类名 |
47
- |----------|------------|
48
- | Process | 流程型 |
49
- | Subject | 主体型 |
50
- | Comparison | 对比型 |
51
- | Snapshot | 快照型 |
52
-
53
- > 时间增强不单独建 Cube(347 §4.2),不设平台分类。
54
-
55
- ### 3.3 本体对象(`category_kind=ontology_object_type`)
56
-
57
- | 347 分类 | 平台分类名 |
58
- |----------|------------|
59
- | Master | 主数据 |
60
- | Transaction | 事务 |
61
- | Analytical | 分析 |
62
- | Reference | 参考 |
63
- | Configuration | 配置 |
64
-
65
- ### 3.4 表间关系(`category_kind=relation`,347 扩展)
66
-
67
- | 关系类别 | 平台分类名 |
68
- |----------|------------|
69
- | 时间关联 | 时间关联 |
70
- | 主数据关联 | 主数据关联 |
71
- | 层级自关联 | 层级自关联 |
72
- | 预实关联 | 预实关联 |
73
- | 桥接关联 | 桥接关联 |
74
-
75
- ### 3.5 本体链接(`category_kind=ontology_link_type`,347 扩展)
76
-
77
- | 链接类别 | 平台分类名 |
78
- |----------|------------|
79
- | 归属/包含 | 归属关系 |
80
- | 分析归因 | 分析归因 |
81
- | 层级/结构 | 层级关系 |
82
- | 对比/映射 | 对比关系 |
83
-
84
- ### 3.6 本体函数(`category_kind=ontology_function`,347 扩展)
85
-
86
- | 函数类别 | 平台分类名 |
87
- |----------|------------|
88
- | 总览 | 总览分析 |
89
- | 趋势 | 趋势分析 |
90
- | 结构 | 结构分析 |
91
- | 预实 | 预实分析 |
92
- | 组织 | 组织分析 |
93
-
94
- ---
95
-
96
- ## 4. SDK 设计
97
-
98
- ### 4.1 模块
99
-
100
- ```python
101
- s.categories # CategoryManager
102
- s.categories.apply_registry(CATEGORY_REGISTRY)
103
- s.categories.ensure_347(kind="table", category="维度表")
104
- s.categories.assign_table("维度表", "dim_account")
105
- s.categories.auto_assign_tables(["dim_account", "fact_gl_journal_entry"])
106
- ```
107
-
108
- ### 4.2 init 脚本
109
-
110
- **方式 A — 批量**(推荐):顶部 `CATEGORY_REGISTRY` 与规划 **附录 B** 对齐;资源注册完成后:
111
-
112
- ```python
113
- cat_counts = s.categories.apply_registry(CATEGORY_REGISTRY, skip_missing=True)
114
- ```
115
-
116
- **方式 B — 内联**(P2):各注册 API 支持 `category_347=`,注册后即时挂载(与方式 A 幂等可并存):
117
-
118
- ```python
119
- s.tables.register_with_meta("dim_product", ..., category_347="维度表")
120
- s.register_cube("SalesCube", ..., category_347="流程型")
121
- s.onto.define_object_type("Product", "产品", category_347="主数据")
122
- s.tables.add_relationship(..., category_347="时间关联")
123
- s.onto.define_link_type(..., category_347="归属关系")
124
- s.onto.register_function("sales.fn.get_summary", adapter, category_347="总览分析")
125
- ```
126
-
127
- 函数类资源若 init 未 `register_function`,批量方式须 `skip_missing=True`。
128
-
129
- ---
130
-
131
- ## 5. 规划与 init 约定
132
-
133
- | 产出 | 位置 | 说明 |
134
- | ---- | ---- | ---- |
135
- | 规划附录 B | `plans/<主题>.md` | 6 类资源分类对照表 |
136
- | `CATEGORY_REGISTRY` | `setup/*_ontology_init.py` 顶部 | 与附录 B 逐行一致 |
137
- | 分类步骤 | init 末尾 | `[10/10] apply_registry` |
138
-
139
- 参考:[规划示例_产品销售](./规划示例_产品销售本体规划方案.md#附录-b347-分类挂载对照表category_registry)、[规划示例_利润分析](./规划示例_利润分析本体方案.md#附录-b347-分类挂载对照表category_registry)。
140
-
141
- ---
142
-
143
- ## 6. 验收标准
144
-
145
- 1. 平台侧栏分类名与 347 标准表一致
146
- 2. `dim_*` / `fact_*` 自动归入维度表/事实表
147
- 3. init 重跑幂等,桥表不重复
148
- 4. `CATEGORY_REGISTRY` 与规划附录 B 逐行一致
149
-
150
- ---
151
-
152
- ## 7. 相关文档
153
-
154
- | 文档 | 路径(`dazi docs sync` 后) |
155
- | ---- | --------------------------- |
156
- | 347 命名规范 | `资源/docs/onto/本体命名规范_物理表Cube与对象.md` |
157
- | 本体规划指南 | `资源/docs/onto/本体规划指南.md` |
158
- | SDK 参考 §5.6 | `资源/docs/onto/dazi_script_sdk_reference.md` |
159
- | 脚本编写指南 | `资源/docs/onto/本体脚本编写指南.md` |
160
-
161
- ---
162
-
163
- **变更记录**
164
-
165
- | 日期 | 说明 |
166
- | ---- | ---- |
167
- | 2026-06-06 | 首版:对齐 347 分类方案 + SDK 设计 |
168
- | 2026-06-06 | 改为 `dazi-vscode` 完整可同步正文(客户环境不依赖 `dazi/docs/`) |
1
+ # 本体分类规划与 SDK 扩展方案
2
+
3
+ **文档 ID**:`onto/category-taxonomy-sdk`
4
+
5
+ > **类型**:规范 + 实施方案(对齐 `ads_categories` 平台分类)
6
+ > **同步路径**:`dazi docs sync` `资源/docs/onto/本体分类规划与SDK扩展方案.md`
7
+ > **前置依据**:[本体命名规范](./本体命名规范_物理表Cube与对象.md)、[本体规划指南](./本体规划指南.md)
8
+
9
+ ---
10
+
11
+ ## 1. 目标
12
+
13
+ 将 **规划语义分类**(规划表「类别/分类」列)与 **`ads_categories` 平台分类**(侧栏分组、桥表挂载)打通,支持 init 脚本幂等注册。
14
+
15
+ > **术语**:下文 **平台标准分类** = 侧栏 `ads_categories` 使用的标准中文名(如「维度表」「总览分析」)。SDK 中的 `category_347`、`ensure_347` 为历史参数/方法名,**含义即平台标准分类**,与文档编号无关。
16
+
17
+ **约束**:本体规划阶段分类 **全部平级**(挂空间默认根下,不建多层树)。
18
+
19
+ ---
20
+
21
+ ## 2. 两类分类,一套语言
22
+
23
+ | 维度 | 规划语义分类 | ads_categories 平台分类 |
24
+ |------|-------------|------------------------|
25
+ | 作用 | 规划自检、命名约束 | 侧栏展示、资源分组 |
26
+ | 对齐 | 平台 `category_name` **=** 平台标准分类中文名 | 禁止自定义别名 |
27
+
28
+ ---
29
+
30
+ ## 3. 平台标准分类字典(6 类资源)
31
+
32
+ ### 3.1 物理表(`category_kind=dataspace_table`)
33
+
34
+ | 平台分类类别 | 前缀 | 平台分类名 |
35
+ |----------|------|------------|
36
+ | 时间维 | `dim_date` | 时间维 |
37
+ | 维度表 | `dim_` | 维度表 |
38
+ | 事实表 | `fact_` | 事实表 |
39
+ | 桥表 | `bridge_` | 桥表 |
40
+ | 映射表 | `map_` | 映射表 |
41
+ | 配置表 | `cfg_` | 配置表 |
42
+ | 汇总表 | `agg_` | 汇总表 |
43
+ | 临时表 | `tmp_` | 临时表 |
44
+
45
+ ### 3.2 Cube(`category_kind=cube`)
46
+
47
+ | 平台分类类别 | 平台分类名 |
48
+ |----------|------------|
49
+ | Process | 流程型 |
50
+ | Subject | 主体型 |
51
+ | Comparison | 对比型 |
52
+ | Snapshot | 快照型 |
53
+
54
+ > 时间增强不单独建 Cube(命名规范 §4.2),不设平台分类。
55
+
56
+ ### 3.3 本体对象(`category_kind=ontology_object_type`)
57
+
58
+ | 平台分类 | 平台分类名 |
59
+ |----------|------------|
60
+ | Master | 主数据 |
61
+ | Transaction | 事务 |
62
+ | Analytical | 分析 |
63
+ | Reference | 参考 |
64
+ | Configuration | 配置 |
65
+
66
+ ### 3.4 表间关系(`category_kind=relation`,平台扩展)
67
+
68
+ | 关系类别 | 平台分类名 |
69
+ |----------|------------|
70
+ | 时间关联 | 时间关联 |
71
+ | 主数据关联 | 主数据关联 |
72
+ | 层级自关联 | 层级自关联 |
73
+ | 预实关联 | 预实关联 |
74
+ | 桥接关联 | 桥接关联 |
75
+
76
+ ### 3.5 本体链接(`category_kind=ontology_link_type`,平台扩展)
77
+
78
+ | 链接类别 | 平台分类名 |
79
+ |----------|------------|
80
+ | 归属/包含 | 归属关系 |
81
+ | 分析归因 | 分析归因 |
82
+ | 层级/结构 | 层级关系 |
83
+ | 对比/映射 | 对比关系 |
84
+
85
+ ### 3.6 本体函数(`category_kind=ontology_function`,平台扩展)
86
+
87
+ | 函数类别 | 平台分类名 |
88
+ |----------|------------|
89
+ | 总览 | 总览分析 |
90
+ | 趋势 | 趋势分析 |
91
+ | 结构 | 结构分析 |
92
+ | 预实 | 预实分析 |
93
+ | 组织 | 组织分析 |
94
+
95
+ ---
96
+
97
+ ## 4. SDK 设计
98
+
99
+ ### 4.1 模块
100
+
101
+ ```python
102
+ s.categories # CategoryManager
103
+ s.categories.apply_registry(CATEGORY_REGISTRY)
104
+ s.categories.ensure_347(kind="table", category="维度表")
105
+ s.categories.assign_table("维度表", "dim_account")
106
+ s.categories.auto_assign_tables(["dim_account", "fact_gl_journal_entry"])
107
+ ```
108
+
109
+ ### 4.2 分类挂载脚本 `*_category_mount.py`
110
+
111
+ **方式 A — 批量**(推荐,类灌数):独立 `setup/*_category_mount.py` 顶部 `CATEGORY_REGISTRY` 与规划 **附录 B** 对齐;在 **init + seed + 全部函数 publish 之后** 执行:
112
+
113
+ ```python
114
+ cat_counts = s.categories.apply_registry(CATEGORY_REGISTRY, skip_missing=True)
115
+ ```
116
+
117
+ **方式 B — 内联**(P2):各注册 API 支持 `category_347=`,注册后即时挂载(与方式 A 幂等可并存):
118
+
119
+ ```python
120
+ s.tables.register_with_meta("dim_product", ..., category_347="维度表")
121
+ s.register_cube("SalesCube", ..., category_347="流程型")
122
+ s.onto.define_object_type("Product", "产品", category_347="主数据")
123
+ s.tables.add_relationship(..., category_347="时间关联")
124
+ s.onto.define_link_type(..., category_347="归属关系")
125
+ s.onto.register_function("sales.fn.get_summary", adapter, category_347="总览分析")
126
+ ```
127
+
128
+ 函数类资源若 init 未 `register_function`,批量方式须 `skip_missing=True`。
129
+
130
+ ---
131
+
132
+ ## 5. 规划与 init 约定
133
+
134
+ | 产出 | 位置 | 说明 |
135
+ | ---- | ---- | ---- |
136
+ | 规划附录 B | `plans/<主题>.md` | 6 类资源分类对照表 |
137
+ | `CATEGORY_REGISTRY` | `setup/*_category_mount.py` 顶部 | 与附录 B 逐行一致 |
138
+ | 分类步骤 | 流程最后 | publish + run `*_category_mount.py` |
139
+
140
+ 参考:`资源/examples/onto/销售示例/plans/`、`利润示例/plans/`、`设备运营/plans/` 各附录 B 与 `setup/*_category_mount.py`。
141
+
142
+ ---
143
+
144
+ ## 6. 验收标准
145
+
146
+ 1. 平台侧栏分类名与平台标准分类表一致
147
+ 2. `dim_*` / `fact_*` 自动归入维度表/事实表
148
+ 3. init 重跑幂等,桥表不重复
149
+ 4. `CATEGORY_REGISTRY` 与规划附录 B 逐行一致
150
+
151
+ ---
152
+
153
+ ## 7. 相关文档
154
+
155
+ | 文档 | 路径(`dazi docs sync` 后) |
156
+ | ---- | --------------------------- |
157
+ | 本体命名规范 | `资源/docs/onto/本体命名规范_物理表Cube与对象.md` |
158
+ | 本体规划指南 | `资源/docs/onto/本体规划指南.md` |
159
+ | SDK 参考 §5.6 | `资源/docs/onto/dazi_script_sdk_reference.md` |
160
+ | 脚本编写指南 | `资源/docs/onto/本体脚本编写指南.md` |
161
+
162
+ ---
163
+
164
+ **变更记录**
165
+
166
+ | 日期 | 说明 |
167
+ | ---- | ---- |
168
+ | 2026-06-06 | 首版:对齐 平台分类方案 + SDK 设计 |
169
+ | 2026-06-06 | 改为 `dazi-vscode` 完整可同步正文(客户环境不依赖 `dazi/docs/`) |