统计局区划对齐
灵感:能力工具箱 area-statsgov(AreaCity-JsSpider 口径场景)。
小四原创:用精简样本树演示 code↔名称路径对齐;完整数据需自行替换权威源。与「省市区级联」互补:级联偏表单 UI,本包偏码表对齐逻辑。
何时使用
- 客户地址只有名称或只有 code,要对齐成标准路径
- 演示「统计局/民政口径」六位码查找
- 导入清洗前做区划规范化 POC
硬约束
- Skill 内样本仅演示;禁止声称已内置全国完整最新库。
- 对齐结果返回:
codes[]+names[]+ 是否唯一匹配。 - 重名区县:标
ambiguous,要求用户选省/市上下文。 - 实现要点注释标 小四原创。
- 不爬取统计局网站;数据由用户提供合法数据包。
推荐实现
export type AreaNode = { code: string; name: string; children?: AreaNode[] }
// 小四原创:演示样本(可替换)
export const SAMPLE_TREE: AreaNode[] = [
{
code: '440000',
name: '广东省',
children: [
{
code: '440300',
name: '深圳市',
children: [
{ code: '440305', name: '南山区' },
{ code: '440304', name: '福田区' },
],
},
],
},
]
// 小四原创:按 code 取路径
export function pathByCode(code: string, tree = SAMPLE_TREE): AreaNode[] {
const path: AreaNode[] = []
const walk = (nodes: AreaNode[], stack: AreaNode[]): boolean => {
for (const n of nodes) {
const next = [...stack, n]
if (n.code === code) {
path.push(...next)
return true
}
if (n.children && walk(n.children, next)) return true
}
return false
}
walk(tree, [])
return path
}
// 小四原创:按名称模糊对齐(同名则 ambiguous)
export function alignByName(name: string, tree = SAMPLE_TREE) {
const hits: AreaNode[][] = []
const walk = (nodes: AreaNode[], stack: AreaNode[]) => {
for (const n of nodes) {
const next = [...stack, n]
if (n.name === name || n.name.includes(name)) hits.push(next)
if (n.children) walk(n.children, next)
}
}
walk(tree, [])
if (!hits.length) return { ok: false as const, reason: '未匹配' }
if (hits.length > 1) return { ok: false as const, reason: 'ambiguous', hits }
const path = hits[0]
return {
ok: true as const,
codes: path.map((x) => x.code),
names: path.map((x) => x.name),
text: path.map((x) => x.name).join('/'),
}
}
Agent 步骤
- 放入样本树或用户完整 JSON。
- 提供「按 code 查路径」「按名称对齐」。
- 歧义时列出候选路径让用户选。
- 自测:440305 → 广东/深圳/南山;「南山区」在多样本下可能 ambiguous。
不要做
- 把演示样本当生产主数据长期不更新。
- 教违规爬取官方站点。
附加
- README.md · reference.md · templates/usage.md




