@mailwoman/registry 10.0.0 → 10.1.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 +10 -10
- package/lib/address-key.ts +14 -10
- package/lib/geocode-handler.ts +6 -4
- package/lib/geojson.ts +11 -6
- package/lib/ingest.ts +57 -83
- package/lib/learned-scorer.ts +38 -44
- package/lib/map-html.ts +24 -70
- 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 +43 -53
- package/lib/resolve.ts +180 -124
- package/lib/types.ts +18 -12
- 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 +6 -4
- 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 +11 -6
- package/out/geojson.js.map +1 -1
- package/out/ingest.d.ts +46 -75
- package/out/ingest.d.ts.map +1 -1
- package/out/ingest.js +27 -54
- 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 +9 -62
- 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 +35 -50
- package/out/reconcile.d.ts.map +1 -1
- package/out/reconcile.js +17 -41
- package/out/reconcile.js.map +1 -1
- package/out/resolve.d.ts +150 -90
- package/out/resolve.d.ts.map +1 -1
- package/out/resolve.js +62 -63
- 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 +20 -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 +22 -15
- 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 +22 -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 +21 -41
- package/out/tools/nppes/dedup-benchmark.d.ts.map +1 -1
- package/out/tools/nppes/dedup-benchmark.js +20 -66
- package/out/tools/nppes/dedup-benchmark.js.map +1 -1
- package/out/tools/nppes/org-name.d.ts +5 -4
- package/out/tools/nppes/org-name.d.ts.map +1 -1
- package/out/tools/nppes/org-name.js +2 -2
- 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 +5 -6
- 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 +28 -17
- package/out/tools/nppes/sample.d.ts.map +1 -1
- package/out/tools/nppes/sample.js +23 -26
- 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 +63 -59
- package/out/tools/shared.d.ts.map +1 -1
- package/out/tools/shared.js +49 -66
- package/out/tools/shared.js.map +1 -1
- package/out/tools/train/cross-gbt.d.ts +36 -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 +37 -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 +10 -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 +17 -11
- package/out/types.d.ts.map +1 -1
- package/out/types.js +2 -2
- package/out/types.js.map +1 -1
- package/package.json +41 -184
- package/{lib/tools → tools}/coverage-reconciliation.ts +27 -30
- package/{lib/tools → tools}/cross/dataset-correlation.ts +31 -72
- 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 +74 -0
- package/{lib/tools → tools}/geocoder/namesake-probe.ts +9 -8
- package/{lib/tools → tools}/geocoder/vs-provided-coords.ts +39 -30
- 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 +35 -78
- package/{lib/tools → tools}/matcher-scale.ts +21 -33
- package/{lib/tools → tools}/nppes/dedup-benchmark.ts +37 -82
- package/{lib/tools → tools}/nppes/org-name.ts +5 -4
- package/{lib/tools → tools}/nppes/overmerge-packet.ts +15 -11
- package/{lib/tools → tools}/nppes/report.ts +32 -25
- package/{lib/tools → tools}/nppes/sample.ts +41 -36
- 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 +73 -83
- package/{lib/tools → tools}/train/cross-gbt.ts +38 -34
- package/{lib/tools → tools}/train/gbt.ts +55 -41
- package/{lib/tools → tools}/train/org-cross-gbt.ts +39 -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 +28 -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/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/README.md
CHANGED
|
@@ -10,7 +10,7 @@ calibrated, label-free matcher.
|
|
|
10
10
|
```ts
|
|
11
11
|
import { ingestRows, resolveEntities, toGeoJSON } from "@mailwoman/registry"
|
|
12
12
|
|
|
13
|
-
// 1. Ingest — rows → normalized SourceRecords. The mapping is POSITIONAL (arg 2)
|
|
13
|
+
// 1. Ingest — rows → normalized SourceRecords. The mapping is POSITIONAL (arg 2) rather than a field of the
|
|
14
14
|
// options object, and `geocodeAddress` belongs here: each address is resolved as it is ingested.
|
|
15
15
|
const records = await ingestRows(
|
|
16
16
|
rows,
|
|
@@ -19,7 +19,7 @@ const records = await ingestRows(
|
|
|
19
19
|
)
|
|
20
20
|
|
|
21
21
|
// 2. Resolve — block → score → cluster with geo-first defaults. SYNCHRONOUS, and it returns a
|
|
22
|
-
// ResolveResult
|
|
22
|
+
// ResolveResult rather than a bare array: `entities` alongside the pair counts blocking produced.
|
|
23
23
|
const { entities, candidatePairs, droppedBlocks } = resolveEntities(records)
|
|
24
24
|
|
|
25
25
|
// 3. Export — GeoJSON for QGIS. Entities with no resolved coordinate are skipped, so the feature
|
|
@@ -63,19 +63,19 @@ import { reconcile, toGeoJSON, toMapHTML } from "@mailwoman/registry"
|
|
|
63
63
|
import { DEDUP_GBT_META, DEDUP_GBT_MODEL } from "@mailwoman/registry"
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
`geocodeAddress` is an `ingestRows` option
|
|
66
|
+
`geocodeAddress` is an `ingestRows` option rather than a `resolveEntities` one — coordinates have to exist
|
|
67
67
|
before blocking can use them.
|
|
68
68
|
|
|
69
69
|
## Default configuration
|
|
70
70
|
|
|
71
71
|
`resolveEntities` ships with these defaults:
|
|
72
72
|
|
|
73
|
-
- **
|
|
73
|
+
- **The blocking keys:** geo-cell on the resolved coordinate (0.05°, neighbors expanded) + canonical
|
|
74
74
|
address + phone + email
|
|
75
|
-
- **
|
|
75
|
+
- **The scoring model:** Fellegi-Sunter with label-free EM, term frequency adjustment
|
|
76
76
|
- **Learned scorer:** the bundled `DEDUP_GBT_MODEL`, on by default for single-dataset dedup
|
|
77
77
|
- **Threshold:** `DEDUP_GBT_META.recommendedThreshold` (2.8324) while the bundled model is active,
|
|
78
|
-
otherwise 0. The unit is the GBT's own logit
|
|
78
|
+
otherwise 0. The unit is the GBT's own logit rather than a Fellegi-Sunter match weight in bits and not a
|
|
79
79
|
probability, so a 0-to-1 value is a category error here. Higher is stricter.
|
|
80
80
|
- **Linkage:** single (connected components), with average linkage available for the over-merge case
|
|
81
81
|
|
|
@@ -97,11 +97,11 @@ then prefers the candidate backend and never touches the WOF path (`run.tsx`'s o
|
|
|
97
97
|
this correctly: "`$MAILWOMAN_CANDIDATE_DB` → the demo-parity candidate backend; else FTS over wofPath").
|
|
98
98
|
A nonexistent path satisfies that requirement.
|
|
99
99
|
|
|
100
|
-
So: set `$MAILWOMAN_CANDIDATE_DB` and pass anything to `--resolve-db`. Do
|
|
101
|
-
`--resolve-db` with the environment variable unset
|
|
100
|
+
So: set `$MAILWOMAN_CANDIDATE_DB` and pass anything to `--resolve-db`. Do not pass `candidate.db` to
|
|
101
|
+
`--resolve-db` with the environment variable unset. The flag is believed on that path, and the admin
|
|
102
102
|
backend queries `place_search`/`spr`, which a candidate gazetteer does not have.
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
An argument required only to discard it is a defect in this command. Documented rather than fixed.
|
|
105
105
|
|
|
106
106
|
Two CLI defaults differ from the library defaults: `--threshold` defaults to `0`, which is the
|
|
107
107
|
Fellegi-Sunter baseline rather than the bundled model's calibrated 2.8324, and `--train-em` is on.
|
|
@@ -115,4 +115,4 @@ Fellegi-Sunter baseline rather than the bundled model's calibrated 2.8324, and `
|
|
|
115
115
|
|
|
116
116
|
## License
|
|
117
117
|
|
|
118
|
-
[AGPL-3.0-only](https://www.gnu.org/licenses/
|
|
118
|
+
[AGPL-3.0-only](https://www.gnu.org/licenses/AGPL-3.0.html)
|
package/lib/address-key.ts
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* The address-id consumer for the matcher
|
|
7
|
-
* resolved {@link SourceRecord} and exposes it as a blocking key
|
|
6
|
+
* The address-id consumer for the matcher. Derives a stable {@link PostalAddressID} from a
|
|
7
|
+
* resolved {@link SourceRecord} and exposes it as a blocking key, the deterministic
|
|
8
8
|
* exact-canonical-address complement to the fuzzy Fellegi-Sunter / GBT scoring. Two uses:
|
|
9
9
|
*
|
|
10
|
-
* - **As a pre-dedup / join key:** `
|
|
11
|
-
* to the same place
|
|
12
|
-
*
|
|
10
|
+
* - **As a pre-dedup / join key:** `group BY postalAddressID(record)` collapses records that resolve
|
|
11
|
+
* to the same place and share a canonical address with no scoring at all. That is the cheap,
|
|
12
|
+
* certain part of dedup before the matcher does the fuzzy rest.
|
|
13
13
|
* - **As a blocking key:** {@link addressIDBlockingKey} adds the address-id to the blocking union, so
|
|
14
14
|
* records sharing one are guaranteed to be compared.
|
|
15
15
|
*/
|
|
@@ -20,9 +20,10 @@ import { type BlockingKey, exactKey } from "@mailwoman/match"
|
|
|
20
20
|
import type { SourceRecord } from "#types"
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* The stable address primary key for a record, or null when it
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* The stable address primary key for a record, or null when it is not geocoded
|
|
24
|
+
* (no coordinate means no locality cell) or includes no raw address to hash.
|
|
25
|
+
*
|
|
26
|
+
* The state prefix is plucked from the address when present.
|
|
26
27
|
*/
|
|
27
28
|
export function postalAddressID(record: SourceRecord): PostalAddressID | null {
|
|
28
29
|
const coordinate = record.address?.geocode?.coordinate
|
|
@@ -34,8 +35,11 @@ export function postalAddressID(record: SourceRecord): PostalAddressID | null {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
|
-
* A blocking key on the {@link postalAddressID}
|
|
38
|
-
*
|
|
38
|
+
* A blocking key on the {@link postalAddressID}.
|
|
39
|
+
*
|
|
40
|
+
* Records that resolve to the same place with the same canonical address block together.
|
|
41
|
+
*
|
|
42
|
+
* Add it to {@link defaultBlockingKeys}'s union when an exact address join should never be missed.
|
|
39
43
|
*/
|
|
40
44
|
export function addressIDBlockingKey(): BlockingKey<SourceRecord> {
|
|
41
45
|
return exactKey((record) => postalAddressID(record))
|
package/lib/geocode-handler.ts
CHANGED
|
@@ -11,10 +11,12 @@ import { type ColumnMapping, type GeocodeAddress, pick } from "#ingest"
|
|
|
11
11
|
import type { SourceRecord } from "#types"
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Build the handler `geocodeStream` runs per normalized record: recompute the joined address
|
|
15
|
-
* `mapping.address` (the worker can't receive the original closure),
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* Build the handler `geocodeStream` runs per normalized record: recompute the joined address
|
|
15
|
+
* string from `record.raw` + `mapping.address` (the worker can't receive the original closure),
|
|
16
|
+
* geocode it via `geocode`, and attach the result.
|
|
17
|
+
*
|
|
18
|
+
* Records with no mapped address pass through untouched (no geocode call).
|
|
19
|
+
* The default separator matches {@link ingestRow}'s `addressSeparator`.
|
|
18
20
|
*/
|
|
19
21
|
export function makeGeocodeHandler(
|
|
20
22
|
geocode: GeocodeAddress,
|
package/lib/geojson.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Export resolved entities as GeoJSON — the bridge to QGIS and any web map. Each entity becomes a
|
|
7
7
|
* Point at its resolved coordinate, carrying the properties an analyst needs: how many records
|
|
8
|
-
* merged into it, how tightly (cohesion), the canonical name/org/address
|
|
8
|
+
* merged into it, how tightly (cohesion), the canonical name/org/address and the geocode tier
|
|
9
9
|
* (so rooftop-precise entities can be styled apart from admin-centroid guesses). Entities without
|
|
10
10
|
* a coordinate are omitted (a Point feature needs one).
|
|
11
11
|
*/
|
|
@@ -23,8 +23,11 @@ function displayName(record: SourceRecord): string | null {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* One entity → one GeoJSON Point feature.
|
|
27
|
-
*
|
|
26
|
+
* One entity → one GeoJSON Point feature.
|
|
27
|
+
*
|
|
28
|
+
* `extra` merges over (and may override) the standard properties.
|
|
29
|
+
* The reconciliation flow adds its `bucket` and swaps the display name for the
|
|
30
|
+
* representative's org-or-person form.
|
|
28
31
|
*/
|
|
29
32
|
export function toFeature(
|
|
30
33
|
entity: ResolvedEntity,
|
|
@@ -44,7 +47,8 @@ export function toFeature(
|
|
|
44
47
|
recordCount: entity.records.length,
|
|
45
48
|
cohesion: entity.cohesion,
|
|
46
49
|
sourceIDs: entity.records.map((r) => r.id),
|
|
47
|
-
// Distinct provenance labels the entity's records span
|
|
50
|
+
// Distinct provenance labels the entity's records span.
|
|
51
|
+
// An entity with ≥2 is a cross-dataset link.
|
|
48
52
|
sources: [...new Set(entity.records.map((r) => r.source).filter((s): s is string => !!s))].toSorted(),
|
|
49
53
|
name: displayName(rep),
|
|
50
54
|
organization: rep.organization?.canonical ?? null,
|
|
@@ -56,8 +60,9 @@ export function toFeature(
|
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
/**
|
|
59
|
-
* Convert resolved entities into a GeoJSON `FeatureCollection` of points, ready for QGIS.
|
|
60
|
-
*
|
|
63
|
+
* Convert resolved entities into a GeoJSON `FeatureCollection` of points, ready for QGIS.
|
|
64
|
+
*
|
|
65
|
+
* Entities with no resolved coordinate are skipped.
|
|
61
66
|
*/
|
|
62
67
|
export function toGeoJSON(entities: readonly ResolvedEntity[]): GeoFeatureCollection<PointLiteral, EntityGeoData> {
|
|
63
68
|
return {
|
package/lib/ingest.ts
CHANGED
|
@@ -3,42 +3,27 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* {@link SourceRecord}s, the front of the cascade.
|
|
8
|
-
*
|
|
9
|
-
* Two concerns, kept separate:
|
|
10
|
-
*
|
|
11
|
-
* 1. **Column mapping + normalization** (this is pure): a {@link ColumnMapping} says which column(s)
|
|
12
|
-
* hold the name, organization, address, phone, email; each row is normalized with
|
|
13
|
-
* `@mailwoman/record` (parse the person name, canonicalize the org). This is deterministic
|
|
14
|
-
* and testable with no heavy runtime.
|
|
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
|
-
* geocode primitives (which the CLI constructs with the model + data in hand), so the wiring
|
|
19
|
-
* is concrete and testable without pinning the heavy runtime into this package.
|
|
20
|
-
*
|
|
21
|
-
* LLM-assisted column mapping (infer the mapping from a header + samples) is a documented
|
|
22
|
-
* fast-follow; the mapping is an explicit input here.
|
|
6
|
+
* Column mapping and normalization are pure. The caller injects geocoding, so this package never imports the neural parser, resolver, or extracts.
|
|
23
7
|
*/
|
|
24
8
|
|
|
25
9
|
import { isPresent } from "@mailwoman/core/objects"
|
|
26
10
|
import type { AddressGeocode, PostalAddress } from "@mailwoman/record"
|
|
27
11
|
import { canonicalizeOrganizationName, parsePersonName, toPostalAddress, withGeocode } from "@mailwoman/record"
|
|
12
|
+
import type { PathBuilderLike } from "path-ts"
|
|
28
13
|
import { type AsyncSequence, CSVSpliterator, Delimiters } from "spliterator"
|
|
29
14
|
|
|
30
15
|
import type { SourceRecord } from "#types"
|
|
31
16
|
|
|
32
17
|
/**
|
|
33
|
-
* Resolve a raw address string into a {@link PostalAddress}
|
|
18
|
+
* Resolve a raw address string into a {@link PostalAddress}, the entry point to mailwoman's geocoder.
|
|
34
19
|
*/
|
|
35
20
|
export type GeocodeAddress = (raw: string) => Promise<PostalAddress | null> | PostalAddress | null
|
|
36
21
|
|
|
37
22
|
/**
|
|
38
23
|
* The column delimiters a tabular source may declare, by name, each the spliterator's own byte.
|
|
39
24
|
*
|
|
40
|
-
* The `satisfies` clause
|
|
41
|
-
*
|
|
25
|
+
* The `satisfies` clause makes a delimiter name spliterator no longer ships a compile error
|
|
26
|
+
* rather than a silently parallel vocabulary.
|
|
42
27
|
*/
|
|
43
28
|
const COLUMN_DELIMITERS = {
|
|
44
29
|
comma: Delimiters.Comma,
|
|
@@ -60,29 +45,31 @@ export function delimiterFor(path: string): Delimiter {
|
|
|
60
45
|
/**
|
|
61
46
|
* Stream a delimited file's rows lazily as header-keyed objects.
|
|
62
47
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* operators away.
|
|
48
|
+
* @returns The spliterator's own {@linkcode AsyncSequence}, whose `map`/`filter`
|
|
49
|
+
* fuse into the same pull loop.
|
|
50
|
+
* An `async function*` wrapper would add an async frame per row and remove those operators.
|
|
67
51
|
*/
|
|
68
52
|
export function streamRows(
|
|
69
|
-
source:
|
|
53
|
+
source: PathBuilderLike,
|
|
70
54
|
opts: { delimiter?: Delimiter } = {}
|
|
71
55
|
): AsyncSequence<Record<string, string>> {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
56
|
+
const path = source.toString()
|
|
57
|
+
|
|
58
|
+
return CSVSpliterator.fromAsync<Record<string, string>>(path, {
|
|
59
|
+
columnDelimiter: COLUMN_DELIMITERS[opts.delimiter ?? delimiterFor(path)],
|
|
60
|
+
// A {@linkcode ColumnMapping} holds columns in the publisher's spelling rather than a
|
|
61
|
+
// normalized key such as `facility_name`, so the keys must arrive as the file writes them.
|
|
62
|
+
// The reader's default normalizes.
|
|
76
63
|
normalizeKeys: false,
|
|
77
64
|
})
|
|
78
65
|
}
|
|
79
66
|
|
|
80
67
|
/**
|
|
81
|
-
* Maps dataset columns to record fields
|
|
68
|
+
* Maps dataset columns to record fields, where a field may draw from several columns joined with spaces.
|
|
82
69
|
*/
|
|
83
70
|
export interface ColumnMapping {
|
|
84
71
|
/**
|
|
85
|
-
* Column holding a stable row id
|
|
72
|
+
* Column holding a stable row id, falling back to the row index.
|
|
86
73
|
*/
|
|
87
74
|
id?: string
|
|
88
75
|
/**
|
|
@@ -95,20 +82,14 @@ export interface ColumnMapping {
|
|
|
95
82
|
phone?: string
|
|
96
83
|
email?: string
|
|
97
84
|
/**
|
|
98
|
-
* Extra secondary-identifier fields
|
|
99
|
-
* `SourceRecord.attributes` under the same key
|
|
100
|
-
* taxonomy, license…).
|
|
85
|
+
* Extra secondary-identifier fields mapped to the column(s) to draw each from, landing
|
|
86
|
+
* on `SourceRecord.attributes` under the same key for the matcher's `discriminators`.
|
|
101
87
|
*/
|
|
102
88
|
attributes?: Record<string, string | string[]>
|
|
103
89
|
}
|
|
104
90
|
|
|
105
91
|
/**
|
|
106
|
-
* Best-effort {@link ColumnMapping} inferred from a header row
|
|
107
|
-
* is matched (case- and punctuation-insensitive, on whole tokens) to a field by keyword, in a precedence that resolves
|
|
108
|
-
* the common ambiguities: a dedicated id / phone / email column is claimed before the generic sweep, an org / facility
|
|
109
|
-
* column beats a person "name", and address columns (street / city / state / zip…) collect into one multi-column field.
|
|
110
|
-
* Imperfect on bespoke headers (an explicit mapping or the LLM-assisted inference #603 is the answer there), but it
|
|
111
|
-
* nails tidy and semi-tidy files with no hand-mapping. Unmatched columns are left out.
|
|
92
|
+
* Best-effort {@link ColumnMapping} inferred from a header row, the "point it at any CSV" convenience.
|
|
112
93
|
*/
|
|
113
94
|
export function inferMapping(header: readonly string[]): ColumnMapping {
|
|
114
95
|
// Pad to whole-token boundaries so "state" doesn't match inside "statement".
|
|
@@ -172,30 +153,27 @@ export function inferMapping(header: readonly string[]): ColumnMapping {
|
|
|
172
153
|
*/
|
|
173
154
|
export interface IngestOptions {
|
|
174
155
|
/**
|
|
175
|
-
* The geocoding interface.
|
|
156
|
+
* The geocoding interface.
|
|
157
|
+
*
|
|
158
|
+
* Without it records include name/org but have no resolved address.
|
|
176
159
|
*/
|
|
177
160
|
geocodeAddress?: GeocodeAddress
|
|
178
161
|
/**
|
|
179
|
-
* Separator for joining a multi-column
|
|
180
|
-
*
|
|
181
|
-
* St Austin TX 78701"`) — the latter strips the parser's segmentation boundaries and is partly OOD (it also breaks
|
|
182
|
-
* all-caps case-normalization; #694). **Default `", "` (#694 flip, validated).** Comma-join is the correct shape for
|
|
183
|
-
* an address built from separate columns, and #700 measured it at +15% cross-dataset rooftop (579→667) with no
|
|
184
|
-
* comma-less crater. The dedup GBT was trained on the old space-joined coords, so this flip is paired with a GBT
|
|
185
|
-
* re-validation (#694). Pass `" "` to restore the legacy space-join for a byte-stable A/B.
|
|
162
|
+
* Separator for joining a multi-column address mapping, comma-join giving the parser delimited
|
|
163
|
+
* input rather than a concatenated run (name/org always join with a space). @default ", "
|
|
186
164
|
*/
|
|
187
165
|
addressSeparator?: string
|
|
188
166
|
}
|
|
189
167
|
|
|
190
168
|
/**
|
|
191
|
-
* Join the
|
|
169
|
+
* Join the selected columns of a row into a single trimmed string, or undefined if empty.
|
|
192
170
|
*/
|
|
193
171
|
export function pick(row: Record<string, string>, columns?: string | string[], separator = " "): string | undefined {
|
|
194
172
|
if (!columns) return undefined
|
|
195
173
|
const list = Array.isArray(columns) ? columns : [columns]
|
|
196
174
|
|
|
197
175
|
const value = list
|
|
198
|
-
.map((c) => row[c]
|
|
176
|
+
.map((c) => row[c])
|
|
199
177
|
.filter(isPresent)
|
|
200
178
|
.join(separator)
|
|
201
179
|
.trim()
|
|
@@ -204,10 +182,9 @@ export function pick(row: Record<string, string>, columns?: string | string[], s
|
|
|
204
182
|
}
|
|
205
183
|
|
|
206
184
|
/**
|
|
207
|
-
* Normalize one tabular row into a {@link SourceRecord} under a {@link ColumnMapping}
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
* single-threaded (see {@link normalizeCSV}) while geocoding is offloaded (see `geocodeStream`).
|
|
185
|
+
* Normalize one tabular row into a {@link SourceRecord} under a {@link ColumnMapping},
|
|
186
|
+
* pure aside from the optional geocode interface so the deterministic normalization
|
|
187
|
+
* can run single-threaded while geocoding is offloaded.
|
|
211
188
|
*/
|
|
212
189
|
export async function ingestRow(
|
|
213
190
|
row: Record<string, string>,
|
|
@@ -215,7 +192,7 @@ export async function ingestRow(
|
|
|
215
192
|
index: number,
|
|
216
193
|
opts: IngestOptions = {}
|
|
217
194
|
): Promise<SourceRecord> {
|
|
218
|
-
const id = (mapping.id ? row[mapping.id]
|
|
195
|
+
const id = (mapping.id ? row[mapping.id] : "") || String(index)
|
|
219
196
|
const nameValue = pick(row, mapping.name)
|
|
220
197
|
const orgValue = pick(row, mapping.organization)
|
|
221
198
|
const addressValue = pick(row, mapping.address, opts.addressSeparator ?? ", ")
|
|
@@ -237,8 +214,8 @@ export async function ingestRow(
|
|
|
237
214
|
source: mapping.source,
|
|
238
215
|
name: nameValue ? parsePersonName(nameValue) : undefined,
|
|
239
216
|
organization: orgValue ? canonicalizeOrganizationName(orgValue) : undefined,
|
|
240
|
-
phone: (mapping.phone && row[mapping.phone]
|
|
241
|
-
email: (mapping.email && row[mapping.email]?.
|
|
217
|
+
phone: (mapping.phone && row[mapping.phone]) || undefined,
|
|
218
|
+
email: (mapping.email && row[mapping.email]?.toLowerCase()) || undefined,
|
|
242
219
|
address: addressValue && opts.geocodeAddress ? ((await opts.geocodeAddress(addressValue)) ?? undefined) : undefined,
|
|
243
220
|
attributes,
|
|
244
221
|
raw: row,
|
|
@@ -248,7 +225,7 @@ export async function ingestRow(
|
|
|
248
225
|
/**
|
|
249
226
|
* Normalize tabular rows into {@link SourceRecord}s under a {@link ColumnMapping}.
|
|
250
227
|
*
|
|
251
|
-
* @see {@link streamRows} for the streaming path
|
|
228
|
+
* @see {@link streamRows} for the streaming path. It is preferred for multi-GB files.
|
|
252
229
|
*/
|
|
253
230
|
export async function ingestRows(
|
|
254
231
|
rows: Iterable<Record<string, string>> | AsyncIterable<Record<string, string>>,
|
|
@@ -268,24 +245,19 @@ export async function ingestRows(
|
|
|
268
245
|
}
|
|
269
246
|
|
|
270
247
|
/**
|
|
271
|
-
* Stream a delimited file as normalized {@link SourceRecord}s
|
|
272
|
-
*
|
|
273
|
-
* a multi-GB file, line by line. Geocode separately by piping the output through `geocodeStream` (the only heavy step
|
|
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.
|
|
248
|
+
* Stream a delimited file as normalized {@link SourceRecord}s in file order with no geocoding.
|
|
249
|
+
* Geocode separately through `geocodeStream`.
|
|
278
250
|
*/
|
|
279
251
|
export function normalizeCSV(
|
|
280
|
-
source:
|
|
252
|
+
source: PathBuilderLike,
|
|
281
253
|
opts: { mapping: ColumnMapping; delimiter?: Delimiter }
|
|
282
254
|
): AsyncSequence<SourceRecord> {
|
|
283
255
|
return streamRows(source, { delimiter: opts.delimiter }).map((row, index) => ingestRow(row, opts.mapping, index))
|
|
284
256
|
}
|
|
285
257
|
|
|
286
258
|
/**
|
|
287
|
-
* The subset of mailwoman's `GeocodeResult` the adapter consumes
|
|
288
|
-
*
|
|
259
|
+
* The subset of mailwoman's `GeocodeResult` the adapter consumes, kept structural
|
|
260
|
+
* so this package never imports the heavy geocoder.
|
|
289
261
|
*/
|
|
290
262
|
export interface RawGeocode {
|
|
291
263
|
lat: number | null
|
|
@@ -296,24 +268,28 @@ export interface RawGeocode {
|
|
|
296
268
|
}
|
|
297
269
|
|
|
298
270
|
/**
|
|
299
|
-
* The component map {@link toPostalAddress} consumes
|
|
271
|
+
* The component map {@link toPostalAddress} consumes
|
|
272
|
+
* (kept structural so this package never imports the geocoder).
|
|
300
273
|
*/
|
|
301
274
|
type GeocodeComponents = Parameters<typeof toPostalAddress>[0]
|
|
302
275
|
|
|
303
276
|
/**
|
|
304
|
-
* What every shape of {@link geocodeAddressVia}'s dependencies
|
|
277
|
+
* What every shape of {@link geocodeAddressVia}'s dependencies includes.
|
|
305
278
|
*/
|
|
306
279
|
export interface GeocodeDepsBase {
|
|
307
280
|
/**
|
|
308
|
-
* Country (ISO-2 or name) the address is formatted under.
|
|
309
|
-
*
|
|
281
|
+
* Country (ISO-2 or name) the address is formatted under.
|
|
282
|
+
*
|
|
283
|
+
* When omitted, {@link toPostalAddress} reads the parsed `country` component instead.
|
|
310
284
|
*/
|
|
311
285
|
country?: string
|
|
312
286
|
}
|
|
313
287
|
|
|
314
288
|
/**
|
|
315
|
-
* Two independent calls: parse the address, then geocode it.
|
|
316
|
-
*
|
|
289
|
+
* Two independent calls: parse the address, then geocode it.
|
|
290
|
+
*
|
|
291
|
+
* Mailwoman's `geocodeAddress` re-parses internally, so the address is read twice
|
|
292
|
+
* unless the two callbacks share a parser.
|
|
317
293
|
*/
|
|
318
294
|
export interface TwoStepGeocodeDeps extends GeocodeDepsBase {
|
|
319
295
|
parse: (raw: string) => Promise<GeocodeComponents> | GeocodeComponents
|
|
@@ -321,25 +297,23 @@ export interface TwoStepGeocodeDeps extends GeocodeDepsBase {
|
|
|
321
297
|
}
|
|
322
298
|
|
|
323
299
|
/**
|
|
324
|
-
* Parse the address
|
|
325
|
-
* you'd rather not pay for twice
|
|
326
|
-
* `parsedTree`). ~1.3× over the two-call shape on a real geocode pipeline.
|
|
300
|
+
* Parse the address once and answer both the components and the geocode, for
|
|
301
|
+
* when the parse is the expensive step you'd rather not pay for twice.
|
|
327
302
|
*/
|
|
328
303
|
export interface OneStepGeocodeDeps extends GeocodeDepsBase {
|
|
329
304
|
parseAndGeocode: (raw: string) => Promise<{ components: GeocodeComponents; geo: RawGeocode | null }>
|
|
330
305
|
}
|
|
331
306
|
|
|
332
307
|
/**
|
|
333
|
-
* The dependencies {@link geocodeAddressVia} builds a {@link GeocodeAddress} from;
|
|
334
|
-
* two shapes apart.
|
|
308
|
+
* The dependencies {@link geocodeAddressVia} builds a {@link GeocodeAddress} from;
|
|
309
|
+
* `"parseAndGeocode" in deps` tells the two shapes apart.
|
|
335
310
|
*/
|
|
336
311
|
export type GeocodeAddressViaDeps = TwoStepGeocodeDeps | OneStepGeocodeDeps
|
|
337
312
|
|
|
338
313
|
/**
|
|
339
|
-
* Build a {@link GeocodeAddress} from
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
* parsed-but-unlocated address is still returned.
|
|
314
|
+
* Build a {@link GeocodeAddress} from injected parse and geocode primitives.
|
|
315
|
+
*
|
|
316
|
+
* When geocoding can't place the address, the parsed-but-unlocated address is still returned.
|
|
343
317
|
*/
|
|
344
318
|
export function geocodeAddressVia(deps: GeocodeAddressViaDeps): GeocodeAddress {
|
|
345
319
|
return async (raw: string): Promise<PostalAddress | null> => {
|
package/lib/learned-scorer.ts
CHANGED
|
@@ -3,24 +3,19 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* The learned scorer
|
|
7
|
-
* {@link ResolveConfig.scorer}.
|
|
6
|
+
* The learned scorer, the production wiring for the gradient-boosted-tree model behind
|
|
7
|
+
* {@link ResolveConfig.scorer}.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* 2. {@link createGBTScorer} — wraps a trained {@link GBT} + the featurizer into the `(a, b) => number`
|
|
15
|
-
* the resolve pipeline's `scorer` hook expects (a logit, threshold-comparable with the
|
|
16
|
-
* Fellegi-Sunter weight it replaces).
|
|
9
|
+
* {@link createMatchFeaturizer} is the one feature extractor for a candidate pair, used
|
|
10
|
+
* identically at train time (`registry/tools/train-gbt.ts`), eval time and inference time.
|
|
11
|
+
* {@link createGBTScorer} wraps a trained {@link GBT} and the featurizer into the `(a, b) => number`
|
|
12
|
+
* the resolve pipeline's `scorer` hook expects (a logit, threshold-comparable with the
|
|
13
|
+
* Fellegi-Sunter weight it replaces).
|
|
17
14
|
*
|
|
18
|
-
* Both take the comparison set as
|
|
19
|
-
* module has no dependency cycle with `resolve.ts`.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* VALUES differ between the training corpus and the matched set, which is the point (the model
|
|
23
|
-
* generalizes, as the cross-state eval showed).
|
|
15
|
+
* Both take the comparison set as input rather than importing {@link buildDefaultModel}, so this
|
|
16
|
+
* module has no dependency cycle with `resolve.ts`. Feed the comparisons from
|
|
17
|
+
* `buildDefaultModel({ collapseSpatial: true, addressFrequency })`, since that config fixes the
|
|
18
|
+
* feature layout.
|
|
24
19
|
*/
|
|
25
20
|
|
|
26
21
|
import {
|
|
@@ -35,9 +30,9 @@ import {
|
|
|
35
30
|
import type { SourceRecord } from "#types"
|
|
36
31
|
|
|
37
32
|
/**
|
|
38
|
-
* Similarity at which two official names count as the same
|
|
39
|
-
*
|
|
40
|
-
*
|
|
33
|
+
* Similarity at which two official names count as the same organization.
|
|
34
|
+
*
|
|
35
|
+
* Set high because the feature is a near-exact agreement signal rather than a fuzzy one.
|
|
41
36
|
*/
|
|
42
37
|
const OFFICIAL_NAME_AGREEMENT = 0.93
|
|
43
38
|
|
|
@@ -46,10 +41,13 @@ const OFFICIAL_NAME_AGREEMENT = 0.93
|
|
|
46
41
|
*/
|
|
47
42
|
export interface LearnedFeatureConfig {
|
|
48
43
|
/**
|
|
49
|
-
* The comparison set the features are built over
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
44
|
+
* The comparison set the features are built over.
|
|
45
|
+
*
|
|
46
|
+
* It must be `buildDefaultModel({ collapseSpatial: true, addressFrequency }).comparisons`
|
|
47
|
+
* so the feature layout matches the trained model.
|
|
48
|
+
*
|
|
49
|
+
* `usePhone` and `discriminators` are not part of the learned feature model,
|
|
50
|
+
* since the GBT replaces the Fellegi-Sunter weight wholesale and owns its feature vector.
|
|
53
51
|
*/
|
|
54
52
|
comparisons: Comparison<SourceRecord>[]
|
|
55
53
|
/**
|
|
@@ -59,9 +57,12 @@ export interface LearnedFeatureConfig {
|
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
/**
|
|
62
|
-
* Build the per-pair feature extractor.
|
|
63
|
-
*
|
|
64
|
-
*
|
|
60
|
+
* Build the per-pair feature extractor.
|
|
61
|
+
*
|
|
62
|
+
* The vector is: one-hot of each comparison's agreement level, then the two over-merge
|
|
63
|
+
* interaction terms (spatial-exact × name-disagree, spatial-exact × org-disagree,
|
|
64
|
+
* the "same place, different names" signature that drives co-located over-merges),
|
|
65
|
+
* then address crowdedness scaled into [0, 1].
|
|
65
66
|
* Deterministic and EM-independent, so it is identical across train / eval / inference.
|
|
66
67
|
*/
|
|
67
68
|
export function createMatchFeaturizer(config: LearnedFeatureConfig): (a: SourceRecord, b: SourceRecord) => number[] {
|
|
@@ -86,7 +87,6 @@ export function createMatchFeaturizer(config: LearnedFeatureConfig): (a: SourceR
|
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
// Interaction: co-located (spatial exact = level 0) AND names/org disagree (catch-all level).
|
|
90
90
|
const spatialExact = spatialI !== undefined && pat[spatialI] === 0 ? 1 : 0
|
|
91
91
|
|
|
92
92
|
const nameDisagree =
|
|
@@ -98,37 +98,31 @@ export function createMatchFeaturizer(config: LearnedFeatureConfig): (a: SourceR
|
|
|
98
98
|
: 0
|
|
99
99
|
|
|
100
100
|
const orgDisagree = orgI !== undefined && pat[orgI] === lastLevel(orgI) ? 1 : 0
|
|
101
|
-
f.push(spatialExact * nameDisagree)
|
|
101
|
+
f.push(spatialExact * nameDisagree)
|
|
102
102
|
f.push(spatialExact * orgDisagree)
|
|
103
|
-
// Address crowdedness (how shared this address is) — high → "same address" is weak evidence.
|
|
104
103
|
const freq = a.address?.raw ? addressFrequency.frequency(a.address.raw) : 0
|
|
105
104
|
f.push(Math.min(1, freq * 1000))
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
// learned feature model), so the GBT could never see — let alone learn — that officialAgree in
|
|
111
|
-
// the presence of orgDisagree is ANTI-identity evidence. These three appended features express
|
|
112
|
-
// it directly from `attributes.authorizedOfficial`; appended at the END so models trained
|
|
113
|
-
// without them (the cross-source GBT) keep scoring unchanged (trailing features are ignored).
|
|
105
|
+
// Roll-up signature: a shared corporate address can host differently-branded
|
|
106
|
+
// operating entities whose authorized official also agrees.
|
|
107
|
+
// The official is not in the comparison set, so these three features express that evidence directly.
|
|
108
|
+
// They are appended at the end, so models trained without them keep scoring unchanged.
|
|
114
109
|
const offA = a.attributes?.["authorizedOfficial"]?.trim()
|
|
115
110
|
const offB = b.attributes?.["authorizedOfficial"]?.trim()
|
|
116
111
|
const officialAgree = offA && offB && nameSimilarity(offA, offB) >= OFFICIAL_NAME_AGREEMENT ? 1 : 0
|
|
117
112
|
f.push(officialAgree)
|
|
118
|
-
f.push(officialAgree * orgDisagree)
|
|
113
|
+
f.push(officialAgree * orgDisagree)
|
|
119
114
|
f.push(officialAgree * orgDisagree * spatialExact)
|
|
120
115
|
|
|
121
|
-
// …at the same place
|
|
122
|
-
|
|
123
|
-
// scale into a usable range
|
|
124
116
|
return f
|
|
125
117
|
}
|
|
126
118
|
}
|
|
127
119
|
|
|
128
120
|
/**
|
|
129
|
-
* Wrap a trained {@link GBT} into the `(a, b) => number` link scorer for {@link ResolveConfig.scorer}.
|
|
130
|
-
*
|
|
131
|
-
*
|
|
121
|
+
* Wrap a trained {@link GBT} into the `(a, b) => number` link scorer for {@link ResolveConfig.scorer}.
|
|
122
|
+
*
|
|
123
|
+
* The returned weight is the model's logit.
|
|
124
|
+
* Same threshold-comparable units as the Fellegi-Sunter weight it replaces,
|
|
125
|
+
* so the pipeline's clustering + threshold semantics are unchanged.
|
|
132
126
|
*/
|
|
133
127
|
export function createGBTScorer(
|
|
134
128
|
config: LearnedFeatureConfig & { model: GBT }
|