feat(labels): M9 两级词表检索 — labels CLI + MLSP labels.search
第一级(内置,数据常量):六组关键词 —— 未完成/假数据/示例/实验/废弃/待校验,
pending = 未完成 ∪ 假数据。作用是默认查询、LLM 范例、跨项目可比。
第二级(参数):--grep 替换,--also-builtin 并集,--group 选组。
**词表是数据不是语法**:扩充它不改任何解析规则。
CLI:
marqdo labels . # pending 口径
marqdo labels . --grep "联调" # 自定义替换
marqdo labels . --grep "联调" --also-builtin # 并集
marqdo labels . --group 示例,实验
marqdo labels . --count / --json
MLSP:{"method":"labels.search","params":{path|source, grep?, also_builtin?, group?}}
→ {"ok":true,"words":[…],"count":N,"hits":[{line,unit,label,words,has_payload}]}
与 CLI 共用同一份 label::search。
检索语义 v1:子串匹配(CJK 无词边界)、多词 OR、英文大小写不敏感;
误判只影响计数,输出带描述原文可人工判断;不做否定语法(留 v1.1)。
测试:4 个集成(pending=2 / grep 替换=1 / also-builtin 并集=3 / MLSP 返回 hits);
全量 cargo test --release:587 passed / 0 failed(M4 后 583 + 4)。
实测:
pending → 2 命中("待开发"、"模拟"两处)
--grep 联调 → 1 命中
--grep 联调 --also-builtin → 3 命中
文档:doc/design/change-m9-label-search.md
This commit is contained in:
1 parent
6dd0ce47b1
commit
fd0cfcb566
6 files changed
+468
No files matched your search
+101
@@ -336,3 +336,104 @@ mod tests {
|
||||
assert!(refs("空 `` 引号").is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// M9: 两级词表检索(built-in groups = 默认/范例;`--grep` = 调用方自定义)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// One built-in keyword group. `<TAB>` M9
|
||||
///
|
||||
/// The table is **data**, not syntax: it seeds the default query
|
||||
/// (`marqdo labels pending`) and gives LLMs a stable vocabulary; any project can
|
||||
/// override or extend it at the call site with `--grep`.
|
||||
pub struct WordGroup {
|
||||
pub name: &'static str,
|
||||
pub words: &'static [&'static str],
|
||||
}
|
||||
|
||||
/// Built-in groups (v1). Extending this table never changes the grammar.
|
||||
pub const BUILTIN_GROUPS: &[WordGroup] = &[
|
||||
WordGroup {
|
||||
name: "未完成",
|
||||
words: &[
|
||||
"待开发", "未开发", "开发中", "未实现", "待实现", "未接", "接口未接", "TODO",
|
||||
],
|
||||
},
|
||||
WordGroup {
|
||||
name: "假数据",
|
||||
words: &["模拟", "假数据", "桩", "占位", "stub", "mock"],
|
||||
},
|
||||
WordGroup {
|
||||
name: "示例",
|
||||
words: &["示例", "样例", "demo"],
|
||||
},
|
||||
WordGroup {
|
||||
name: "实验",
|
||||
words: &["实验", "试验", "experimental"],
|
||||
},
|
||||
WordGroup {
|
||||
name: "废弃",
|
||||
words: &["废弃", "弃用", "deprecated"],
|
||||
},
|
||||
WordGroup {
|
||||
name: "待校验",
|
||||
words: &["待校验", "未验证", "待确认"],
|
||||
},
|
||||
];
|
||||
|
||||
/// Groups that count as "pending" (default query for `labels pending`).
|
||||
pub const PENDING_GROUPS: &[&str] = &["未完成", "假数据"];
|
||||
|
||||
/// Expand group names into their words; unknown names are ignored.
|
||||
pub fn group_words(names: &[&str]) -> Vec<String> {
|
||||
let mut out = Vec::new();
|
||||
for g in BUILTIN_GROUPS {
|
||||
if names.iter().any(|n| *n == g.name) {
|
||||
out.extend(g.words.iter().map(|w| w.to_string()));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Split a `--grep` value (`a,b` / `a,b`) into words.
|
||||
pub fn parse_words(spec: &str) -> Vec<String> {
|
||||
spec.split([',', ','])
|
||||
.map(|w| w.trim())
|
||||
.filter(|w| !w.is_empty())
|
||||
.map(|w| w.to_string())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Words that hit `label` (substring, ASCII case-insensitive). `<TAB>` M9
|
||||
pub fn matched_words(label: &str, words: &[String]) -> Vec<String> {
|
||||
let hay = label.to_lowercase();
|
||||
let mut out = Vec::new();
|
||||
for w in words {
|
||||
if w.is_empty() {
|
||||
continue;
|
||||
}
|
||||
if hay.contains(&w.to_lowercase()) {
|
||||
out.push(w.clone());
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// One search hit: where, what the label says, which words matched.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Hit {
|
||||
pub site: OcclusionSite,
|
||||
pub words: Vec<String>,
|
||||
}
|
||||
|
||||
/// Search every occlusion whose label matches any of `words`.
|
||||
pub fn search(module: &Module, words: &[String]) -> Vec<Hit> {
|
||||
let mut out = Vec::new();
|
||||
for site in collect(module) {
|
||||
let words = matched_words(&site.label, words);
|
||||
if !words.is_empty() {
|
||||
out.push(Hit { site, words });
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
Reference in new issue
Block a user