consistency.ts
2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* 「区 + 街道一致性」判定:把上游已经算出来的结论写成一列结构化值,交给主程序直接读。
*
* 为什么要有这一列:`districtOfStreet` 这份属区知识只存在于补全工具里,主程序导入时
* 不知道「桃源街道属南山区」,只能看着 G 类「街道低频」的副产品猜。把结论写进表里,
* 下游就不必重造判据,也不会因为两份词表分叉而得出不同答案。
*
* 判定四步(依次短路):
* 1. 行政区为空 → 不适用(没有可比对象;与现有 annotate 要求 district 非空一致)
* 2. 街道为空 → 未判定
* 3. 街道不在词表(含跨区重名被剔除的)→ 无判据
* 4. 属区 === 行政区 → 一致;否则 → 不一致
*
* 大鹏三街道豁免:`街道 ∈ {大鹏,葵涌,南澳} && 行政区 === 龙岗区` 判「一致(大鹏单列)」。
* 这不是数据库里的真实属区(真实属大鹏新区),而是主程序 ingestCore 的既有口径 ——
* 它把这三街道从龙岗单列成大鹏新区。真表里这类 499 条,按错配剔掉就是事故。
*
* 五档取值故意不加「需复核」以外的处置语义:这一列只陈述事实,剔不剔由导入人在报告里勾。
*/
import type { Vocab } from './vocab.ts';
export const CONSISTENCY = {
same: '一致',
different: '不一致',
unknown: '未判定',
noBasis: '无判据',
notApplicable: '不适用',
dapeng: '一致(大鹏单列)',
} as const;
export type Consistency = (typeof CONSISTENCY)[keyof typeof CONSISTENCY];
/** 与 ingestCore.ts 的 DAPENG_STREETS 同源;真表里只有这三街道存在「行政上属龙岗、业务上单列」 */
export const DAPENG_STREETS: ReadonlySet<string> = new Set(['南澳街道', '葵涌街道', '大鹏街道']);
export const DAPENG_WRITTEN_DISTRICT = '龙岗区';
export function districtStreetConsistency(
district: string,
street: string,
vocab: Vocab,
): Consistency {
if (district === '') return CONSISTENCY.notApplicable;
if (street === '') return CONSISTENCY.unknown;
if (
DAPENG_STREETS.has(street) && district === DAPENG_WRITTEN_DISTRICT
) return CONSISTENCY.dapeng;
const owner = vocab.districtOfStreet.get(street);
if (owner === undefined) return CONSISTENCY.noBasis;
return owner === district ? CONSISTENCY.same : CONSISTENCY.different;
}