@mailwoman/entity-resolution 0.0.0-stage → 11.0.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 +114 -2
- package/lib/address-key.ts +46 -0
- package/lib/geocode-handler.ts +37 -0
- package/lib/geojson.ts +72 -0
- package/lib/index.ts +23 -0
- package/lib/ingest.ts +349 -0
- package/lib/learned-scorer.ts +134 -0
- package/lib/map-html.ts +287 -0
- package/lib/models/crosssource-gbt-en-us.ts +43 -0
- package/lib/models/dedup-gbt-en-us.ts +47 -0
- package/lib/models/org-crosssource-gbt-en-us.ts +43 -0
- package/lib/reconcile.ts +239 -0
- package/lib/resolve.ts +569 -0
- package/lib/types.ts +110 -0
- package/out/address-key.d.ts +34 -0
- package/out/address-key.d.ts.map +1 -0
- package/out/address-key.js +41 -0
- package/out/address-key.js.map +1 -0
- package/out/geocode-handler.d.ts +20 -0
- package/out/geocode-handler.d.ts.map +1 -0
- package/out/geocode-handler.js +29 -0
- package/out/geocode-handler.js.map +1 -0
- package/out/geojson.d.ts +28 -0
- package/out/geojson.d.ts.map +1 -0
- package/out/geojson.js +62 -0
- package/out/geojson.js.map +1 -0
- package/out/index.d.ts +23 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +23 -0
- package/out/index.js.map +1 -0
- package/out/ingest.d.ts +173 -0
- package/out/ingest.d.ts.map +1 -0
- package/out/ingest.js +185 -0
- package/out/ingest.js.map +1 -0
- package/out/learned-scorer.d.ts +61 -0
- package/out/learned-scorer.d.ts.map +1 -0
- package/out/learned-scorer.js +91 -0
- package/out/learned-scorer.js.map +1 -0
- package/out/map-html.d.ts +39 -0
- package/out/map-html.d.ts.map +1 -0
- package/out/map-html.js +220 -0
- package/out/map-html.js.map +1 -0
- package/out/models/crosssource-gbt-en-us.d.ts +45 -0
- package/out/models/crosssource-gbt-en-us.d.ts.map +1 -0
- package/out/models/crosssource-gbt-en-us.js +40 -0
- package/out/models/crosssource-gbt-en-us.js.map +1 -0
- package/out/models/dedup-gbt-en-us.d.ts +44 -0
- package/out/models/dedup-gbt-en-us.d.ts.map +1 -0
- package/out/models/dedup-gbt-en-us.js +44 -0
- package/out/models/dedup-gbt-en-us.js.map +1 -0
- package/out/models/org-crosssource-gbt-en-us.d.ts +45 -0
- package/out/models/org-crosssource-gbt-en-us.d.ts.map +1 -0
- package/out/models/org-crosssource-gbt-en-us.js +40 -0
- package/out/models/org-crosssource-gbt-en-us.js.map +1 -0
- package/out/reconcile.d.ts +96 -0
- package/out/reconcile.d.ts.map +1 -0
- package/out/reconcile.js +127 -0
- package/out/reconcile.js.map +1 -0
- package/out/resolve.d.ts +264 -0
- package/out/resolve.d.ts.map +1 -0
- package/out/resolve.js +282 -0
- package/out/resolve.js.map +1 -0
- package/out/tools/coverage-reconciliation.d.ts +67 -0
- package/out/tools/coverage-reconciliation.d.ts.map +1 -0
- package/out/tools/coverage-reconciliation.js +113 -0
- package/out/tools/coverage-reconciliation.js.map +1 -0
- package/out/tools/cross/dataset-correlation.d.ts +61 -0
- package/out/tools/cross/dataset-correlation.d.ts.map +1 -0
- package/out/tools/cross/dataset-correlation.js +244 -0
- package/out/tools/cross/dataset-correlation.js.map +1 -0
- package/out/tools/cross/source-threshold-sweep.d.ts +60 -0
- package/out/tools/cross/source-threshold-sweep.d.ts.map +1 -0
- package/out/tools/cross/source-threshold-sweep.js +264 -0
- package/out/tools/cross/source-threshold-sweep.js.map +1 -0
- package/out/tools/dedup-ceiling.d.ts +62 -0
- package/out/tools/dedup-ceiling.d.ts.map +1 -0
- package/out/tools/dedup-ceiling.js +171 -0
- package/out/tools/dedup-ceiling.js.map +1 -0
- package/out/tools/eval-geocoder.d.ts +68 -0
- package/out/tools/eval-geocoder.d.ts.map +1 -0
- package/out/tools/eval-geocoder.js +13 -0
- package/out/tools/eval-geocoder.js.map +1 -0
- package/out/tools/geocoder/namesake-probe.d.ts +33 -0
- package/out/tools/geocoder/namesake-probe.d.ts.map +1 -0
- package/out/tools/geocoder/namesake-probe.js +60 -0
- package/out/tools/geocoder/namesake-probe.js.map +1 -0
- package/out/tools/geocoder/vs-provided-coords.d.ts +53 -0
- package/out/tools/geocoder/vs-provided-coords.d.ts.map +1 -0
- package/out/tools/geocoder/vs-provided-coords.js +161 -0
- package/out/tools/geocoder/vs-provided-coords.js.map +1 -0
- package/out/tools/gold-set-sample.d.ts +67 -0
- package/out/tools/gold-set-sample.d.ts.map +1 -0
- package/out/tools/gold-set-sample.js +81 -0
- package/out/tools/gold-set-sample.js.map +1 -0
- package/out/tools/learned/scorer/clustering-eval.d.ts +77 -0
- package/out/tools/learned/scorer/clustering-eval.d.ts.map +1 -0
- package/out/tools/learned/scorer/clustering-eval.js +207 -0
- package/out/tools/learned/scorer/clustering-eval.js.map +1 -0
- package/out/tools/learned/scorer/crossstate-eval.d.ts +65 -0
- package/out/tools/learned/scorer/crossstate-eval.d.ts.map +1 -0
- package/out/tools/learned/scorer/crossstate-eval.js +168 -0
- package/out/tools/learned/scorer/crossstate-eval.js.map +1 -0
- package/out/tools/learned/scorer/eval.d.ts +64 -0
- package/out/tools/learned/scorer/eval.d.ts.map +1 -0
- package/out/tools/learned/scorer/eval.js +275 -0
- package/out/tools/learned/scorer/eval.js.map +1 -0
- package/out/tools/matcher-scale.d.ts +40 -0
- package/out/tools/matcher-scale.d.ts.map +1 -0
- package/out/tools/matcher-scale.js +111 -0
- package/out/tools/matcher-scale.js.map +1 -0
- package/out/tools/nppes/dedup-benchmark.d.ts +82 -0
- package/out/tools/nppes/dedup-benchmark.d.ts.map +1 -0
- package/out/tools/nppes/dedup-benchmark.js +226 -0
- package/out/tools/nppes/dedup-benchmark.js.map +1 -0
- package/out/tools/nppes/org-name.d.ts +15 -0
- package/out/tools/nppes/org-name.d.ts.map +1 -0
- package/out/tools/nppes/org-name.js +6 -0
- package/out/tools/nppes/org-name.js.map +1 -0
- package/out/tools/nppes/overmerge-packet.d.ts +43 -0
- package/out/tools/nppes/overmerge-packet.d.ts.map +1 -0
- package/out/tools/nppes/overmerge-packet.js +54 -0
- package/out/tools/nppes/overmerge-packet.js.map +1 -0
- package/out/tools/nppes/report.d.ts +97 -0
- package/out/tools/nppes/report.d.ts.map +1 -0
- package/out/tools/nppes/report.js +178 -0
- package/out/tools/nppes/report.js.map +1 -0
- package/out/tools/nppes/sample.d.ts +101 -0
- package/out/tools/nppes/sample.d.ts.map +1 -0
- package/out/tools/nppes/sample.js +127 -0
- package/out/tools/nppes/sample.js.map +1 -0
- package/out/tools/nppes/scoring.d.ts +37 -0
- package/out/tools/nppes/scoring.d.ts.map +1 -0
- package/out/tools/nppes/scoring.js +81 -0
- package/out/tools/nppes/scoring.js.map +1 -0
- package/out/tools/nppes/settings.d.ts +41 -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 +63 -0
- package/out/tools/nppes/truth-grains.d.ts.map +1 -0
- package/out/tools/nppes/truth-grains.js +142 -0
- package/out/tools/nppes/truth-grains.js.map +1 -0
- package/out/tools/shared.d.ts +325 -0
- package/out/tools/shared.d.ts.map +1 -0
- package/out/tools/shared.js +453 -0
- package/out/tools/shared.js.map +1 -0
- package/out/tools/train/cross-gbt.d.ts +89 -0
- package/out/tools/train/cross-gbt.d.ts.map +1 -0
- package/out/tools/train/cross-gbt.js +132 -0
- package/out/tools/train/cross-gbt.js.map +1 -0
- package/out/tools/train/gbt.d.ts +85 -0
- package/out/tools/train/gbt.d.ts.map +1 -0
- package/out/tools/train/gbt.js +155 -0
- package/out/tools/train/gbt.js.map +1 -0
- package/out/tools/train/org-cross-gbt.d.ts +85 -0
- package/out/tools/train/org-cross-gbt.d.ts.map +1 -0
- package/out/tools/train/org-cross-gbt.js +122 -0
- package/out/tools/train/org-cross-gbt.js.map +1 -0
- package/out/tools/txhhsc-to-oarow.d.ts +42 -0
- package/out/tools/txhhsc-to-oarow.d.ts.map +1 -0
- package/out/tools/txhhsc-to-oarow.js +78 -0
- package/out/tools/txhhsc-to-oarow.js.map +1 -0
- package/out/tools/viz/browser.d.ts +31 -0
- package/out/tools/viz/browser.d.ts.map +1 -0
- package/out/tools/viz/browser.js +26 -0
- package/out/tools/viz/browser.js.map +1 -0
- package/out/tools/viz/cross-dataset-map.d.ts +39 -0
- package/out/tools/viz/cross-dataset-map.d.ts.map +1 -0
- package/out/tools/viz/cross-dataset-map.js +84 -0
- package/out/tools/viz/cross-dataset-map.js.map +1 -0
- package/out/tools/viz/geocode-first-surface.d.ts +36 -0
- package/out/tools/viz/geocode-first-surface.d.ts.map +1 -0
- package/out/tools/viz/geocode-first-surface.js +234 -0
- package/out/tools/viz/geocode-first-surface.js.map +1 -0
- package/out/tools/viz/render/map.d.ts +42 -0
- package/out/tools/viz/render/map.d.ts.map +1 -0
- package/out/tools/viz/render/map.js +40 -0
- package/out/tools/viz/render/map.js.map +1 -0
- package/out/tools/viz/render.d.ts +46 -0
- package/out/tools/viz/render.d.ts.map +1 -0
- package/out/tools/viz/render.js +49 -0
- package/out/tools/viz/render.js.map +1 -0
- package/out/tools/viz/source-provenance-map.d.ts +57 -0
- package/out/tools/viz/source-provenance-map.d.ts.map +1 -0
- package/out/tools/viz/source-provenance-map.js +82 -0
- package/out/tools/viz/source-provenance-map.js.map +1 -0
- package/out/tools/viz/yardstick-figure.d.ts +22 -0
- package/out/tools/viz/yardstick-figure.d.ts.map +1 -0
- package/out/tools/viz/yardstick-figure.js +106 -0
- package/out/tools/viz/yardstick-figure.js.map +1 -0
- package/out/types.d.ts +108 -0
- package/out/types.d.ts.map +1 -0
- package/out/types.js +11 -0
- package/out/types.js.map +1 -0
- package/package.json +113 -3
- package/tools/coverage-reconciliation.ts +192 -0
- package/tools/cross/dataset-correlation.ts +380 -0
- package/tools/cross/source-threshold-sweep.ts +416 -0
- package/tools/dedup-ceiling.ts +225 -0
- package/tools/eval-geocoder.ts +77 -0
- package/tools/geocoder/namesake-probe.ts +91 -0
- package/tools/geocoder/vs-provided-coords.ts +232 -0
- package/tools/gold-set-sample.ts +147 -0
- package/tools/learned/scorer/clustering-eval.ts +349 -0
- package/tools/learned/scorer/crossstate-eval.ts +280 -0
- package/tools/learned/scorer/eval.ts +429 -0
- package/tools/matcher-scale.ts +185 -0
- package/tools/nppes/dedup-benchmark.ts +364 -0
- package/tools/nppes/org-name.ts +15 -0
- package/tools/nppes/overmerge-packet.ts +98 -0
- package/tools/nppes/report.ts +380 -0
- package/tools/nppes/sample.ts +250 -0
- package/tools/nppes/scoring.ts +115 -0
- package/tools/nppes/settings.ts +102 -0
- package/tools/nppes/truth-grains.ts +185 -0
- package/tools/shared.ts +743 -0
- package/tools/train/cross-gbt.ts +214 -0
- package/tools/train/gbt.ts +261 -0
- package/tools/train/org-cross-gbt.ts +189 -0
- package/tools/txhhsc-to-oarow.ts +118 -0
- package/tools/viz/browser.ts +41 -0
- package/tools/viz/cross-dataset-map.ts +133 -0
- package/tools/viz/geocode-first-surface.ts +305 -0
- package/tools/viz/render/map.ts +61 -0
- package/tools/viz/render.ts +103 -0
- package/tools/viz/source-provenance-map.ts +154 -0
- package/tools/viz/yardstick-figure.ts +197 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Render a self-contained Plotly html to a PNG via headless Chromium — the shared renderer behind
|
|
7
|
+
* the `registry viz` figures (an internal helper rather than a command).
|
|
8
|
+
*
|
|
9
|
+
* Plotly 3D (`surface`/`scatter3d`) needs a real WebGL context. The shared harness
|
|
10
|
+
* (`./browser.ts`) provides through SwiftShader. 2D traces (`contour`/`heatmap`) render on the 2D
|
|
11
|
+
* canvas regardless. We wait for Plotly's `plotly_afterplot` to fire on every graph div rather
|
|
12
|
+
* than a fixed sleep, so the screenshot can't race the (async) WebGL paint.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { pathToFileURL } from "@mailwoman/core/module/file-url"
|
|
16
|
+
import { resolvePath as resolve } from "path-ts"
|
|
17
|
+
|
|
18
|
+
import { withChromiumPage } from "#tools/viz/browser"
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Options for {@linkcode renderPlotlyHTMLToPNG}.
|
|
22
|
+
*/
|
|
23
|
+
export interface RenderPlotlyOptions {
|
|
24
|
+
/**
|
|
25
|
+
* The self-contained Plotly html file.
|
|
26
|
+
*/
|
|
27
|
+
inHTML: string
|
|
28
|
+
/**
|
|
29
|
+
* Output PNG path.
|
|
30
|
+
*/
|
|
31
|
+
outPNG: string
|
|
32
|
+
/**
|
|
33
|
+
* Viewport width.
|
|
34
|
+
*
|
|
35
|
+
* @defaultValue `1160`
|
|
36
|
+
*/
|
|
37
|
+
width?: number
|
|
38
|
+
/**
|
|
39
|
+
* Viewport height.
|
|
40
|
+
*
|
|
41
|
+
* @defaultValue `1000`
|
|
42
|
+
*/
|
|
43
|
+
height?: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Screenshot a Plotly html page after every graph div's `plotly_afterplot` fires.
|
|
48
|
+
*/
|
|
49
|
+
export async function renderPlotlyHTMLToPNG(
|
|
50
|
+
options: RenderPlotlyOptions,
|
|
51
|
+
report?: (line: string) => void
|
|
52
|
+
): Promise<{ outPNG: string; consoleErrors: string[] }> {
|
|
53
|
+
const { consoleErrors: errors } = await withChromiumPage(
|
|
54
|
+
{ viewport: { width: options.width ?? 1160, height: options.height ?? 1000 } },
|
|
55
|
+
async (page) => {
|
|
56
|
+
await page.goto(pathToFileURL(resolve(options.inHTML)).href, { waitUntil: "networkidle" })
|
|
57
|
+
|
|
58
|
+
// Resolve once every Plotly graph div has fired plotly_afterplot
|
|
59
|
+
// (3D paints land async, after newPlot's promise resolves), with a per-div fallback
|
|
60
|
+
// so an already-painted div can't hang us.
|
|
61
|
+
await page.evaluate(async () => {
|
|
62
|
+
// Runs in the browser — reach DOM/Plotly globals via globalThis so the script needs no DOM lib.
|
|
63
|
+
interface PlotlyDiv {
|
|
64
|
+
_fullLayout?: unknown
|
|
65
|
+
on?: (event: string, cb: () => void) => void
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const doc = Reflect.get(globalThis, "document") as { querySelectorAll(s: string): Iterable<unknown> }
|
|
69
|
+
|
|
70
|
+
const divs = [...doc.querySelectorAll("div")]
|
|
71
|
+
.map((d) => d as PlotlyDiv)
|
|
72
|
+
.filter((d) => d._fullLayout && typeof d.on === "function")
|
|
73
|
+
|
|
74
|
+
await Promise.all(
|
|
75
|
+
divs.map(
|
|
76
|
+
(d) =>
|
|
77
|
+
new Promise<void>((res) => {
|
|
78
|
+
d.on!("plotly_afterplot", () => res())
|
|
79
|
+
setTimeout(() => res(), 2000)
|
|
80
|
+
})
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
// Final settle for the software WebGL rasterizer.
|
|
86
|
+
await page.waitForTimeout(800)
|
|
87
|
+
|
|
88
|
+
await page.screenshot({ path: resolve(options.outPNG), fullPage: true })
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
if (errors.length) {
|
|
93
|
+
report?.(`[render] ${errors.length} console error(s):`)
|
|
94
|
+
|
|
95
|
+
for (const e of errors.slice(0, 8)) {
|
|
96
|
+
report?.(" " + e)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
report?.(`[render] ${options.outPNG}`)
|
|
101
|
+
|
|
102
|
+
return { outPNG: options.outPNG, consoleErrors: errors }
|
|
103
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Sample `address_point.source` rows from a state database and render them by source in MapLibre.
|
|
7
|
+
* The output requires an http origin because the tile server does not serve `file:` origins.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { tempRootPath } from "@mailwoman/core/data-root"
|
|
11
|
+
import { writeLocalFile } from "@mailwoman/core/fs/writers"
|
|
12
|
+
import { isPresent } from "@mailwoman/core/objects"
|
|
13
|
+
import type { AddressPointDatabase } from "@mailwoman/resolver-wof-sqlite/address"
|
|
14
|
+
import { addressPointDatabasePath } from "@mailwoman/resolver-wof-sqlite/paths"
|
|
15
|
+
import type { GeoFeature, GeoFeatureCollection, PointLiteral } from "@mailwoman/spatial"
|
|
16
|
+
import { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
17
|
+
|
|
18
|
+
import { type MapFeatureData, toMapHTML } from "#index"
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Options for {@linkcode sourceProvenanceMap}.
|
|
22
|
+
*/
|
|
23
|
+
export interface SourceProvenanceMapOptions {
|
|
24
|
+
/**
|
|
25
|
+
* State (lowercase postal).
|
|
26
|
+
*
|
|
27
|
+
* @defaultValue `"ny"`
|
|
28
|
+
*/
|
|
29
|
+
state?: string
|
|
30
|
+
/**
|
|
31
|
+
* Address-point DB path.
|
|
32
|
+
*
|
|
33
|
+
* @defaultValue `$MAILWOMAN_DATA_ROOT/db/address-points/address-points-us-<state>.db`
|
|
34
|
+
*/
|
|
35
|
+
db?: string
|
|
36
|
+
/**
|
|
37
|
+
* Output html path.
|
|
38
|
+
*
|
|
39
|
+
* @defaultValue `/tmp/source-provenance.html`
|
|
40
|
+
*/
|
|
41
|
+
outHTML?: string
|
|
42
|
+
/**
|
|
43
|
+
* Keep ~1/N of NAD points.
|
|
44
|
+
*
|
|
45
|
+
* @defaultValue `700`
|
|
46
|
+
*/
|
|
47
|
+
nadMod?: number
|
|
48
|
+
/**
|
|
49
|
+
* Keep ~1/N of OpenAddresses points.
|
|
50
|
+
*
|
|
51
|
+
* @defaultValue `120`
|
|
52
|
+
*/
|
|
53
|
+
oaMod?: number
|
|
54
|
+
/**
|
|
55
|
+
* Per-source marker cap.
|
|
56
|
+
*
|
|
57
|
+
* @defaultValue `7000`
|
|
58
|
+
*/
|
|
59
|
+
cap?: number
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Collapse the raw `source` string into a human, mappable category.
|
|
63
|
+
// The address-point DB stores e.g. "overture:NAD" or "overture:OpenAddresses/NY/NYC Open Data".
|
|
64
|
+
// The suffix gives the real upstream publisher.
|
|
65
|
+
// Color features by that value (the "overture:" prefix names only the theme it arrived in).
|
|
66
|
+
function categorize(source: string): { bucket: string; publisher: string } {
|
|
67
|
+
if (source === "overture:NAD") return { bucket: "National Address Database", publisher: "NAD (federal)" }
|
|
68
|
+
|
|
69
|
+
if (source.startsWith("overture:OpenAddresses")) {
|
|
70
|
+
const publisher = source.split("/").at(-1) || "OpenAddresses"
|
|
71
|
+
|
|
72
|
+
return { bucket: "OpenAddresses", publisher: `OpenAddresses · ${publisher}` }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { bucket: source, publisher: source }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Must stay a type alias. Rows come back from the driver as `Record<string, SQLOutputValue>[]` and
|
|
79
|
+
// are asserted to `Row[]`; an object type alias includes an implicit index signature that makes that
|
|
80
|
+
// assertion legal, an interface does not.
|
|
81
|
+
// oxlint-disable-next-line typescript/consistent-type-definitions -- needs the implicit index signature
|
|
82
|
+
type Row = { lat: number; lon: number; source: string; number: string | null; street_raw: string | null }
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Render the per-state address-point provenance map — see the module doc.
|
|
86
|
+
*/
|
|
87
|
+
export async function sourceProvenanceMap(
|
|
88
|
+
options: SourceProvenanceMapOptions = {},
|
|
89
|
+
report?: (line: string) => void
|
|
90
|
+
): Promise<{ outHTML: string; points: number }> {
|
|
91
|
+
const STATE = (options.state || "ny").toLowerCase()
|
|
92
|
+
const DB = options.db || addressPointDatabasePath(`address-points-us-${STATE}.db`)
|
|
93
|
+
const OUT = options.outHTML || tempRootPath("source-provenance.html")
|
|
94
|
+
const NAD_MOD = options.nadMod ?? 700 // keep ~1/700 of NAD points
|
|
95
|
+
const OA_MOD = options.oaMod ?? 120 // keep ~1/120 of OpenAddresses points
|
|
96
|
+
const CAP = options.cap ?? 7000 // per-source marker cap
|
|
97
|
+
|
|
98
|
+
using db = new DatabaseClient<AddressPointDatabase>(DB, { readOnly: true })
|
|
99
|
+
|
|
100
|
+
// Two stratified samples so the smaller source (OpenAddresses, ~1/6 of NY) stays visible
|
|
101
|
+
// next to NAD. abs(random()) % mod == 0 keeps a spatially-uniform ~1/mod fraction.
|
|
102
|
+
// Limit caps the marker count.
|
|
103
|
+
const sample = (where: string, mod: number): Row[] =>
|
|
104
|
+
db
|
|
105
|
+
.prepare(
|
|
106
|
+
`SELECT lat, lon, source, number, street_raw FROM address_point
|
|
107
|
+
WHERE ${where} AND lat IS NOT NULL AND lon IS NOT NULL AND abs(random()) % ${mod} = 0
|
|
108
|
+
LIMIT ${CAP}`
|
|
109
|
+
)
|
|
110
|
+
.all() as Row[]
|
|
111
|
+
|
|
112
|
+
const rows = [
|
|
113
|
+
...sample("source = 'overture:NAD'", NAD_MOD),
|
|
114
|
+
...sample("source LIKE 'overture:OpenAddresses%'", OA_MOD),
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
const counts = new Map<string, number>()
|
|
118
|
+
|
|
119
|
+
const features: GeoFeature<PointLiteral, MapFeatureData>[] = rows.map((r) => {
|
|
120
|
+
const { bucket, publisher } = categorize(r.source)
|
|
121
|
+
counts.set(bucket, (counts.get(bucket) ?? 0) + 1)
|
|
122
|
+
const addr = [r.number, r.street_raw].filter(isPresent).join(" ").trim()
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
type: "Feature",
|
|
126
|
+
geometry: { type: "Point", coordinates: [r.lon, r.lat] },
|
|
127
|
+
properties: {
|
|
128
|
+
bucket,
|
|
129
|
+
sources: [bucket],
|
|
130
|
+
recordCount: 1,
|
|
131
|
+
geocodeTier: "address_point",
|
|
132
|
+
organization: publisher,
|
|
133
|
+
address: addr || null,
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
const geojson: GeoFeatureCollection<PointLiteral, MapFeatureData> = { type: "FeatureCollection", features }
|
|
139
|
+
|
|
140
|
+
const html = toMapHTML(geojson, {
|
|
141
|
+
title: `Address-point provenance — ${STATE.toUpperCase()}, every point colored by its open-data source`,
|
|
142
|
+
flavor: "light",
|
|
143
|
+
colorBy: "bucket",
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
await writeLocalFile(html, OUT)
|
|
147
|
+
report?.(`[written] ${OUT} (${features.length} points)`)
|
|
148
|
+
|
|
149
|
+
for (const [bucket, n] of [...counts.entries()].toSorted((a, b) => b[1] - a[1])) {
|
|
150
|
+
report?.(` ${n.toString().padStart(5)} ${bucket}`)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return { outHTML: OUT, points: features.length }
|
|
154
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { writeLocalTextFile } from "@mailwoman/core/fs/writers"
|
|
8
|
+
import { escapeHTML } from "@mailwoman/core/strings/escape"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Options for {@linkcode yardstickFigure}.
|
|
12
|
+
*/
|
|
13
|
+
export interface YardstickFigureOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Sets the output SVG path relative to the working directory, defaulting
|
|
16
|
+
* to `docs/records/evals/charts/dedup-yardstick.svg`.
|
|
17
|
+
*/
|
|
18
|
+
outSVG?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface Grain {
|
|
22
|
+
key: "NPI" | "site" | "org-name" | "org-name-coord"
|
|
23
|
+
label: string
|
|
24
|
+
classes: number
|
|
25
|
+
note: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const GRAINS: Grain[] = [
|
|
29
|
+
{ key: "NPI", label: "NPI", classes: 1000, note: "one entity per registration\n(over-segments orgs)" },
|
|
30
|
+
{ key: "site", label: "site", classes: 1456, note: "subpart-collapse +\naddress-split (conservative)" },
|
|
31
|
+
{ key: "org-name", label: "org-name", classes: 956, note: "same-org collapse by\naddress STRING key" },
|
|
32
|
+
{
|
|
33
|
+
key: "org-name-coord",
|
|
34
|
+
label: "org-name (coord)",
|
|
35
|
+
classes: 928,
|
|
36
|
+
note: "collapse by geocoded\nBUILDING (geocode-first key)",
|
|
37
|
+
},
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
const F1: Record<string, [number, number, number, number]> = {
|
|
41
|
+
GBT: [53.6, 55.3, 60.7, 68.1],
|
|
42
|
+
FS: [45.1, 42.7, 52.3, 60.3],
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const OVERMERGE: Record<string, [number, number, number, number]> = {
|
|
46
|
+
GBT: [109, 208, 92, 76],
|
|
47
|
+
FS: [144, 253, 129, 114],
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const W = 760
|
|
51
|
+
const H = 430
|
|
52
|
+
const PAD = { top: 64, right: 168, bottom: 92, left: 64 }
|
|
53
|
+
const plotL = PAD.left
|
|
54
|
+
const plotR = W - PAD.right
|
|
55
|
+
const plotT = PAD.top
|
|
56
|
+
const plotB = H - PAD.bottom
|
|
57
|
+
|
|
58
|
+
const Y_MIN = 40
|
|
59
|
+
const Y_MAX = 72
|
|
60
|
+
const yFor = (f1: number) => plotB - ((f1 - Y_MIN) / (Y_MAX - Y_MIN)) * (plotB - plotT)
|
|
61
|
+
const xFor = (i: number) => plotL + (i / (GRAINS.length - 1)) * (plotR - plotL)
|
|
62
|
+
|
|
63
|
+
const MODELS = [
|
|
64
|
+
{ key: "GBT", label: "GBT (shipped default)", color: "#3578e5", width: 3, dash: "" },
|
|
65
|
+
{ key: "FS", label: "FS full stack", color: "#9ca3af", width: 2, dash: "5 4" },
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
const esc = escapeHTML
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Emit the dedup-yardstick slope chart as a self-contained SVG — see the module doc.
|
|
72
|
+
*/
|
|
73
|
+
export async function yardstickFigure(
|
|
74
|
+
options: YardstickFigureOptions = {},
|
|
75
|
+
report?: (line: string) => void
|
|
76
|
+
): Promise<{ outSVG: string }> {
|
|
77
|
+
const OUT = options.outSVG || "docs/records/evals/charts/dedup-yardstick.svg"
|
|
78
|
+
|
|
79
|
+
const parts: string[] = []
|
|
80
|
+
const push = (s: string) => parts.push(s)
|
|
81
|
+
|
|
82
|
+
push(
|
|
83
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="ui-sans-serif, system-ui, sans-serif" font-size="11"><rect width="${W}" height="${H}" fill="white"/>`
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
push(
|
|
87
|
+
`<text x="${W / 2}" y="24" text-anchor="middle" font-size="15" font-weight="600">The dedup F1 climbs as the entity-truth gets honest</text>`
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
push(
|
|
91
|
+
`<text x="${W / 2}" y="42" text-anchor="middle" font-size="11.5" fill="#555">Identical matcher output (the same clusters) graded against four rulers — 1000 TX NPIs → 2757 records, NPI held out</text>`
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
for (let v = Y_MIN; v <= Y_MAX; v += 5) {
|
|
95
|
+
const y = yFor(v)
|
|
96
|
+
|
|
97
|
+
push(
|
|
98
|
+
`<line x1="${plotL}" y1="${y.toFixed(1)}" x2="${plotR}" y2="${y.toFixed(1)}" stroke="#e5e7eb" stroke-width="1"/>`
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
push(`<text x="${plotL - 8}" y="${(y + 3).toFixed(1)}" text-anchor="end" fill="#374151">${v}%</text>`)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
push(
|
|
105
|
+
`<text transform="translate(20, ${(plotT + plotB) / 2}) rotate(-90)" text-anchor="middle" font-size="12" fill="#374151">entity-resolution F1</text>`
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
GRAINS.forEach((g, i) => {
|
|
109
|
+
const x = xFor(i)
|
|
110
|
+
|
|
111
|
+
push(
|
|
112
|
+
`<line x1="${x.toFixed(1)}" y1="${plotT}" x2="${x.toFixed(1)}" y2="${plotB}" stroke="#f1f1f1" stroke-width="1"/>`
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
push(
|
|
116
|
+
`<text x="${x.toFixed(1)}" y="${plotB + 20}" text-anchor="middle" font-size="12.5" font-weight="600">${esc(g.label)}</text>`
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
push(
|
|
120
|
+
`<text x="${x.toFixed(1)}" y="${plotB + 36}" text-anchor="middle" font-size="10" fill="#6b7280">${g.classes} classes</text>`
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
// oxlint-disable-next-line mailwoman/prefer-spliterator -- `g.note` is a literal label from the models table rather than a file.
|
|
124
|
+
g.note.split("\n").forEach((line, k) => {
|
|
125
|
+
push(
|
|
126
|
+
`<text x="${x.toFixed(1)}" y="${plotB + 50 + k * 12}" text-anchor="middle" font-size="9" fill="#9ca3af">${esc(line)}</text>`
|
|
127
|
+
)
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
for (const m of MODELS) {
|
|
132
|
+
const f1s = F1[m.key]!
|
|
133
|
+
const pts = f1s.map((f, i) => `${xFor(i).toFixed(1)},${yFor(f).toFixed(1)}`).join(" ")
|
|
134
|
+
|
|
135
|
+
push(
|
|
136
|
+
`<polyline points="${pts}" fill="none" stroke="${m.color}" stroke-width="${m.width}"${m.dash ? ` stroke-dasharray="${m.dash}"` : ""}/>`
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
f1s.forEach((f, i) => {
|
|
140
|
+
const x = xFor(i)
|
|
141
|
+
const y = yFor(f)
|
|
142
|
+
push(`<circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="${m.key === "GBT" ? 5 : 4}" fill="${m.color}"/>`)
|
|
143
|
+
|
|
144
|
+
const dy = m.key === "GBT" ? -10 : 16
|
|
145
|
+
|
|
146
|
+
push(
|
|
147
|
+
`<text x="${x.toFixed(1)}" y="${(y + dy).toFixed(1)}" text-anchor="middle" font-size="11" font-weight="${m.key === "GBT" ? 700 : 400}" fill="${m.color}">${f.toFixed(1)}</text>`
|
|
148
|
+
)
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const lx = plotR + 16
|
|
153
|
+
let ly = plotT + 6
|
|
154
|
+
|
|
155
|
+
for (const m of MODELS) {
|
|
156
|
+
push(
|
|
157
|
+
`<line x1="${lx}" y1="${ly}" x2="${lx + 22}" y2="${ly}" stroke="${m.color}" stroke-width="${m.width}"${m.dash ? ` stroke-dasharray="${m.dash}"` : ""}/>`
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
push(`<text x="${lx + 28}" y="${ly + 3.5}" font-size="10.5" fill="#374151">${esc(m.label)}</text>`)
|
|
161
|
+
ly += 18
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const gCoord = yFor(F1.GBT![3])
|
|
165
|
+
const gNPI = yFor(F1.GBT![0])
|
|
166
|
+
|
|
167
|
+
push(
|
|
168
|
+
`<g font-size="10.5">` +
|
|
169
|
+
`<text x="${lx}" y="${ly + 18}" font-weight="700" fill="#3578e5">+14.5pp NPI → coord</text>` +
|
|
170
|
+
`<text x="${lx}" y="${ly + 33}" fill="#555">same clusters —</text>` +
|
|
171
|
+
`<text x="${lx}" y="${ly + 46}" fill="#555">the ruler, not the model.</text>` +
|
|
172
|
+
`<text x="${lx}" y="${ly + 64}" fill="#555">over-merge 109 → 76,</text>` +
|
|
173
|
+
`<text x="${lx}" y="${ly + 77}" fill="#555">precision 43.7% → 64.6%.</text>` +
|
|
174
|
+
`</g>`
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
push(
|
|
178
|
+
`<path d="M ${(plotR - 4).toFixed(1)} ${gNPI.toFixed(1)} L ${(plotR + 2).toFixed(1)} ${gNPI.toFixed(1)} L ${(plotR + 2).toFixed(1)} ${gCoord.toFixed(1)} L ${(plotR - 4).toFixed(1)} ${gCoord.toFixed(1)}" fill="none" stroke="#3578e5" stroke-width="1" opacity="0.5"/>`
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
push(
|
|
182
|
+
`<text x="${plotL}" y="${H - 10}" font-size="9.5" fill="#9ca3af">Gold set (2026-06-16-dedup-gold-set-tx120): 120/120 hard co-located pairs = same org, 0 genuine over-merges. The coordinate (geocode-first building key) is the tightest honest ruler; NPI charges correct same-org merges as errors.</text>`
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
push(`</svg>`)
|
|
186
|
+
|
|
187
|
+
await writeLocalTextFile(parts.join(""), OUT)
|
|
188
|
+
report?.(`[written] ${OUT}`)
|
|
189
|
+
|
|
190
|
+
report?.(
|
|
191
|
+
` GBT F1: NPI ${F1.GBT![0]} → site ${F1.GBT![1]} → org-name ${F1.GBT![2]} → coord ${F1.GBT![3]} (+${(F1.GBT![3] - F1.GBT![0]).toFixed(1)}pp)`
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
report?.(` over-merge: ${OVERMERGE.GBT!.join(" → ")}`)
|
|
195
|
+
|
|
196
|
+
return { outSVG: OUT }
|
|
197
|
+
}
|