@mailwoman/corpus 11.5.0 → 12.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.
Files changed (144) hide show
  1. package/data/builds/v0.8.22-wofrank-overlay/OVERLAY_PLAN.json +51 -0
  2. package/data/builds/v0.8.24-everyplace/inputs.json +35 -0
  3. package/data/training-configs/v8.17.0-stage1-gazetteer-v0822-s42.yaml +557 -0
  4. package/data/training-configs/v8.17.0-stage2-corpus-v0822-s42.yaml +1008 -0
  5. package/data/training-configs/v8.18.0-gazetteer-then-mixture-v0822-s42.yaml +1225 -0
  6. package/data/training-configs/v8.20.0-wofrank-v0822-s42.yaml +863 -0
  7. package/data/training-configs/v8.21.0-outcomes-v0822-s42.yaml +873 -0
  8. package/data/training-configs/v8.22.0-stage1-everyplace-v0824-s42.yaml +374 -0
  9. package/data/training-configs/v8.22.0-stage2-corpus-v0824-s42.yaml +808 -0
  10. package/data/training-configs/v8.22.1-stage1-everyplace-v0824-s42.yaml +376 -0
  11. package/data/training-configs/v8.22.1-stage2-corpus-v0824-s42.yaml +793 -0
  12. package/data/training-configs/v9.0.0-bytestem-v090-s42.yaml +665 -0
  13. package/data/training-manifests/v0.8.22-wofrank-overlay.json +9000 -0
  14. package/data/training-manifests/v0.8.24-everyplace-overlay.json +9000 -0
  15. package/data/training-manifests/v0.9.0-compact.effective.json +2556 -0
  16. package/data/training-manifests/v0.9.0-compact.json +9000 -0
  17. package/lib/adapters/wof/admin/json/adapter.ts +38 -3
  18. package/lib/adapters/wof/json-rows.ts +84 -5
  19. package/lib/adapters/wof/sample.ts +42 -6
  20. package/lib/build/code-hash.ts +1 -1
  21. package/lib/cjk/foreign-places.ts +1 -1
  22. package/lib/kr/adapters/localdata/permit-rows.ts +1 -1
  23. package/lib/parquet/schema.ts +7 -0
  24. package/lib/tools/anthropic/batches.ts +221 -0
  25. package/lib/tools/anthropic/labeling.ts +263 -0
  26. package/lib/tools/compact-v9.ts +872 -0
  27. package/lib/tools/fetch/wikidata/vital-places/entities.ts +20 -2
  28. package/lib/tools/fetch/wikidata/vital-places/qrank.ts +5 -4
  29. package/lib/tools/fragment-assay.run.ts +2 -1
  30. package/lib/tools/name-roles/name-roles.run.ts +296 -0
  31. package/lib/tools/name-roles/prompt.ts +253 -0
  32. package/lib/tools/overlay/deletions.ts +1 -1
  33. package/lib/tools/overlay/draw-weight.ts +275 -0
  34. package/lib/tools/place-twins/place-twins.run.ts +528 -0
  35. package/lib/tools/place-twins/prompt.ts +276 -0
  36. package/lib/tools/prominent-shapes/prominent-shapes.run.ts +420 -0
  37. package/lib/tools/prominent-shapes/prompt.ts +189 -0
  38. package/lib/tools/prominent-shapes/read-seeds.ts +286 -0
  39. package/lib/tools/prominent-shapes/seeds.ts +281 -0
  40. package/lib/tools/prominent-shapes/validate.ts +563 -0
  41. package/lib/training/config/admission.ts +9 -2
  42. package/lib/training/config/schema.ts +68 -1
  43. package/lib/types.ts +23 -0
  44. package/lib/utils/split.ts +1 -1
  45. package/out/adapters/wof/admin/json/adapter.d.ts +7 -0
  46. package/out/adapters/wof/admin/json/adapter.d.ts.map +1 -1
  47. package/out/adapters/wof/admin/json/adapter.js +28 -3
  48. package/out/adapters/wof/admin/json/adapter.js.map +1 -1
  49. package/out/adapters/wof/json-rows.d.ts +8 -0
  50. package/out/adapters/wof/json-rows.d.ts.map +1 -1
  51. package/out/adapters/wof/json-rows.js +56 -4
  52. package/out/adapters/wof/json-rows.js.map +1 -1
  53. package/out/adapters/wof/sample.d.ts +12 -0
  54. package/out/adapters/wof/sample.d.ts.map +1 -1
  55. package/out/adapters/wof/sample.js +37 -6
  56. package/out/adapters/wof/sample.js.map +1 -1
  57. package/out/build/code-hash.js +1 -1
  58. package/out/build/code-hash.js.map +1 -1
  59. package/out/cjk/foreign-places.js +1 -1
  60. package/out/cjk/foreign-places.js.map +1 -1
  61. package/out/kr/adapters/localdata/permit-rows.js +1 -1
  62. package/out/kr/adapters/localdata/permit-rows.js.map +1 -1
  63. package/out/parquet/schema.d.ts +6 -0
  64. package/out/parquet/schema.d.ts.map +1 -1
  65. package/out/parquet/schema.js +6 -0
  66. package/out/parquet/schema.js.map +1 -1
  67. package/out/tools/anthropic/batches.d.ts +117 -0
  68. package/out/tools/anthropic/batches.d.ts.map +1 -0
  69. package/out/tools/anthropic/batches.js +141 -0
  70. package/out/tools/anthropic/batches.js.map +1 -0
  71. package/out/tools/anthropic/labeling.d.ts +97 -0
  72. package/out/tools/anthropic/labeling.d.ts.map +1 -0
  73. package/out/tools/anthropic/labeling.js +146 -0
  74. package/out/tools/anthropic/labeling.js.map +1 -0
  75. package/out/tools/compact-v9.d.ts +117 -0
  76. package/out/tools/compact-v9.d.ts.map +1 -0
  77. package/out/tools/compact-v9.js +494 -0
  78. package/out/tools/compact-v9.js.map +1 -0
  79. package/out/tools/fetch/wikidata/vital-places/entities.d.ts +3 -0
  80. package/out/tools/fetch/wikidata/vital-places/entities.d.ts.map +1 -1
  81. package/out/tools/fetch/wikidata/vital-places/entities.js +19 -1
  82. package/out/tools/fetch/wikidata/vital-places/entities.js.map +1 -1
  83. package/out/tools/fetch/wikidata/vital-places/qrank.d.ts.map +1 -1
  84. package/out/tools/fetch/wikidata/vital-places/qrank.js +4 -4
  85. package/out/tools/fetch/wikidata/vital-places/qrank.js.map +1 -1
  86. package/out/tools/fragment-assay.run.js +1 -1
  87. package/out/tools/fragment-assay.run.js.map +1 -1
  88. package/out/tools/name-roles/name-roles.run.d.ts +2 -0
  89. package/out/tools/name-roles/name-roles.run.d.ts.map +1 -0
  90. package/out/tools/name-roles/name-roles.run.js +230 -0
  91. package/out/tools/name-roles/name-roles.run.js.map +1 -0
  92. package/out/tools/name-roles/prompt.d.ts +166 -0
  93. package/out/tools/name-roles/prompt.d.ts.map +1 -0
  94. package/out/tools/name-roles/prompt.js +176 -0
  95. package/out/tools/name-roles/prompt.js.map +1 -0
  96. package/out/tools/overlay/deletions.js +1 -1
  97. package/out/tools/overlay/deletions.js.map +1 -1
  98. package/out/tools/overlay/draw-weight.d.ts +86 -0
  99. package/out/tools/overlay/draw-weight.d.ts.map +1 -0
  100. package/out/tools/overlay/draw-weight.js +131 -0
  101. package/out/tools/overlay/draw-weight.js.map +1 -0
  102. package/out/tools/place-twins/place-twins.run.d.ts +2 -0
  103. package/out/tools/place-twins/place-twins.run.d.ts.map +1 -0
  104. package/out/tools/place-twins/place-twins.run.js +385 -0
  105. package/out/tools/place-twins/place-twins.run.js.map +1 -0
  106. package/out/tools/place-twins/prompt.d.ts +169 -0
  107. package/out/tools/place-twins/prompt.d.ts.map +1 -0
  108. package/out/tools/place-twins/prompt.js +183 -0
  109. package/out/tools/place-twins/prompt.js.map +1 -0
  110. package/out/tools/prominent-shapes/prominent-shapes.run.d.ts +2 -0
  111. package/out/tools/prominent-shapes/prominent-shapes.run.d.ts.map +1 -0
  112. package/out/tools/prominent-shapes/prominent-shapes.run.js +302 -0
  113. package/out/tools/prominent-shapes/prominent-shapes.run.js.map +1 -0
  114. package/out/tools/prominent-shapes/prompt.d.ts +74 -0
  115. package/out/tools/prominent-shapes/prompt.d.ts.map +1 -0
  116. package/out/tools/prominent-shapes/prompt.js +156 -0
  117. package/out/tools/prominent-shapes/prompt.js.map +1 -0
  118. package/out/tools/prominent-shapes/read-seeds.d.ts +23 -0
  119. package/out/tools/prominent-shapes/read-seeds.d.ts.map +1 -0
  120. package/out/tools/prominent-shapes/read-seeds.js +219 -0
  121. package/out/tools/prominent-shapes/read-seeds.js.map +1 -0
  122. package/out/tools/prominent-shapes/seeds.d.ts +132 -0
  123. package/out/tools/prominent-shapes/seeds.d.ts.map +1 -0
  124. package/out/tools/prominent-shapes/seeds.js +178 -0
  125. package/out/tools/prominent-shapes/seeds.js.map +1 -0
  126. package/out/tools/prominent-shapes/validate.d.ts +152 -0
  127. package/out/tools/prominent-shapes/validate.d.ts.map +1 -0
  128. package/out/tools/prominent-shapes/validate.js +389 -0
  129. package/out/tools/prominent-shapes/validate.js.map +1 -0
  130. package/out/training/config/admission.d.ts +2 -1
  131. package/out/training/config/admission.d.ts.map +1 -1
  132. package/out/training/config/admission.js +9 -2
  133. package/out/training/config/admission.js.map +1 -1
  134. package/out/training/config/schema.d.ts +276 -1
  135. package/out/training/config/schema.d.ts.map +1 -1
  136. package/out/training/config/schema.js +64 -1
  137. package/out/training/config/schema.js.map +1 -1
  138. package/out/types.d.ts +21 -0
  139. package/out/types.d.ts.map +1 -1
  140. package/out/types.js +13 -0
  141. package/out/types.js.map +1 -1
  142. package/out/utils/split.js +1 -1
  143. package/out/utils/split.js.map +1 -1
  144. package/package.json +24 -24
@@ -0,0 +1,385 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+ /**
4
+ * @file Asks a language model whether a settlement the admin build added from Overture or GeoNames is a WOF
5
+ * record under another spelling or script.
6
+ *
7
+ * Usage:
8
+ * node packages/corpus/lib/tools/place-twins/place-twins.run.ts <mode> --out <dir> [--unmatched <jsonl>]
9
+ * [--take <items>] [--model <id>] [--effort <level>] [--chunk <items per request>] [--limit <requests>]
10
+ *
11
+ * `census` reads the admin build's unmatched-places file, finds each settlement's WOF records inside the
12
+ * match radius, and writes `items.jsonl` with one line per settlement that has at least one.
13
+ * `pilot`, `submit`, `status` and `collect` then work as `name-roles.run.ts` does, over the first `--take`
14
+ * items in the order `rankItems` gives them. `collect` writes `pairs.jsonl`.
15
+ *
16
+ * The output is a review file. An Overture pair belongs in `overture_wof_match`, a table of the Overture
17
+ * part, and a GeoNames pair in the WOF forks' concordances. This tool writes to neither.
18
+ */
19
+ import { appendLocalTextFile, writeLocalJSONFile, writeLocalJSONLFile, writeLocalTextFile, } from "@mailwoman/core/fs/writers";
20
+ import { OVERTURE_ID_BASE } from "@mailwoman/core/resolver/synthetic-id-ranges";
21
+ import { parseArguments } from "@mailwoman/core/scripting/arguments";
22
+ import { stringifyJSON } from "@mailwoman/core/values/json";
23
+ import { ownNameSimilarity, romanizeNameKey } from "@mailwoman/resolver-wof-sqlite/candidate/own-name";
24
+ import { normalizeLocalityForKey } from "@mailwoman/resolver-wof-sqlite/labels/street/normalize";
25
+ import { wofDatabasePath } from "@mailwoman/resolver-wof-sqlite/paths";
26
+ import { haversine } from "@mailwoman/spatial/geometries/point/distance";
27
+ import { openBuiltClient } from "@mailwoman/sqlite/sealed";
28
+ import { PathBuilder, resolvePath } from "path-ts";
29
+ import { JSONSpliterator } from "spliterator";
30
+ import { collectLabelingBatch, pilotLabelingRequests, readLabelingBatch, submitLabelingBatch, countEach, toLabelingChunks, } from "#tools/anthropic/labeling";
31
+ import { NameComparison, parsePlaceTwinResponse, placeTwinRequestParams, } from "#tools/place-twins/prompt";
32
+ /**
33
+ * The settlement tier of the admin build's matcher (`MATCH_TIERS.settlement` in
34
+ * `packages/gazetteer/tools/pipeline/admin/sources/wof-match.ts`): the placetypes a
35
+ * settlement may match across, and the farthest a matching WOF record may sit.
36
+ */
37
+ const SETTLEMENT_PLACETYPES = ["locality", "localadmin", "borough"];
38
+ const MATCH_RADIUS_KM = 5;
39
+ const GRID_DEGREES = 0.05;
40
+ const KM_PER_DEGREE = 111.32;
41
+ const MAX_CANDIDATES = 4;
42
+ const MAX_CANDIDATE_NAMES = 8;
43
+ const MAX_ADDED_NAMES = 6;
44
+ const ID_QUERY_SIZE = 500;
45
+ const { values, positionals } = parseArguments({
46
+ allowPositionals: true,
47
+ options: {
48
+ out: { type: "string" },
49
+ unmatched: { type: "string" },
50
+ take: { type: "string" },
51
+ skip: { type: "string" },
52
+ items: { type: "string" },
53
+ model: { type: "string", default: "claude-opus-5-5" },
54
+ effort: { type: "string", default: "medium" },
55
+ chunk: { type: "string", default: "15" },
56
+ limit: { type: "string" },
57
+ },
58
+ });
59
+ const mode = positionals[0];
60
+ if (!values.out)
61
+ throw new Error("--out names the directory the items, batch record and pairs are written to");
62
+ const out = PathBuilder.from(resolvePath(values.out));
63
+ const settings = { model: values.model, effort: values.effort };
64
+ const parseLabels = (text, items) => parsePlaceTwinResponse(text, items.map((item) => item.candidates.length));
65
+ /**
66
+ * Reads every name row of `ids`, grouped by id in the table's order.
67
+ */
68
+ async function readNames(db, ids) {
69
+ const names = new Map();
70
+ for (let start = 0; start < ids.length; start += ID_QUERY_SIZE) {
71
+ const rows = await db
72
+ .selectFrom("names")
73
+ .select(["id", "name", "privateuse"])
74
+ .where("id", "in", ids.slice(start, start + ID_QUERY_SIZE))
75
+ .execute();
76
+ // A preferred name leads, so the cap on names keeps it.
77
+ rows.sort((a, b) => Number(b.privateuse === "preferred") - Number(a.privateuse === "preferred"));
78
+ for (const row of rows) {
79
+ const held = names.get(row.id);
80
+ if (held) {
81
+ held.push(row.name);
82
+ }
83
+ else {
84
+ names.set(row.id, [row.name]);
85
+ }
86
+ }
87
+ }
88
+ return names;
89
+ }
90
+ /**
91
+ * The primary name first, then the other distinct names up to `cap`.
92
+ */
93
+ function leadNames(primary, others, cap) {
94
+ return [...new Set([primary, ...(others ?? [])])].slice(0, cap);
95
+ }
96
+ /**
97
+ * The name key with every character outside letters, digits and spaces replaced by a space.
98
+ *
99
+ * `romanizeNameKey` returns `null` for a key that holds a hyphen, an apostrophe or an ʻokina,
100
+ * so without this step `Ermengol-Serra` and `Al Miʻli` read as names in an uncovered script.
101
+ */
102
+ function comparisonKey(name) {
103
+ return normalizeLocalityForKey(name)
104
+ .replaceAll(/[^\p{L}\p{N}\s]/gu, " ")
105
+ .replaceAll(/\s+/g, " ")
106
+ .trim();
107
+ }
108
+ /**
109
+ * Compares every name of an added place with every name of its candidates.
110
+ */
111
+ function compareNames(added, candidates) {
112
+ const addedKeys = added.map((name) => comparisonKey(name));
113
+ const addedRomanizes = addedKeys.map((key) => romanizeNameKey(key) != null);
114
+ let similarity = null;
115
+ let crossScript = false;
116
+ for (const candidate of candidates) {
117
+ for (const name of candidate.names) {
118
+ const key = comparisonKey(name);
119
+ const romanizes = romanizeNameKey(key) != null;
120
+ for (const [index, addedKey] of addedKeys.entries()) {
121
+ if (romanizes !== addedRomanizes[index]) {
122
+ crossScript = true;
123
+ }
124
+ const score = ownNameSimilarity(addedKey, key);
125
+ if (score != null && (similarity == null || score > similarity)) {
126
+ similarity = score;
127
+ }
128
+ }
129
+ }
130
+ }
131
+ if (similarity != null)
132
+ return { comparison: NameComparison.Romanized, similarity: Number(similarity.toFixed(3)) };
133
+ return { comparison: crossScript ? NameComparison.CrossScript : NameComparison.Uncovered, similarity: null };
134
+ }
135
+ /**
136
+ * Builds the items of one country: each unmatched settlement with its WOF records inside the match radius.
137
+ */
138
+ async function buildCountryItems(db, country, unmatched) {
139
+ const records = await db
140
+ .selectFrom("spr")
141
+ .select(["id", "name", "placetype", "latitude", "longitude"])
142
+ .where("country", "=", country)
143
+ .where("placetype", "in", SETTLEMENT_PLACETYPES)
144
+ .where("is_current", "=", 1)
145
+ .where("id", "<", OVERTURE_ID_BASE)
146
+ .execute();
147
+ const grid = new Map();
148
+ for (const [index, record] of records.entries()) {
149
+ const cell = `${Math.floor(record.latitude / GRID_DEGREES)}:${Math.floor(record.longitude / GRID_DEGREES)}`;
150
+ const held = grid.get(cell);
151
+ if (held) {
152
+ held.push(index);
153
+ }
154
+ else {
155
+ grid.set(cell, [index]);
156
+ }
157
+ }
158
+ const near = [];
159
+ for (const place of unmatched) {
160
+ const row = Math.floor(place.latitude / GRID_DEGREES);
161
+ const column = Math.floor(place.longitude / GRID_DEGREES);
162
+ const rowSpan = Math.ceil(MATCH_RADIUS_KM / (KM_PER_DEGREE * GRID_DEGREES));
163
+ // A degree of longitude shortens toward the poles, so the radius spans more columns there.
164
+ const kmPerLongitudeCell = KM_PER_DEGREE * GRID_DEGREES * Math.max(0.01, Math.cos((place.latitude * Math.PI) / 180));
165
+ const columnSpan = Math.min(200, Math.ceil(MATCH_RADIUS_KM / kmPerLongitudeCell));
166
+ const found = [];
167
+ for (let r = row - rowSpan; r <= row + rowSpan; r++) {
168
+ for (let c = column - columnSpan; c <= column + columnSpan; c++) {
169
+ for (const index of grid.get(`${r}:${c}`) ?? []) {
170
+ const record = records[index];
171
+ const km = haversine(place.latitude, place.longitude, record.latitude, record.longitude, "km");
172
+ if (km <= MATCH_RADIUS_KM) {
173
+ found.push({ index, km });
174
+ }
175
+ }
176
+ }
177
+ }
178
+ if (!found.length)
179
+ continue;
180
+ found.sort((a, b) => a.km - b.km);
181
+ near.push({ place, found: found.slice(0, MAX_CANDIDATES) });
182
+ }
183
+ const candidateNames = await readNames(db, [
184
+ ...new Set(near.flatMap(({ found }) => found.map(({ index }) => records[index].id))),
185
+ ]);
186
+ const addedNames = await readNames(db, near.map(({ place }) => place.id));
187
+ return near.map(({ place, found }) => {
188
+ const names = leadNames(place.name, addedNames.get(place.id), MAX_ADDED_NAMES);
189
+ const candidates = found.map(({ index, km }) => {
190
+ const record = records[index];
191
+ return {
192
+ wofID: record.id,
193
+ names: leadNames(record.name ?? "", candidateNames.get(record.id), MAX_CANDIDATE_NAMES).filter((name) => name !== ""),
194
+ placetype: record.placetype ?? "",
195
+ km: Number(km.toFixed(2)),
196
+ };
197
+ });
198
+ return {
199
+ id: place.id,
200
+ source: place.source,
201
+ sourceID: place.sourceID,
202
+ names,
203
+ placetype: place.placetype,
204
+ country: place.country,
205
+ latitude: place.latitude,
206
+ longitude: place.longitude,
207
+ candidates,
208
+ ...compareNames(names, candidates),
209
+ };
210
+ });
211
+ }
212
+ /**
213
+ * Orders the items a budget admits.
214
+ *
215
+ * Names in different scripts come first, because the romanizer cannot compare them and the model can.
216
+ * The romanized pairs below a similarity of 1 follow from the most alike down.
217
+ *
218
+ * A pair at exactly 1 has two names that romanize to one string, so code can pair
219
+ * it without the model, and it ranks after them.
220
+ * The names outside the romanizer's scripts come last.
221
+ */
222
+ function rankItems(items) {
223
+ const tier = (item) => {
224
+ if (item.comparison === NameComparison.CrossScript)
225
+ return 0;
226
+ if (item.comparison === NameComparison.Uncovered)
227
+ return 3;
228
+ return item.similarity === 1 ? 2 : 1;
229
+ };
230
+ return items.toSorted((a, b) => tier(a) - tier(b) ||
231
+ (b.similarity ?? 0) - (a.similarity ?? 0) ||
232
+ a.country.localeCompare(b.country) ||
233
+ a.id - b.id);
234
+ }
235
+ async function readRankedItems() {
236
+ // `--items` reads another directory's census, so a second batch over the same census keeps its own batch record.
237
+ const itemsPath = values.items ? resolvePath(values.items) : out("items.jsonl");
238
+ const items = rankItems(await JSONSpliterator.fromAsync(itemsPath).toArray());
239
+ const skip = Number(values.skip ?? 0);
240
+ return values.take ? items.slice(skip, skip + Number(values.take)) : items.slice(skip);
241
+ }
242
+ if (mode === "census") {
243
+ if (!values.unmatched)
244
+ throw new Error("--unmatched names the admin build's unmatched-places file");
245
+ const byCountry = new Map();
246
+ let read = 0;
247
+ for await (const line of JSONSpliterator.fromAsync(resolvePath(values.unmatched))) {
248
+ read++;
249
+ if (!SETTLEMENT_PLACETYPES.includes(line.placetype))
250
+ continue;
251
+ const held = byCountry.get(line.country);
252
+ if (held) {
253
+ held.push(line);
254
+ }
255
+ else {
256
+ byCountry.set(line.country, [line]);
257
+ }
258
+ }
259
+ using db = await openBuiltClient(wofDatabasePath("admin-global-priority.db"));
260
+ // The file belongs to one build.
261
+ // A line whose row the database lacks means the two came from different builds.
262
+ const probe = [...byCountry.values()].flat().slice(0, 500);
263
+ const present = await db
264
+ .selectFrom("spr")
265
+ .select("id")
266
+ .where("id", "in", probe.map((line) => line.id))
267
+ .execute();
268
+ if (present.length !== probe.length) {
269
+ throw new Error(`${probe.length - present.length} of the first ${probe.length} unmatched places have no row in the admin database`);
270
+ }
271
+ await writeLocalTextFile("", out("items.jsonl"));
272
+ const comparisons = [];
273
+ const sources = [];
274
+ const similarities = [];
275
+ let settlements = 0;
276
+ for (const [country, lines] of [...byCountry].toSorted(([a], [b]) => a.localeCompare(b))) {
277
+ settlements += lines.length;
278
+ const items = await buildCountryItems(db, country, lines);
279
+ if (!items.length)
280
+ continue;
281
+ await appendLocalTextFile(items.map((item) => `${stringifyJSON(item)}\n`).join(""), out("items.jsonl"));
282
+ for (const item of items) {
283
+ comparisons.push(item.comparison);
284
+ sources.push(item.source);
285
+ if (item.similarity != null) {
286
+ similarities.push(item.similarity);
287
+ }
288
+ }
289
+ }
290
+ const census = {
291
+ unmatchedPlaces: read,
292
+ unmatchedSettlements: settlements,
293
+ withAWOFRecordInRadius: comparisons.length,
294
+ radiusKm: MATCH_RADIUS_KM,
295
+ bySource: countEach(sources),
296
+ byComparison: countEach(comparisons),
297
+ romanizedSimilarity: countEach(similarities.map((value) => (Math.floor(value * 10) / 10).toFixed(1))),
298
+ };
299
+ await writeLocalJSONFile(census, out("census.json"));
300
+ console.log(stringifyJSON(census));
301
+ }
302
+ else if (mode === "pilot") {
303
+ const chunks = toLabelingChunks(await readRankedItems(), Number(values.chunk), "place-twins");
304
+ const pilot = await pilotLabelingRequests(chunks, Number(values.limit ?? 3), settings, placeTwinRequestParams, parseLabels);
305
+ for (const { chunk, labels, usage } of pilot.requests) {
306
+ for (const [i, item] of chunk.items.entries()) {
307
+ const label = labels[i];
308
+ const paired = label.match == null ? "-" : item.candidates[label.match].names.slice(0, 3).join(" / ");
309
+ const offered = item.candidates.map((candidate) => `${candidate.names[0]} ${candidate.km} km`).join("; ");
310
+ console.log(`${label.reason}\t${label.confidence}\t${item.country} ${item.names.slice(0, 3).join(" / ")} => ${paired} | offered: ${offered} | ${item.comparison} ${item.similarity ?? ""}`);
311
+ }
312
+ console.log(stringifyJSON(usage));
313
+ }
314
+ console.log(stringifyJSON({
315
+ requests: chunks.length,
316
+ batchCostPerRequestUSD: Number(pilot.batchCostPerRequestUSD.toFixed(5)),
317
+ projectedBatchCostUSD: Number((pilot.batchCostPerRequestUSD * chunks.length).toFixed(2)),
318
+ }));
319
+ }
320
+ else if (mode === "submit") {
321
+ let chunks = toLabelingChunks(await readRankedItems(), Number(values.chunk), "place-twins");
322
+ if (values.limit) {
323
+ chunks = chunks.slice(0, Number(values.limit));
324
+ }
325
+ console.log(stringifyJSON(await submitLabelingBatch(out, chunks, settings, placeTwinRequestParams)));
326
+ }
327
+ else if (mode === "status") {
328
+ const batch = await readLabelingBatch(out);
329
+ console.log(stringifyJSON({ id: batch.id, status: batch.processing_status, ...batch.request_counts }));
330
+ }
331
+ else if (mode === "collect") {
332
+ const { record, labeled, failed, resultsByType, costUSD } = await collectLabelingBatch(out, parseLabels);
333
+ const rows = labeled.map(({ item, label }) => {
334
+ const paired = label.match == null ? null : item.candidates[label.match];
335
+ return {
336
+ added_id: item.id,
337
+ source: item.source,
338
+ source_id: item.sourceID,
339
+ country: item.country,
340
+ placetype: item.placetype,
341
+ names: item.names,
342
+ wof_id: paired?.wofID ?? null,
343
+ wof_names: paired?.names ?? null,
344
+ km: paired?.km ?? null,
345
+ candidates: item.candidates.length,
346
+ comparison: item.comparison,
347
+ similarity: item.similarity,
348
+ reason: label.reason,
349
+ confidence: label.confidence,
350
+ model: record.model,
351
+ effort: record.effort,
352
+ batch_id: record.id,
353
+ };
354
+ });
355
+ await writeLocalJSONLFile(rows, out("pairs.jsonl"));
356
+ const paired = rows.filter((row) => row.wof_id != null);
357
+ const summary = {
358
+ batch: record.id,
359
+ model: record.model,
360
+ effort: record.effort,
361
+ requests: record.requests,
362
+ resultsByType,
363
+ items: record.items,
364
+ labeled: rows.length,
365
+ failedRequests: failed.length,
366
+ failedItems: failed.reduce((sum, chunk) => sum + chunk.items, 0),
367
+ paired: paired.length,
368
+ pairedBySource: countEach(paired.map((row) => row.source)),
369
+ pairedHighConfidence: paired.filter((row) => row.confidence === "high").length,
370
+ reasons: countEach(rows.map((row) => row.reason)),
371
+ confidences: countEach(rows.map((row) => row.confidence)),
372
+ reasonsByComparison: Object.fromEntries(Object.values(NameComparison).map((comparison) => [
373
+ comparison,
374
+ countEach(rows.filter((row) => row.comparison === comparison).map((row) => row.reason)),
375
+ ])),
376
+ pairedCountries: Object.keys(countEach(paired.map((row) => row.country))).length,
377
+ costUSD,
378
+ };
379
+ await writeLocalJSONFile(summary, out("summary.json"));
380
+ console.log(stringifyJSON(summary));
381
+ }
382
+ else {
383
+ throw new Error(`The mode is one of census, pilot, submit, status and collect, and this run named ${String(mode)}`);
384
+ }
385
+ //# sourceMappingURL=place-twins.run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"place-twins.run.js","sourceRoot":"","sources":["../../../lib/tools/place-twins/place-twins.run.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACN,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,GAClB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,mDAAmD,CAAA;AACtG,OAAO,EAAE,uBAAuB,EAAE,MAAM,wDAAwD,CAAA;AAChG,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AAEtE,OAAO,EAAE,SAAS,EAAE,MAAM,8CAA8C,CAAA;AAExE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,EACN,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACT,gBAAgB,GAChB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACN,cAAc,EACd,sBAAsB,EACtB,sBAAsB,GAItB,MAAM,2BAA2B,CAAA;AAElC;;;;GAIG;AACH,MAAM,qBAAqB,GAAG,CAAC,UAAU,EAAE,YAAY,EAAE,SAAS,CAAC,CAAA;AACnE,MAAM,eAAe,GAAG,C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,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM;QAChF,OAAO;KACP,CAAA;IAED,MAAM,kBAAkB,CAAC,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC,CAAA;IAEtD,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;AACpC,CAAC;KAAM,CAAC;IACP,MAAM,IAAI,KAAK,CAAC,oFAAoF,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACpH,CAAC"}
@@ -0,0 +1,169 @@
1
+ import type { MessageBatchRequest } from "#tools/anthropic/batches";
2
+ /**
3
+ * Why the model paired, or declined to pair, an added place with a WOF record.
4
+ */
5
+ export declare const TwinReason: {
6
+ /**
7
+ * The two names write one name in two scripts or romanizations.
8
+ */
9
+ readonly Transliteration: "transliteration";
10
+ /**
11
+ * The two names are one name in two languages.
12
+ */
13
+ readonly Translation: "translation";
14
+ /**
15
+ * The two names differ by spelling, spacing, an article, an abbreviation or an administrative suffix.
16
+ */
17
+ readonly Spelling: "spelling";
18
+ /**
19
+ * The model recalls that the two names belong to one settlement.
20
+ */
21
+ readonly Known: "known_same";
22
+ /**
23
+ * The names belong to different settlements.
24
+ */
25
+ readonly Different: "different_place";
26
+ /**
27
+ * The evidence decides neither way.
28
+ */
29
+ readonly Unclear: "unclear";
30
+ };
31
+ export type TwinReason = (typeof TwinReason)[keyof typeof TwinReason];
32
+ declare const CONFIDENCES: readonly ["high", "medium", "low"];
33
+ export type TwinConfidence = (typeof CONFIDENCES)[number];
34
+ /**
35
+ * A WOF record near an added place.
36
+ */
37
+ export interface TwinCandidate {
38
+ wofID: number;
39
+ /**
40
+ * The record's primary name first, then its other names.
41
+ */
42
+ names: string[];
43
+ placetype: string;
44
+ km: number;
45
+ }
46
+ /**
47
+ * One added place with the WOF records inside the match radius.
48
+ */
49
+ export interface AddedPlaceItem {
50
+ /**
51
+ * The id of the place's own row in the admin database.
52
+ */
53
+ id: number;
54
+ source: "overture" | "geonames";
55
+ /**
56
+ * The place's id in its source: an Overture GERS id or a GeoNames id.
57
+ */
58
+ sourceID: string;
59
+ /**
60
+ * The place's primary name first, then its other names.
61
+ */
62
+ names: string[];
63
+ placetype: string;
64
+ country: string;
65
+ latitude: number;
66
+ longitude: number;
67
+ candidates: TwinCandidate[];
68
+ /**
69
+ * How the place's names compare with its candidates' names in code.
70
+ * `rankItems` orders the items a budget admits by it.
71
+ */
72
+ comparison: NameComparison;
73
+ /**
74
+ * The highest romanized edit similarity between one of the place's names and one of a candidate's.
75
+ * It is `null` unless `comparison` is `romanized`.
76
+ */
77
+ similarity: number | null;
78
+ }
79
+ /**
80
+ * What the romanizer could compare between an added place's names and its candidates' names.
81
+ */
82
+ export declare const NameComparison: {
83
+ /**
84
+ * At least one pair of names romanizes on both sides, so an edit similarity exists.
85
+ */
86
+ readonly Romanized: "romanized";
87
+ /**
88
+ * No pair romanizes on both sides, and at least one pair romanizes on exactly one:
89
+ * the names are in different scripts.
90
+ */
91
+ readonly CrossScript: "cross_script";
92
+ /**
93
+ * No name on either side romanizes.
94
+ */
95
+ readonly Uncovered: "uncovered";
96
+ };
97
+ export type NameComparison = (typeof NameComparison)[keyof typeof NameComparison];
98
+ /**
99
+ * The model's answer for one added place.
100
+ *
101
+ * `match` is the paired candidate's index in the item's `candidates`, or `null`
102
+ * when the place pairs with none.
103
+ */
104
+ export interface TwinLabel {
105
+ match: number | null;
106
+ reason: TwinReason;
107
+ confidence: TwinConfidence;
108
+ }
109
+ /**
110
+ * The system prompt of every place-twin request states the four reasons that pair an
111
+ * added place with a candidate, the two that pair it with none, and the rule that a
112
+ * short distance without a name relation pairs no two places.
113
+ */
114
+ export declare const PLACE_TWIN_SYSTEM_PROMPT = "You adjudicate duplicate settlements for a gazetteer.\n\nThe gazetteer holds Who's On First records and adds places from Overture and GeoNames. An added place joins a Who's On First record when the two share an identifier or a normalized name within 5 kilometers. Each item below is an added place that joined none, with the Who's On First settlements within 5 kilometers of it. The names differ, so either the added place is a separate settlement, or it is one of the candidates written in another script, language, romanization or spelling.\n\nFor each item you receive the added place's names, placetype, country and coordinates, and each candidate's index, names, placetype and distance in kilometers.\n\nDecide whether the added place is the same settlement as exactly one candidate:\n- transliteration: the names write one name in two scripts or romanization systems.\n- translation: the names are one name in two languages, including an exonym.\n- spelling: the names differ by spelling, diacritics, spacing, an article, an abbreviation, or an administrative word such as village, commune, town or its local equivalent.\n- known_same: you recall that the two names belong to one settlement, although the strings do not show it.\n- different_place: the names belong to different settlements. Two villages a few kilometers apart with unrelated names are different places, and so are places distinguished by a qualifier such as upper and lower, old and new, north and south, or a number.\n- unclear: the evidence decides neither way.\n\nGive \"match\" as the index of the candidate for the first four reasons, and -1 for different_place and unclear. A neighborhood or hamlet inside a larger candidate is a different place. Distance alone never establishes a match. State your confidence as high, medium or low, and prefer unclear over a guess.\n\nReturn one label per item, with the item's index.";
115
+ /**
116
+ * The structured-output schema of one response.
117
+ */
118
+ export declare const PLACE_TWIN_RESPONSE_SCHEMA: {
119
+ readonly type: "object";
120
+ readonly additionalProperties: false;
121
+ readonly required: readonly ["labels"];
122
+ readonly properties: {
123
+ readonly labels: {
124
+ readonly type: "array";
125
+ readonly items: {
126
+ readonly type: "object";
127
+ readonly additionalProperties: false;
128
+ readonly required: readonly ["i", "match", "reason", "confidence"];
129
+ readonly properties: {
130
+ readonly i: {
131
+ readonly type: "integer";
132
+ };
133
+ readonly match: {
134
+ readonly type: "integer";
135
+ };
136
+ readonly reason: {
137
+ readonly type: "string";
138
+ readonly enum: ("different_place" | "known_same" | "spelling" | "translation" | "transliteration" | "unclear")[];
139
+ };
140
+ readonly confidence: {
141
+ readonly type: "string";
142
+ readonly enum: readonly ["high", "medium", "low"];
143
+ };
144
+ };
145
+ };
146
+ };
147
+ };
148
+ };
149
+ /**
150
+ * Renders the items of one request as the user message the model reads.
151
+ */
152
+ export declare function renderPlaceTwinItems(items: readonly AddedPlaceItem[]): string;
153
+ /**
154
+ * Builds the Messages parameters of one request.
155
+ */
156
+ export declare function placeTwinRequestParams(items: readonly AddedPlaceItem[], options: {
157
+ model: string;
158
+ effort: string;
159
+ }): MessageBatchRequest["params"];
160
+ /**
161
+ * Parses one response into a label per item, given the candidate count of each item of the request.
162
+ *
163
+ * @throws When the text fails to parse as the schema's object, an index is outside
164
+ * the request or repeated, an item is unlabeled, a value is outside its enumeration,
165
+ * a match index is outside the item's candidates, or a match and its reason disagree.
166
+ */
167
+ export declare function parsePlaceTwinResponse(text: string, candidateCounts: readonly number[]): TwinLabel[];
168
+ export {};
169
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../lib/tools/place-twins/prompt.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAEnE;;GAEG;AACH,eAAO,MAAM,UAAU;IACtB;;OAEG;aACH,eAAe,EAAE,iBAAiB;IAClC;;OAEG;aACH,WAAW,EAAE,aAAa;IAC1B;;OAEG;aACH,QAAQ,EAAE,UAAU;IACpB;;OAEG;aACH,KAAK,EAAE,YAAY;IACnB;;OAEG;aACH,SAAS,EAAE,iBAAiB;IAC5B;;OAEG;aACH,OAAO,EAAE,SAAS;CACT,CAAA;AAEV,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAA;AASrE,QAAA,MAAM,WAAW,YAAI,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAU,CAAA;AAEtD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAA;AAEzD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,EAAE,EAAE,MAAM,CAAA;CACV;AAED;;G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