TBox
TBox(Schema)· 术语层
Section titled “TBox(Schema)· 术语层”定位:TBox(Terminological Box)= 本体的术语组件——用一套类与属性,把领域的词汇与结构定义出来:有哪些类、属性、关系、约束规则。它是 DSL 的词典,也是口径护栏的承载处。
📎 来源:实践分享第三章 + 好 Skill 与 CLI/CI 设计指南。上级:设计指南/本体设计;姊妹:设计指南/本体设计/ABox。
一、TBox 定义什么
Section titled “一、TBox 定义什么”| 成分 | 说明 | 成本领域例 |
|---|---|---|
| 类 Class | 领域里的概念实体 | 项目成本指标 成本合同 |
| 维度属性 dimension | 可筛选/分组的字段 | 成本科目 / 是否末级 / 业态 |
| 度量属性 measure | 可聚合的数值 | 建安造价费 / 建面单方 |
| 关系 relation | 类之间的链接 | 合同→属于→项目 |
| 约束 axiom | 口径铁律 | 默认只取末级 isEndCost=1 |
TBox 更稳定——像字典/数据模型,不常变(对比 设计指南/本体设计/ABox 的动态流水)。
二、TBox 示例(成本问数模式层)
Section titled “二、TBox 示例(成本问数模式层)”# TBox · 成本科目类型与约束tbox: classes: - id: Class.ProjectIndicator label: 项目成本指标 dimensionProperties: - {name: costSubject, label: 成本科目} - {name: isEndCost, label: 是否末级科目} - {name: productType, label: 业态} measureProperties: - {name: jianAnAmount, label: 建安造价费} - {name: areaUnitCost, label: 建面单方} axioms: # 口径铁律 - rule: "默认只取末级科目 isEndCost=1" - rule: "父子科目不可混算(防重复)"三、DSL 是对 TBox 的「应用」
Section titled “三、DSL 是对 TBox 的「应用」”DSL 不是凭空写的——它的每个 cube/measure/filter 都必须在 TBox 里有定义。TBox 是 DSL 的词典:
# ① 用户业务问句"深圳住宅的建安单方是多少?"
# ② 转成查询 DSL(每个字段都来自 TBox){ cube: ProjectIndicator, # ← TBox 的类 measures: [areaUnitCost], # ← TBox 属性 filters: [{productType: 住宅}, {city: 深圳}] # isEndCost=1 由 axiom 自动补}口径铁律写成 axiom,引擎自动补——用户无需知道、也绕不过。
四、护栏:把口径写成 defaultFilters(本体即代码)
Section titled “四、护栏:把口径写成 defaultFilters(本体即代码)”业务铁律落到 schema 的 defaultFilters,引擎自动注入 WHERE:
🐛 货值三倍累加 bug —— dwd_s_projectvalueabledetail 同一笔货值在 Level=1/2/3 三层各存一份等额金额:
- ❌ AI 直接
SUM(TotalValue) WHERE IsBenchmark=1→ 8490 万(语法 100% 对,错 3 倍) - ✅ 引擎自动补
AND Level=3→ 2830 万(口径对)
ProjectValue: defaultFilters: - { field: level, value: 3, unless: [level, hierarchyCode], hint: "默认 level=3,避免三倍累加" } - { field: isBenchmark, value: 1 }护栏不是枷锁,是默认安全值。完整案例见 实践分享/控制价审核CLI化实战。
五、TBox 的 CLI 形态
Section titled “五、TBox 的 CLI 形态”TBox 通过命令暴露给 Agent(对接 API 或宽表都一样):
biz schema list --domain cost --output jsonbiz schema describe cost-contract --output jsonbiz dsl generate --question "本月成本异常项目有哪些" --domain cost --output json详见 设计指南/CLI设计/CLI设计规范 的「与业务本体的关系」。
六、只建 TBox 就够的场景
Section titled “六、只建 TBox 就够的场景”- L1 事实查询:查一个项目/科目的值
- L2 多维对比:区域均值、项目排名、区间
有 Schema、有口径,就能查、能比。要做 L3 归因 / L4 决策,才补 设计指南/本体设计/ABox。
- 概览 → 设计指南/本体设计;实例层 → 设计指南/本体设计/ABox
- Schema 双层(编译源 vs AI 速查)与 DSL 编译 → 场景指南/问数/03、/04