@mailwoman/corpus 11.3.0 → 11.4.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 (336) hide show
  1. package/data/PROVENANCE.md +3 -4
  2. package/data/address-source-register.json +4 -4
  3. package/data/builds/v0.8.23-overlay/OVERLAY_PLAN.json +3656 -0
  4. package/data/builds/v0.8.23-prominent-overlay/OVERLAY_PLAN.json +42 -0
  5. package/data/builds/v0.8.23-rebuild/inputs.json +141 -0
  6. package/data/builds/v0.8.24-rebuild/inputs.json +111 -0
  7. package/data/corpus-source-inputs.json +95 -1
  8. package/data/holdout/evaluation-groups.v0.8.24.json +222158 -0
  9. package/data/license-decisions.json +5 -0
  10. package/data/region-slot-second-level.json +1 -1
  11. package/data/training-configs/v8.11.0-base-c6-90k-v0823-s42.yaml +920 -0
  12. package/data/training-configs/v8.12.0-base-c6-wofreps-v0823-s42.yaml +944 -0
  13. package/data/training-configs/v8.13.0-base-c6-wofreps-v0822-s42.yaml +918 -0
  14. package/lib/adapters/cordis/adapter.ts +3 -2
  15. package/lib/adapters/gleif/adapter.ts +123 -20
  16. package/lib/adapters/openaddresses/adapter.ts +2 -2
  17. package/lib/adapters/osm/adapter.ts +62 -4
  18. package/lib/adapters/overture/adapter.ts +97 -15
  19. package/lib/adapters/overture/address-key.ts +89 -0
  20. package/lib/adapters/overture/places-in/adapter.ts +258 -0
  21. package/lib/adapters/street/convention.ts +49 -0
  22. package/lib/adapters/street/country-line.ts +65 -0
  23. package/lib/adapters/wof/admin/json/adapter.ts +4 -4
  24. package/lib/adapters/wof/admin/json/region-codes.ts +98 -0
  25. package/lib/adapters/wof/json-rows.ts +2 -2
  26. package/lib/adapters.ts +2 -0
  27. package/lib/build/align/range.ts +21 -11
  28. package/lib/build/align/totals.ts +20 -0
  29. package/lib/build/align.ts +218 -20
  30. package/lib/build/budget.ts +55 -20
  31. package/lib/build/checkpoint.ts +9 -0
  32. package/lib/build/component-check.ts +97 -3
  33. package/lib/build/inputs.ts +122 -31
  34. package/lib/build/manifest.ts +1 -0
  35. package/lib/build/parallel.ts +140 -23
  36. package/lib/build/{region-names.ts → region/names.ts} +16 -4
  37. package/lib/build/region/recount.ts +153 -0
  38. package/lib/build/reuse.ts +112 -0
  39. package/lib/build/settings.ts +84 -3
  40. package/lib/build/source-record.ts +45 -8
  41. package/lib/build/types.ts +26 -0
  42. package/lib/build/worker.ts +75 -10
  43. package/lib/build.ts +2 -1
  44. package/lib/de/recipes/locale.ts +9 -3
  45. package/lib/evaluation/corpus-adapter.ts +2 -2
  46. package/lib/fi/adapters/ryhti/adapter.ts +2 -2
  47. package/lib/fo/adapters/adressur/adapter.ts +2 -2
  48. package/lib/fr/recipes/lieudit.ts +3 -4
  49. package/lib/in/street-line/segment.ts +370 -0
  50. package/lib/international/recipes/locale.ts +6 -3
  51. package/lib/li/adapters/llv/adapter.ts +2 -2
  52. package/lib/lu/adapters/bd-adresses/adapter.ts +2 -2
  53. package/lib/no/adapters/matrikkelen/adapter.ts +2 -2
  54. package/lib/parquet/streams.ts +18 -3
  55. package/lib/parquet/writers.ts +161 -29
  56. package/lib/recipes/country-balanced.ts +32 -18
  57. package/lib/recipes/fragment-assay/build.ts +8 -5
  58. package/lib/recipes/fragment-assay/rows.ts +4 -4
  59. package/lib/recipes/house/venue.ts +2 -1
  60. package/lib/recipes/postal/guideline/leg.ts +3 -2
  61. package/lib/recipes/prominent/places.ts +4 -4
  62. package/lib/runner.ts +139 -20
  63. package/lib/sg/recipes/register.ts +6 -1
  64. package/lib/source-register/row-license.ts +12 -2
  65. package/lib/surfaces/corpus-row.ts +84 -0
  66. package/lib/surfaces/locale.ts +20 -24
  67. package/lib/synthesizers/house-venue.ts +33 -40
  68. package/lib/synthesizers/no-street.ts +2 -2
  69. package/lib/synthesizers/po-box.ts +3 -3
  70. package/lib/synthesizers/tail.ts +3 -2
  71. package/lib/synthesizers/utils.ts +95 -56
  72. package/lib/test-kit.ts +50 -1
  73. package/lib/tools/fetch/overture-places-in.ts +118 -0
  74. package/lib/tools/fetch/storage.ts +3 -0
  75. package/lib/tools/fetch.ts +2 -0
  76. package/lib/tools/region-slot-census.run.ts +2 -2
  77. package/lib/types.ts +39 -0
  78. package/lib/us/adapters/state/tx-notaries/adapter.ts +2 -1
  79. package/lib/us/adapters/usgov/imls-pls/adapter.ts +2 -1
  80. package/lib/us/adapters/usgov/nad/adapter.ts +32 -4
  81. package/lib/us/adapters/usgov/nad/address-key.ts +8 -47
  82. package/lib/us/adapters/usgov/nppes/adapter.ts +2 -1
  83. package/lib/utils/address-key.ts +57 -0
  84. package/lib/utils/align.ts +22 -10
  85. package/lib/utils/evaluation-groups.ts +13 -6
  86. package/lib/utils/split.ts +24 -3
  87. package/out/adapters/cordis/adapter.d.ts.map +1 -1
  88. package/out/adapters/cordis/adapter.js +3 -2
  89. package/out/adapters/cordis/adapter.js.map +1 -1
  90. package/out/adapters/gleif/adapter.d.ts +4 -0
  91. package/out/adapters/gleif/adapter.d.ts.map +1 -1
  92. package/out/adapters/gleif/adapter.js +100 -20
  93. package/out/adapters/gleif/adapter.js.map +1 -1
  94. package/out/adapters/openaddresses/adapter.js +2 -2
  95. package/out/adapters/openaddresses/adapter.js.map +1 -1
  96. package/out/adapters/osm/adapter.d.ts +9 -0
  97. package/out/adapters/osm/adapter.d.ts.map +1 -1
  98. package/out/adapters/osm/adapter.js +55 -13
  99. package/out/adapters/osm/adapter.js.map +1 -1
  100. package/out/adapters/overture/adapter.d.ts +6 -0
  101. package/out/adapters/overture/adapter.d.ts.map +1 -1
  102. package/out/adapters/overture/adapter.js +72 -9
  103. package/out/adapters/overture/adapter.js.map +1 -1
  104. package/out/adapters/overture/address-key.d.ts +39 -0
  105. package/out/adapters/overture/address-key.d.ts.map +1 -0
  106. package/out/adapters/overture/address-key.js +75 -0
  107. package/out/adapters/overture/address-key.js.map +1 -0
  108. package/out/adapters/overture/places-in/adapter.d.ts +20 -0
  109. package/out/adapters/overture/places-in/adapter.d.ts.map +1 -0
  110. package/out/adapters/overture/places-in/adapter.js +191 -0
  111. package/out/adapters/overture/places-in/adapter.js.map +1 -0
  112. package/out/adapters/street/convention.d.ts +11 -0
  113. package/out/adapters/street/convention.d.ts.map +1 -0
  114. package/out/adapters/street/convention.js +40 -0
  115. package/out/adapters/street/convention.js.map +1 -0
  116. package/out/adapters/street/country-line.d.ts +31 -0
  117. package/out/adapters/street/country-line.d.ts.map +1 -0
  118. package/out/adapters/street/country-line.js +31 -0
  119. package/out/adapters/street/country-line.js.map +1 -0
  120. package/out/adapters/wof/admin/json/adapter.js +4 -4
  121. package/out/adapters/wof/admin/json/adapter.js.map +1 -1
  122. package/out/adapters/wof/admin/json/region-codes.d.ts +5 -0
  123. package/out/adapters/wof/admin/json/region-codes.d.ts.map +1 -1
  124. package/out/adapters/wof/admin/json/region-codes.js +83 -0
  125. package/out/adapters/wof/admin/json/region-codes.js.map +1 -1
  126. package/out/adapters/wof/json-rows.d.ts.map +1 -1
  127. package/out/adapters/wof/json-rows.js +2 -2
  128. package/out/adapters/wof/json-rows.js.map +1 -1
  129. package/out/adapters.d.ts.map +1 -1
  130. package/out/adapters.js +2 -0
  131. package/out/adapters.js.map +1 -1
  132. package/out/build/align/range.d.ts +7 -3
  133. package/out/build/align/range.d.ts.map +1 -1
  134. package/out/build/align/range.js +17 -9
  135. package/out/build/align/range.js.map +1 -1
  136. package/out/build/align/totals.d.ts +12 -0
  137. package/out/build/align/totals.d.ts.map +1 -1
  138. package/out/build/align/totals.js +8 -0
  139. package/out/build/align/totals.js.map +1 -1
  140. package/out/build/align.d.ts +60 -5
  141. package/out/build/align.d.ts.map +1 -1
  142. package/out/build/align.js +136 -12
  143. package/out/build/align.js.map +1 -1
  144. package/out/build/budget.d.ts +35 -11
  145. package/out/build/budget.d.ts.map +1 -1
  146. package/out/build/budget.js +52 -20
  147. package/out/build/budget.js.map +1 -1
  148. package/out/build/checkpoint.d.ts +9 -0
  149. package/out/build/checkpoint.d.ts.map +1 -1
  150. package/out/build/checkpoint.js.map +1 -1
  151. package/out/build/component-check.d.ts +29 -1
  152. package/out/build/component-check.d.ts.map +1 -1
  153. package/out/build/component-check.js +57 -2
  154. package/out/build/component-check.js.map +1 -1
  155. package/out/build/inputs.d.ts +58 -0
  156. package/out/build/inputs.d.ts.map +1 -1
  157. package/out/build/inputs.js +57 -20
  158. package/out/build/inputs.js.map +1 -1
  159. package/out/build/manifest.d.ts.map +1 -1
  160. package/out/build/manifest.js +1 -0
  161. package/out/build/manifest.js.map +1 -1
  162. package/out/build/parallel.d.ts +19 -1
  163. package/out/build/parallel.d.ts.map +1 -1
  164. package/out/build/parallel.js +92 -11
  165. package/out/build/parallel.js.map +1 -1
  166. package/out/build/{region-names.d.ts → region/names.d.ts} +10 -1
  167. package/out/build/region/names.d.ts.map +1 -0
  168. package/out/build/{region-names.js → region/names.js} +16 -5
  169. package/out/build/region/names.js.map +1 -0
  170. package/out/build/region/recount.d.ts +47 -0
  171. package/out/build/region/recount.d.ts.map +1 -0
  172. package/out/build/region/recount.js +105 -0
  173. package/out/build/region/recount.js.map +1 -0
  174. package/out/build/reuse.d.ts +31 -0
  175. package/out/build/reuse.d.ts.map +1 -0
  176. package/out/build/reuse.js +50 -0
  177. package/out/build/reuse.js.map +1 -0
  178. package/out/build/settings.d.ts +38 -0
  179. package/out/build/settings.d.ts.map +1 -1
  180. package/out/build/settings.js +67 -3
  181. package/out/build/settings.js.map +1 -1
  182. package/out/build/source-record.d.ts +32 -7
  183. package/out/build/source-record.d.ts.map +1 -1
  184. package/out/build/source-record.js +17 -4
  185. package/out/build/source-record.js.map +1 -1
  186. package/out/build/types.d.ts +24 -0
  187. package/out/build/types.d.ts.map +1 -1
  188. package/out/build/worker.d.ts +17 -0
  189. package/out/build/worker.d.ts.map +1 -1
  190. package/out/build/worker.js +44 -9
  191. package/out/build/worker.js.map +1 -1
  192. package/out/build.d.ts.map +1 -1
  193. package/out/build.js +2 -1
  194. package/out/build.js.map +1 -1
  195. package/out/de/recipes/locale.d.ts.map +1 -1
  196. package/out/de/recipes/locale.js +9 -3
  197. package/out/de/recipes/locale.js.map +1 -1
  198. package/out/evaluation/corpus-adapter.d.ts +14 -0
  199. package/out/evaluation/corpus-adapter.d.ts.map +1 -1
  200. package/out/evaluation/corpus-adapter.js +2 -16
  201. package/out/evaluation/corpus-adapter.js.map +1 -1
  202. package/out/fi/adapters/ryhti/adapter.js +2 -2
  203. package/out/fi/adapters/ryhti/adapter.js.map +1 -1
  204. package/out/fo/adapters/adressur/adapter.js +2 -2
  205. package/out/fo/adapters/adressur/adapter.js.map +1 -1
  206. package/out/fr/recipes/lieudit.d.ts.map +1 -1
  207. package/out/fr/recipes/lieudit.js +3 -3
  208. package/out/fr/recipes/lieudit.js.map +1 -1
  209. package/out/in/street-line/segment.d.ts +75 -0
  210. package/out/in/street-line/segment.d.ts.map +1 -0
  211. package/out/in/street-line/segment.js +298 -0
  212. package/out/in/street-line/segment.js.map +1 -0
  213. package/out/international/recipes/locale.d.ts.map +1 -1
  214. package/out/international/recipes/locale.js +6 -3
  215. package/out/international/recipes/locale.js.map +1 -1
  216. package/out/li/adapters/llv/adapter.js +2 -2
  217. package/out/li/adapters/llv/adapter.js.map +1 -1
  218. package/out/lu/adapters/bd-adresses/adapter.js +2 -2
  219. package/out/lu/adapters/bd-adresses/adapter.js.map +1 -1
  220. package/out/no/adapters/matrikkelen/adapter.js +2 -2
  221. package/out/no/adapters/matrikkelen/adapter.js.map +1 -1
  222. package/out/parquet/streams.d.ts +9 -0
  223. package/out/parquet/streams.d.ts.map +1 -1
  224. package/out/parquet/streams.js +7 -3
  225. package/out/parquet/streams.js.map +1 -1
  226. package/out/parquet/writers.d.ts +55 -2
  227. package/out/parquet/writers.d.ts.map +1 -1
  228. package/out/parquet/writers.js +109 -27
  229. package/out/parquet/writers.js.map +1 -1
  230. package/out/recipes/country-balanced.d.ts.map +1 -1
  231. package/out/recipes/country-balanced.js +32 -15
  232. package/out/recipes/country-balanced.js.map +1 -1
  233. package/out/recipes/fragment-assay/build.d.ts +5 -2
  234. package/out/recipes/fragment-assay/build.d.ts.map +1 -1
  235. package/out/recipes/fragment-assay/build.js +8 -5
  236. package/out/recipes/fragment-assay/build.js.map +1 -1
  237. package/out/recipes/fragment-assay/rows.d.ts +2 -2
  238. package/out/recipes/fragment-assay/rows.js +4 -4
  239. package/out/recipes/fragment-assay/rows.js.map +1 -1
  240. package/out/recipes/house/venue.d.ts.map +1 -1
  241. package/out/recipes/house/venue.js +2 -1
  242. package/out/recipes/house/venue.js.map +1 -1
  243. package/out/recipes/postal/guideline/leg.d.ts.map +1 -1
  244. package/out/recipes/postal/guideline/leg.js +2 -7
  245. package/out/recipes/postal/guideline/leg.js.map +1 -1
  246. package/out/recipes/prominent/places.js +4 -4
  247. package/out/recipes/prominent/places.js.map +1 -1
  248. package/out/runner.d.ts +28 -0
  249. package/out/runner.d.ts.map +1 -1
  250. package/out/runner.js +85 -18
  251. package/out/runner.js.map +1 -1
  252. package/out/sg/recipes/register.d.ts.map +1 -1
  253. package/out/sg/recipes/register.js +6 -1
  254. package/out/sg/recipes/register.js.map +1 -1
  255. package/out/source-register/row-license.d.ts +8 -0
  256. package/out/source-register/row-license.d.ts.map +1 -1
  257. package/out/source-register/row-license.js +10 -2
  258. package/out/source-register/row-license.js.map +1 -1
  259. package/out/surfaces/corpus-row.d.ts +32 -0
  260. package/out/surfaces/corpus-row.d.ts.map +1 -0
  261. package/out/surfaces/corpus-row.js +70 -0
  262. package/out/surfaces/corpus-row.js.map +1 -0
  263. package/out/surfaces/locale.d.ts.map +1 -1
  264. package/out/surfaces/locale.js +16 -22
  265. package/out/surfaces/locale.js.map +1 -1
  266. package/out/synthesizers/house-venue.d.ts +9 -4
  267. package/out/synthesizers/house-venue.d.ts.map +1 -1
  268. package/out/synthesizers/house-venue.js +25 -35
  269. package/out/synthesizers/house-venue.js.map +1 -1
  270. package/out/synthesizers/no-street.js +2 -9
  271. package/out/synthesizers/no-street.js.map +1 -1
  272. package/out/synthesizers/po-box.js +3 -7
  273. package/out/synthesizers/po-box.js.map +1 -1
  274. package/out/synthesizers/tail.d.ts.map +1 -1
  275. package/out/synthesizers/tail.js +2 -2
  276. package/out/synthesizers/tail.js.map +1 -1
  277. package/out/synthesizers/utils.d.ts +20 -3
  278. package/out/synthesizers/utils.d.ts.map +1 -1
  279. package/out/synthesizers/utils.js +74 -57
  280. package/out/synthesizers/utils.js.map +1 -1
  281. package/out/test-kit.d.ts +11 -0
  282. package/out/test-kit.d.ts.map +1 -1
  283. package/out/test-kit.js +30 -1
  284. package/out/test-kit.js.map +1 -1
  285. package/out/tools/fetch/overture-places-in.d.ts +14 -0
  286. package/out/tools/fetch/overture-places-in.d.ts.map +1 -0
  287. package/out/tools/fetch/overture-places-in.js +82 -0
  288. package/out/tools/fetch/overture-places-in.js.map +1 -0
  289. package/out/tools/fetch/storage.d.ts +2 -0
  290. package/out/tools/fetch/storage.d.ts.map +1 -1
  291. package/out/tools/fetch/storage.js +3 -0
  292. package/out/tools/fetch/storage.js.map +1 -1
  293. package/out/tools/fetch.d.ts +2 -0
  294. package/out/tools/fetch.d.ts.map +1 -1
  295. package/out/tools/fetch.js +2 -0
  296. package/out/tools/fetch.js.map +1 -1
  297. package/out/tools/region-slot-census.run.js +2 -2
  298. package/out/types.d.ts +41 -0
  299. package/out/types.d.ts.map +1 -1
  300. package/out/types.js.map +1 -1
  301. package/out/us/adapters/state/tx-notaries/adapter.d.ts.map +1 -1
  302. package/out/us/adapters/state/tx-notaries/adapter.js +2 -1
  303. package/out/us/adapters/state/tx-notaries/adapter.js.map +1 -1
  304. package/out/us/adapters/usgov/imls-pls/adapter.d.ts.map +1 -1
  305. package/out/us/adapters/usgov/imls-pls/adapter.js +2 -1
  306. package/out/us/adapters/usgov/imls-pls/adapter.js.map +1 -1
  307. package/out/us/adapters/usgov/nad/adapter.d.ts +15 -0
  308. package/out/us/adapters/usgov/nad/adapter.d.ts.map +1 -1
  309. package/out/us/adapters/usgov/nad/adapter.js +21 -3
  310. package/out/us/adapters/usgov/nad/adapter.js.map +1 -1
  311. package/out/us/adapters/usgov/nad/address-key.d.ts +1 -5
  312. package/out/us/adapters/usgov/nad/address-key.d.ts.map +1 -1
  313. package/out/us/adapters/usgov/nad/address-key.js +8 -33
  314. package/out/us/adapters/usgov/nad/address-key.js.map +1 -1
  315. package/out/us/adapters/usgov/nppes/adapter.d.ts.map +1 -1
  316. package/out/us/adapters/usgov/nppes/adapter.js +2 -1
  317. package/out/us/adapters/usgov/nppes/adapter.js.map +1 -1
  318. package/out/utils/address-key.d.ts +23 -0
  319. package/out/utils/address-key.d.ts.map +1 -0
  320. package/out/utils/address-key.js +43 -0
  321. package/out/utils/address-key.js.map +1 -0
  322. package/out/utils/align.d.ts +7 -0
  323. package/out/utils/align.d.ts.map +1 -1
  324. package/out/utils/align.js +18 -8
  325. package/out/utils/align.js.map +1 -1
  326. package/out/utils/evaluation-groups.d.ts +5 -1
  327. package/out/utils/evaluation-groups.d.ts.map +1 -1
  328. package/out/utils/evaluation-groups.js +12 -1
  329. package/out/utils/evaluation-groups.js.map +1 -1
  330. package/out/utils/split.d.ts +11 -0
  331. package/out/utils/split.d.ts.map +1 -1
  332. package/out/utils/split.js +18 -3
  333. package/out/utils/split.js.map +1 -1
  334. package/package.json +19 -19
  335. package/out/build/region-names.d.ts.map +0 -1
  336. package/out/build/region-names.js.map +0 -1
@@ -42,6 +42,10 @@ export interface AlignSettings {
42
42
  exclude_licenses: readonly string[]
43
43
  profile: string
44
44
  holdout_digest: string
45
+ /**
46
+ * Each capped source's `trainShare`, present only when one is capped.
47
+ */
48
+ train_shares?: Record<string, number>
45
49
  }
46
50
 
47
51
  /**
@@ -87,6 +91,11 @@ export interface AlignCheckpoint {
87
91
  * rather than restarting it at zero and understating the refusal in its manifest.
88
92
  */
89
93
  refused_by_source: Record<string, number>
94
+ /**
95
+ * Training rows each source's `trainShare` left out.
96
+ * A checkpoint written before the share existed has none.
97
+ */
98
+ train_rows_left_out_by_source?: Record<string, number>
90
99
  excluded_by_license: number
91
100
  admitted_unresolved_license_rows: number
92
101
  excluded_by_eligibility: number
@@ -14,7 +14,7 @@ import { acceptPostcode, statesPostcodeSyntax } from "@mailwoman/postcode/countr
14
14
 
15
15
  import type { UnitSplitter } from "#adapters/street/unit"
16
16
  import { writtenSubdivisionCode } from "#adapters/wof/admin/json/region-codes"
17
- import type { RegionNames } from "#build/region-names"
17
+ import type { RegionNames } from "#build/region/names"
18
18
  import type { CanonicalRow } from "#types"
19
19
 
20
20
  /**
@@ -106,6 +106,35 @@ export function componentFindingsRecord(counts: ComponentFindingCounts): Record<
106
106
  return Object.fromEntries([...counts].map(([source, rules]) => [source, Object.fromEntries(rules)]))
107
107
  }
108
108
 
109
+ /**
110
+ * The key under which a row's region value is counted: its country and the value as the row writes it.
111
+ */
112
+ export function regionValueKey(country: string, region: string): string {
113
+ return `${country}\u001E${region}`
114
+ }
115
+
116
+ /**
117
+ * The `region:unknown` count of rows counted per {@linkcode regionValueKey}, under `regions`.
118
+ *
119
+ * It applies the rule's own test, so it equals the count an align under `regions` would write.
120
+ */
121
+ export function countRegionUnknown(
122
+ values: Iterable<readonly [key: string, rows: number]>,
123
+ regions: RegionNames
124
+ ): number {
125
+ let unknown = 0
126
+
127
+ for (const [key, rows] of values) {
128
+ const separator = key.indexOf("\u001E")
129
+
130
+ if (regions.holds(key.slice(0, separator), key.slice(separator + 1)) === false) {
131
+ unknown += rows
132
+ }
133
+ }
134
+
135
+ return unknown
136
+ }
137
+
109
138
  /**
110
139
  * The fewest digits a street's ending needs before it is compared with the row's postcode.
111
140
  */
@@ -132,6 +161,57 @@ export interface ComponentCheckContext {
132
161
  * Without them the rule isn't checked.
133
162
  */
134
163
  regions?: RegionNames | null
164
+ /**
165
+ * Answers already computed for a (country, value) pair, from {@linkcode createComponentCheckMemo}.
166
+ *
167
+ * A source repeats one postcode or region on every row of a place.
168
+ * Each answer reads only the country and the value.
169
+ */
170
+ memo?: ComponentCheckMemo | null
171
+ }
172
+
173
+ /**
174
+ * The postcode and region answers one aligner has computed, keyed by country and value.
175
+ */
176
+ export interface ComponentCheckMemo {
177
+ readonly postcodeRejected: Map<string, boolean>
178
+ readonly regionUnknown: Map<string, boolean>
179
+ }
180
+
181
+ /**
182
+ * Entries the postcode table holds before it starts again empty.
183
+ *
184
+ * NAD writes ZIP+4 forms, millions of distinct values, and an align worker's heap is 1.5 GiB.
185
+ * Regions take a few thousand values per country, so their table needs no bound.
186
+ */
187
+ const POSTCODE_MEMO_ENTRIES = 200_000
188
+
189
+ /**
190
+ * An empty memo for one aligner.
191
+ */
192
+ export function createComponentCheckMemo(): ComponentCheckMemo {
193
+ return { postcodeRejected: new Map(), regionUnknown: new Map() }
194
+ }
195
+
196
+ function memoized(
197
+ table: Map<string, boolean>,
198
+ key: string,
199
+ compute: () => boolean,
200
+ bound = Number.POSITIVE_INFINITY
201
+ ): boolean {
202
+ const known = table.get(key)
203
+
204
+ if (known !== undefined) return known
205
+
206
+ if (table.size >= bound) {
207
+ table.clear()
208
+ }
209
+
210
+ const answer = compute()
211
+
212
+ table.set(key, answer)
213
+
214
+ return answer
135
215
  }
136
216
 
137
217
  /**
@@ -145,7 +225,21 @@ export function componentFindings(
145
225
  const findings: ComponentFinding[] = []
146
226
  const { postcode, street, locality, region } = components
147
227
 
148
- if (postcode && statesPostcodeSyntax(country) && acceptPostcode(postcode, country) == null) {
228
+ const postcodeRejected = (value: string): boolean => {
229
+ const compute = () => statesPostcodeSyntax(country) && acceptPostcode(value, country) == null
230
+
231
+ return context.memo
232
+ ? memoized(context.memo.postcodeRejected, `${country}\u001E${value}`, compute, POSTCODE_MEMO_ENTRIES)
233
+ : compute()
234
+ }
235
+
236
+ const regionUnknown = (value: string): boolean => {
237
+ const compute = () => context.regions?.holds(country, value) === false
238
+
239
+ return context.memo ? memoized(context.memo.regionUnknown, `${country}\u001E${value}`, compute) : compute()
240
+ }
241
+
242
+ if (postcode && postcodeRejected(postcode)) {
149
243
  findings.push({ rule: ComponentRule.PostcodeFormat, values: [postcode] })
150
244
  }
151
245
 
@@ -213,7 +307,7 @@ export function componentFindings(
213
307
  }
214
308
  }
215
309
 
216
- if (region && context.regions?.holds(country, region) === false) {
310
+ if (region && regionUnknown(region)) {
217
311
  findings.push({ rule: ComponentRule.RegionUnknown, values: [region] })
218
312
  }
219
313
 
@@ -59,6 +59,37 @@ export interface BuildInputRecord {
59
59
  * A build reads the index built from the previous corpus version.
60
60
  */
61
61
  streetIndex?: string
62
+ /**
63
+ * The fraction of rows rendered with a country surface, for a country-implicit source.
64
+ */
65
+ countryFraction?: number
66
+ /**
67
+ * The seed of the {@linkcode BuildInputRecord.countryFraction} draw.
68
+ */
69
+ seed?: number
70
+ /**
71
+ * The share of the source's training rows the build keeps (`AdapterOptions.trainShare`).
72
+ */
73
+ trainShare?: number
74
+ }
75
+
76
+ /**
77
+ * One `corpus run` of an adapter under a source name of its own.
78
+ *
79
+ * A build's `adapters` map holds one entry per adapter id and can't state several runs of one adapter.
80
+ * The `overture` runs for BR, MX and CA stamped `overture-latam` are each a run here.
81
+ *
82
+ * Their rows join a corpus as an overlay (`corpus overlay-manifest --replace-source`).
83
+ */
84
+ export interface SourceRunRecord extends BuildInputRecord {
85
+ /**
86
+ * The adapter id `corpus run` resolves.
87
+ */
88
+ adapter: string
89
+ /**
90
+ * The `source` the run stamps on every row (`corpus run --source-name`).
91
+ */
92
+ sourceName: string
62
93
  }
63
94
 
64
95
  /**
@@ -68,6 +99,20 @@ export interface BuildInputsRecord {
68
99
  corpusVersion: string
69
100
  builtAt?: string
70
101
  adapters: Record<string, BuildInputRecord>
102
+ /**
103
+ * The runs whose rows join the corpus as an overlay, run by `corpus recorded-runs`.
104
+ * `corpus build` reads `adapters` only.
105
+ */
106
+ sourceRuns?: SourceRunRecord[]
107
+ }
108
+
109
+ /**
110
+ * One recorded source run with its input resolved, as `corpus recorded-runs` runs it.
111
+ */
112
+ export interface SourceRun {
113
+ adapter: string
114
+ sourceName: string
115
+ options: AdapterOptions
71
116
  }
72
117
 
73
118
  /**
@@ -93,35 +138,81 @@ export async function readBuildInputs(path: PathBuilderLike): Promise<Record<str
93
138
  throw new Error(`${path.toString()} names no adapter under \`adapters\`, so the build would read nothing.`)
94
139
  }
95
140
 
96
- return Object.fromEntries(
97
- entries.map(([id, input]) => {
98
- if (typeof input?.inputPath !== "string" || !input.inputPath) {
99
- throw new Error(`${path.toString()}: adapter ${id} has no \`inputPath\`.`)
100
- }
101
-
102
- const { inputPath, streetIndex, root = BuildInputRoot.data, ...options } = input
103
-
104
- if (root !== BuildInputRoot.cache && root !== BuildInputRoot.data) {
105
- throw new Error(`${path.toString()}: adapter ${id} names root "${String(root)}", not "cache" or "data".`)
106
- }
107
-
108
- const under = (base: (relative: string) => PathBuilderLike, relative: string) =>
109
- isAbsolute(relative) ? relative : base(relative).toString()
110
-
111
- return [
112
- id,
113
- {
114
- ...options,
115
- inputPath: under(
116
- root === BuildInputRoot.cache
117
- ? (relative) => cacheRootPathBuilder(relative)
118
- : (relative) => dataRootPath(relative),
119
- inputPath
120
- ),
121
- // The street index is built from the previous corpus, a built artifact under the data root.
122
- ...(streetIndex ? { streetIndex: under((relative) => dataRootPath(relative), streetIndex) } : {}),
123
- } satisfies AdapterOptions,
124
- ]
125
- })
126
- )
141
+ return Object.fromEntries(entries.map(([id, input]) => [id, resolveBuildInput(path, `adapter ${id}`, input)]))
142
+ }
143
+
144
+ /**
145
+ * One recorded input as {@linkcode AdapterOptions}, its paths resolved against their roots.
146
+ *
147
+ * @throws When the input has no `inputPath`, or its root is neither `cache` nor `data`.
148
+ */
149
+ function resolveBuildInput(path: PathBuilderLike, label: string, input: BuildInputRecord): AdapterOptions {
150
+ if (typeof input?.inputPath !== "string" || !input.inputPath) {
151
+ throw new Error(`${path.toString()}: ${label} has no \`inputPath\`.`)
152
+ }
153
+
154
+ const { inputPath, streetIndex, root = BuildInputRoot.data, ...options } = input
155
+
156
+ if (root !== BuildInputRoot.cache && root !== BuildInputRoot.data) {
157
+ throw new Error(`${path.toString()}: ${label} names root "${String(root)}", not "cache" or "data".`)
158
+ }
159
+
160
+ const under = (base: (relative: string) => PathBuilderLike, relative: string) =>
161
+ isAbsolute(relative) ? relative : base(relative).toString()
162
+
163
+ return {
164
+ ...options,
165
+ inputPath: under(
166
+ root === BuildInputRoot.cache
167
+ ? (relative) => cacheRootPathBuilder(relative)
168
+ : (relative) => dataRootPath(relative),
169
+ inputPath
170
+ ),
171
+ // The street index is built from the previous corpus, a built artifact under the data root.
172
+ ...(streetIndex ? { streetIndex: under((relative) => dataRootPath(relative), streetIndex) } : {}),
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Read a committed record's `sourceRuns`, each input resolved as {@linkcode readBuildInputs} resolves one.
178
+ *
179
+ * @throws When the record lists no source run, a run lacks its adapter or source name,
180
+ * or two runs would write one source and country.
181
+ */
182
+ export async function readSourceRuns(path: PathBuilderLike): Promise<SourceRun[]> {
183
+ const record = await readLocalJSONFile<BuildInputsRecord>(path)
184
+ const runs = record.sourceRuns ?? []
185
+
186
+ if (!runs.length) throw new Error(`${path.toString()} lists no run under \`sourceRuns\`.`)
187
+
188
+ const seen = new Set<string>()
189
+
190
+ return runs.map((run, index) => {
191
+ const label = `source run ${index}`
192
+
193
+ if (typeof run?.adapter !== "string" || !run.adapter)
194
+ throw new Error(`${path.toString()}: ${label} names no adapter.`)
195
+
196
+ if (typeof run.sourceName !== "string" || !run.sourceName) {
197
+ throw new Error(`${path.toString()}: ${label} names no \`sourceName\`.`)
198
+ }
199
+
200
+ const slot = sourceRunDirectoryName(run)
201
+
202
+ if (seen.has(slot)) throw new Error(`${path.toString()}: ${label} repeats ${slot}.`)
203
+
204
+ seen.add(slot)
205
+
206
+ const { adapter, sourceName, ...input } = run
207
+
208
+ return { adapter, sourceName, options: resolveBuildInput(path, label, input) }
209
+ })
210
+ }
211
+
212
+ /**
213
+ * The directory a source run writes under the output root: its source name,
214
+ * and its country when it has one.
215
+ */
216
+ export function sourceRunDirectoryName(run: { sourceName: string; country?: string }): string {
217
+ return run.country ? `${run.sourceName}-${run.country.toLowerCase()}` : run.sourceName
127
218
  }
@@ -116,6 +116,7 @@ export async function writeBuildManifests(inputs: BuildManifestInputs): Promise<
116
116
  refused_by_license_kind: Object.fromEntries(totals.refusedByKind),
117
117
  refused_license_values: Object.fromEntries(refusedValues),
118
118
  refused_rows_by_source: Object.fromEntries(totals.refusedBySource),
119
+ train_rows_left_out_by_source: Object.fromEntries(totals.trainRowsLeftOutBySource),
119
120
  admitted_unresolved_license_rows: totals.admittedUnresolved,
120
121
  profile: inputs.profile,
121
122
  excluded_by_eligibility: totals.excludedByEligibility,
@@ -36,14 +36,21 @@ import type { PathBuilder, PathBuilderLike } from "path-ts"
36
36
  import { TextSpliterator } from "spliterator"
37
37
 
38
38
  import { adapterRunInputs, reusableRun } from "#build/adapters"
39
- import { alignSettings } from "#build/align"
39
+ import { alignSettings, trainSharesOf } from "#build/align"
40
40
  import { planAlignRanges, reusableAlignRange, type AlignRangePlan } from "#build/align/range"
41
41
  import { mergeAlignTotals } from "#build/align/totals"
42
42
  import { WORKER_CLASSES, workerReservationBytes, type WorkerBudget, type WorkerClass } from "#build/budget"
43
43
  import { readSourceDecisionTable } from "#build/eligibility"
44
44
  import { admitParquetManifest, UNCHECKED_PARQUET_MANIFEST_FILE } from "#build/holdout-check"
45
45
  import { writeBuildManifests } from "#build/manifest"
46
- import { adapterDerivations, derivationConfig, type ResolvedBuildSettings } from "#build/settings"
46
+ import { tryReadDefaultRegionNames, type RegionNames } from "#build/region/names"
47
+ import { importPriorSource } from "#build/reuse"
48
+ import {
49
+ adapterDerivations,
50
+ derivationConfig,
51
+ regionCheckFingerprints,
52
+ type ResolvedBuildSettings,
53
+ } from "#build/settings"
47
54
  import {
48
55
  readReusableSource,
49
56
  sourceStateDirectory,
@@ -57,7 +64,7 @@ import { corpusDirectoryName } from "#directory"
57
64
  import { resolveDerivation } from "#parquet/record"
58
65
  import { parquetManifestOf } from "#parquet/writers"
59
66
  import type { SourceRightsAdmission } from "#source-register/corpus-inputs"
60
- import type { CorpusAdapter } from "#types"
67
+ import type { AdapterOptions, CorpusAdapter } from "#types"
61
68
  import { defaultHoldouts, SPLIT_NAMES, writeSplitManifestsFromLabeledFiles, type SplitName } from "#utils/split"
62
69
 
63
70
  /**
@@ -331,6 +338,38 @@ export function alignRangeCount(bytes: number, rangeBytes: number, jobs: number)
331
338
  return Math.min(2 * jobs, Math.max(1, Math.ceil(bytes / rangeBytes)))
332
339
  }
333
340
 
341
+ /**
342
+ * Input rows per adapter partition.
343
+ *
344
+ * NAD's adapter reads about 14,700 rows a second on one core, so a partition
345
+ * of this size runs in about 11 minutes.
346
+ */
347
+ export const PARTITION_ROWS = 10_000_000
348
+
349
+ /**
350
+ * The row ranges a source's adapter run is split into, or `null` to run it in one worker.
351
+ *
352
+ * A source splits when its adapter declares `inputRowCount`, no `limit` caps the run,
353
+ * and its input holds more than one partition's rows.
354
+ * A capped run stops at a count of the rows before it, and a partition can't know that count.
355
+ */
356
+ export async function partitionRanges(
357
+ adapter: CorpusAdapter,
358
+ options: AdapterOptions,
359
+ partitionRows: number
360
+ ): Promise<{ start: number; end: number }[] | null> {
361
+ if (!adapter.inputRowCount || typeof options.limit === "number") return null
362
+
363
+ const rows = await adapter.inputRowCount(options)
364
+
365
+ if (rows <= partitionRows) return null
366
+
367
+ return Array.from({ length: Math.ceil(rows / partitionRows) }, (_, index) => ({
368
+ start: index * partitionRows,
369
+ end: Math.min(rows, (index + 1) * partitionRows),
370
+ }))
371
+ }
372
+
334
373
  /**
335
374
  * Concatenate files in order into `destination`.
336
375
  *
@@ -378,6 +417,7 @@ export async function runParallelBuild(ctx: ParallelBuildContext): Promise<Build
378
417
  licensePolicy: settings.licensePolicy,
379
418
  excludeLicenses: settings.excludeLicenses.map((pattern) => ({ source: pattern.source, flags: pattern.flags })),
380
419
  holdouts,
420
+ trainShares: trainSharesOf(opts.adapterInputs),
381
421
  }
382
422
 
383
423
  const buildSettings: SourceBuildSettings = {
@@ -420,6 +460,11 @@ export async function runParallelBuild(ctx: ParallelBuildContext): Promise<Build
420
460
  `${ctx.adapters.length} sources`
421
461
  )
422
462
 
463
+ // A reused source made under other region data recounts `region:unknown` under these.
464
+ const regionCheck = await regionCheckFingerprints()
465
+ let regionNames: Promise<RegionNames | null> | null = null
466
+ const readRegions = (): Promise<RegionNames | null> => (regionNames ??= tryReadDefaultRegionNames())
467
+
423
468
  const buildSource = async (adapter: CorpusAdapter): Promise<SourceCompletionRecord> => {
424
469
  const source = adapter.id
425
470
  const sourceDir = sourceStateDirectory(intermediateDir, source)
@@ -434,6 +479,8 @@ export async function runParallelBuild(ctx: ParallelBuildContext): Promise<Build
434
479
  const reusable = await readReusableSource(sourceDir, {
435
480
  settings: buildSettings,
436
481
  derivation: await resolveDerivation(await sourceDerivation()),
482
+ regionCheck,
483
+ readRegions,
437
484
  })
438
485
 
439
486
  if (reusable.record) {
@@ -445,6 +492,31 @@ export async function runParallelBuild(ctx: ParallelBuildContext): Promise<Build
445
492
  onProgress("adapter-run", `[${source}] not complete: ${reusable.problem}`)
446
493
  }
447
494
 
495
+ for (const priorOutputDir of opts.reuseFrom ?? []) {
496
+ const imported = await importPriorSource({
497
+ source,
498
+ priorOutputDir,
499
+ outputDir,
500
+ expected: {
501
+ settings: buildSettings,
502
+ derivation: await resolveDerivation(await sourceDerivation()),
503
+ regionCheck,
504
+ readRegions,
505
+ },
506
+ })
507
+
508
+ if (imported.record) {
509
+ onProgress(
510
+ "adapter-run",
511
+ `[${source}] cloned the complete source from ${priorOutputDir.toString()} (${imported.record.parts.length} parts)`
512
+ )
513
+
514
+ return imported.record
515
+ }
516
+
517
+ onProgress("adapter-run", `[${source}] not reusable from ${priorOutputDir.toString()}: ${imported.problem}`)
518
+ }
519
+
448
520
  const inputStat = await tryStat(options.inputPath)
449
521
  // A directory input's size doesn't predict its rows, so it is ranked first and starts early.
450
522
  const inputWeight = inputStat?.isFile() ? inputStat.size : Number.MAX_SAFE_INTEGER
@@ -460,22 +532,67 @@ export async function runParallelBuild(ctx: ParallelBuildContext): Promise<Build
460
532
  } else {
461
533
  const { signal: _signal, dropped: _dropped, ...serializable } = options
462
534
 
463
- await pool.run(
464
- {
465
- kind: "adapter",
466
- id: `${source}/adapter`,
467
- source,
468
- resources: WORKER_CLASSES.standard,
469
- temporaryRoot: temporaryRoot("adapter"),
470
- adapterModule: derivationFor.modules.get(source)!,
471
- adapterOptions: { ...serializable, inputPath: options.inputPath.toString() },
472
- corpusVersion: opts.corpusVersion,
473
- inputs,
474
- intermediateDir: intermediateDir.toString(),
475
- },
476
- "standard",
477
- inputWeight
478
- )
535
+ const adapterTask = {
536
+ kind: "adapter" as const,
537
+ source,
538
+ adapterModule: derivationFor.modules.get(source)!,
539
+ adapterOptions: { ...serializable, inputPath: options.inputPath.toString() },
540
+ corpusVersion: opts.corpusVersion,
541
+ inputs,
542
+ intermediateDir: intermediateDir.toString(),
543
+ }
544
+
545
+ const ranges = await partitionRanges(adapter, options, opts.partitionRows ?? PARTITION_ROWS)
546
+
547
+ if (ranges) {
548
+ const partitionDir = adapterDir("partitions")
549
+
550
+ await removePathIfPresent(partitionDir)
551
+ await makeDirectories(partitionDir)
552
+
553
+ const records = await Promise.all(
554
+ ranges.map(async (rowRange, index) => {
555
+ const recordPath = partitionDir(`part-${index}.json`).toString()
556
+
557
+ await pool.run(
558
+ {
559
+ ...adapterTask,
560
+ id: `${source}/adapter-${index + 1}-of-${ranges.length}`,
561
+ resources: WORKER_CLASSES.partition,
562
+ temporaryRoot: temporaryRoot(`adapter-${index}`),
563
+ partition: { rowRange, outputPath: partitionDir(`part-${index}.tsv`).toString(), recordPath },
564
+ },
565
+ "partition",
566
+ inputWeight
567
+ )
568
+
569
+ return recordPath
570
+ })
571
+ )
572
+
573
+ await pool.run(
574
+ {
575
+ ...adapterTask,
576
+ id: `${source}/adapter-merge`,
577
+ resources: WORKER_CLASSES.adapter,
578
+ temporaryRoot: temporaryRoot("adapter"),
579
+ mergeRecords: records,
580
+ },
581
+ "adapter",
582
+ inputWeight
583
+ )
584
+ } else {
585
+ await pool.run(
586
+ {
587
+ ...adapterTask,
588
+ id: `${source}/adapter`,
589
+ resources: WORKER_CLASSES.adapter,
590
+ temporaryRoot: temporaryRoot("adapter"),
591
+ },
592
+ "adapter",
593
+ inputWeight
594
+ )
595
+ }
479
596
 
480
597
  run = await readLocalJSONFile(adapterDir("MANIFEST.json"))
481
598
  }
@@ -497,14 +614,14 @@ export async function runParallelBuild(ctx: ParallelBuildContext): Promise<Build
497
614
  kind: "align",
498
615
  id: `${source}/align-${plan.index + 1}-of-${plan.count}`,
499
616
  source,
500
- resources: WORKER_CLASSES.standard,
617
+ resources: WORKER_CLASSES.align,
501
618
  temporaryRoot: temporaryRoot(`align-${plan.index}`),
502
619
  canonicalPath,
503
620
  plan,
504
621
  sourceDir: sourceDir.toString(),
505
622
  settings: taskSettings,
506
623
  },
507
- "standard",
624
+ "align",
508
625
  weight
509
626
  )
510
627
  })
@@ -515,7 +632,7 @@ export async function runParallelBuild(ctx: ParallelBuildContext): Promise<Build
515
632
  kind: "finish",
516
633
  id: `${source}/finish`,
517
634
  source,
518
- resources: WORKER_CLASSES.standard,
635
+ resources: WORKER_CLASSES.finish,
519
636
  temporaryRoot: temporaryRoot("finish"),
520
637
  sourceDir: sourceDir.toString(),
521
638
  outputDir: outputDir.toString(),
@@ -526,7 +643,7 @@ export async function runParallelBuild(ctx: ParallelBuildContext): Promise<Build
526
643
  derivation: await sourceDerivation(),
527
644
  resume: settings.resume,
528
645
  },
529
- "standard",
646
+ "finish",
530
647
  weight
531
648
  )
532
649
 
@@ -598,12 +598,24 @@ async function readSecondLevelRegionCountries(): Promise<string[]> {
598
598
  * @throws When the database is on this host and the GeoNames first-level file isn't.
599
599
  */
600
600
  export async function tryReadDefaultRegionNames(): Promise<RegionNames | null> {
601
- const path = wofDatabasePath("admin-global-priority.db")
601
+ const inputs = defaultRegionNameInputs()
602
602
 
603
- if (!(await pathExists(path))) return null
603
+ if (!(await pathExists(inputs.database))) return null
604
604
 
605
- return readRegionNames(path, {
605
+ return readRegionNames(inputs.database, {
606
606
  secondLevelCountries: await readSecondLevelRegionCountries(),
607
- geonamesDirectory: dataRootPath("geonames"),
607
+ geonamesDirectory: inputs.geonamesDirectory,
608
608
  })
609
609
  }
610
+
611
+ /**
612
+ * The files {@linkcode tryReadDefaultRegionNames} reads, so a build can
613
+ * fingerprint what its align phase read.
614
+ */
615
+ export function defaultRegionNameInputs(): { database: string; geonamesDirectory: string; secondLevelTable: string } {
616
+ return {
617
+ database: wofDatabasePath("admin-global-priority.db").toString(),
618
+ geonamesDirectory: dataRootPath("geonames").toString(),
619
+ secondLevelTable: SECOND_LEVEL_REGION_TABLE_PATH.toString(),
620
+ }
621
+ }