Files
AgentLab/backend/app/ledger/metric_matching.py
T
ThearchyHelios e15e94f93e 口径工作台:结构化语义导入、起草续跑恢复与本体关系编排
- 新增口径结构化语义定义、分批解析与 SQL 生成管道(semantic / semantic_import / semantic_sql)
- 支持起草断点续跑恢复、指标自动匹配对齐与存量口径语义迁移面板(MigrationPanel / SemanticPanel)
- 口径草稿与变更流程接入候选本体边提议、审阅确认与一键修改保护,同步更新可移植 SQLite 基线校验
2026-11-12 12:58:12 +08:00

19 lines
814 B
Python

"""Deterministic candidate retrieval. Matching a name is not permission to execute a metric."""
from __future__ import annotations
import re
from collections.abc import Iterable
from app.ledger.semantic import mention
def score(question: str, name: str, aliases: Iterable[str] = ()) -> int:
terms = [name, *aliases]
exact = [len(term) for term in terms if isinstance(term, str) and mention(question, term)]
if exact:
return 100 + max(exact)
# OEE/RTY/TEEP are discoverable even when the old metric only has a qualified display name.
# This only produces candidates; it never selects between their different business formulas.
tokens = set(re.findall(r"(?<![A-Za-z])[A-Z][A-Z0-9]{1,9}(?![A-Za-z])", name))
return 1 if any(mention(question, token) for token in tokens) else 0