@mailwoman/registry 10.0.0 → 10.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -14
- package/lib/address-key.ts +14 -10
- package/lib/geocode-handler.ts +7 -5
- package/lib/geojson.ts +13 -7
- package/lib/ingest.ts +70 -92
- package/lib/learned-scorer.ts +38 -44
- package/lib/map-html.ts +26 -72
- package/lib/models/crosssource-gbt-en-us.ts +9 -7
- package/lib/models/dedup-gbt-en-us.ts +9 -8
- package/lib/models/org-crosssource-gbt-en-us.ts +10 -8
- package/lib/reconcile.ts +45 -54
- package/lib/resolve.ts +187 -130
- package/lib/types.ts +35 -29
- package/out/address-key.d.ts +14 -10
- package/out/address-key.d.ts.map +1 -1
- package/out/address-key.js +14 -10
- package/out/address-key.js.map +1 -1
- package/out/geocode-handler.d.ts +6 -4
- package/out/geocode-handler.d.ts.map +1 -1
- package/out/geocode-handler.js +7 -5
- package/out/geocode-handler.js.map +1 -1
- package/out/geojson.d.ts +9 -5
- package/out/geojson.d.ts.map +1 -1
- package/out/geojson.js +13 -7
- package/out/geojson.js.map +1 -1
- package/out/ingest.d.ts +49 -76
- package/out/ingest.d.ts.map +1 -1
- package/out/ingest.js +37 -62
- package/out/ingest.js.map +1 -1
- package/out/learned-scorer.d.ts +29 -26
- package/out/learned-scorer.d.ts.map +1 -1
- package/out/learned-scorer.js +31 -39
- package/out/learned-scorer.js.map +1 -1
- package/out/map-html.d.ts +13 -32
- package/out/map-html.d.ts.map +1 -1
- package/out/map-html.js +11 -64
- package/out/map-html.js.map +1 -1
- package/out/models/crosssource-gbt-en-us.d.ts +9 -7
- package/out/models/crosssource-gbt-en-us.d.ts.map +1 -1
- package/out/models/crosssource-gbt-en-us.js +9 -7
- package/out/models/crosssource-gbt-en-us.js.map +1 -1
- package/out/models/dedup-gbt-en-us.d.ts +9 -8
- package/out/models/dedup-gbt-en-us.d.ts.map +1 -1
- package/out/models/dedup-gbt-en-us.js +9 -8
- package/out/models/dedup-gbt-en-us.js.map +1 -1
- package/out/models/org-crosssource-gbt-en-us.d.ts +10 -8
- package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -1
- package/out/models/org-crosssource-gbt-en-us.js +10 -8
- package/out/models/org-crosssource-gbt-en-us.js.map +1 -1
- package/out/reconcile.d.ts +36 -50
- package/out/reconcile.d.ts.map +1 -1
- package/out/reconcile.js +18 -42
- package/out/reconcile.js.map +1 -1
- package/out/resolve.d.ts +152 -91
- package/out/resolve.d.ts.map +1 -1
- package/out/resolve.js +67 -68
- package/out/resolve.js.map +1 -1
- package/out/tools/coverage-reconciliation.d.ts +23 -23
- package/out/tools/coverage-reconciliation.d.ts.map +1 -1
- package/out/tools/coverage-reconciliation.js +15 -26
- package/out/tools/coverage-reconciliation.js.map +1 -1
- package/out/tools/cross/dataset-correlation.d.ts +23 -27
- package/out/tools/cross/dataset-correlation.d.ts.map +1 -1
- package/out/tools/cross/dataset-correlation.js +9 -61
- package/out/tools/cross/dataset-correlation.js.map +1 -1
- package/out/tools/cross/source-threshold-sweep.d.ts +20 -26
- package/out/tools/cross/source-threshold-sweep.d.ts.map +1 -1
- package/out/tools/cross/source-threshold-sweep.js +14 -40
- package/out/tools/cross/source-threshold-sweep.js.map +1 -1
- package/out/tools/dedup-ceiling.d.ts +23 -26
- package/out/tools/dedup-ceiling.d.ts.map +1 -1
- package/out/tools/dedup-ceiling.js +22 -41
- package/out/tools/dedup-ceiling.js.map +1 -1
- package/out/tools/eval-geocoder.d.ts +25 -16
- package/out/tools/eval-geocoder.d.ts.map +1 -1
- package/out/tools/eval-geocoder.js +5 -6
- package/out/tools/eval-geocoder.js.map +1 -1
- package/out/tools/geocoder/namesake-probe.d.ts +9 -8
- package/out/tools/geocoder/namesake-probe.d.ts.map +1 -1
- package/out/tools/geocoder/namesake-probe.js +6 -7
- package/out/tools/geocoder/namesake-probe.js.map +1 -1
- package/out/tools/geocoder/vs-provided-coords.d.ts +18 -15
- package/out/tools/geocoder/vs-provided-coords.d.ts.map +1 -1
- package/out/tools/geocoder/vs-provided-coords.js +30 -27
- package/out/tools/geocoder/vs-provided-coords.js.map +1 -1
- package/out/tools/gold-set-sample.d.ts +27 -18
- package/out/tools/gold-set-sample.d.ts.map +1 -1
- package/out/tools/gold-set-sample.js +18 -22
- package/out/tools/gold-set-sample.js.map +1 -1
- package/out/tools/learned/scorer/clustering-eval.d.ts +30 -27
- package/out/tools/learned/scorer/clustering-eval.d.ts.map +1 -1
- package/out/tools/learned/scorer/clustering-eval.js +28 -38
- package/out/tools/learned/scorer/clustering-eval.js.map +1 -1
- package/out/tools/learned/scorer/crossstate-eval.d.ts +24 -18
- package/out/tools/learned/scorer/crossstate-eval.d.ts.map +1 -1
- package/out/tools/learned/scorer/crossstate-eval.js +19 -25
- package/out/tools/learned/scorer/crossstate-eval.js.map +1 -1
- package/out/tools/learned/scorer/eval.d.ts +26 -39
- package/out/tools/learned/scorer/eval.d.ts.map +1 -1
- package/out/tools/learned/scorer/eval.js +11 -71
- package/out/tools/learned/scorer/eval.js.map +1 -1
- package/out/tools/matcher-scale.d.ts +12 -17
- package/out/tools/matcher-scale.d.ts.map +1 -1
- package/out/tools/matcher-scale.js +11 -29
- package/out/tools/matcher-scale.js.map +1 -1
- package/out/tools/nppes/dedup-benchmark.d.ts +22 -41
- package/out/tools/nppes/dedup-benchmark.d.ts.map +1 -1
- package/out/tools/nppes/dedup-benchmark.js +21 -67
- package/out/tools/nppes/dedup-benchmark.js.map +1 -1
- package/out/tools/nppes/org-name.d.ts +5 -11
- package/out/tools/nppes/org-name.d.ts.map +1 -1
- package/out/tools/nppes/org-name.js +2 -9
- package/out/tools/nppes/org-name.js.map +1 -1
- package/out/tools/nppes/overmerge-packet.d.ts +15 -11
- package/out/tools/nppes/overmerge-packet.d.ts.map +1 -1
- package/out/tools/nppes/overmerge-packet.js +6 -7
- package/out/tools/nppes/overmerge-packet.js.map +1 -1
- package/out/tools/nppes/report.d.ts +17 -13
- package/out/tools/nppes/report.d.ts.map +1 -1
- package/out/tools/nppes/report.js +6 -14
- package/out/tools/nppes/report.js.map +1 -1
- package/out/tools/nppes/sample.d.ts +29 -18
- package/out/tools/nppes/sample.d.ts.map +1 -1
- package/out/tools/nppes/sample.js +24 -28
- package/out/tools/nppes/sample.js.map +1 -1
- package/out/tools/nppes/scoring.d.ts +7 -6
- package/out/tools/nppes/scoring.d.ts.map +1 -1
- package/out/tools/nppes/scoring.js +6 -5
- package/out/tools/nppes/scoring.js.map +1 -1
- package/out/tools/nppes/settings.d.ts +10 -7
- package/out/tools/nppes/settings.d.ts.map +1 -1
- package/out/tools/nppes/settings.js +16 -16
- package/out/tools/nppes/settings.js.map +1 -1
- package/out/tools/nppes/truth-grains.d.ts +36 -23
- package/out/tools/nppes/truth-grains.d.ts.map +1 -1
- package/out/tools/nppes/truth-grains.js +36 -20
- package/out/tools/nppes/truth-grains.js.map +1 -1
- package/out/tools/shared.d.ts +68 -72
- package/out/tools/shared.d.ts.map +1 -1
- package/out/tools/shared.js +50 -67
- package/out/tools/shared.js.map +1 -1
- package/out/tools/train/cross-gbt.d.ts +37 -26
- package/out/tools/train/cross-gbt.d.ts.map +1 -1
- package/out/tools/train/cross-gbt.js +14 -25
- package/out/tools/train/cross-gbt.js.map +1 -1
- package/out/tools/train/gbt.d.ts +36 -20
- package/out/tools/train/gbt.d.ts.map +1 -1
- package/out/tools/train/gbt.js +27 -31
- package/out/tools/train/gbt.js.map +1 -1
- package/out/tools/train/org-cross-gbt.d.ts +38 -24
- package/out/tools/train/org-cross-gbt.d.ts.map +1 -1
- package/out/tools/train/org-cross-gbt.js +18 -22
- package/out/tools/train/org-cross-gbt.js.map +1 -1
- package/out/tools/txhhsc-to-oarow.d.ts +14 -9
- package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
- package/out/tools/txhhsc-to-oarow.js +16 -15
- package/out/tools/txhhsc-to-oarow.js.map +1 -1
- package/out/tools/viz/browser.d.ts +6 -5
- package/out/tools/viz/browser.d.ts.map +1 -1
- package/out/tools/viz/browser.js +6 -5
- package/out/tools/viz/browser.js.map +1 -1
- package/out/tools/viz/cross-dataset-map.d.ts +7 -4
- package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
- package/out/tools/viz/cross-dataset-map.js +9 -6
- package/out/tools/viz/cross-dataset-map.js.map +1 -1
- package/out/tools/viz/geocode-first-surface.d.ts +11 -5
- package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
- package/out/tools/viz/geocode-first-surface.js +16 -11
- package/out/tools/viz/geocode-first-surface.js.map +1 -1
- package/out/tools/viz/render/map.d.ts +5 -5
- package/out/tools/viz/render/map.d.ts.map +1 -1
- package/out/tools/viz/render/map.js +6 -5
- package/out/tools/viz/render/map.js.map +1 -1
- package/out/tools/viz/{render/index.d.ts → render.d.ts} +13 -9
- package/out/tools/viz/render.d.ts.map +1 -0
- package/out/tools/viz/{render/index.js → render.js} +9 -8
- package/out/tools/viz/render.js.map +1 -0
- package/out/tools/viz/source-provenance-map.d.ts +19 -7
- package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
- package/out/tools/viz/source-provenance-map.js +11 -8
- package/out/tools/viz/source-provenance-map.js.map +1 -1
- package/out/tools/viz/yardstick-figure.d.ts +2 -21
- package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
- package/out/tools/viz/yardstick-figure.js +3 -39
- package/out/tools/viz/yardstick-figure.js.map +1 -1
- package/out/types.d.ts +35 -29
- package/out/types.d.ts.map +1 -1
- package/out/types.js +2 -2
- package/out/types.js.map +1 -1
- package/package.json +42 -185
- package/{lib/tools → tools}/coverage-reconciliation.ts +27 -30
- package/{lib/tools → tools}/cross/dataset-correlation.ts +35 -73
- package/{lib/tools → tools}/cross/source-threshold-sweep.ts +29 -46
- package/{lib/tools → tools}/dedup-ceiling.ts +34 -45
- package/tools/eval-geocoder.ts +77 -0
- package/{lib/tools → tools}/geocoder/namesake-probe.ts +9 -8
- package/{lib/tools → tools}/geocoder/vs-provided-coords.ts +40 -31
- package/{lib/tools → tools}/gold-set-sample.ts +35 -29
- package/{lib/tools → tools}/learned/scorer/clustering-eval.ts +49 -45
- package/{lib/tools → tools}/learned/scorer/crossstate-eval.ts +34 -30
- package/{lib/tools → tools}/learned/scorer/eval.ts +39 -78
- package/{lib/tools → tools}/matcher-scale.ts +21 -33
- package/{lib/tools → tools}/nppes/dedup-benchmark.ts +39 -83
- package/tools/nppes/org-name.ts +15 -0
- package/{lib/tools → tools}/nppes/overmerge-packet.ts +16 -12
- package/{lib/tools → tools}/nppes/report.ts +32 -25
- package/{lib/tools → tools}/nppes/sample.ts +43 -38
- package/{lib/tools → tools}/nppes/scoring.ts +7 -6
- package/{lib/tools → tools}/nppes/settings.ts +16 -16
- package/{lib/tools → tools}/nppes/truth-grains.ts +46 -26
- package/{lib/tools → tools}/shared.ts +79 -98
- package/{lib/tools → tools}/train/cross-gbt.ts +39 -34
- package/{lib/tools → tools}/train/gbt.ts +55 -41
- package/{lib/tools → tools}/train/org-cross-gbt.ts +40 -30
- package/{lib/tools → tools}/txhhsc-to-oarow.ts +24 -18
- package/{lib/tools → tools}/viz/browser.ts +6 -5
- package/{lib/tools → tools}/viz/cross-dataset-map.ts +15 -9
- package/{lib/tools → tools}/viz/geocode-first-surface.ts +29 -17
- package/{lib/tools → tools}/viz/render/map.ts +7 -6
- package/{lib/tools/viz/render/index.ts → tools/viz/render.ts} +16 -11
- package/{lib/tools → tools}/viz/source-provenance-map.ts +30 -15
- package/{lib/tools → tools}/viz/yardstick-figure.ts +6 -43
- package/lib/tools/eval-geocoder.ts +0 -67
- package/lib/tools/index.ts +0 -31
- package/lib/tools/nppes/org-name.ts +0 -23
- package/out/tools/index.d.ts +0 -31
- package/out/tools/index.d.ts.map +0 -1
- package/out/tools/index.js +0 -31
- package/out/tools/index.js.map +0 -1
- package/out/tools/viz/render/index.d.ts.map +0 -1
- package/out/tools/viz/render/index.js.map +0 -1
package/lib/resolve.ts
CHANGED
|
@@ -3,18 +3,9 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* The resolve pipeline
|
|
7
|
-
* (geo-first) → score (Fellegi-Sunter) → cluster → canonical entities.
|
|
6
|
+
* The resolve pipeline wires the matching modules over concrete contact and organization records.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
* phone / email; score on name, organization, address key, and great-circle distance — and can
|
|
11
|
-
* fit the scorer's `m`/`u` to the data with EM (`trainEM`), so it runs with no labels and no
|
|
12
|
-
* per-dataset tuning. Everything is overridable: pass your own model, blocking keys, or
|
|
13
|
-
* threshold.
|
|
14
|
-
*
|
|
15
|
-
* Geocoding is assumed already done upstream (each `address` carries its coordinate + canonical
|
|
16
|
-
* key). Wiring mailwoman's parser + geocoder to turn raw rows into `SourceRecord`s is the ingest
|
|
17
|
-
* layer that sits in front of this.
|
|
8
|
+
* The upstream pipeline geocodes each `address` and supplies its coordinate and canonical key.
|
|
18
9
|
*/
|
|
19
10
|
|
|
20
11
|
import {
|
|
@@ -46,11 +37,14 @@ import { DEDUP_GBT_META, DEDUP_GBT_MODEL } from "#models/dedup-gbt-en-us"
|
|
|
46
37
|
import type { ResolvedEntity, SourceRecord } from "#types"
|
|
47
38
|
|
|
48
39
|
/**
|
|
49
|
-
* Cheap, parse-free normalization for the address-frequency key
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
40
|
+
* Cheap, parse-free normalization for the address-frequency key: uppercase,
|
|
41
|
+
* collapse whitespace, drop punctuation.
|
|
42
|
+
*
|
|
43
|
+
* The count covers distinct entities that share an address.
|
|
44
|
+
* It is computable over millions of rows without geocoding.
|
|
45
|
+
*
|
|
46
|
+
* A crowded clinic or billing address is weak identity evidence.
|
|
47
|
+
* A lonely address is strong.
|
|
54
48
|
*/
|
|
55
49
|
export function addressFrequencyKey(raw: string): string {
|
|
56
50
|
return raw
|
|
@@ -61,7 +55,9 @@ export function addressFrequencyKey(raw: string): string {
|
|
|
61
55
|
}
|
|
62
56
|
|
|
63
57
|
/**
|
|
64
|
-
* Default tiered levels for a name-like text field.
|
|
58
|
+
* Default tiered levels for a name-like text field.
|
|
59
|
+
*
|
|
60
|
+
* `m`/`u` are EM-estimable seeds.
|
|
65
61
|
*/
|
|
66
62
|
const NAME_LEVELS: ComparisonLevel[] = [
|
|
67
63
|
{ label: "exact", minSimilarity: 1, m: 0.8, u: 0.01 },
|
|
@@ -70,7 +66,9 @@ const NAME_LEVELS: ComparisonLevel[] = [
|
|
|
70
66
|
]
|
|
71
67
|
|
|
72
68
|
/**
|
|
73
|
-
* Exact-vs-different levels for a normalized phone.
|
|
69
|
+
* Exact-vs-different levels for a normalized phone.
|
|
70
|
+
*
|
|
71
|
+
* A shared line is strong, rarely-coincidental evidence.
|
|
74
72
|
*/
|
|
75
73
|
const PHONE_LEVELS: ComparisonLevel[] = [
|
|
76
74
|
{ label: "exact", minSimilarity: 1, m: 0.6, u: 0.002 },
|
|
@@ -78,24 +76,24 @@ const PHONE_LEVELS: ComparisonLevel[] = [
|
|
|
78
76
|
]
|
|
79
77
|
|
|
80
78
|
/**
|
|
81
|
-
* Exact-vs-different levels for a closed-vocabulary code
|
|
82
|
-
*
|
|
83
|
-
*
|
|
79
|
+
* Exact-vs-different levels for a closed-vocabulary code set
|
|
80
|
+
* ({@link DefaultModelOptions.exactDiscriminators}), such as NPPES taxonomy codes or license numbers.
|
|
81
|
+
*
|
|
82
|
+
* These are seeds only, since EM refits.
|
|
83
|
+
* `u` starts well above phone's 0.002, because two random providers share a
|
|
84
|
+
* specialty far more often than a phone line.
|
|
84
85
|
*/
|
|
85
86
|
const CODE_SET_LEVELS: ComparisonLevel[] = [
|
|
86
87
|
{ label: "exact", minSimilarity: 1, m: 0.75, u: 0.08 },
|
|
87
88
|
{ label: "different", minSimilarity: 0, m: 0.25, u: 0.92 },
|
|
88
89
|
]
|
|
89
90
|
|
|
90
|
-
/**
|
|
91
|
-
* 1 when the whitespace-joined code sets share ANY code, else 0 (order/count-insensitive, case-folded).
|
|
92
|
-
*/
|
|
93
91
|
function codeSetOverlap(a: string, b: string): number {
|
|
94
92
|
const sa = new Set(
|
|
95
93
|
a
|
|
96
94
|
.toUpperCase()
|
|
97
95
|
.split(/\s+/)
|
|
98
|
-
.filter((value) => value.length
|
|
96
|
+
.filter((value) => value.length)
|
|
99
97
|
)
|
|
100
98
|
|
|
101
99
|
for (const t of b.toUpperCase().split(/\s+/)) if (t && sa.has(t)) return 1
|
|
@@ -104,9 +102,11 @@ function codeSetOverlap(a: string, b: string): number {
|
|
|
104
102
|
}
|
|
105
103
|
|
|
106
104
|
/**
|
|
107
|
-
* Last-10-
|
|
108
|
-
*
|
|
109
|
-
*
|
|
105
|
+
* Last-10-digit normalization for phone agreement, dropping country code, punctuation and extensions.
|
|
106
|
+
*
|
|
107
|
+
* A shorter digit string is kept as-is, since partial agreement still contributes
|
|
108
|
+
* weight in the comparison model.
|
|
109
|
+
* `null` means no digits at all.
|
|
110
110
|
*/
|
|
111
111
|
export function normalizePhone(raw: string | null | undefined): string | null {
|
|
112
112
|
if (!raw) return null
|
|
@@ -116,9 +116,12 @@ export function normalizePhone(raw: string | null | undefined): string | null {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
* {@link normalizePhone} under the probes' stricter
|
|
120
|
-
*
|
|
121
|
-
*
|
|
119
|
+
* {@link normalizePhone} under the probes' stricter interface, where only a full line counts.
|
|
120
|
+
*
|
|
121
|
+
* Returns the last 10 digits when the input contains at least 10.
|
|
122
|
+
* Returns `""` for shorter input, so callers never receive a partial digit string.
|
|
123
|
+
*
|
|
124
|
+
* Callers guard on truthiness, so `""` reads as no comparable phone rather than a weaker key.
|
|
122
125
|
*/
|
|
123
126
|
export function normalizePhoneStrict(raw: string | null | undefined): string {
|
|
124
127
|
const digits = normalizePhone(raw)
|
|
@@ -127,56 +130,75 @@ export function normalizePhoneStrict(raw: string | null | undefined): string {
|
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
/**
|
|
130
|
-
* The identity-corroborating comparisons
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
133
|
+
* The identity-corroborating comparisons: person name, organization and phone.
|
|
134
|
+
*
|
|
135
|
+
* At least one must positively agree before a pair may link, since a shared
|
|
136
|
+
* address provides no identity evidence by itself.
|
|
137
|
+
* Phone is the secondary identifier that rescues a true same-entity link across name drift.
|
|
134
138
|
*/
|
|
135
139
|
const CORROBORATING_FIELDS = new Set(["given", "family", "organization", "phone"])
|
|
136
140
|
|
|
137
141
|
/**
|
|
138
|
-
* Options for {@link buildDefaultModel}.
|
|
142
|
+
* Options for {@link buildDefaultModel}.
|
|
143
|
+
*
|
|
144
|
+
* Each change is default-off, so the base model is byte-stable.
|
|
139
145
|
*/
|
|
140
146
|
export interface DefaultModelOptions {
|
|
141
147
|
/**
|
|
142
|
-
* Corpus-wide address-frequency table
|
|
143
|
-
*
|
|
144
|
-
*
|
|
148
|
+
* Corpus-wide address-frequency table over {@link addressFrequencyKey}, which makes
|
|
149
|
+
* the address agreement weight inverse to how shared the address is.
|
|
150
|
+
*
|
|
151
|
+
* A building with 50 providers makes a same-address match near-worthless evidence.
|
|
152
|
+
*
|
|
153
|
+
* The table's `value` is the record's raw address string.
|
|
145
154
|
*/
|
|
146
155
|
addressFrequency?: TermFrequencyTable
|
|
147
156
|
/**
|
|
148
|
-
*
|
|
149
|
-
* {@link spatialComparison spatial-agreement} signal
|
|
150
|
-
*
|
|
151
|
-
*
|
|
157
|
+
* Collapse the redundant address-key and great-circle-distance comparisons into one
|
|
158
|
+
* {@link spatialComparison spatial-agreement} signal, an exact-key tier over distance buckets.
|
|
159
|
+
*
|
|
160
|
+
* Removes the double-count that over-merges co-located providers, since an
|
|
161
|
+
* exact key match already implies distance ≈ 0.
|
|
152
162
|
*/
|
|
153
163
|
collapseSpatial?: boolean
|
|
154
164
|
/**
|
|
155
|
-
*
|
|
156
|
-
*
|
|
165
|
+
* Add a normalized-phone exact-match comparison.
|
|
166
|
+
*
|
|
167
|
+
* A shared line is strong evidence and the secondary corroborator that lets a
|
|
168
|
+
* true same-entity link survive name drift.
|
|
157
169
|
*/
|
|
158
170
|
usePhone?: boolean
|
|
159
171
|
/**
|
|
160
|
-
* Extra secondary-identifier comparisons drawn from {@link SourceRecord.attributes}
|
|
161
|
-
*
|
|
162
|
-
*
|
|
172
|
+
* Extra secondary-identifier comparisons drawn from {@link SourceRecord.attributes},
|
|
173
|
+
* such as `["authorizedOfficial"]`.
|
|
174
|
+
*
|
|
175
|
+
* Each becomes an `attr:<key>` comparison and counts toward corroboration.
|
|
176
|
+
* It is a more reliable discriminator than phone where the data has one.
|
|
163
177
|
*/
|
|
164
178
|
discriminators?: string[]
|
|
165
179
|
/**
|
|
166
|
-
* Closed-vocabulary
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
180
|
+
* Closed-vocabulary code-set discriminators drawn from {@link SourceRecord.attributes},
|
|
181
|
+
* such as NPPES taxonomy codes or license numbers.
|
|
182
|
+
*
|
|
183
|
+
* The attribute value is a whitespace-joined set of codes.
|
|
184
|
+
* Any shared code counts as agreement.
|
|
185
|
+
*
|
|
186
|
+
* This is set overlap rather than string similarity, since `207R00000X`
|
|
187
|
+
* and `207Q00000X` are different specialties despite near-identical text.
|
|
188
|
+
*
|
|
189
|
+
* Similarity scores mis-rank that case because the codes identify different specialties.
|
|
190
|
+
* The over-merge separator: two co-located records of one entity nearly always share
|
|
191
|
+
* a code, while two distinct co-located providers usually do not.
|
|
171
192
|
*/
|
|
172
193
|
exactDiscriminators?: string[]
|
|
173
194
|
}
|
|
174
195
|
|
|
175
196
|
/**
|
|
176
|
-
* The default geocode-first scoring model: name
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
197
|
+
* The default geocode-first scoring model: name, organization and a spatial signal.
|
|
198
|
+
*
|
|
199
|
+
* The spatial signal is either two comparisons (address-key similarity and great-circle distance)
|
|
200
|
+
* or, with {@link DefaultModelOptions.collapseSpatial}, one collapsed {@link spatialComparison}.
|
|
201
|
+
* `addressFrequency` down-weights agreement on a crowded address either way.
|
|
180
202
|
*/
|
|
181
203
|
export function buildDefaultModel(opts: DefaultModelOptions = {}): FellegiSunterModel<SourceRecord> {
|
|
182
204
|
const identity = [
|
|
@@ -194,7 +216,7 @@ export function buildDefaultModel(opts: DefaultModelOptions = {}): FellegiSunter
|
|
|
194
216
|
similarityComparison<SourceRecord>({
|
|
195
217
|
name: "phone",
|
|
196
218
|
extract: (r) => normalizePhone(r.phone),
|
|
197
|
-
similarity: (a, b) => (a === b ? 1 : 0),
|
|
219
|
+
similarity: (a, b) => (a === b ? 1 : 0),
|
|
198
220
|
levels: PHONE_LEVELS,
|
|
199
221
|
})
|
|
200
222
|
)
|
|
@@ -215,7 +237,7 @@ export function buildDefaultModel(opts: DefaultModelOptions = {}): FellegiSunter
|
|
|
215
237
|
similarityComparison<SourceRecord>({
|
|
216
238
|
name: `attr:${key}`,
|
|
217
239
|
extract: (r) => r.attributes?.[key],
|
|
218
|
-
similarity: codeSetOverlap,
|
|
240
|
+
similarity: codeSetOverlap,
|
|
219
241
|
levels: CODE_SET_LEVELS,
|
|
220
242
|
})
|
|
221
243
|
)
|
|
@@ -233,14 +255,13 @@ export function buildDefaultModel(opts: DefaultModelOptions = {}): FellegiSunter
|
|
|
233
255
|
spatial = withTermFrequency(spatial, {
|
|
234
256
|
table: opts.addressFrequency,
|
|
235
257
|
value: (a) => a.address?.raw ?? null,
|
|
236
|
-
levels: [0],
|
|
258
|
+
levels: [0],
|
|
237
259
|
})
|
|
238
260
|
}
|
|
239
261
|
|
|
240
262
|
return { lambda: 0.0001, comparisons: [...identity, spatial] }
|
|
241
263
|
}
|
|
242
264
|
|
|
243
|
-
// Legacy two-signal spatial: address-key similarity + great-circle distance (redundant; A1 collapses it).
|
|
244
265
|
let address = similarityComparison<SourceRecord>({
|
|
245
266
|
name: "address",
|
|
246
267
|
extract: (r) => r.address?.canonicalKey,
|
|
@@ -266,14 +287,15 @@ export function buildDefaultModel(opts: DefaultModelOptions = {}): FellegiSunter
|
|
|
266
287
|
}
|
|
267
288
|
|
|
268
289
|
/**
|
|
269
|
-
* The default blocking keys
|
|
290
|
+
* The default blocking keys include location and canonical address.
|
|
291
|
+
* They also include phone and email.
|
|
270
292
|
*/
|
|
271
293
|
export function defaultBlockingKeys(): BlockingKey<SourceRecord>[] {
|
|
272
294
|
return [
|
|
273
|
-
geoCellKey((r) => r.address?.geocode?.coordinate),
|
|
274
|
-
exactKey((r) => r.address?.canonicalKey),
|
|
275
|
-
exactKey((r) => r.phone),
|
|
276
|
-
exactKey((r) => r.email),
|
|
295
|
+
geoCellKey((r) => r.address?.geocode?.coordinate ?? null),
|
|
296
|
+
exactKey((r) => r.address?.canonicalKey ?? null),
|
|
297
|
+
exactKey((r) => r.phone ?? null),
|
|
298
|
+
exactKey((r) => r.email ?? null),
|
|
277
299
|
]
|
|
278
300
|
}
|
|
279
301
|
|
|
@@ -282,15 +304,21 @@ export function defaultBlockingKeys(): BlockingKey<SourceRecord>[] {
|
|
|
282
304
|
*/
|
|
283
305
|
export interface ResolveConfig {
|
|
284
306
|
/**
|
|
285
|
-
*
|
|
307
|
+
* The model used to score candidate pairs.
|
|
308
|
+
*
|
|
309
|
+
* @defaultValue {@link buildDefaultModel}
|
|
286
310
|
*/
|
|
287
311
|
model?: FellegiSunterModel<SourceRecord>
|
|
288
312
|
/**
|
|
289
|
-
*
|
|
313
|
+
* The blocking keys whose union forms the candidate set.
|
|
314
|
+
*
|
|
315
|
+
* @defaultValue {@link defaultBlockingKeys}
|
|
290
316
|
*/
|
|
291
317
|
blockingKeys?: BlockingKey<SourceRecord>[]
|
|
292
318
|
/**
|
|
293
|
-
* Link two records into the same entity at or above this match weight (bits).
|
|
319
|
+
* Link two records into the same entity at or above this match weight (bits).
|
|
320
|
+
*
|
|
321
|
+
* @defaultValue `0`
|
|
294
322
|
*/
|
|
295
323
|
threshold?: number
|
|
296
324
|
/**
|
|
@@ -298,80 +326,115 @@ export interface ResolveConfig {
|
|
|
298
326
|
*/
|
|
299
327
|
maxBlockSize?: number
|
|
300
328
|
/**
|
|
301
|
-
* Fit the model's `m`/`u` to the candidate pairs with EM before scoring (label-free).
|
|
329
|
+
* Fit the model's `m`/`u` to the candidate pairs with EM before scoring (label-free).
|
|
330
|
+
*
|
|
331
|
+
* @defaultValue `false`
|
|
302
332
|
*/
|
|
303
333
|
trainEM?: boolean
|
|
304
334
|
/**
|
|
305
|
-
* Address-frequency table
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
335
|
+
* Address-frequency table over {@link addressFrequencyKey}, which down-weights address
|
|
336
|
+
* agreement by how shared the address is. **Default-on:** when omitted, `resolveEntities`
|
|
337
|
+
* computes the table over the input records' addresses, the right scope for a single dataset.
|
|
338
|
+
*
|
|
339
|
+
* Pass your own {@link TermFrequencyTable} (for example a corpus-wide one) to override,
|
|
340
|
+
* or `false` to disable (the legacy bare baseline).
|
|
341
|
+
* Ignored if `model` is supplied.
|
|
310
342
|
*/
|
|
311
343
|
addressFrequency?: TermFrequencyTable | false
|
|
312
344
|
/**
|
|
313
|
-
*
|
|
314
|
-
* (true)**
|
|
315
|
-
*
|
|
345
|
+
* Collapse the redundant address-key and distance pair into one {@link spatialComparison}.
|
|
346
|
+
* **Default-on (true)** is the cleaner, less-over-merging spatial model.
|
|
347
|
+
*
|
|
348
|
+
* Set `false` for the legacy two-signal baseline.
|
|
349
|
+
* Ignored if `model` is supplied.
|
|
316
350
|
*/
|
|
317
351
|
collapseSpatial?: boolean
|
|
318
352
|
/**
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
353
|
+
* Require positive name or organization corroboration ({@link CORROBORATING_FIELDS}) for
|
|
354
|
+
* a link, so a shared address cannot merge two records without that corroboration.
|
|
355
|
+
*
|
|
356
|
+
* Suppresses the spatial-only links that fuse distinct co-located providers.
|
|
357
|
+
*
|
|
358
|
+
* @defaultValue `false`
|
|
322
359
|
*/
|
|
323
360
|
requireCorroboration?: boolean
|
|
324
361
|
/**
|
|
325
|
-
*
|
|
326
|
-
*
|
|
362
|
+
* Add a normalized-phone comparison to the default model.
|
|
363
|
+
*
|
|
364
|
+
* Phone agreement provides strong secondary evidence when entity names have drifted.
|
|
365
|
+
*
|
|
366
|
+
* Ignored if `model` is supplied.
|
|
327
367
|
*/
|
|
328
368
|
usePhone?: boolean
|
|
329
369
|
/**
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
370
|
+
* The linkage method used for clustering.
|
|
371
|
+
*
|
|
372
|
+
* `"single"` (default) is connected components, while `"average"` is an average-linkage
|
|
373
|
+
* refinement that splits a component whose sub-clusters are joined only by a weak bridge.
|
|
333
374
|
*/
|
|
334
375
|
linkage?: "single" | "average"
|
|
335
376
|
/**
|
|
336
|
-
* Extra secondary-identifier keys
|
|
337
|
-
* `["authorizedOfficial"]`.
|
|
377
|
+
* Extra secondary-identifier keys from {@link SourceRecord.attributes} to add as
|
|
378
|
+
* comparisons and corroborators, for example `["authorizedOfficial"]`.
|
|
379
|
+
*
|
|
380
|
+
* Ignored if `model` is supplied.
|
|
338
381
|
*/
|
|
339
382
|
discriminators?: string[]
|
|
340
383
|
/**
|
|
341
|
-
* Closed-vocabulary code-
|
|
342
|
-
*
|
|
384
|
+
* Closed-vocabulary code-set discriminator keys ({@link DefaultModelOptions.exactDiscriminators}),
|
|
385
|
+
* which use set-overlap agreement.
|
|
386
|
+
* An example is `["taxonomy"]`.
|
|
387
|
+
*
|
|
388
|
+
* Also corroborators.
|
|
389
|
+
* Ignored if `model` is supplied.
|
|
343
390
|
*/
|
|
344
391
|
exactDiscriminators?: string[]
|
|
345
392
|
/**
|
|
346
|
-
* Override the Fellegi-Sunter link weight with a
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
393
|
+
* Override the Fellegi-Sunter link weight with a learned score.
|
|
394
|
+
*
|
|
395
|
+
* When set, a candidate pair's match weight is this function's return value instead of
|
|
396
|
+
* {@link scorePair}'s, in the same threshold-comparable units as the FS weight.
|
|
397
|
+
* Default is undefined (pure FS).
|
|
351
398
|
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
399
|
+
* The blocking and clustering are unchanged, so a trained scorer can be A/B tested
|
|
400
|
+
* against the FS baseline on the identical pipeline.
|
|
401
|
+
* The function is responsible for its own feature computation, such as the
|
|
402
|
+
* agreement pattern plus any corpus statistics it captured.
|
|
403
|
+
*
|
|
404
|
+
* The corroboration check is independent of the learned score and is still evaluated on
|
|
405
|
+
* the Fellegi-Sunter `contributions`, so a learned-high pair with no positive FS name,
|
|
406
|
+
* organization or phone agreement is still held out.
|
|
407
|
+
*
|
|
408
|
+
* A learned scorer is normally trained to subsume corroboration, so use one or the other.
|
|
409
|
+
* The independent FS check can veto the learned score when both checks run.
|
|
357
410
|
*/
|
|
358
411
|
scorer?: (a: SourceRecord, b: SourceRecord) => number
|
|
359
412
|
/**
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
413
|
+
* The learned gradient-boosted-tree scorer, default-on.
|
|
414
|
+
*
|
|
415
|
+
* Omitted or `true` uses the bundled {@link DEDUP_GBT_MODEL}, which was trained on
|
|
416
|
+
* the NPPES NPI-truth set and beats the Fellegi-Sunter baseline by roughly +5pp dedup
|
|
417
|
+
* F1 held-out within a state and +22pp on states it never trained on.
|
|
418
|
+
*
|
|
419
|
+
* `false` opts out to the pure FS baseline.
|
|
420
|
+
* Pass your own {@link GBT} for a custom model.
|
|
421
|
+
*
|
|
422
|
+
* The scorer is built over the same collapsed-spatial and address-frequency feature
|
|
423
|
+
* model as training, independent of this call's comparison config.
|
|
424
|
+
* An explicit {@link scorer} takes precedence.
|
|
425
|
+
*
|
|
426
|
+
* When the bundled model is active and no {@link threshold} is set,
|
|
427
|
+
* its calibrated link threshold ({@link DEDUP_GBT_META}.recommendedThreshold) is used,
|
|
428
|
+
* because the GBT logit is not in FS-weight units and 0 would over-merge.
|
|
429
|
+
*
|
|
430
|
+
* The model is NPPES/US-trained.
|
|
431
|
+
* For a very different domain, A/B it or pass `false`.
|
|
369
432
|
*/
|
|
370
433
|
learnedScorer?: boolean | GBT
|
|
371
434
|
}
|
|
372
435
|
|
|
373
436
|
/**
|
|
374
|
-
* The
|
|
437
|
+
* The result of a resolve pass.
|
|
375
438
|
*/
|
|
376
439
|
export interface ResolveResult {
|
|
377
440
|
entities: ResolvedEntity[]
|
|
@@ -386,13 +449,12 @@ export interface ResolveResult {
|
|
|
386
449
|
}
|
|
387
450
|
|
|
388
451
|
/**
|
|
389
|
-
* Resolve source records into canonical entities: block
|
|
390
|
-
*
|
|
452
|
+
* Resolve source records into canonical entities: block, score, cluster.
|
|
453
|
+
*
|
|
454
|
+
* Every record belongs to exactly one entity.
|
|
455
|
+
* A record without a confident link forms a singleton entity.
|
|
391
456
|
*/
|
|
392
457
|
export function resolveEntities(records: readonly SourceRecord[], config: ResolveConfig = {}): ResolveResult {
|
|
393
|
-
// The proven changes are DEFAULT-ON (#625): the address-frequency down-weight (auto-computed over the
|
|
394
|
-
// input records when not supplied; `false` disables) + the collapsed spatial signal (A1). A new
|
|
395
|
-
// caller gets the strong config out of the box; pass explicit values to override.
|
|
396
458
|
const addressFrequency =
|
|
397
459
|
config.addressFrequency === false
|
|
398
460
|
? undefined
|
|
@@ -416,11 +478,6 @@ export function resolveEntities(records: readonly SourceRecord[], config: Resolv
|
|
|
416
478
|
|
|
417
479
|
const blockingKeys = config.blockingKeys ?? defaultBlockingKeys()
|
|
418
480
|
|
|
419
|
-
// #603: the learned scorer is DEFAULT-ON. An explicit `scorer` overrides everything; otherwise
|
|
420
|
-
// `learnedScorer === false` opts out to the FS baseline, a GBT supplies a custom model, and
|
|
421
|
-
// `true`/omitted uses the bundled DEDUP_GBT_MODEL. The scorer is built over the FIXED
|
|
422
|
-
// collapsed-spatial + address-frequency feature model (matching training, independent of this call's
|
|
423
|
-
// comparison config), using the resolved address-frequency table.
|
|
424
481
|
let scorer = config.scorer
|
|
425
482
|
let usingBundledModel = false
|
|
426
483
|
|
|
@@ -437,8 +494,10 @@ export function resolveEntities(records: readonly SourceRecord[], config: Resolv
|
|
|
437
494
|
})
|
|
438
495
|
}
|
|
439
496
|
|
|
440
|
-
//
|
|
441
|
-
//
|
|
497
|
+
// An explicit threshold wins.
|
|
498
|
+
// Otherwise the bundled model uses its calibrated threshold, because its logit
|
|
499
|
+
// is not in FS-weight units and 0 would over-merge.
|
|
500
|
+
// The FS baseline or a custom model uses 0.
|
|
442
501
|
const threshold = config.threshold ?? (usingBundledModel ? DEDUP_GBT_META.recommendedThreshold : 0)
|
|
443
502
|
|
|
444
503
|
const { pairs, droppedBlocks } = block(records, blockingKeys, { maxBlockSize: config.maxBlockSize })
|
|
@@ -452,12 +511,10 @@ export function resolveEntities(records: readonly SourceRecord[], config: Resolv
|
|
|
452
511
|
|
|
453
512
|
const links: ScoredLink<SourceRecord>[] = pairs.map(([a, b]) => {
|
|
454
513
|
const score = scorePair(scoringModel, a, b)
|
|
455
|
-
// #603: a learned scorer (explicit `scorer` or the opt-in `learnedScorer`) replaces the FS weight
|
|
456
|
-
// (same clustering + threshold semantics).
|
|
457
514
|
let weight = scorer ? scorer(a, b) : score.weight
|
|
458
515
|
|
|
459
|
-
//
|
|
460
|
-
// address
|
|
516
|
+
// A link requires positive name or organization corroboration, since a shared
|
|
517
|
+
// address provides no identity evidence by itself.
|
|
461
518
|
if (config.requireCorroboration) {
|
|
462
519
|
const corroborated = score.contributions.some(
|
|
463
520
|
(c) => (CORROBORATING_FIELDS.has(c.name) || c.name.startsWith("attr:")) && c.weight > 0
|
|
@@ -473,9 +530,9 @@ export function resolveEntities(records: readonly SourceRecord[], config: Resolv
|
|
|
473
530
|
|
|
474
531
|
const clusters = cluster(records, links, { threshold, linkage: config.linkage })
|
|
475
532
|
|
|
476
|
-
// Cohesion
|
|
477
|
-
// in
|
|
478
|
-
//
|
|
533
|
+
// Cohesion is the weakest within-cluster link weight.
|
|
534
|
+
// Compute it in one pass over links with a record-to-cluster index, because filtering
|
|
535
|
+
// every link for every cluster is O(clusters x links) and dominates the resolve at scale.
|
|
479
536
|
const clusterOf = new Map<SourceRecord, number>()
|
|
480
537
|
|
|
481
538
|
clusters.forEach((group, i) => {
|
|
@@ -504,7 +561,7 @@ export function resolveEntities(records: readonly SourceRecord[], config: Resolv
|
|
|
504
561
|
id: `entity-${i}`,
|
|
505
562
|
records: group,
|
|
506
563
|
representative: rep,
|
|
507
|
-
coordinate: rep.address?.geocode?.coordinate ??
|
|
564
|
+
coordinate: rep.address?.geocode?.coordinate ?? null,
|
|
508
565
|
cohesion: group.length > 1 && minIntraWeight[i]! !== Infinity ? minIntraWeight[i]! : null,
|
|
509
566
|
}
|
|
510
567
|
})
|