@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,156 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+ /**
4
+ * @file The request that asks a language model for the query forms of a country's prominent places (#3156).
5
+ *
6
+ * One request lists about ten places of one country.
7
+ * Each place lists its surfaces under keys, and the model returns texts with the keys each contains.
8
+ * The model decides which surfaces people combine, in which order, case and punctuation.
9
+ * It supplies no name: `#tools/prominent-shapes/validate` drops a text holding anything but cited surfaces.
10
+ */
11
+ import { stringifyJSON } from "@mailwoman/core/values/json";
12
+ import { SurfaceSlot } from "#tools/prominent-shapes/seeds";
13
+ /**
14
+ * The worked example of the instructions: a place's surface lines as a request renders them,
15
+ * and one form citing the second name and the second country by their numbered keys.
16
+ */
17
+ const SHAPE_KEY_EXAMPLE = {
18
+ surfaces: 'n1="Munich" n2="München"[deu] with country surfaces c1="Germany" c2="Deutschland"[deu],',
19
+ form: '{"raw": "München, Deutschland", "uses": ["n2", "c2"]}',
20
+ };
21
+ /**
22
+ * The instructions every request shares.
23
+ */
24
+ export const SHAPE_SYSTEM_PROMPT = [
25
+ "You write the short queries people type into a map or geocoder search box to find a well-known place.",
26
+ "",
27
+ "Each request names one country and lists places in it. Every place lists its surfaces, each under a key",
28
+ "made of a slot letter and a number, such as n1, n2 or c3. The letter is the surface's slot:",
29
+ "n = the place's own name, p = its parent city, r = its region (state, province, prefecture),",
30
+ "a = the region's abbreviation, c = the country. A bracket after a surface is its language code.",
31
+ "",
32
+ "For each place, write the queries a person would plausibly type, and for each give `raw` (the query text)",
33
+ "and `uses` (the keys of the surfaces it contains, in the order they appear in `raw`).",
34
+ "`uses` lists the numbered keys exactly as supplied, never the bare letter: for a place listing",
35
+ SHAPE_KEY_EXAMPLE.surfaces,
36
+ `the form ${SHAPE_KEY_EXAMPLE.form} is right, and "uses": ["n", "c"] is wrong.`,
37
+ "",
38
+ "Rules:",
39
+ "- `raw` contains only the cited surfaces and separators (spaces, commas, and the separators the country's",
40
+ " own writing uses). Add no other word: no street, postcode, 'city', 'near', article, preposition or suffix.",
41
+ "- Write each surface exactly as supplied, letter for letter, including its diacritics. You may change its",
42
+ " letter case only (lower, UPPER, Title). Never abbreviate, translate, transliterate, respell, shorten,",
43
+ " extend or misspell a surface, and never use a name that isn't in the list.",
44
+ "- Use exactly one n surface. Use at most one p, at most one of r or a, and at most one c.",
45
+ "- A place's line states which keys every form must contain; follow it.",
46
+ "- Keep one language per query: do not put a surface in one script beside a surface in another script.",
47
+ " Queries in the country's own language and script matter as much as English ones; use each supplied",
48
+ " language's surfaces together and in that language's customary order and punctuation (for example",
49
+ " larger-to-smaller without separators where that is how the language writes places).",
50
+ "- Vary the forms the way real typing varies: the name alone, name then region, name then region",
51
+ " abbreviation, name then country, with a comma, without a comma, all lower case, and sometimes upper case.",
52
+ " Prefer the combinations people type most. Skip a combination nobody would type.",
53
+ "- Do not repeat a `raw`. Return each place under the id given, and every place of the request.",
54
+ ].join("\n");
55
+ /**
56
+ * The structured-output schema of a response.
57
+ */
58
+ export const SHAPE_RESPONSE_SCHEMA = {
59
+ type: "object",
60
+ additionalProperties: false,
61
+ required: ["places"],
62
+ properties: {
63
+ places: {
64
+ type: "array",
65
+ items: {
66
+ type: "object",
67
+ additionalProperties: false,
68
+ required: ["id", "forms"],
69
+ properties: {
70
+ id: { type: "string" },
71
+ forms: {
72
+ type: "array",
73
+ items: {
74
+ type: "object",
75
+ additionalProperties: false,
76
+ required: ["raw", "uses"],
77
+ properties: {
78
+ raw: { type: "string" },
79
+ uses: { type: "array", items: { type: "string" } },
80
+ },
81
+ },
82
+ },
83
+ },
84
+ },
85
+ },
86
+ },
87
+ };
88
+ function renderSurfaces(surfaces, slot) {
89
+ const listed = surfaces.filter((surface) => surface.slot === slot);
90
+ if (!listed.length)
91
+ return null;
92
+ return listed
93
+ .map((surface) => `${surface.key}=${stringifyJSON(surface.text)}${surface.language ? `[${surface.language}]` : ""}`)
94
+ .join(" ");
95
+ }
96
+ /**
97
+ * The keys every form of `seed` must contain, in the words the request states them.
98
+ */
99
+ function requiredKeys(seed) {
100
+ if (seed.parent_tag === "locality")
101
+ return "every form contains one n and one p";
102
+ if (seed.parent_tag === "region") {
103
+ return seed.surfaces.some((surface) => surface.slot === SurfaceSlot.RegionAbbreviation)
104
+ ? "every form contains one n and either one p or one a"
105
+ : "every form contains one n and one p";
106
+ }
107
+ return "every form contains one n";
108
+ }
109
+ /**
110
+ * Renders the places of one request as the user message.
111
+ *
112
+ * Every seed is of one country, and that country's surfaces are listed once from the first seed.
113
+ *
114
+ * @throws When the seeds are empty or of more than one country.
115
+ */
116
+ export function renderShapeRequest(seeds, formsPerPlace) {
117
+ const [first] = seeds;
118
+ if (!first || seeds.some((seed) => seed.country !== first.country)) {
119
+ throw new Error("A request lists the places of exactly one country");
120
+ }
121
+ const lines = [
122
+ `Country ${first.country}. Country surfaces: ${renderSurfaces(first.surfaces, SurfaceSlot.Country) ?? "none; write no country"}`,
123
+ `Write about ${formsPerPlace} forms for each place, fewer when the place has few surfaces.`,
124
+ "",
125
+ ];
126
+ for (const seed of seeds) {
127
+ const kind = seed.band === "locality" ? "city or town" : "district of its parent city";
128
+ lines.push(`Place ${seed.wof_id} (${kind}; ${requiredKeys(seed)})`);
129
+ for (const slot of [SurfaceSlot.Name, SurfaceSlot.Parent, SurfaceSlot.Region, SurfaceSlot.RegionAbbreviation]) {
130
+ const rendered = renderSurfaces(seed.surfaces, slot);
131
+ if (rendered) {
132
+ lines.push(` ${rendered}`);
133
+ }
134
+ }
135
+ }
136
+ return lines.join("\n");
137
+ }
138
+ /**
139
+ * Builds the Messages parameters of one request.
140
+ */
141
+ export function shapeRequestParams(seeds, options) {
142
+ return {
143
+ model: options.model,
144
+ max_tokens: options.maxTokens,
145
+ system: SHAPE_SYSTEM_PROMPT,
146
+ output_config: { effort: options.effort, format: { type: "json_schema", schema: SHAPE_RESPONSE_SCHEMA } },
147
+ messages: [{ role: "user", content: renderShapeRequest(seeds, options.formsPerPlace) }],
148
+ };
149
+ }
150
+ /**
151
+ * The batch id of the request at `index`.
152
+ */
153
+ export function shapeRequestID(index) {
154
+ return `shapes-${String(index).padStart(5, "0")}`;
155
+ }
156
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../lib/tools/prominent-shapes/prompt.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAG3D,OAAO,EAAoC,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAE7F;;;GAGG;AACH,MAAM,iBAAiB,GAAG;IACzB,QAAQ,EAAE,yFAAyF;IACnG,IAAI,EAAE,uDAAuD;CACpD,CAAA;AAEV;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC,uGAAuG;IACvG,EAAE;IACF,yGAAyG;IACzG,6FAA6F;IAC7F,8FAA8F;IAC9F,iGAAiG;IACjG,EAAE;IACF,2GAA2G;IAC3G,uFAAuF;IACvF,gGAAgG;IAChG,iBAAiB,CAAC,QAAQ;IAC1B,YAAY,iBAAiB,CAAC,IAAI,6CAA6C;IAC/E,EAAE;IACF,QAAQ;IACR,2GAA2G;IAC3G,8GAA8G;IAC9G,2GAA2G;IAC3G,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C,CAAC,EAAE,GAAG,CAAC,EAAE,CAAA;AAClD,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type SeedSkip, type ShapeSeed } from "#tools/prominent-shapes/seeds";
2
+ /**
3
+ * The seeds read, and the places left without one by reason.
4
+ */
5
+ export interface SeedReadResult {
6
+ seeds: ShapeSeed[];
7
+ selected: number;
8
+ skipped: Partial<Record<SeedSkip, number>>;
9
+ }
10
+ /**
11
+ * Reads the seed of every prominent place in `placesParquet`.
12
+ *
13
+ * A parent locality or region takes its other-language surfaces from the ancestor
14
+ * whose WOF name is the census's name for it.
15
+ * Without such an ancestor its only surface is the census's name.
16
+ *
17
+ * @throws When the census file lacks a column a seed is read from.
18
+ */
19
+ export declare function readShapeSeeds(options: {
20
+ placesParquet: string;
21
+ wofDatabase: string;
22
+ }): Promise<SeedReadResult>;
23
+ //# sourceMappingURL=read-seeds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-seeds.d.ts","sourceRoot":"","sources":["../../../lib/tools/prominent-shapes/read-seeds.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAgB,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAqB,MAAM,+BAA+B,CAAA;AAwC9G;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,KAAK,EAAE,SAAS,EAAE,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;CAC1C;AAyDD;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAoJrH"}
@@ -0,0 +1,219 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+ /**
4
+ * @file Reads the seeds of the prominent places the #3156 census selected.
5
+ *
6
+ * The census's `places.parquet` supplies the selection, each place's name, parent locality, region,
7
+ * region abbreviations and postal-pair reading.
8
+ * The Who's On First admin database supplies the other-language surfaces: the `preferred` rows of
9
+ * `names` in the country's official languages and English, for the place, for the parent locality and
10
+ * region among its ancestors, and for its country.
11
+ * The codex supplies the country's rendered forms.
12
+ */
13
+ import { countryRenderForms, isTwoLetterCountryCode } from "@mailwoman/codex/country/country";
14
+ import { officialLanguagesAlpha3 } from "@mailwoman/codex/country/region-languages";
15
+ import { foldCaseWhitespace } from "@mailwoman/normalize/fold";
16
+ import { openBuiltClient } from "@mailwoman/sqlite/sealed";
17
+ import { escapeSQLString, openDuckDB } from "#parquet/duckdb";
18
+ import { parquetColumnNames } from "#parquet/readers";
19
+ import { chunked } from "#tools/fetch/wikidata/vital-places/progress";
20
+ import { assembleSeed } from "#tools/prominent-shapes/seeds";
21
+ /**
22
+ * The census columns a seed is read from.
23
+ */
24
+ const CENSUS_COLUMNS = [
25
+ "spr_id",
26
+ "country",
27
+ "band",
28
+ "name",
29
+ "rank",
30
+ "by_rank",
31
+ "capital",
32
+ "parent_locality",
33
+ "region",
34
+ "region_abbrs",
35
+ "postal_pair",
36
+ ];
37
+ /**
38
+ * The ids one SQLite query lists.
39
+ */
40
+ const ID_CHUNK = 500;
41
+ async function readCensusPlaces(placesParquet) {
42
+ const columns = new Set(await parquetColumnNames(placesParquet));
43
+ const missing = CENSUS_COLUMNS.filter((column) => !columns.has(column));
44
+ if (missing.length) {
45
+ throw new Error(`${placesParquet} lacks the census columns ${missing.join(", ")}; a seed cannot be read without them`);
46
+ }
47
+ using db = await openDuckDB();
48
+ const result = await db.runAndReadAll(`SELECT ${CENSUS_COLUMNS.join(", ")} FROM read_parquet('${escapeSQLString(placesParquet)}') ` +
49
+ "WHERE by_rank OR capital ORDER BY country, band, rank NULLS LAST, spr_id");
50
+ return result.getRowObjectsJson().map((row) => ({
51
+ spr_id: Number(row["spr_id"]),
52
+ country: String(row["country"]),
53
+ band: String(row["band"]),
54
+ name: String(row["name"]),
55
+ rank: row["rank"] == null ? null : Number(row["rank"]),
56
+ capital: row["capital"] === true,
57
+ parent_locality: typeof row["parent_locality"] === "string" ? row["parent_locality"] : null,
58
+ region: typeof row["region"] === "string" ? row["region"] : null,
59
+ region_abbrs: Array.isArray(row["region_abbrs"]) ? row["region_abbrs"].map(String) : [],
60
+ postal_pair: row["postal_pair"] === true,
61
+ }));
62
+ }
63
+ /**
64
+ * The languages a country's surfaces are read in: its official languages, then English.
65
+ */
66
+ function surfaceLanguages(country) {
67
+ return [...new Set([...officialLanguagesAlpha3(country), "eng"])];
68
+ }
69
+ /**
70
+ * The shortest Latin-script country surface a form writes.
71
+ *
72
+ * A shorter one collides with region abbreviations, as `packages/corpus/AGENTS.md` records.
73
+ * `日本` is two characters of another script and stays.
74
+ */
75
+ const LATIN_COUNTRY_SURFACE_MIN_LENGTH = 3;
76
+ /**
77
+ * Whether a country surface is written: neither a two-letter code nor a Latin surface under the floor.
78
+ */
79
+ function isWritableCountrySurface(text) {
80
+ const shortLatin = /^[\p{Script=Latin}.\s]*$/u.test(text) && text.trim().length < LATIN_COUNTRY_SURFACE_MIN_LENGTH;
81
+ return !isTwoLetterCountryCode(text) && !shortLatin;
82
+ }
83
+ /**
84
+ * Reads the seed of every prominent place in `placesParquet`.
85
+ *
86
+ * A parent locality or region takes its other-language surfaces from the ancestor
87
+ * whose WOF name is the census's name for it.
88
+ * Without such an ancestor its only surface is the census's name.
89
+ *
90
+ * @throws When the census file lacks a column a seed is read from.
91
+ */
92
+ export async function readShapeSeeds(options) {
93
+ const places = await readCensusPlaces(options.placesParquet);
94
+ using wof = await openBuiltClient(options.wofDatabase);
95
+ // The parent locality and region records among each place's ancestors, matched by the census's name.
96
+ const parentID = new Map();
97
+ const regionID = new Map();
98
+ const byID = new Map(places.map((place) => [place.spr_id, place]));
99
+ for (const ids of chunked([...byID.keys()], ID_CHUNK)) {
100
+ const ancestors = await wof
101
+ .selectFrom("ancestors")
102
+ .innerJoin("spr", "spr.id", "ancestors.ancestor_id")
103
+ .select(["ancestors.id", "ancestors.ancestor_id", "ancestors.ancestor_placetype", "spr.name"])
104
+ .where("ancestors.id", "in", ids)
105
+ .where("ancestors.ancestor_placetype", "in", ["locality", "localadmin", "region"])
106
+ .execute();
107
+ for (const ancestor of ancestors) {
108
+ const place = byID.get(ancestor.id);
109
+ const fold = foldCaseWhitespace(ancestor.name ?? "");
110
+ const isRegion = ancestor.ancestor_placetype === "region";
111
+ const expected = isRegion ? place.region : place.parent_locality;
112
+ const target = isRegion ? regionID : parentID;
113
+ if (ancestor.ancestor_id !== place.spr_id && expected != null && fold === foldCaseWhitespace(expected)) {
114
+ target.set(place.spr_id, Math.min(target.get(place.spr_id) ?? Infinity, ancestor.ancestor_id));
115
+ }
116
+ }
117
+ }
118
+ // Each country's own record: a country before a dependency, the lowest id first.
119
+ const countries = [...new Set(places.map((place) => place.country))];
120
+ const countryRecord = new Map();
121
+ const countryRows = await wof
122
+ .selectFrom("spr")
123
+ .select(["id", "name", "placetype", "country"])
124
+ .where("placetype", "in", ["country", "dependency"])
125
+ .where("country", "in", countries)
126
+ .where("is_current", "!=", 0)
127
+ .where("is_deprecated", "=", 0)
128
+ .orderBy("placetype")
129
+ .orderBy("id")
130
+ .execute();
131
+ for (const row of countryRows) {
132
+ // `XX` is WOF's code for a place of no recorded country, so a record filed under
133
+ // it belongs to no country's row. country-branch: `XX` is WOF's placeholder for an
134
+ // unrecorded country, a sentinel of the source and no country's rule.
135
+ if (row.country && row.country !== "XX" && row.name && !countryRecord.has(row.country)) {
136
+ countryRecord.set(row.country, { id: row.id, name: row.name });
137
+ }
138
+ }
139
+ // The preferred names of every record a seed reads, in the languages its country writes.
140
+ const languages = new Set(countries.flatMap(surfaceLanguages));
141
+ const namedIDs = new Set([...byID.keys(), ...parentID.values(), ...regionID.values()]);
142
+ for (const record of countryRecord.values()) {
143
+ namedIDs.add(record.id);
144
+ }
145
+ const namesByID = new Map();
146
+ for (const ids of chunked([...namedIDs], ID_CHUNK)) {
147
+ const rows = await wof
148
+ .selectFrom("names")
149
+ .select(["id", "name", "language"])
150
+ .where("id", "in", ids)
151
+ .where("privateuse", "=", "preferred")
152
+ .where("language", "in", [...languages])
153
+ .orderBy("id")
154
+ .orderBy("language")
155
+ .orderBy("name")
156
+ .execute();
157
+ for (const row of rows) {
158
+ if (!row.language)
159
+ continue;
160
+ const list = namesByID.get(row.id) ?? [];
161
+ list.push({ name: row.name, language: row.language });
162
+ namesByID.set(row.id, list);
163
+ }
164
+ }
165
+ const nameDrafts = (id, country) => {
166
+ if (id == null)
167
+ return [];
168
+ const wanted = surfaceLanguages(country);
169
+ return (namesByID.get(id) ?? [])
170
+ .filter((row) => wanted.includes(row.language))
171
+ .toSorted((a, b) => wanted.indexOf(a.language) - wanted.indexOf(b.language))
172
+ .map((row) => ({ text: row.name, language: row.language, origin: `wof:names:${id}:${row.language}:preferred` }));
173
+ };
174
+ const censusDraft = (text, column, id) => text == null ? [] : [{ text, language: null, origin: `census:${column}:${id}` }];
175
+ const seeds = [];
176
+ const skipped = {};
177
+ for (const place of places) {
178
+ const country = countryRecord.get(place.country);
179
+ const seed = assembleSeed({
180
+ wof_id: place.spr_id,
181
+ country: place.country,
182
+ band: place.band,
183
+ rank: place.rank,
184
+ capital: place.capital,
185
+ postal_pair: place.postal_pair,
186
+ names: [...censusDraft(place.name, "name", place.spr_id), ...nameDrafts(place.spr_id, place.country)],
187
+ parents: [
188
+ ...censusDraft(place.parent_locality, "parent_locality", place.spr_id),
189
+ ...nameDrafts(parentID.get(place.spr_id), place.country),
190
+ ],
191
+ regions: [
192
+ ...censusDraft(place.region, "region", place.spr_id),
193
+ ...nameDrafts(regionID.get(place.spr_id), place.country),
194
+ ],
195
+ region_abbreviations: place.region_abbrs.map((text) => ({
196
+ text,
197
+ language: null,
198
+ origin: `census:region_abbrs:${place.spr_id}`,
199
+ })),
200
+ countries: [
201
+ ...countryRenderForms(place.country).map((text) => ({
202
+ text,
203
+ language: null,
204
+ origin: `codex:countryRenderForms:${place.country}`,
205
+ })),
206
+ ...(country ? [{ text: country.name, language: null, origin: `wof:spr:${country.id}:name` }] : []),
207
+ ...nameDrafts(country?.id, place.country),
208
+ ].filter((draft) => isWritableCountrySurface(draft.text)),
209
+ });
210
+ if (typeof seed === "string") {
211
+ skipped[seed] = (skipped[seed] ?? 0) + 1;
212
+ }
213
+ else {
214
+ seeds.push(seed);
215
+ }
216
+ }
217
+ return { seeds, selected: places.length, skipped };
218
+ }
219
+ //# sourceMappingURL=read-seeds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-seeds.js","sourceRoot":"","sources":["../../../lib/tools/prominent-shapes/read-seeds.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;;;;;;;;GASG;AAEH,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAA;AAC7F,OAAO,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAA;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAE9D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAErD,OAAO,EAAE,OAAO,EAAE,MAAM,6CAA6C,CAAA;AACrE,OAAO,EAAE,YAAY,EAAoD,MAAM,+BAA+B,CAAA;AAE9G;;GAEG;AACH,MAAM,cAAc,GAAG;IACtB,QAAQ;IACR,SAAS;IACT,MAAM;IACN,MAAM;IACN,MAAM;IACN,SAAS;IACT,SAAS;IACT,iBAAiB;IACjB,QAAQ;IACR,cAAc;IACd,aAAa;CACJ,CAAA;AAEV;;GAEG;AACH,MAAM,QAAQ,GAAG,GAAG,CAAA;AA2BpB,KAAK,UAAU,gBAAgB,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CAAC,CAAC;gBACvD,IAAI;gBACJ,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE,uBAAuB,KAAK,CAAC,MAAM,EAAE;aAC7C,CAAC,CAAC;YACH,SAAS,EAAE;gBACV,GAAG,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;oBACnD,IAAI;oBACJ,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE,4BAA4B,KAAK,CAAC,OAAO,EAAE;iBACnD,CAAC,CAAC;gBACH,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBAClG,GAAG,UAAU,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,OAAO,CAAC;aACzC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,wBAAwB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SACzD,CAAC,CAAA;QAEF,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;QACzC,CAAC;aAAM,CAAC;YACP,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACjB,CAAC;IACF,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAA;AACnD,CAAC"}
@@ -0,0 +1,132 @@
1
+ import type { PlaceBand } from "#recipes/prominent/places";
2
+ /**
3
+ * The slots a surface fills, by the letter its key starts with.
4
+ */
5
+ export declare const SurfaceSlot: {
6
+ /**
7
+ * The place's own name.
8
+ */
9
+ readonly Name: "n";
10
+ /**
11
+ * The parent locality of a sub-locality.
12
+ */
13
+ readonly Parent: "p";
14
+ /**
15
+ * The region's name.
16
+ */
17
+ readonly Region: "r";
18
+ /**
19
+ * The region's abbreviation.
20
+ */
21
+ readonly RegionAbbreviation: "a";
22
+ /**
23
+ * The country.
24
+ */
25
+ readonly Country: "c";
26
+ };
27
+ /**
28
+ * One slot.
29
+ */
30
+ export type SurfaceSlot = (typeof SurfaceSlot)[keyof typeof SurfaceSlot];
31
+ /**
32
+ * One surface a form may contain.
33
+ */
34
+ export interface SeedSurface {
35
+ /**
36
+ * The slot letter and a one-based index, the key the model cites: `n1`, `c3`.
37
+ */
38
+ key: string;
39
+ slot: SurfaceSlot;
40
+ text: string;
41
+ /**
42
+ * The ISO 639-3 language of a WOF `names` row, or `null` for a surface recorded without one.
43
+ */
44
+ language: string | null;
45
+ /**
46
+ * The record the surface was read from, such as `wof:names:85922583:eng:preferred`.
47
+ */
48
+ origin: string;
49
+ }
50
+ /**
51
+ * A surface before it has a key.
52
+ */
53
+ export type SurfaceDraft = Omit<SeedSurface, "key" | "slot">;
54
+ /**
55
+ * One prominent place and the surfaces its forms are written from.
56
+ */
57
+ export interface ShapeSeed {
58
+ wof_id: number;
59
+ country: string;
60
+ band: PlaceBand;
61
+ /**
62
+ * The place's rank within its country and band, or `null` for a capital the rank left out.
63
+ */
64
+ rank: number | null;
65
+ capital: boolean;
66
+ /**
67
+ * The tag of the place's own span.
68
+ */
69
+ place_tag: "locality" | "dependent_locality";
70
+ /**
71
+ * The tag of a parent span, or `null` when the seed has no parent slot.
72
+ */
73
+ parent_tag: "locality" | "region" | null;
74
+ surfaces: SeedSurface[];
75
+ }
76
+ /**
77
+ * The reasons a prominent place gets no seed.
78
+ */
79
+ export declare const SeedSkip: {
80
+ /**
81
+ * A sub-locality without a parent locality: the label policy writes it only beside one.
82
+ */
83
+ readonly NoParent: "sublocality_without_parent";
84
+ /**
85
+ * A sub-locality whose name equals its parent's, so every query form reads the same for both.
86
+ */
87
+ readonly ParentNamesake: "sublocality_named_as_parent";
88
+ /**
89
+ * Every name of the place is refused as a typed surface, so no form could cite a name.
90
+ */
91
+ readonly NoName: "no_typed_name";
92
+ };
93
+ /**
94
+ * One skip reason.
95
+ */
96
+ export type SeedSkip = (typeof SeedSkip)[keyof typeof SeedSkip];
97
+ /**
98
+ * What one prominent place contributes to a seed, as read from the census and Who's On First.
99
+ */
100
+ export interface SeedInput {
101
+ wof_id: number;
102
+ country: string;
103
+ band: PlaceBand;
104
+ rank: number | null;
105
+ capital: boolean;
106
+ postal_pair: boolean;
107
+ names: readonly SurfaceDraft[];
108
+ parents: readonly SurfaceDraft[];
109
+ regions: readonly SurfaceDraft[];
110
+ region_abbreviations: readonly SurfaceDraft[];
111
+ countries: readonly SurfaceDraft[];
112
+ }
113
+ /**
114
+ * Builds a place's seed, or returns the reason the label policy writes no form for it.
115
+ *
116
+ * A place whose every name is refused gets no seed in either band, because every form needs one name.
117
+ * A locality has no parent slot.
118
+ *
119
+ * A postal pair writes its parent's name in the region slot, and keeps the region's
120
+ * abbreviations only when the region is that same name (`Brooklyn, NY`).
121
+ */
122
+ export declare function assembleSeed(input: SeedInput): ShapeSeed | SeedSkip;
123
+ /**
124
+ * Keeps each country and band's highest-ranked `limit` seeds, and every capital.
125
+ */
126
+ export declare function limitSeedsPerBand(seeds: readonly ShapeSeed[], limit: number): ShapeSeed[];
127
+ /**
128
+ * Groups seeds into requests of at most `size` places, each of one country,
129
+ * so a request lists its country's surfaces once.
130
+ */
131
+ export declare function chunkSeedsByCountry(seeds: readonly ShapeSeed[], size: number): ShapeSeed[][];
132
+ //# sourceMappingURL=seeds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seeds.d.ts","sourceRoot":"","sources":["../../../lib/tools/prominent-shapes/seeds.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAE1D;;GAEG;AACH,e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