@mailwoman/registry 9.1.0 → 9.3.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 +2 -2
- package/{address-key.ts → lib/address-key.ts} +1 -1
- package/{geocode-handler.ts → lib/geocode-handler.ts} +7 -7
- package/{geojson.ts → lib/geojson.ts} +12 -6
- package/{index.ts → lib/index.ts} +10 -10
- package/{ingest.ts → lib/ingest.ts} +77 -69
- package/{learned-scorer.ts → lib/learned-scorer.ts} +1 -1
- package/{map-html.ts → lib/map-html.ts} +10 -16
- package/{reconcile.ts → lib/reconcile.ts} +9 -24
- package/{resolve.ts → lib/resolve.ts} +31 -13
- package/{tools → lib/tools}/coverage-reconciliation.ts +13 -15
- package/{tools → lib/tools}/cross-dataset-correlation.ts +64 -139
- package/{tools → lib/tools}/cross-source-threshold-sweep.ts +21 -32
- package/{tools → lib/tools}/dedup-ceiling.ts +33 -144
- package/{tools → lib/tools}/eval-geocoder.ts +10 -11
- package/{tools → lib/tools}/geocoder-namesake-probe.ts +5 -12
- package/{tools → lib/tools}/geocoder-vs-provided-coords.ts +12 -11
- package/lib/tools/gold-set-sample.ts +141 -0
- package/lib/tools/index.ts +31 -0
- package/{tools → lib/tools}/learned-scorer-clustering-eval.ts +71 -260
- package/{tools → lib/tools}/learned-scorer-crossstate-eval.ts +62 -245
- package/{tools → lib/tools}/learned-scorer-eval.ts +64 -263
- package/{tools → lib/tools}/matcher-scale.ts +5 -5
- package/lib/tools/nppes/org-name.ts +23 -0
- package/lib/tools/nppes/overmerge-packet.ts +94 -0
- package/lib/tools/nppes/report.ts +373 -0
- package/lib/tools/nppes/sample.ts +245 -0
- package/lib/tools/nppes/scoring.ts +114 -0
- package/lib/tools/nppes/settings.ts +102 -0
- package/lib/tools/nppes/truth-grains.ts +161 -0
- package/lib/tools/nppes-dedup-benchmark.ts +408 -0
- package/lib/tools/shared.ts +763 -0
- package/lib/tools/train-cross-gbt.ts +209 -0
- package/{tools → lib/tools}/train-gbt.ts +38 -156
- package/lib/tools/train-org-cross-gbt.ts +179 -0
- package/{tools → lib/tools}/txhhsc-to-oarow.ts +10 -28
- package/lib/tools/viz/browser.ts +50 -0
- package/{tools → lib/tools}/viz/cross-dataset-map.ts +16 -39
- package/{tools → lib/tools}/viz/geocode-first-surface.ts +13 -39
- package/{tools → lib/tools}/viz/render-map.ts +10 -23
- package/lib/tools/viz/render.ts +98 -0
- package/{tools → lib/tools}/viz/source-provenance-map.ts +20 -39
- package/{tools → lib/tools}/viz/yardstick-figure.ts +6 -5
- package/{types.ts → lib/types.ts} +10 -1
- package/out/address-key.d.ts +1 -1
- package/out/address-key.d.ts.map +1 -1
- package/out/address-key.js.map +1 -1
- package/out/geocode-handler.d.ts +6 -6
- package/out/geocode-handler.d.ts.map +1 -1
- package/out/geocode-handler.js +6 -6
- package/out/geocode-handler.js.map +1 -1
- package/out/geojson.d.ts +7 -2
- package/out/geojson.d.ts.map +1 -1
- package/out/geojson.js +8 -5
- package/out/geojson.js.map +1 -1
- package/out/index.d.ts +10 -10
- package/out/index.d.ts.map +1 -1
- package/out/index.js +10 -10
- package/out/index.js.map +1 -1
- package/out/ingest.d.ts +64 -46
- package/out/ingest.d.ts.map +1 -1
- package/out/ingest.js +33 -46
- package/out/ingest.js.map +1 -1
- package/out/learned-scorer.d.ts +1 -1
- package/out/learned-scorer.d.ts.map +1 -1
- package/out/learned-scorer.js.map +1 -1
- package/out/map-html.d.ts +4 -4
- package/out/map-html.d.ts.map +1 -1
- package/out/map-html.js +6 -11
- package/out/map-html.js.map +1 -1
- package/out/models/crosssource-gbt-en-us.d.ts.map +1 -1
- package/out/models/crosssource-gbt-en-us.js.map +1 -1
- package/out/models/dedup-gbt-en-us.d.ts.map +1 -1
- package/out/models/dedup-gbt-en-us.js.map +1 -1
- package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -1
- package/out/models/org-crosssource-gbt-en-us.js.map +1 -1
- package/out/reconcile.d.ts +6 -1
- package/out/reconcile.d.ts.map +1 -1
- package/out/reconcile.js +7 -21
- package/out/reconcile.js.map +1 -1
- package/out/resolve.d.ts +19 -7
- package/out/resolve.d.ts.map +1 -1
- package/out/resolve.js +20 -6
- package/out/resolve.js.map +1 -1
- package/out/tools/coverage-reconciliation.d.ts +1 -1
- package/out/tools/coverage-reconciliation.d.ts.map +1 -1
- package/out/tools/coverage-reconciliation.js +12 -12
- package/out/tools/coverage-reconciliation.js.map +1 -1
- package/out/tools/cross-dataset-correlation.d.ts +4 -4
- package/out/tools/cross-dataset-correlation.d.ts.map +1 -1
- package/out/tools/cross-dataset-correlation.js +60 -111
- package/out/tools/cross-dataset-correlation.js.map +1 -1
- package/out/tools/cross-source-threshold-sweep.d.ts +2 -2
- package/out/tools/cross-source-threshold-sweep.d.ts.map +1 -1
- package/out/tools/cross-source-threshold-sweep.js +19 -27
- package/out/tools/cross-source-threshold-sweep.js.map +1 -1
- package/out/tools/dedup-ceiling.d.ts.map +1 -1
- package/out/tools/dedup-ceiling.js +36 -118
- package/out/tools/dedup-ceiling.js.map +1 -1
- package/out/tools/eval-geocoder.d.ts +9 -13
- package/out/tools/eval-geocoder.d.ts.map +1 -1
- package/out/tools/eval-geocoder.js +2 -2
- package/out/tools/eval-geocoder.js.map +1 -1
- package/out/tools/geocoder-namesake-probe.d.ts +2 -2
- package/out/tools/geocoder-namesake-probe.d.ts.map +1 -1
- package/out/tools/geocoder-namesake-probe.js +4 -8
- package/out/tools/geocoder-namesake-probe.js.map +1 -1
- package/out/tools/geocoder-vs-provided-coords.d.ts +1 -1
- package/out/tools/geocoder-vs-provided-coords.d.ts.map +1 -1
- package/out/tools/geocoder-vs-provided-coords.js +11 -9
- package/out/tools/geocoder-vs-provided-coords.js.map +1 -1
- package/out/tools/gold-set-sample.d.ts +5 -5
- package/out/tools/gold-set-sample.d.ts.map +1 -1
- package/out/tools/gold-set-sample.js +37 -121
- package/out/tools/gold-set-sample.js.map +1 -1
- package/out/tools/index.d.ts +24 -29
- package/out/tools/index.d.ts.map +1 -1
- package/out/tools/index.js +24 -29
- package/out/tools/index.js.map +1 -1
- package/out/tools/learned-scorer-clustering-eval.d.ts +1 -1
- package/out/tools/learned-scorer-clustering-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-clustering-eval.js +35 -170
- package/out/tools/learned-scorer-clustering-eval.js.map +1 -1
- package/out/tools/learned-scorer-crossstate-eval.d.ts +5 -5
- package/out/tools/learned-scorer-crossstate-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-crossstate-eval.js +44 -166
- package/out/tools/learned-scorer-crossstate-eval.js.map +1 -1
- package/out/tools/learned-scorer-eval.d.ts +1 -1
- package/out/tools/learned-scorer-eval.d.ts.map +1 -1
- package/out/tools/learned-scorer-eval.js +37 -173
- package/out/tools/learned-scorer-eval.js.map +1 -1
- package/out/tools/matcher-scale.d.ts.map +1 -1
- package/out/tools/matcher-scale.js +5 -5
- package/out/tools/matcher-scale.js.map +1 -1
- package/out/tools/nppes/org-name.d.ts +21 -0
- package/out/tools/nppes/org-name.d.ts.map +1 -0
- package/out/tools/nppes/org-name.js +13 -0
- package/out/tools/nppes/org-name.js.map +1 -0
- package/out/tools/nppes/overmerge-packet.d.ts +39 -0
- package/out/tools/nppes/overmerge-packet.d.ts.map +1 -0
- package/out/tools/nppes/overmerge-packet.js +55 -0
- package/out/tools/nppes/overmerge-packet.js.map +1 -0
- package/out/tools/nppes/report.d.ts +93 -0
- package/out/tools/nppes/report.d.ts.map +1 -0
- package/out/tools/nppes/report.js +186 -0
- package/out/tools/nppes/report.js.map +1 -0
- package/out/tools/nppes/sample.d.ts +90 -0
- package/out/tools/nppes/sample.d.ts.map +1 -0
- package/out/tools/nppes/sample.js +131 -0
- package/out/tools/nppes/sample.js.map +1 -0
- package/out/tools/nppes/scoring.d.ts +36 -0
- package/out/tools/nppes/scoring.d.ts.map +1 -0
- package/out/tools/nppes/scoring.js +80 -0
- package/out/tools/nppes/scoring.js.map +1 -0
- package/out/tools/nppes/settings.d.ts +38 -0
- package/out/tools/nppes/settings.d.ts.map +1 -0
- package/out/tools/nppes/settings.js +79 -0
- package/out/tools/nppes/settings.js.map +1 -0
- package/out/tools/nppes/truth-grains.d.ts +50 -0
- package/out/tools/nppes/truth-grains.d.ts.map +1 -0
- package/out/tools/nppes/truth-grains.js +123 -0
- package/out/tools/nppes/truth-grains.js.map +1 -0
- package/out/tools/nppes-dedup-benchmark.d.ts +7 -3
- package/out/tools/nppes-dedup-benchmark.d.ts.map +1 -1
- package/out/tools/nppes-dedup-benchmark.js +106 -673
- package/out/tools/nppes-dedup-benchmark.js.map +1 -1
- package/out/tools/shared.d.ts +244 -7
- package/out/tools/shared.d.ts.map +1 -1
- package/out/tools/shared.js +353 -21
- package/out/tools/shared.js.map +1 -1
- package/out/tools/train-cross-gbt.d.ts +7 -7
- package/out/tools/train-cross-gbt.d.ts.map +1 -1
- package/out/tools/train-cross-gbt.js +47 -145
- package/out/tools/train-cross-gbt.js.map +1 -1
- package/out/tools/train-gbt.d.ts +7 -7
- package/out/tools/train-gbt.d.ts.map +1 -1
- package/out/tools/train-gbt.js +31 -111
- package/out/tools/train-gbt.js.map +1 -1
- package/out/tools/train-org-cross-gbt.d.ts +7 -5
- package/out/tools/train-org-cross-gbt.d.ts.map +1 -1
- package/out/tools/train-org-cross-gbt.js +45 -141
- package/out/tools/train-org-cross-gbt.js.map +1 -1
- package/out/tools/txhhsc-to-oarow.d.ts +2 -2
- package/out/tools/txhhsc-to-oarow.d.ts.map +1 -1
- package/out/tools/txhhsc-to-oarow.js +9 -23
- package/out/tools/txhhsc-to-oarow.js.map +1 -1
- package/out/tools/viz/browser.d.ts +34 -0
- package/out/tools/viz/browser.d.ts.map +1 -0
- package/out/tools/viz/browser.js +33 -0
- package/out/tools/viz/browser.js.map +1 -0
- package/out/tools/viz/cross-dataset-map.d.ts +4 -25
- package/out/tools/viz/cross-dataset-map.d.ts.map +1 -1
- package/out/tools/viz/cross-dataset-map.js +12 -33
- package/out/tools/viz/cross-dataset-map.js.map +1 -1
- package/out/tools/viz/geocode-first-surface.d.ts +6 -35
- package/out/tools/viz/geocode-first-surface.d.ts.map +1 -1
- package/out/tools/viz/geocode-first-surface.js +10 -37
- package/out/tools/viz/geocode-first-surface.js.map +1 -1
- package/out/tools/viz/render-map.d.ts +3 -6
- package/out/tools/viz/render-map.d.ts.map +1 -1
- package/out/tools/viz/render-map.js +9 -19
- package/out/tools/viz/render-map.js.map +1 -1
- package/out/tools/viz/render.d.ts +4 -9
- package/out/tools/viz/render.d.ts.map +1 -1
- package/out/tools/viz/render.js +24 -39
- package/out/tools/viz/render.js.map +1 -1
- package/out/tools/viz/source-provenance-map.d.ts +4 -24
- package/out/tools/viz/source-provenance-map.d.ts.map +1 -1
- package/out/tools/viz/source-provenance-map.js +12 -32
- package/out/tools/viz/source-provenance-map.js.map +1 -1
- package/out/tools/viz/yardstick-figure.d.ts +2 -2
- package/out/tools/viz/yardstick-figure.d.ts.map +1 -1
- package/out/tools/viz/yardstick-figure.js +5 -4
- package/out/tools/viz/yardstick-figure.js.map +1 -1
- package/out/types.d.ts +11 -1
- package/out/types.d.ts.map +1 -1
- package/out/types.js.map +1 -1
- package/package.json +180 -11
- package/tools/gold-set-sample.ts +0 -252
- package/tools/index.ts +0 -36
- package/tools/nppes-dedup-benchmark.ts +0 -1180
- package/tools/shared.ts +0 -160
- package/tools/train-cross-gbt.ts +0 -358
- package/tools/train-org-cross-gbt.ts +0 -329
- package/tools/viz/render.ts +0 -113
- /package/{models → lib/models}/crosssource-gbt-en-us.ts +0 -0
- /package/{models → lib/models}/dedup-gbt-en-us.ts +0 -0
- /package/{models → lib/models}/org-crosssource-gbt-en-us.ts +0 -0
package/README.md
CHANGED
|
@@ -95,7 +95,7 @@ mailwoman registry --sources tx-nppes.json --reconcile tx-fcc.json --resolve-db
|
|
|
95
95
|
`$MAILWOMAN_CANDIDATE_DB` is set. `resolveWOFPath` throws before anything opens; `createResolverBackend`
|
|
96
96
|
then prefers the candidate backend and never touches the WOF path (`run.tsx`'s own inline comment states
|
|
97
97
|
this correctly: "`$MAILWOMAN_CANDIDATE_DB` → the demo-parity candidate backend; else FTS over wofPath").
|
|
98
|
-
A nonexistent path
|
|
98
|
+
A nonexistent path satisfies that requirement.
|
|
99
99
|
|
|
100
100
|
So: set `$MAILWOMAN_CANDIDATE_DB` and pass anything to `--resolve-db`. Do NOT pass `candidate.db` to
|
|
101
101
|
`--resolve-db` with the environment variable unset — the flag is believed on that path, and the admin
|
|
@@ -111,7 +111,7 @@ Fellegi-Sunter baseline rather than the bundled model's calibrated 2.8324, and `
|
|
|
111
111
|
- [`@mailwoman/match`](../match) — the low-level block/score/cluster primitives
|
|
112
112
|
- [`@mailwoman/record`](../record) — `SourceRecord` schema and normalizers
|
|
113
113
|
- [`@mailwoman/address-id`](../address-id) — exact-match join key
|
|
114
|
-
- [Match messy records to one entity each](https://mailwoman.
|
|
114
|
+
- [Match messy records to one entity each](https://mailwoman.ai/docs/developers/how-to/match-messy-records)
|
|
115
115
|
|
|
116
116
|
## License
|
|
117
117
|
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import { createPostalAddressID, type PostalAddressID } from "@mailwoman/address-id"
|
|
18
18
|
import { type BlockingKey, exactKey } from "@mailwoman/match"
|
|
19
19
|
|
|
20
|
-
import type { SourceRecord } from "
|
|
20
|
+
import type { SourceRecord } from "#types"
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* The stable address primary key for a record, or null when it isn't geocoded (no coordinate → no locality cell) or
|
|
@@ -3,21 +3,21 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* The per-record geocode step, factored out of the worker so it unit-tests against a fake
|
|
7
|
-
* neural model / SQLite). `geocode-worker.ts` builds the real
|
|
6
|
+
* The per-record geocode step, factored out of the worker so it unit-tests against a fake geocoder (no
|
|
7
|
+
* neural model / SQLite). `geocode-worker.ts` builds the real geocoder from config and wraps this.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { type ColumnMapping, type GeocodeAddress, pick } from "
|
|
11
|
-
import type { SourceRecord } from "
|
|
10
|
+
import { type ColumnMapping, type GeocodeAddress, pick } from "#ingest"
|
|
11
|
+
import type { SourceRecord } from "#types"
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Build the handler `geocodeStream` runs per normalized record: recompute the joined address string from `record.raw` +
|
|
15
|
-
* `mapping.address` (the worker can't receive the original closure), geocode it via `
|
|
15
|
+
* `mapping.address` (the worker can't receive the original closure), geocode it via `geocode`, and attach the result.
|
|
16
16
|
* Records with no mapped address pass through untouched (no geocode call). The default separator matches
|
|
17
17
|
* {@link ingestRow}'s `addressSeparator`.
|
|
18
18
|
*/
|
|
19
19
|
export function makeGeocodeHandler(
|
|
20
|
-
|
|
20
|
+
geocode: GeocodeAddress,
|
|
21
21
|
mapping: ColumnMapping,
|
|
22
22
|
addressSeparator = ", "
|
|
23
23
|
): (record: SourceRecord) => Promise<SourceRecord> {
|
|
@@ -28,7 +28,7 @@ export function makeGeocodeHandler(
|
|
|
28
28
|
|
|
29
29
|
if (!addressValue) return record
|
|
30
30
|
|
|
31
|
-
const address = (await
|
|
31
|
+
const address = (await geocode(addressValue)) ?? undefined
|
|
32
32
|
|
|
33
33
|
return { ...record, address }
|
|
34
34
|
}
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
* a coordinate are omitted (a Point feature needs one).
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import { isPresent } from "@mailwoman/core/objects"
|
|
13
14
|
import type { GeoFeature, GeoFeatureCollection, PointLiteral } from "@mailwoman/spatial"
|
|
14
15
|
|
|
15
|
-
import type { EntityGeoData, ResolvedEntity, SourceRecord } from "
|
|
16
|
+
import type { EntityGeoData, ResolvedEntity, SourceRecord } from "#types"
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Assemble a display name from a record's parsed person name, if any.
|
|
@@ -23,7 +24,7 @@ function displayName(record: SourceRecord): string | null {
|
|
|
23
24
|
if (!name) return null
|
|
24
25
|
|
|
25
26
|
const joined = [name.prefix, name.given, name.middle, name.familyParticle, name.family, name.suffix]
|
|
26
|
-
.filter(
|
|
27
|
+
.filter(isPresent)
|
|
27
28
|
.join(" ")
|
|
28
29
|
.trim()
|
|
29
30
|
|
|
@@ -31,9 +32,13 @@ function displayName(record: SourceRecord): string | null {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
|
-
* One entity → one GeoJSON Point feature.
|
|
35
|
+
* One entity → one GeoJSON Point feature. `extra` merges over (and may override) the standard properties — the
|
|
36
|
+
* reconciliation flow adds its `bucket` and swaps the display name for the representative's org-or-person form.
|
|
35
37
|
*/
|
|
36
|
-
function toFeature(
|
|
38
|
+
export function toFeature(
|
|
39
|
+
entity: ResolvedEntity,
|
|
40
|
+
extra?: Partial<EntityGeoData>
|
|
41
|
+
): GeoFeature<PointLiteral, EntityGeoData> {
|
|
37
42
|
const rep = entity.representative
|
|
38
43
|
|
|
39
44
|
return {
|
|
@@ -47,13 +52,14 @@ function toFeature(entity: ResolvedEntity): GeoFeature<PointLiteral, EntityGeoDa
|
|
|
47
52
|
entityID: entity.id,
|
|
48
53
|
recordCount: entity.records.length,
|
|
49
54
|
cohesion: entity.cohesion,
|
|
50
|
-
|
|
55
|
+
sourceIDs: entity.records.map((r) => r.id),
|
|
51
56
|
// Distinct provenance labels the entity's records span — an entity with ≥2 is a cross-dataset link.
|
|
52
57
|
sources: [...new Set(entity.records.map((r) => r.source).filter((s): s is string => !!s))].toSorted(),
|
|
53
58
|
name: displayName(rep),
|
|
54
59
|
organization: rep.organization?.canonical ?? null,
|
|
55
60
|
address: rep.address?.formatted ?? null,
|
|
56
61
|
geocodeTier: rep.address?.geocode?.tier ?? null,
|
|
62
|
+
...extra,
|
|
57
63
|
},
|
|
58
64
|
}
|
|
59
65
|
}
|
|
@@ -65,6 +71,6 @@ function toFeature(entity: ResolvedEntity): GeoFeature<PointLiteral, EntityGeoDa
|
|
|
65
71
|
export function toGeoJSON(entities: readonly ResolvedEntity[]): GeoFeatureCollection<PointLiteral, EntityGeoData> {
|
|
66
72
|
return {
|
|
67
73
|
type: "FeatureCollection",
|
|
68
|
-
features: entities.filter((entity) => entity.coordinate).map(toFeature),
|
|
74
|
+
features: entities.filter((entity) => entity.coordinate).map((entity) => toFeature(entity)),
|
|
69
75
|
}
|
|
70
76
|
}
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
* for, finally standing on a calibrated, label-free matcher.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
export * from "
|
|
15
|
-
export * from "
|
|
16
|
-
export * from "
|
|
17
|
-
export * from "
|
|
18
|
-
export * from "
|
|
19
|
-
export * from "
|
|
20
|
-
export * from "
|
|
21
|
-
export * from "
|
|
22
|
-
export * from "
|
|
23
|
-
export * from "
|
|
14
|
+
export * from "#address-key"
|
|
15
|
+
export * from "#geojson"
|
|
16
|
+
export * from "#ingest"
|
|
17
|
+
export * from "#geocode-handler"
|
|
18
|
+
export * from "#learned-scorer"
|
|
19
|
+
export * from "#map-html"
|
|
20
|
+
export * from "#models/dedup-gbt-en-us"
|
|
21
|
+
export * from "#reconcile"
|
|
22
|
+
export * from "#resolve"
|
|
23
|
+
export * from "#types"
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
* hold the name, organization, address, phone, email; each row is normalized with
|
|
13
13
|
* `@mailwoman/record` (parse the person name, canonicalize the org). This is deterministic
|
|
14
14
|
* and testable with no heavy runtime.
|
|
15
|
-
* 2. **Geocoding** (the heavy part) is an injected
|
|
16
|
-
* Ingest never imports the neural parser, the resolver, or the
|
|
17
|
-
*
|
|
15
|
+
* 2. **Geocoding** (the heavy part) is an injected dependency — a {@link GeocodeAddress} the caller provides.
|
|
16
|
+
* Ingest never imports the neural parser, the resolver, or the extracts; it just calls the
|
|
17
|
+
* call per address. {@link geocodeAddressVia} builds that geocoder from mailwoman's real parse +
|
|
18
18
|
* geocode primitives (which the CLI constructs with the model + data in hand), so the wiring
|
|
19
19
|
* is concrete and testable without pinning the heavy runtime into this package.
|
|
20
20
|
*
|
|
@@ -22,21 +22,33 @@
|
|
|
22
22
|
* fast-follow; the mapping is an explicit input here.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
+
import { isPresent } from "@mailwoman/core/objects"
|
|
25
26
|
import type { AddressGeocode, PostalAddress } from "@mailwoman/record"
|
|
26
27
|
import { canonicalizeOrganizationName, parsePersonName, toPostalAddress, withGeocode } from "@mailwoman/record"
|
|
27
|
-
import { CSVSpliterator, Delimiters } from "spliterator"
|
|
28
|
+
import { type AsyncSequence, CSVSpliterator, Delimiters } from "spliterator"
|
|
28
29
|
|
|
29
|
-
import type { SourceRecord } from "
|
|
30
|
+
import type { SourceRecord } from "#types"
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
|
-
* Resolve a raw address string into a {@link PostalAddress}. The
|
|
33
|
+
* Resolve a raw address string into a {@link PostalAddress}. The entry point to mailwoman's geocoder.
|
|
33
34
|
*/
|
|
34
35
|
export type GeocodeAddress = (raw: string) => Promise<PostalAddress | null> | PostalAddress | null
|
|
35
36
|
|
|
37
|
+
/**
|
|
38
|
+
* The column delimiters a tabular source may declare, by name, each the spliterator's own byte.
|
|
39
|
+
*
|
|
40
|
+
* The `satisfies` clause keys every name to a member of spliterator's `Delimiters` const, so a delimiter this map names
|
|
41
|
+
* that spliterator no longer ships is a compile error rather than a silently parallel vocabulary.
|
|
42
|
+
*/
|
|
43
|
+
const COLUMN_DELIMITERS = {
|
|
44
|
+
comma: Delimiters.Comma,
|
|
45
|
+
tab: Delimiters.Tab,
|
|
46
|
+
} as const satisfies Partial<Record<Lowercase<keyof typeof Delimiters>, (typeof Delimiters)[keyof typeof Delimiters]>>
|
|
47
|
+
|
|
36
48
|
/**
|
|
37
49
|
* Column delimiter of a delimited source.
|
|
38
50
|
*/
|
|
39
|
-
export type Delimiter =
|
|
51
|
+
export type Delimiter = keyof typeof COLUMN_DELIMITERS
|
|
40
52
|
|
|
41
53
|
/**
|
|
42
54
|
* Infer the delimiter from a path's extension (`.tsv` → tab, else comma).
|
|
@@ -46,28 +58,20 @@ export function delimiterFor(path: string): Delimiter {
|
|
|
46
58
|
}
|
|
47
59
|
|
|
48
60
|
/**
|
|
49
|
-
* Stream a delimited file's rows lazily as header-keyed objects
|
|
50
|
-
* **without loading the file into memory**. A multi-GB source (the NPPES registry is ~4.8 GB / 9.6M rows — too big for
|
|
51
|
-
* `readFileSync`, which throws `ERR_STRING_TOO_LONG`) streams line by line. Keys are the original header names
|
|
52
|
-
* (`normalizeKeys: false`) so a {@link ColumnMapping} written against the source's headers matches. Filter/sample the
|
|
53
|
-
* stream before {@link ingestRows} to keep only the rows you geocode.
|
|
61
|
+
* Stream a delimited file's rows lazily as header-keyed objects.
|
|
54
62
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* which dropped empty fields and mis-parsed quotes.) Missing trailing fields land as `""`, matching the header
|
|
60
|
-
* contract. For small in-memory parses {@link parseCSV} remains.
|
|
63
|
+
* Returns the spliterator's own {@linkcode AsyncSequence}: nothing is opened until something iterates, a `take` that is
|
|
64
|
+
* satisfied (or a `break` out of `for await`) closes the file handle, and any `map`/`filter` a caller composes fuses
|
|
65
|
+
* into the same pull loop. Wrapping this in an `async function*` would cost an async frame per row and take those
|
|
66
|
+
* operators away.
|
|
61
67
|
*/
|
|
62
|
-
export
|
|
68
|
+
export function streamRows(
|
|
63
69
|
source: string,
|
|
64
70
|
opts: { delimiter?: Delimiter } = {}
|
|
65
|
-
):
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
yield* CSVSpliterator.fromAsync<Record<string, string>>(source, {
|
|
71
|
+
): AsyncSequence<Record<string, string>> {
|
|
72
|
+
return CSVSpliterator.fromAsync<Record<string, string>>(source, {
|
|
69
73
|
mode: "object",
|
|
70
|
-
columnDelimiter,
|
|
74
|
+
columnDelimiter: COLUMN_DELIMITERS[opts.delimiter ?? delimiterFor(source)],
|
|
71
75
|
normalizeKeys: false,
|
|
72
76
|
enableQuoteHandling: true,
|
|
73
77
|
})
|
|
@@ -168,7 +172,7 @@ export function inferMapping(header: readonly string[]): ColumnMapping {
|
|
|
168
172
|
*/
|
|
169
173
|
export interface IngestOptions {
|
|
170
174
|
/**
|
|
171
|
-
* The geocoding
|
|
175
|
+
* The geocoding interface. Without it, records carry name/org but no resolved address.
|
|
172
176
|
*/
|
|
173
177
|
geocodeAddress?: GeocodeAddress
|
|
174
178
|
/**
|
|
@@ -183,19 +187,6 @@ export interface IngestOptions {
|
|
|
183
187
|
addressSeparator?: string
|
|
184
188
|
}
|
|
185
189
|
|
|
186
|
-
/**
|
|
187
|
-
* Parse a CSV string (with a header row) into row objects keyed by column name.
|
|
188
|
-
*
|
|
189
|
-
* Keys and values are trimmed, and keys keep the source's own header spelling so a {@link ColumnMapping} written against
|
|
190
|
-
* those headers matches — the same contract {@link streamRows} holds for the streaming path.
|
|
191
|
-
*/
|
|
192
|
-
export function parseCSV(text: string): Record<string, string>[] {
|
|
193
|
-
return Array.from(
|
|
194
|
-
CSVSpliterator.from(text, { mode: "object", normalizeKeys: false, enableQuoteHandling: true }),
|
|
195
|
-
(row) => Object.fromEntries(Object.entries(row).map(([key, value]) => [key.trim(), String(value ?? "").trim()]))
|
|
196
|
-
)
|
|
197
|
-
}
|
|
198
|
-
|
|
199
190
|
/**
|
|
200
191
|
* Join the named column(s) of a row into a single trimmed string, or undefined if empty.
|
|
201
192
|
*/
|
|
@@ -205,7 +196,7 @@ export function pick(row: Record<string, string>, columns?: string | string[], s
|
|
|
205
196
|
|
|
206
197
|
const value = list
|
|
207
198
|
.map((c) => row[c]?.trim())
|
|
208
|
-
.filter(
|
|
199
|
+
.filter(isPresent)
|
|
209
200
|
.join(separator)
|
|
210
201
|
.trim()
|
|
211
202
|
|
|
@@ -215,7 +206,7 @@ export function pick(row: Record<string, string>, columns?: string | string[], s
|
|
|
215
206
|
/**
|
|
216
207
|
* Normalize one tabular row into a {@link SourceRecord} under a {@link ColumnMapping}: parse the person name,
|
|
217
208
|
* canonicalize the org, and (if `opts.geocodeAddress` is provided) geocode the joined address. `id` falls back to the
|
|
218
|
-
* caller-supplied row index. Pure aside from the optional geocode
|
|
209
|
+
* caller-supplied row index. Pure aside from the optional geocode interface, so the deterministic normalization can run
|
|
219
210
|
* single-threaded (see {@link normalizeCSV}) while geocoding is offloaded (see `geocodeStream`).
|
|
220
211
|
*/
|
|
221
212
|
export async function ingestRow(
|
|
@@ -255,8 +246,9 @@ export async function ingestRow(
|
|
|
255
246
|
}
|
|
256
247
|
|
|
257
248
|
/**
|
|
258
|
-
* Normalize tabular rows into {@link SourceRecord}s under a {@link ColumnMapping}.
|
|
259
|
-
*
|
|
249
|
+
* Normalize tabular rows into {@link SourceRecord}s under a {@link ColumnMapping}.
|
|
250
|
+
*
|
|
251
|
+
* @see {@link streamRows} for the streaming path, which is the preferred way to handle multi-GB files.
|
|
260
252
|
*/
|
|
261
253
|
export async function ingestRows(
|
|
262
254
|
rows: Iterable<Record<string, string>> | AsyncIterable<Record<string, string>>,
|
|
@@ -280,18 +272,15 @@ export async function ingestRows(
|
|
|
280
272
|
* This is the single-threaded, "fast enough" ergonomic core: column mapping, name parsing, and org canonicalization for
|
|
281
273
|
* a multi-GB file, line by line. Geocode separately by piping the output through `geocodeStream` (the only heavy step
|
|
282
274
|
* worth threading); for a light file (e.g. one that already carries geo cells) just consume this and stop.
|
|
275
|
+
*
|
|
276
|
+
* Records come out in file order: the sequence's `map` settles each row before pulling the next, and its counter is the
|
|
277
|
+
* row's index — the id a row without a mapped `id` column falls back to.
|
|
283
278
|
*/
|
|
284
|
-
export
|
|
279
|
+
export function normalizeCSV(
|
|
285
280
|
source: string,
|
|
286
281
|
opts: { mapping: ColumnMapping; delimiter?: Delimiter }
|
|
287
|
-
):
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
for await (const row of streamRows(source, { delimiter: opts.delimiter })) {
|
|
291
|
-
yield await ingestRow(row, opts.mapping, index)
|
|
292
|
-
|
|
293
|
-
index++
|
|
294
|
-
}
|
|
282
|
+
): AsyncSequence<SourceRecord> {
|
|
283
|
+
return streamRows(source, { delimiter: opts.delimiter }).map((row, index) => ingestRow(row, opts.mapping, index))
|
|
295
284
|
}
|
|
296
285
|
|
|
297
286
|
/**
|
|
@@ -311,29 +300,48 @@ export interface RawGeocode {
|
|
|
311
300
|
*/
|
|
312
301
|
type GeocodeComponents = Parameters<typeof toPostalAddress>[0]
|
|
313
302
|
|
|
303
|
+
/**
|
|
304
|
+
* What every shape of {@link geocodeAddressVia}'s dependencies carries.
|
|
305
|
+
*/
|
|
306
|
+
export interface GeocodeDepsBase {
|
|
307
|
+
/**
|
|
308
|
+
* Country (ISO-2 or name) the address is formatted under. When omitted, {@link toPostalAddress} reads the parsed
|
|
309
|
+
* `country` component instead.
|
|
310
|
+
*/
|
|
311
|
+
country?: string
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Two independent calls: parse the address, then geocode it. mailwoman's `geocodeAddress` re-parses internally, so this
|
|
316
|
+
* shape parses the address twice — fine when the two callbacks don't share a parser.
|
|
317
|
+
*/
|
|
318
|
+
export interface TwoStepGeocodeDeps extends GeocodeDepsBase {
|
|
319
|
+
parse: (raw: string) => Promise<GeocodeComponents> | GeocodeComponents
|
|
320
|
+
geocode: (raw: string) => Promise<RawGeocode | null> | RawGeocode | null
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Parse the address ONCE and answer both the components and the geocode. Use this when the parse is the expensive step
|
|
325
|
+
* you'd rather not pay for twice (e.g. share `parseForGeocode`'s tree between the PostalAddress and `geocodeAddress`'s
|
|
326
|
+
* `parsedTree`). ~1.3× over the two-call shape on a real geocode pipeline.
|
|
327
|
+
*/
|
|
328
|
+
export interface OneStepGeocodeDeps extends GeocodeDepsBase {
|
|
329
|
+
parseAndGeocode: (raw: string) => Promise<{ components: GeocodeComponents; geo: RawGeocode | null }>
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* The dependencies {@link geocodeAddressVia} builds a {@link GeocodeAddress} from; `"parseAndGeocode" in deps` tells the
|
|
334
|
+
* two shapes apart.
|
|
335
|
+
*/
|
|
336
|
+
export type GeocodeAddressViaDeps = TwoStepGeocodeDeps | OneStepGeocodeDeps
|
|
337
|
+
|
|
314
338
|
/**
|
|
315
339
|
* Build a {@link GeocodeAddress} from mailwoman's real parse + geocode primitives (injected — the CLI constructs the
|
|
316
|
-
* neural parser, resolver, and
|
|
340
|
+
* neural parser, resolver, and extracts and passes them in). Parse → components → {@link toPostalAddress} (which fills
|
|
317
341
|
* the canonical key + formatted form) → attach the resolved coordinate. When geocoding can't place the address, the
|
|
318
342
|
* parsed-but-unlocated address is still returned.
|
|
319
|
-
*
|
|
320
|
-
* Two shapes:
|
|
321
|
-
*
|
|
322
|
-
* - `{ parse, geocode }` — the original: two independent calls. mailwoman's `geocodeAddress` re-parses internally, so
|
|
323
|
-
* this parses the address twice (fine when the two callbacks don't share a parser).
|
|
324
|
-
* - `{ parseAndGeocode }` — parse the address ONCE and return both the components and the geocode. Use this when the
|
|
325
|
-
* parse is the expensive step you'd rather not pay for twice (e.g. share `parseForGeocode`'s tree between the
|
|
326
|
-
* PostalAddress and `geocodeAddress`'s `parsedTree`). ~1.3× over the two-call shape on a real geocode pipeline.
|
|
327
343
|
*/
|
|
328
|
-
export function geocodeAddressVia(
|
|
329
|
-
deps: { country?: string } & (
|
|
330
|
-
| {
|
|
331
|
-
parse: (raw: string) => Promise<GeocodeComponents> | GeocodeComponents
|
|
332
|
-
geocode: (raw: string) => Promise<RawGeocode | null> | RawGeocode | null
|
|
333
|
-
}
|
|
334
|
-
| { parseAndGeocode: (raw: string) => Promise<{ components: GeocodeComponents; geo: RawGeocode | null }> }
|
|
335
|
-
)
|
|
336
|
-
): GeocodeAddress {
|
|
344
|
+
export function geocodeAddressVia(deps: GeocodeAddressViaDeps): GeocodeAddress {
|
|
337
345
|
return async (raw: string): Promise<PostalAddress | null> => {
|
|
338
346
|
let components: GeocodeComponents
|
|
339
347
|
let resolved: RawGeocode | null
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
type TermFrequencyTable,
|
|
33
33
|
} from "@mailwoman/match"
|
|
34
34
|
|
|
35
|
-
import type { SourceRecord } from "
|
|
35
|
+
import type { SourceRecord } from "#types"
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Similarity at which two official names count as the same organisation. Set high because the feature is a near-exact
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
*
|
|
10
10
|
* It renders on the HOUSE stack: MapLibre GL + a Protomaps basemap (`@protomaps/basemaps` generates
|
|
11
11
|
* the `layers()` for a named flavor) over the `basemap-v4` vector tiles served from R2 at
|
|
12
|
-
* `tiles.
|
|
12
|
+
* `tiles.mailwoman.ai` — the same basemap the demo uses. Each entity is a circle sized by
|
|
13
13
|
* records-merged and colored by cross-dataset-link status (≥2 sources stand out), or
|
|
14
14
|
* categorically by `bucket` when the reconciliation output carries one. Pure: GeoJSON in, HTML
|
|
15
15
|
* string out (the Protomaps layer specs are generated at this point and inlined). The generated
|
|
16
16
|
* page fetches MapLibre, the basemap tiles, and glyphs/sprite over the network when opened (the
|
|
17
17
|
* house infra).
|
|
18
18
|
*
|
|
19
|
-
* SERVE IT OVER LOCALHOST, don't open it as a file. The house tile server (`tiles.
|
|
19
|
+
* SERVE IT OVER LOCALHOST, don't open it as a file. The house tile server (`tiles.mailwoman.ai`)
|
|
20
20
|
* CORS-restricts to localhost + the docs domains, so a `file://` page shows the (accurate)
|
|
21
21
|
* markers on a blank basemap. `npx serve` / `python3 -m http.server` in the output directory is
|
|
22
22
|
* enough; the page also surfaces a hint banner when it detects it's running from `file://`.
|
|
@@ -25,10 +25,11 @@
|
|
|
25
25
|
* Bucket labels render verbatim from the data, never editorialized.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
+
import { escapeHTML } from "@mailwoman/core/strings/escape"
|
|
28
29
|
import type { GeoFeatureCollection, PointLiteral } from "@mailwoman/spatial"
|
|
29
30
|
import { layers, namedFlavor } from "@protomaps/basemaps"
|
|
30
31
|
|
|
31
|
-
import type {
|
|
32
|
+
import type { MapFeatureData } from "#types"
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* MapLibre GL release the page pins (CDN + SRI). Matches the workspace's `maplibre-gl` major.
|
|
@@ -38,17 +39,17 @@ const MAPLIBRE_JS_SRI = "sha384-5+cfbwT0iiub6VsQAdn6yz16nr6sDiQoHx6tm4O8OVYXHYOx
|
|
|
38
39
|
const MAPLIBRE_CSS_SRI = "sha384-uTttxo/aOKbdE5RlD/SPzSDoDmNvGlUYPjONi2MN/b7c9HPSvW07OIuyP7uL6jxK"
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
|
-
* The house Protomaps basemap: `basemap-v4` PMTiles (tile-worker → R2 at `tiles.
|
|
42
|
+
* The house Protomaps basemap: `basemap-v4` PMTiles (tile-worker → R2 at `tiles.mailwoman.ai`, which sends CORS for
|
|
42
43
|
* localhost + the docs domains).
|
|
43
44
|
*
|
|
44
45
|
* Glyphs + sprite come from the UPSTREAM Protomaps assets (GitHub Pages, `ACAO: *`), not the house mirror at
|
|
45
|
-
* `public.
|
|
46
|
+
* `public.mailwoman.ai` — that bucket sends no CORS headers, so the mirror can't be fetched cross-origin
|
|
46
47
|
* (`cartographer/base/composition.ts` flags the same: "Currently upstream URLs; we mirror these … but no public route
|
|
47
48
|
* fronts that bucket yet"). The upstream assets target the v4 schema, matching the `basemap-v4` tiles. Swap to the
|
|
48
49
|
* house mirror once it has a CORS-enabled route.
|
|
49
50
|
*/
|
|
50
51
|
const BASEMAP_SOURCE_ID = "basemap-v4"
|
|
51
|
-
const BASEMAP_TILEJSON_URL = "https://tiles.
|
|
52
|
+
const BASEMAP_TILEJSON_URL = "https://tiles.mailwoman.ai/basemap-v4.json"
|
|
52
53
|
const GLYPHS_URL = "https://protomaps.github.io/basemaps-assets/fonts/{fontstack}/{range}.pbf"
|
|
53
54
|
const SPRITE_URL = "https://protomaps.github.io/basemaps-assets/sprites/v4/light"
|
|
54
55
|
|
|
@@ -99,14 +100,7 @@ function safeJSONForScript(value: unknown): string {
|
|
|
99
100
|
return JSON.stringify(value).replaceAll("<", "\\u003c").replaceAll(">", "\\u003e").replaceAll("&", "\\u0026")
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
|
|
103
|
-
* Escape text for the HTML document body (title/heading), not the inlined script.
|
|
104
|
-
*/
|
|
105
|
-
function escapeHTML(text: string): string {
|
|
106
|
-
return text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function sourceCount(props: EntityGeoData): number {
|
|
103
|
+
function sourceCount(props: MapFeatureData): number {
|
|
110
104
|
return Array.isArray(props["sources"]) ? props["sources"].length : 0
|
|
111
105
|
}
|
|
112
106
|
|
|
@@ -116,7 +110,7 @@ function sourceCount(props: EntityGeoData): number {
|
|
|
116
110
|
* state rather than a broken map.
|
|
117
111
|
*/
|
|
118
112
|
export function toMapHTML(
|
|
119
|
-
geojson: GeoFeatureCollection<PointLiteral,
|
|
113
|
+
geojson: GeoFeatureCollection<PointLiteral, MapFeatureData>,
|
|
120
114
|
options: MapHTMLOptions = {}
|
|
121
115
|
): string {
|
|
122
116
|
const title = options.title ?? "Mailwoman — resolved entities"
|
|
@@ -141,7 +135,7 @@ export function toMapHTML(
|
|
|
141
135
|
}
|
|
142
136
|
}
|
|
143
137
|
|
|
144
|
-
const colorFor = (props:
|
|
138
|
+
const colorFor = (props: MapFeatureData): string => {
|
|
145
139
|
if (mode === "bucket") {
|
|
146
140
|
const b = props["bucket"] != null ? String(props["bucket"]) : "—"
|
|
147
141
|
|
|
@@ -27,9 +27,11 @@
|
|
|
27
27
|
* which the map auto-detects and colors categorically.
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
import
|
|
30
|
+
import { isPresent } from "@mailwoman/core/objects"
|
|
31
|
+
import type { GeoFeatureCollection, PointLiteral } from "@mailwoman/spatial"
|
|
31
32
|
|
|
32
|
-
import
|
|
33
|
+
import { toFeature } from "#geojson"
|
|
34
|
+
import type { EntityGeoData, ReconciliationBucket, ResolvedEntity } from "#types"
|
|
33
35
|
|
|
34
36
|
/**
|
|
35
37
|
* Which source labels denote eligibility vs funding/enrollment.
|
|
@@ -123,11 +125,12 @@ export function reconcileCoverage(entities: readonly ResolvedEntity[], config: R
|
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
/**
|
|
126
|
-
* A display name for a reconciled entity's representative record
|
|
128
|
+
* A display name for a reconciled entity's representative record — the organization's canonical form, else the person
|
|
129
|
+
* name, else the record id.
|
|
127
130
|
*/
|
|
128
|
-
function repName(entity: ResolvedEntity): string {
|
|
131
|
+
export function repName(entity: ResolvedEntity): string {
|
|
129
132
|
const rep = entity.representative
|
|
130
|
-
const person = [rep.name?.given, rep.name?.family].filter(
|
|
133
|
+
const person = [rep.name?.given, rep.name?.family].filter(isPresent).join(" ")
|
|
131
134
|
|
|
132
135
|
return rep.organization?.canonical ?? (person || rep.id)
|
|
133
136
|
}
|
|
@@ -141,25 +144,7 @@ export function reconciliationGeoJSON(result: ReconciliationResult): GeoFeatureC
|
|
|
141
144
|
type: "FeatureCollection",
|
|
142
145
|
features: result.reconciled
|
|
143
146
|
.filter((c) => c.entity.coordinate)
|
|
144
|
-
.map((c) => {
|
|
145
|
-
const foo: GeoFeature<PointLiteral, EntityGeoData> = {
|
|
146
|
-
type: "Feature" as const,
|
|
147
|
-
id: undefined,
|
|
148
|
-
geometry: {
|
|
149
|
-
type: "Point" as const,
|
|
150
|
-
coordinates: [c.entity.coordinate!.longitude, c.entity.coordinate!.latitude] as [number, number],
|
|
151
|
-
},
|
|
152
|
-
properties: {
|
|
153
|
-
entityID: c.entity.id,
|
|
154
|
-
bucket: c.bucket,
|
|
155
|
-
sources: c.sources,
|
|
156
|
-
name: repName(c.entity),
|
|
157
|
-
recordCount: c.entity.records.length,
|
|
158
|
-
},
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return foo
|
|
162
|
-
}),
|
|
147
|
+
.map((c) => toFeature(c.entity, { bucket: c.bucket, name: repName(c.entity) })),
|
|
163
148
|
}
|
|
164
149
|
}
|
|
165
150
|
|
|
@@ -41,9 +41,9 @@ import {
|
|
|
41
41
|
withTermFrequency,
|
|
42
42
|
} from "@mailwoman/match"
|
|
43
43
|
|
|
44
|
-
import { createGBTScorer } from "
|
|
45
|
-
import { DEDUP_GBT_META, DEDUP_GBT_MODEL } from "
|
|
46
|
-
import type { ResolvedEntity, SourceRecord } from "
|
|
44
|
+
import { createGBTScorer } from "#learned-scorer"
|
|
45
|
+
import { DEDUP_GBT_META, DEDUP_GBT_MODEL } from "#models/dedup-gbt-en-us"
|
|
46
|
+
import type { ResolvedEntity, SourceRecord } from "#types"
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Cheap, parse-free normalization for the address-frequency key — uppercase, collapse whitespace, drop punctuation.
|
|
@@ -91,7 +91,12 @@ const CODE_SET_LEVELS: ComparisonLevel[] = [
|
|
|
91
91
|
* 1 when the whitespace-joined code sets share ANY code, else 0 (order/count-insensitive, case-folded).
|
|
92
92
|
*/
|
|
93
93
|
function codeSetOverlap(a: string, b: string): number {
|
|
94
|
-
const sa = new Set(
|
|
94
|
+
const sa = new Set(
|
|
95
|
+
a
|
|
96
|
+
.toUpperCase()
|
|
97
|
+
.split(/\s+/)
|
|
98
|
+
.filter((value) => value.length > 0)
|
|
99
|
+
)
|
|
95
100
|
|
|
96
101
|
for (const t of b.toUpperCase().split(/\s+/)) if (t && sa.has(t)) return 1
|
|
97
102
|
|
|
@@ -99,15 +104,28 @@ function codeSetOverlap(a: string, b: string): number {
|
|
|
99
104
|
}
|
|
100
105
|
|
|
101
106
|
/**
|
|
102
|
-
* Last-10-digits normalization for phone agreement (drops country code, punctuation, extensions).
|
|
107
|
+
* Last-10-digits normalization for phone agreement (drops country code, punctuation, extensions). A shorter digit
|
|
108
|
+
* string is kept as-is — partial agreement still carries weight in the comparison model; `null` means no digits at
|
|
109
|
+
* all.
|
|
103
110
|
*/
|
|
104
|
-
function normalizePhone(raw: string | null | undefined): string | null {
|
|
111
|
+
export function normalizePhone(raw: string | null | undefined): string | null {
|
|
105
112
|
if (!raw) return null
|
|
106
113
|
const digits = raw.replaceAll(/\D+/g, "")
|
|
107
114
|
|
|
108
115
|
return digits.length >= 10 ? digits.slice(-10) : digits || null
|
|
109
116
|
}
|
|
110
117
|
|
|
118
|
+
/**
|
|
119
|
+
* {@link normalizePhone} under the probes' stricter contract: only a FULL line counts — the last 10 digits when the
|
|
120
|
+
* input carries at least 10, `""` otherwise (never a partial digit string). Callers guard on truthiness, so `""` reads
|
|
121
|
+
* as "no comparable phone" rather than a weaker key.
|
|
122
|
+
*/
|
|
123
|
+
export function normalizePhoneStrict(raw: string | null | undefined): string {
|
|
124
|
+
const digits = normalizePhone(raw)
|
|
125
|
+
|
|
126
|
+
return digits && digits.length === 10 ? digits : ""
|
|
127
|
+
}
|
|
128
|
+
|
|
111
129
|
/**
|
|
112
130
|
* The identity-corroborating comparisons (person name, organization, phone). A2 (#625,
|
|
113
131
|
* {@link ResolveConfig.requireCorroboration}) requires at least one of these to _positively_ agree before a pair may
|
|
@@ -117,7 +135,7 @@ function normalizePhone(raw: string | null | undefined): string | null {
|
|
|
117
135
|
const CORROBORATING_FIELDS = new Set(["given", "family", "organization", "phone"])
|
|
118
136
|
|
|
119
137
|
/**
|
|
120
|
-
* Options for {@link buildDefaultModel}. Each
|
|
138
|
+
* Options for {@link buildDefaultModel}. Each change is default-off, so the base model is byte-stable.
|
|
121
139
|
*/
|
|
122
140
|
export interface DefaultModelOptions {
|
|
123
141
|
/**
|
|
@@ -145,7 +163,7 @@ export interface DefaultModelOptions {
|
|
|
145
163
|
*/
|
|
146
164
|
discriminators?: string[]
|
|
147
165
|
/**
|
|
148
|
-
* Closed-vocabulary CODE-SET discriminators drawn from {@link SourceRecord.attributes} (#625 taxonomy
|
|
166
|
+
* Closed-vocabulary CODE-SET discriminators drawn from {@link SourceRecord.attributes} (#625 taxonomy change). The
|
|
149
167
|
* attribute value is a whitespace-joined set of codes (NPPES taxonomy codes, license numbers, …); agreement = ANY
|
|
150
168
|
* shared code (set overlap, not string similarity — `207R00000X` vs `207Q00000X` are DIFFERENT specialties despite
|
|
151
169
|
* near-identical text, exactly the case string similarity mis-scores). The over-merge separator: two co-located
|
|
@@ -331,17 +349,17 @@ export interface ResolveConfig {
|
|
|
331
349
|
* FS baseline on the identical pipeline. The function is responsible for its own feature computation (e.g. the
|
|
332
350
|
* agreement pattern, which is EM-independent, plus any corpus statistics it captured).
|
|
333
351
|
*
|
|
334
|
-
* INTERACTION with {@link requireCorroboration}: the two are independent and compose, but the corroboration
|
|
352
|
+
* INTERACTION with {@link requireCorroboration}: the two are independent and compose, but the corroboration check is
|
|
335
353
|
* still evaluated on the Fellegi-Sunter `contributions` (NOT the learned score) — so a learned-high pair with no
|
|
336
|
-
* positive FS name/org/phone agreement is still
|
|
337
|
-
* corroboration, so use ONE or the other; combining them lets the FS
|
|
354
|
+
* positive FS name/org/phone agreement is still held out. A learned scorer is normally trained to subsume
|
|
355
|
+
* corroboration, so use ONE or the other; combining them lets the FS check veto the learned score, which is rarely
|
|
338
356
|
* what you want.
|
|
339
357
|
*/
|
|
340
358
|
scorer?: (a: SourceRecord, b: SourceRecord) => number
|
|
341
359
|
/**
|
|
342
360
|
* **#603: the LEARNED gradient-boosted-tree scorer — DEFAULT-ON.** Omitted or `true` uses the bundled
|
|
343
361
|
* {@link DEDUP_GBT_MODEL} (trained on the NPPES NPI-truth set; beats the Fellegi-Sunter baseline ~+5pp dedup F1
|
|
344
|
-
* held-out within a state and ~+22pp on states it never trained on,
|
|
362
|
+
* held-out within a state and ~+22pp on states it never trained on, reducing the co-located over-merge). `false` opts
|
|
345
363
|
* out to the pure FS baseline; pass your own {@link GBT} for a custom model. The scorer is built over the SAME
|
|
346
364
|
* collapsed-spatial + address-frequency feature model as training (via the resolved {@link addressFrequency}),
|
|
347
365
|
* independent of this call's comparison config. An explicit {@link scorer} takes precedence. When the bundled model
|
|
@@ -372,7 +390,7 @@ export interface ResolveResult {
|
|
|
372
390
|
* record with no confident link is its own singleton entity).
|
|
373
391
|
*/
|
|
374
392
|
export function resolveEntities(records: readonly SourceRecord[], config: ResolveConfig = {}): ResolveResult {
|
|
375
|
-
// The proven
|
|
393
|
+
// The proven changes are DEFAULT-ON (#625): the address-frequency down-weight (auto-computed over the
|
|
376
394
|
// input records when not supplied; `false` disables) + the collapsed spatial signal (A1). A new
|
|
377
395
|
// caller gets the strong config out of the box; pass explicit values to override.
|
|
378
396
|
const addressFrequency =
|