@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/out/ingest.js
CHANGED
|
@@ -3,23 +3,7 @@
|
|
|
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
|
import { isPresent } from "@mailwoman/core/objects";
|
|
25
9
|
import { canonicalizeOrganizationName, parsePersonName, toPostalAddress, withGeocode } from "@mailwoman/record";
|
|
@@ -27,8 +11,8 @@ import { CSVSpliterator, Delimiters } from "spliterator";
|
|
|
27
11
|
/**
|
|
28
12
|
* The column delimiters a tabular source may declare, by name, each the spliterator's own byte.
|
|
29
13
|
*
|
|
30
|
-
* The `satisfies` clause
|
|
31
|
-
*
|
|
14
|
+
* The `satisfies` clause makes a delimiter name spliterator no longer ships a compile error
|
|
15
|
+
* rather than a silently parallel vocabulary.
|
|
32
16
|
*/
|
|
33
17
|
const COLUMN_DELIMITERS = {
|
|
34
18
|
comma: Delimiters.Comma,
|
|
@@ -43,26 +27,22 @@ export function delimiterFor(path) {
|
|
|
43
27
|
/**
|
|
44
28
|
* Stream a delimited file's rows lazily as header-keyed objects.
|
|
45
29
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* operators away.
|
|
30
|
+
* @returns The spliterator's own {@linkcode AsyncSequence}, whose `map`/`filter`
|
|
31
|
+
* fuse into the same pull loop.
|
|
32
|
+
* An `async function*` wrapper would add an async frame per row and remove those operators.
|
|
50
33
|
*/
|
|
51
34
|
export function streamRows(source, opts = {}) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
//
|
|
35
|
+
const path = source.toString();
|
|
36
|
+
return CSVSpliterator.fromAsync(path, {
|
|
37
|
+
columnDelimiter: COLUMN_DELIMITERS[opts.delimiter ?? delimiterFor(path)],
|
|
38
|
+
// A {@linkcode ColumnMapping} holds columns in the publisher's spelling rather than a
|
|
39
|
+
// normalized key such as `facility_name`, so the keys must arrive as the file writes them.
|
|
40
|
+
// The reader's default normalizes.
|
|
56
41
|
normalizeKeys: false,
|
|
57
42
|
});
|
|
58
43
|
}
|
|
59
44
|
/**
|
|
60
|
-
* Best-effort {@link ColumnMapping} inferred from a header row
|
|
61
|
-
* is matched (case- and punctuation-insensitive, on whole tokens) to a field by keyword, in a precedence that resolves
|
|
62
|
-
* the common ambiguities: a dedicated id / phone / email column is claimed before the generic sweep, an org / facility
|
|
63
|
-
* column beats a person "name", and address columns (street / city / state / zip…) collect into one multi-column field.
|
|
64
|
-
* Imperfect on bespoke headers (an explicit mapping or the LLM-assisted inference #603 is the answer there), but it
|
|
65
|
-
* nails tidy and semi-tidy files with no hand-mapping. Unmatched columns are left out.
|
|
45
|
+
* Best-effort {@link ColumnMapping} inferred from a header row, the "point it at any CSV" convenience.
|
|
66
46
|
*/
|
|
67
47
|
export function inferMapping(header) {
|
|
68
48
|
// Pad to whole-token boundaries so "state" doesn't match inside "statement".
|
|
@@ -104,31 +84,30 @@ export function inferMapping(header) {
|
|
|
104
84
|
return mapping;
|
|
105
85
|
}
|
|
106
86
|
/**
|
|
107
|
-
* Join the
|
|
87
|
+
* Join the selected columns of a row into a single trimmed string, or null if empty.
|
|
108
88
|
*/
|
|
109
89
|
export function pick(row, columns, separator = " ") {
|
|
110
90
|
if (!columns)
|
|
111
|
-
return
|
|
91
|
+
return null;
|
|
112
92
|
const list = Array.isArray(columns) ? columns : [columns];
|
|
113
93
|
const value = list
|
|
114
|
-
.map((c) => row[c]
|
|
94
|
+
.map((c) => row[c])
|
|
115
95
|
.filter(isPresent)
|
|
116
96
|
.join(separator)
|
|
117
97
|
.trim();
|
|
118
|
-
return value ||
|
|
98
|
+
return value || null;
|
|
119
99
|
}
|
|
120
100
|
/**
|
|
121
|
-
* Normalize one tabular row into a {@link SourceRecord} under a {@link ColumnMapping}
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* single-threaded (see {@link normalizeCSV}) while geocoding is offloaded (see `geocodeStream`).
|
|
101
|
+
* Normalize one tabular row into a {@link SourceRecord} under a {@link ColumnMapping},
|
|
102
|
+
* pure aside from the optional geocode interface so the deterministic normalization
|
|
103
|
+
* can run single-threaded while geocoding is offloaded.
|
|
125
104
|
*/
|
|
126
105
|
export async function ingestRow(row, mapping, index, opts = {}) {
|
|
127
|
-
const id = (mapping.id ? row[mapping.id]
|
|
106
|
+
const id = (mapping.id ? row[mapping.id] : "") || String(index);
|
|
128
107
|
const nameValue = pick(row, mapping.name);
|
|
129
108
|
const orgValue = pick(row, mapping.organization);
|
|
130
109
|
const addressValue = pick(row, mapping.address, opts.addressSeparator ?? ", ");
|
|
131
|
-
let attributes;
|
|
110
|
+
let attributes = null;
|
|
132
111
|
if (mapping.attributes) {
|
|
133
112
|
for (const [key, columns] of Object.entries(mapping.attributes)) {
|
|
134
113
|
const value = pick(row, columns);
|
|
@@ -140,12 +119,12 @@ export async function ingestRow(row, mapping, index, opts = {}) {
|
|
|
140
119
|
}
|
|
141
120
|
return {
|
|
142
121
|
id,
|
|
143
|
-
source: mapping.source,
|
|
144
|
-
name: nameValue ? parsePersonName(nameValue) :
|
|
145
|
-
organization: orgValue ? canonicalizeOrganizationName(orgValue) :
|
|
146
|
-
phone: (mapping.phone && row[mapping.phone]
|
|
147
|
-
email: (mapping.email && row[mapping.email]?.
|
|
148
|
-
address: addressValue && opts.geocodeAddress ? ((await opts.geocodeAddress(addressValue)) ??
|
|
122
|
+
source: mapping.source ?? null,
|
|
123
|
+
name: nameValue ? parsePersonName(nameValue) : null,
|
|
124
|
+
organization: orgValue ? canonicalizeOrganizationName(orgValue) : null,
|
|
125
|
+
phone: (mapping.phone && row[mapping.phone]) || null,
|
|
126
|
+
email: (mapping.email && row[mapping.email]?.toLowerCase()) || null,
|
|
127
|
+
address: addressValue && opts.geocodeAddress ? ((await opts.geocodeAddress(addressValue)) ?? null) : null,
|
|
149
128
|
attributes,
|
|
150
129
|
raw: row,
|
|
151
130
|
};
|
|
@@ -153,7 +132,7 @@ export async function ingestRow(row, mapping, index, opts = {}) {
|
|
|
153
132
|
/**
|
|
154
133
|
* Normalize tabular rows into {@link SourceRecord}s under a {@link ColumnMapping}.
|
|
155
134
|
*
|
|
156
|
-
* @see {@link streamRows} for the streaming path
|
|
135
|
+
* @see {@link streamRows} for the streaming path. It is preferred for multi-GB files.
|
|
157
136
|
*/
|
|
158
137
|
export async function ingestRows(rows, mapping, opts = {}) {
|
|
159
138
|
const records = [];
|
|
@@ -165,22 +144,16 @@ export async function ingestRows(rows, mapping, opts = {}) {
|
|
|
165
144
|
return records;
|
|
166
145
|
}
|
|
167
146
|
/**
|
|
168
|
-
* Stream a delimited file as normalized {@link SourceRecord}s
|
|
169
|
-
*
|
|
170
|
-
* a multi-GB file, line by line. Geocode separately by piping the output through `geocodeStream` (the only heavy step
|
|
171
|
-
* worth threading); for a light file (e.g. one that already carries geo cells) just consume this and stop.
|
|
172
|
-
*
|
|
173
|
-
* Records come out in file order: the sequence's `map` settles each row before pulling the next, and its counter is the
|
|
174
|
-
* row's index — the id a row without a mapped `id` column falls back to.
|
|
147
|
+
* Stream a delimited file as normalized {@link SourceRecord}s in file order with no geocoding.
|
|
148
|
+
* Geocode separately through `geocodeStream`.
|
|
175
149
|
*/
|
|
176
150
|
export function normalizeCSV(source, opts) {
|
|
177
151
|
return streamRows(source, { delimiter: opts.delimiter }).map((row, index) => ingestRow(row, opts.mapping, index));
|
|
178
152
|
}
|
|
179
153
|
/**
|
|
180
|
-
* Build a {@link GeocodeAddress} from
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* parsed-but-unlocated address is still returned.
|
|
154
|
+
* Build a {@link GeocodeAddress} from injected parse and geocode primitives.
|
|
155
|
+
*
|
|
156
|
+
* When geocoding can't place the address, the parsed-but-unlocated address is still returned.
|
|
184
157
|
*/
|
|
185
158
|
export function geocodeAddressVia(deps) {
|
|
186
159
|
return async (raw) => {
|
|
@@ -202,7 +175,9 @@ export function geocodeAddressVia(deps) {
|
|
|
202
175
|
coordinate: { latitude: resolved.lat, longitude: resolved.lon },
|
|
203
176
|
tier: resolved.resolution_tier,
|
|
204
177
|
uncertaintyMeters: resolved.uncertainty_m,
|
|
205
|
-
hierarchy: resolved.hierarchy,
|
|
178
|
+
hierarchy: resolved.hierarchy ?? null,
|
|
179
|
+
poBox: null,
|
|
180
|
+
multiUnit: null,
|
|
206
181
|
};
|
|
207
182
|
return withGeocode(base, geocode);
|
|
208
183
|
};
|
package/out/ingest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ingest.js","sourceRoot":"","sources":["../lib/ingest.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ingest.js","sourceRoot":"","sources":["../lib/ingest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnD,OAAO,EAAE,4BAA4B,EAAE,eAAe,EAAE,eA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IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAClC,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QACnC,CAAC;QAED,MAAM,IAAI,GAAG,eAAe,CAAC,UAAU,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,CAAA;QAExE,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,GAAG,KAAK,IAAI,IAAI,QAAQ,CAAC,GAAG,KAAK,IAAI;YAAE,OAAO,IAAI,CAAA;QAE5E,MAAM,OAAO,GAAmB;YAC/B,UAAU,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,CAAC,GAAG,EAAE;YAC/D,IAAI,EAAE,QAAQ,CAAC,eAAe;YAC9B,iBAAiB,EAAE,QAAQ,CAAC,aAAa;YACzC,SAAS,EAAE,QAAQ,CAAC,SAAS,IAAI,IAAI;YACrC,KAAK,EAAE,IAAI;YACX,SAAS,EAAE,IAAI;SACf,CAAA;QAED,OAAO,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAClC,CAAC,CAAA;AACF,CAAC"}
|
package/out/learned-scorer.d.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
|
import { type Comparison, type GBT, type TermFrequencyTable } from "@mailwoman/match";
|
|
26
21
|
import type { SourceRecord } from "#types";
|
|
@@ -29,10 +24,13 @@ import type { SourceRecord } from "#types";
|
|
|
29
24
|
*/
|
|
30
25
|
export interface LearnedFeatureConfig {
|
|
31
26
|
/**
|
|
32
|
-
* The comparison set the features are built over
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
27
|
+
* The comparison set the features are built over.
|
|
28
|
+
*
|
|
29
|
+
* It must be `buildDefaultModel({ collapseSpatial: true, addressFrequency }).comparisons`
|
|
30
|
+
* so the feature layout matches the trained model.
|
|
31
|
+
*
|
|
32
|
+
* `usePhone` and `discriminators` are not part of the learned feature model,
|
|
33
|
+
* since the GBT replaces the Fellegi-Sunter weight wholesale and owns its feature vector.
|
|
36
34
|
*/
|
|
37
35
|
comparisons: Comparison<SourceRecord>[];
|
|
38
36
|
/**
|
|
@@ -41,16 +39,21 @@ export interface LearnedFeatureConfig {
|
|
|
41
39
|
addressFrequency: TermFrequencyTable;
|
|
42
40
|
}
|
|
43
41
|
/**
|
|
44
|
-
* Build the per-pair feature extractor.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
42
|
+
* Build the per-pair feature extractor.
|
|
43
|
+
*
|
|
44
|
+
* The vector is: one-hot of each comparison's agreement level, then the two over-merge
|
|
45
|
+
* interaction terms (spatial-exact × name-disagree, spatial-exact × org-disagree,
|
|
46
|
+
* the "same place, different names" signature that drives co-located over-merges),
|
|
47
|
+
* then address crowdedness scaled into [0, 1].
|
|
47
48
|
* Deterministic and EM-independent, so it is identical across train / eval / inference.
|
|
48
49
|
*/
|
|
49
50
|
export declare function createMatchFeaturizer(config: LearnedFeatureConfig): (a: SourceRecord, b: SourceRecord) => number[];
|
|
50
51
|
/**
|
|
51
|
-
* Wrap a trained {@link GBT} into the `(a, b) => number` link scorer for {@link ResolveConfig.scorer}.
|
|
52
|
-
*
|
|
53
|
-
*
|
|
52
|
+
* Wrap a trained {@link GBT} into the `(a, b) => number` link scorer for {@link ResolveConfig.scorer}.
|
|
53
|
+
*
|
|
54
|
+
* The returned weight is the model's logit.
|
|
55
|
+
* Same threshold-comparable units as the Fellegi-Sunter weight it replaces,
|
|
56
|
+
* so the pipeline's clustering + threshold semantics are unchanged.
|
|
54
57
|
*/
|
|
55
58
|
export declare function createGBTScorer(config: LearnedFeatureConfig & {
|
|
56
59
|
model: GBT;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"learned-scorer.d.ts","sourceRoot":"","sources":["../lib/learned-scorer.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"learned-scorer.d.ts","sourceRoot":"","sources":["../lib/learned-scorer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAEN,KAAK,UAAU,EACf,KAAK,GAAG,EAGR,KAAK,kBAAkB,EACvB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAS1C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC;;;;;;;;OAQG;IACH,WAAW,EAAE,UAAU,CAAC,YAAY,CAAC,EAAE,CAAA;IACvC;;OAEG;IACH,gBAAgB,EAAE,kBAAkB,CAAA;CACpC;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,oBAAoB,GAAG,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,KAAK,MAAM,EAAE,CAkDlH;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,oBAAoB,GAAG;IAAE,KAAK,EAAE,GAAG,CAAA;CAAE,GAC3C,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,KAAK,MAAM,CAK9C"}
|
package/out/learned-scorer.js
CHANGED
|
@@ -3,36 +3,34 @@
|
|
|
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
|
import { agreementPattern, gbtScore, nameSimilarity, } from "@mailwoman/match";
|
|
26
21
|
/**
|
|
27
|
-
* Similarity at which two official names count as the same
|
|
28
|
-
*
|
|
29
|
-
*
|
|
22
|
+
* Similarity at which two official names count as the same organization.
|
|
23
|
+
*
|
|
24
|
+
* Set high because the feature is a near-exact agreement signal rather than a fuzzy one.
|
|
30
25
|
*/
|
|
31
26
|
const OFFICIAL_NAME_AGREEMENT = 0.93;
|
|
32
27
|
/**
|
|
33
|
-
* Build the per-pair feature extractor.
|
|
34
|
-
*
|
|
35
|
-
*
|
|
28
|
+
* Build the per-pair feature extractor.
|
|
29
|
+
*
|
|
30
|
+
* The vector is: one-hot of each comparison's agreement level, then the two over-merge
|
|
31
|
+
* interaction terms (spatial-exact × name-disagree, spatial-exact × org-disagree,
|
|
32
|
+
* the "same place, different names" signature that drives co-located over-merges),
|
|
33
|
+
* then address crowdedness scaled into [0, 1].
|
|
36
34
|
* Deterministic and EM-independent, so it is identical across train / eval / inference.
|
|
37
35
|
*/
|
|
38
36
|
export function createMatchFeaturizer(config) {
|
|
@@ -53,7 +51,6 @@ export function createMatchFeaturizer(config) {
|
|
|
53
51
|
f.push(lvl === l ? 1 : 0);
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
|
-
// Interaction: co-located (spatial exact = level 0) AND names/org disagree (catch-all level).
|
|
57
54
|
const spatialExact = spatialI !== undefined && pat[spatialI] === 0 ? 1 : 0;
|
|
58
55
|
const nameDisagree = givenI !== undefined &&
|
|
59
56
|
familyI !== undefined &&
|
|
@@ -62,34 +59,29 @@ export function createMatchFeaturizer(config) {
|
|
|
62
59
|
? 1
|
|
63
60
|
: 0;
|
|
64
61
|
const orgDisagree = orgI !== undefined && pat[orgI] === lastLevel(orgI) ? 1 : 0;
|
|
65
|
-
f.push(spatialExact * nameDisagree);
|
|
62
|
+
f.push(spatialExact * nameDisagree);
|
|
66
63
|
f.push(spatialExact * orgDisagree);
|
|
67
|
-
// Address crowdedness (how shared this address is) — high → "same address" is weak evidence.
|
|
68
64
|
const freq = a.address?.raw ? addressFrequency.frequency(a.address.raw) : 0;
|
|
69
65
|
f.push(Math.min(1, freq * 1000));
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
// learned feature model), so the GBT could never see — let alone learn — that officialAgree in
|
|
75
|
-
// the presence of orgDisagree is ANTI-identity evidence. These three appended features express
|
|
76
|
-
// it directly from `attributes.authorizedOfficial`; appended at the END so models trained
|
|
77
|
-
// without them (the cross-source GBT) keep scoring unchanged (trailing features are ignored).
|
|
66
|
+
// Roll-up signature: a shared corporate address can host differently-branded
|
|
67
|
+
// operating entities whose authorized official also agrees.
|
|
68
|
+
// The official is not in the comparison set, so these three features express that evidence directly.
|
|
69
|
+
// They are appended at the end, so models trained without them keep scoring unchanged.
|
|
78
70
|
const offA = a.attributes?.["authorizedOfficial"]?.trim();
|
|
79
71
|
const offB = b.attributes?.["authorizedOfficial"]?.trim();
|
|
80
72
|
const officialAgree = offA && offB && nameSimilarity(offA, offB) >= OFFICIAL_NAME_AGREEMENT ? 1 : 0;
|
|
81
73
|
f.push(officialAgree);
|
|
82
|
-
f.push(officialAgree * orgDisagree);
|
|
74
|
+
f.push(officialAgree * orgDisagree);
|
|
83
75
|
f.push(officialAgree * orgDisagree * spatialExact);
|
|
84
|
-
// …at the same place
|
|
85
|
-
// scale into a usable range
|
|
86
76
|
return f;
|
|
87
77
|
};
|
|
88
78
|
}
|
|
89
79
|
/**
|
|
90
|
-
* Wrap a trained {@link GBT} into the `(a, b) => number` link scorer for {@link ResolveConfig.scorer}.
|
|
91
|
-
*
|
|
92
|
-
*
|
|
80
|
+
* Wrap a trained {@link GBT} into the `(a, b) => number` link scorer for {@link ResolveConfig.scorer}.
|
|
81
|
+
*
|
|
82
|
+
* The returned weight is the model's logit.
|
|
83
|
+
* Same threshold-comparable units as the Fellegi-Sunter weight it replaces,
|
|
84
|
+
* so the pipeline's clustering + threshold semantics are unchanged.
|
|
93
85
|
*/
|
|
94
86
|
export function createGBTScorer(config) {
|
|
95
87
|
const featurize = createMatchFeaturizer(config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"learned-scorer.js","sourceRoot":"","sources":["../lib/learned-scorer.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"learned-scorer.js","sourceRoot":"","sources":["../lib/learned-scorer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACN,gBAAgB,EAGhB,QAAQ,EACR,cAAc,GAEd,MAAM,kBAAkB,CAAA;AAIzB;;;;GAIG;AACH,MAAM,uBAAuB,GAAG,IAAI,CAAA;AAsBpC;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAA4B;IACjE,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAA;IAChD,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC3D,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC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C,aAAa,GAAG,WAAW,GAAG,YAAY,CAAC,CAAA;QAElD,OAAO,CAAC,CAAA;IACT,CAAC,CAAA;AACF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC9B,MAA6C;IAE7C,MAAM,SAAS,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAA;IAC/C,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IAExB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAClD,CAAC"}
|
package/out/map-html.d.ts
CHANGED
|
@@ -2,27 +2,6 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Render resolved entities as a standalone map page — the visual complement to {@link toGeoJSON}'s
|
|
7
|
-
* QGIS/analyst export. `toMapHTML(featureCollection)` returns one HTML file you open in a
|
|
8
|
-
* browser; no server, no build.
|
|
9
|
-
*
|
|
10
|
-
* It renders on the HOUSE stack: MapLibre GL + a Protomaps basemap (`@protomaps/basemaps` generates
|
|
11
|
-
* the `layers()` for a named flavor) over the `basemap-v4` vector tiles served from R2 at
|
|
12
|
-
* `tiles.mailwoman.ai` — the same basemap the demo uses. Each entity is a circle sized by
|
|
13
|
-
* records-merged and colored by cross-dataset-link status (≥2 sources stand out), or
|
|
14
|
-
* categorically by `bucket` when the reconciliation output carries one. Pure: GeoJSON in, HTML
|
|
15
|
-
* string out (the Protomaps layer specs are generated at this point and inlined). The generated
|
|
16
|
-
* page fetches MapLibre, the basemap tiles, and glyphs/sprite over the network when opened (the
|
|
17
|
-
* house infra).
|
|
18
|
-
*
|
|
19
|
-
* SERVE IT OVER LOCALHOST, don't open it as a file. The house tile server (`tiles.mailwoman.ai`)
|
|
20
|
-
* CORS-restricts to localhost + the docs domains, so a `file://` page shows the (accurate)
|
|
21
|
-
* markers on a blank basemap. `npx serve` / `python3 -m http.server` in the output directory is
|
|
22
|
-
* enough; the page also surfaces a hint banner when it detects it's running from `file://`.
|
|
23
|
-
*
|
|
24
|
-
* Neutral entity-resolution view: it shows what resolved to what and how confidently (cohesion).
|
|
25
|
-
* Bucket labels render verbatim from the data, never editorialized.
|
|
26
5
|
*/
|
|
27
6
|
import type { GeoFeatureCollection, PointLiteral } from "@mailwoman/spatial";
|
|
28
7
|
import type { MapFeatureData } from "#types";
|
|
@@ -30,29 +9,31 @@ import type { MapFeatureData } from "#types";
|
|
|
30
9
|
* Protomaps stock flavors (shipped by `@protomaps/basemaps`).
|
|
31
10
|
*/
|
|
32
11
|
export type MapFlavor = "light" | "dark" | "white" | "grayscale" | "black";
|
|
12
|
+
/**
|
|
13
|
+
* Options for {@link toMapHTML}.
|
|
14
|
+
*
|
|
15
|
+
* With `colorBy: "auto"`, markers are colored by `bucket` when any feature has one
|
|
16
|
+
* and otherwise by whether two or more sources agree.
|
|
17
|
+
*/
|
|
33
18
|
export interface MapHTMLOptions {
|
|
34
19
|
/**
|
|
35
|
-
*
|
|
20
|
+
* Sets the document title and on-map heading, defaulting to `Mailwoman — resolved entities`.
|
|
36
21
|
*/
|
|
37
22
|
title?: string;
|
|
38
23
|
/**
|
|
39
|
-
* Protomaps basemap flavor
|
|
24
|
+
* Selects the Protomaps basemap flavor, defaulting to `light`, over which the markers read clearly.
|
|
40
25
|
*/
|
|
41
26
|
flavor?: MapFlavor;
|
|
42
27
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* status.
|
|
47
|
-
* - `"sources"` — always by cross-dataset-link status (≥2 sources stand out).
|
|
48
|
-
* - `"bucket"` — always by the `bucket` property.
|
|
28
|
+
* Chooses marker colors: `bucket` uses the `bucket` property, `sources` shows
|
|
29
|
+
* whether two or more sources are linked.
|
|
30
|
+
* The default `auto` picks `bucket` when any feature has one.
|
|
49
31
|
*/
|
|
50
32
|
colorBy?: "auto" | "sources" | "bucket";
|
|
51
33
|
}
|
|
52
34
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* state rather than a broken map.
|
|
35
|
+
* Renders a {@link toGeoJSON} or reconciliation feature collection as a standalone MapLibre
|
|
36
|
+
* HTML document, with an empty-state panel when the collection has no features.
|
|
56
37
|
*/
|
|
57
38
|
export declare function toMapHTML(geojson: GeoFeatureCollection<PointLiteral, MapFeatureData>, options?: MapHTMLOptions): string;
|
|
58
39
|
//# sourceMappingURL=map-html.d.ts.map
|
package/out/map-html.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-html.d.ts","sourceRoot":"","sources":["../lib/map-html.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"map-html.d.ts","sourceRoot":"","sources":["../lib/map-html.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAG5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAa5C;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,WAAW,GAAG,OAAO,CAAA;AAE1E;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,MAAM,CAAC,EAAE,SAAS,CAAA;IAElB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAA;CACvC;AAgBD;;;GAGG;AACH,wBAAgB,SAAS,CACxB,OAAO,EAAE,oBAAoB,CAAC,YAAY,EAAE,cAAc,CAAC,EAC3D,OAAO,GAAE,cAAmB,GAC1B,MAAM,CAmNR"}
|