@mailwoman/corpus 11.1.0 → 11.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (474) hide show
  1. package/README.md +20 -14
  2. package/data/address-source-register.json +618 -13
  3. package/data/builds/v0.8.19-overlay/OVERLAY_PLAN.json +4778 -0
  4. package/data/builds/v0.8.19-rebuild/inputs.json +128 -0
  5. package/data/builds/v0.8.20-overlay/OVERLAY_PLAN.json +3595 -0
  6. package/data/builds/v0.8.20-rebuild/inputs.json +131 -0
  7. package/data/builds/v0.8.21-overlay/OVERLAY_PLAN.json +72 -0
  8. package/data/corpus-source-inputs.json +104 -2
  9. package/data/holdout/evaluation-groups.v0.8.18.json +90511 -0
  10. package/data/holdout/evaluation-groups.v0.8.19.json +100537 -0
  11. package/data/holdout/evaluation-groups.v0.8.20.json +129215 -0
  12. package/data/holdout/evaluation-groups.v0.8.21.json +173286 -0
  13. package/data/holdout/probe-text-collisions.v0.8.20.json +1478 -0
  14. package/data/license-decisions.json +393 -3
  15. package/data/licenses/PROVENANCE.md +15 -9
  16. package/data/licenses/au-acnc-cc-by-3.0-au.md +37 -0
  17. package/data/licenses/es-sanidad-aviso-legal.md +26 -0
  18. package/data/licenses/it-miur-iodl-2.0.md +41 -0
  19. package/data/licenses/nz-charities-cc-by-3.0-nz.md +36 -0
  20. package/data/region-slot-second-level.json +966 -0
  21. package/data/source-additions.json +126 -6
  22. package/data/source-resolutions.json +97 -0
  23. package/data/training-configs/v8.7.0-base-c6-90k-usgs-structures-s42.yaml +801 -0
  24. package/data/training-configs/v8.7.0-base-c6-90k-usgs-structures-s43.yaml +726 -0
  25. package/data/training-configs/v8.8.0-base-c6-90k-v0820-county-s42.yaml +944 -0
  26. package/data/training-configs/v8.9.0-base-c6-90k-v0821-s42.yaml +848 -0
  27. package/data/training-manifests/v0.8.19-retention-overlay.json +4553 -0
  28. package/data/training-manifests/v0.8.20-retention-overlay.json +4579 -0
  29. package/data/training-manifests/v0.8.21-retention-overlay.effective.json +2521 -0
  30. package/data/training-manifests/v0.8.21-retention-overlay.json +4579 -0
  31. package/lib/adapters/cordis/adapter.ts +10 -2
  32. package/lib/adapters/gleif/adapter.ts +23 -5
  33. package/lib/adapters/osm/adapter.ts +2 -2
  34. package/lib/adapters/street/repetition.ts +87 -0
  35. package/lib/adapters/street/unit.ts +14 -0
  36. package/lib/adapters/wof/admin/json/adapter.ts +34 -21
  37. package/lib/adapters/wof/admin/json/dual-role.ts +274 -0
  38. package/lib/adapters/wof/admin/json/explore.ts +4 -4
  39. package/lib/adapters/wof/admin/json/region-codes.ts +74 -3
  40. package/lib/adapters/wof/json-rows.ts +36 -21
  41. package/lib/adapters/wof/postalcode-json/adapter.ts +10 -28
  42. package/lib/adapters/wof/sample.ts +15 -3
  43. package/lib/adapters/wof/stored-records.ts +162 -0
  44. package/lib/adapters.ts +18 -6
  45. package/lib/au/adapters/acnc-register/adapter.ts +40 -0
  46. package/lib/au/evaluation/acnc-register.ts +144 -0
  47. package/lib/build/align/range.ts +9 -0
  48. package/lib/build/align/totals.ts +23 -0
  49. package/lib/build/align.ts +74 -4
  50. package/lib/build/budget.ts +11 -45
  51. package/lib/build/checkpoint.ts +11 -0
  52. package/lib/build/component-check.ts +99 -3
  53. package/lib/build/manifest.ts +4 -0
  54. package/lib/build/parallel.ts +8 -34
  55. package/lib/build/region-names.ts +609 -0
  56. package/lib/build/source-record.ts +7 -0
  57. package/lib/build/types.ts +20 -0
  58. package/lib/build/worker.ts +3 -1
  59. package/lib/build.ts +3 -6
  60. package/lib/de/recipes/locale.ts +3 -2
  61. package/lib/env.ts +0 -6
  62. package/lib/es/adapters/sanidad-centros-ap/adapter.ts +40 -0
  63. package/lib/es/evaluation/sanidad-centros-ap.ts +164 -0
  64. package/lib/evaluation/corpus-adapter.ts +153 -0
  65. package/lib/evaluation/source.ts +209 -0
  66. package/lib/evaluation/sources.ts +25 -0
  67. package/lib/fr/adapters/laposte-poincont/adapter.ts +381 -0
  68. package/lib/fr/recipes/unit-line-guideline.ts +9 -4
  69. package/lib/fr/structures/laposte.ts +139 -0
  70. package/lib/fr/tools/fetch/laposte-poincont.ts +234 -0
  71. package/lib/it/adapters/miur-scuole/adapter.ts +39 -0
  72. package/lib/it/evaluation/miur-scuole.ts +125 -0
  73. package/lib/jp/adapters/wof-admin/adapter.ts +4 -4
  74. package/lib/nc/adapters/opt-nc/adapter.ts +237 -0
  75. package/lib/nc/structures/opt-nc.ts +101 -0
  76. package/lib/nc/tools/fetch/opt-nc.ts +249 -0
  77. package/lib/nz/adapters/charities-register/adapter.ts +40 -0
  78. package/lib/nz/evaluation/charities-register.ts +149 -0
  79. package/lib/recipes/bare/postcode.ts +14 -11
  80. package/lib/recipes/deepseek/batches.ts +8 -8
  81. package/lib/recipes/po/box/cedex/recipe.ts +12 -1
  82. package/lib/recipes/po/box/cedex/us.ts +43 -2
  83. package/lib/recipes/scaffold.ts +1 -1
  84. package/lib/recipes/sources.ts +16 -0
  85. package/lib/recipes.ts +2 -0
  86. package/lib/registers.ts +28 -2
  87. package/lib/{post-offices → structures}/source.ts +49 -16
  88. package/lib/structures/sources.ts +26 -0
  89. package/lib/synthesizers/house-venue.ts +11 -6
  90. package/lib/synthesizers/tail.ts +27 -3
  91. package/lib/tools/audit.ts +1 -1
  92. package/lib/tools/fetch/storage.ts +18 -4
  93. package/lib/tools/fetch.ts +10 -2
  94. package/lib/tools/overlay/kryptonite.ts +6 -2
  95. package/lib/tools/overlay/split/attribute.ts +14 -2
  96. package/lib/tools/overlay/split/overlay.ts +36 -7
  97. package/lib/tools/postcode/triples.ts +3 -3
  98. package/lib/tools/region-slot-census.run.ts +184 -0
  99. package/lib/training/config/load.ts +19 -0
  100. package/lib/training/config/schema.ts +6 -0
  101. package/lib/tw/registers.ts +15 -4
  102. package/lib/tw/structures/chunghwa-post.ts +191 -0
  103. package/lib/tw/tools/fetch/chunghwa-post.ts +174 -0
  104. package/lib/us/adapters/state/ny-notaries/adapter.ts +7 -2
  105. package/lib/us/adapters/state/tx-notaries/adapter.ts +126 -21
  106. package/lib/us/adapters/usgov/nad/adapter.ts +111 -31
  107. package/lib/us/adapters/usgov/nppes/adapter.ts +8 -11
  108. package/lib/us/adapters/usgov/{usgs-post-offices → usgs-structures}/adapter.ts +65 -35
  109. package/lib/us/recipes/county.ts +474 -0
  110. package/lib/us/street-unit.ts +15 -5
  111. package/lib/us/structures/usgs/layers.ts +171 -0
  112. package/lib/us/structures/usgs/national-map.ts +95 -0
  113. package/lib/us/tools/fetch/usgs/gnis.ts +288 -0
  114. package/lib/us/tools/fetch/usgs/structures.ts +362 -0
  115. package/lib/utils/align.ts +2 -2
  116. package/lib/utils/evaluation-groups.ts +172 -0
  117. package/lib/utils/split.ts +40 -4
  118. package/lib/utils/tokenize.ts +7 -7
  119. package/lib/utils/validation-groups.ts +292 -0
  120. package/lib/utils/wof-json.ts +96 -134
  121. package/out/adapters/cordis/adapter.d.ts +3 -1
  122. package/out/adapters/cordis/adapter.d.ts.map +1 -1
  123. package/out/adapters/cordis/adapter.js +8 -2
  124. package/out/adapters/cordis/adapter.js.map +1 -1
  125. package/out/adapters/gleif/adapter.d.ts.map +1 -1
  126. package/out/adapters/gleif/adapter.js +19 -5
  127. package/out/adapters/gleif/adapter.js.map +1 -1
  128. package/out/adapters/osm/adapter.js +2 -2
  129. package/out/adapters/osm/adapter.js.map +1 -1
  130. package/out/adapters/street/repetition.d.ts +19 -0
  131. package/out/adapters/street/repetition.d.ts.map +1 -0
  132. package/out/adapters/street/repetition.js +71 -0
  133. package/out/adapters/street/repetition.js.map +1 -0
  134. package/out/adapters/street/unit.d.ts +10 -0
  135. package/out/adapters/street/unit.d.ts.map +1 -1
  136. package/out/adapters/street/unit.js +6 -0
  137. package/out/adapters/street/unit.js.map +1 -1
  138. package/out/adapters/wof/admin/json/adapter.d.ts +8 -0
  139. package/out/adapters/wof/admin/json/adapter.d.ts.map +1 -1
  140. package/out/adapters/wof/admin/json/adapter.js +26 -22
  141. package/out/adapters/wof/admin/json/adapter.js.map +1 -1
  142. package/out/adapters/wof/admin/json/dual-role.d.ts +83 -0
  143. package/out/adapters/wof/admin/json/dual-role.d.ts.map +1 -0
  144. package/out/adapters/wof/admin/json/dual-role.js +183 -0
  145. package/out/adapters/wof/admin/json/dual-role.js.map +1 -0
  146. package/out/adapters/wof/admin/json/explore.d.ts.map +1 -1
  147. package/out/adapters/wof/admin/json/explore.js +4 -4
  148. package/out/adapters/wof/admin/json/explore.js.map +1 -1
  149. package/out/adapters/wof/admin/json/region-codes.d.ts +16 -0
  150. package/out/adapters/wof/admin/json/region-codes.d.ts.map +1 -1
  151. package/out/adapters/wof/admin/json/region-codes.js +62 -3
  152. package/out/adapters/wof/admin/json/region-codes.js.map +1 -1
  153. package/out/adapters/wof/json-rows.d.ts +28 -6
  154. package/out/adapters/wof/json-rows.d.ts.map +1 -1
  155. package/out/adapters/wof/json-rows.js +9 -15
  156. package/out/adapters/wof/json-rows.js.map +1 -1
  157. package/out/adapters/wof/postalcode-json/adapter.d.ts +1 -1
  158. package/out/adapters/wof/postalcode-json/adapter.d.ts.map +1 -1
  159. package/out/adapters/wof/postalcode-json/adapter.js +9 -26
  160. package/out/adapters/wof/postalcode-json/adapter.js.map +1 -1
  161. package/out/adapters/wof/sample.d.ts +8 -1
  162. package/out/adapters/wof/sample.d.ts.map +1 -1
  163. package/out/adapters/wof/sample.js +12 -4
  164. package/out/adapters/wof/sample.js.map +1 -1
  165. package/out/adapters/wof/stored-records.d.ts +62 -0
  166. package/out/adapters/wof/stored-records.d.ts.map +1 -0
  167. package/out/adapters/wof/stored-records.js +91 -0
  168. package/out/adapters/wof/stored-records.js.map +1 -0
  169. package/out/adapters.d.ts +1 -1
  170. package/out/adapters.d.ts.map +1 -1
  171. package/out/adapters.js +15 -3
  172. package/out/adapters.js.map +1 -1
  173. package/out/au/adapters/acnc-register/adapter.d.ts +9 -0
  174. package/out/au/adapters/acnc-register/adapter.d.ts.map +1 -0
  175. package/out/au/adapters/acnc-register/adapter.js +37 -0
  176. package/out/au/adapters/acnc-register/adapter.js.map +1 -0
  177. package/out/au/evaluation/acnc-register.d.ts +56 -0
  178. package/out/au/evaluation/acnc-register.d.ts.map +1 -0
  179. package/out/au/evaluation/acnc-register.js +84 -0
  180. package/out/au/evaluation/acnc-register.js.map +1 -0
  181. package/out/build/align/range.d.ts.map +1 -1
  182. package/out/build/align/range.js +9 -0
  183. package/out/build/align/range.js.map +1 -1
  184. package/out/build/align/totals.d.ts +5 -0
  185. package/out/build/align/totals.d.ts.map +1 -1
  186. package/out/build/align/totals.js +15 -0
  187. package/out/build/align/totals.js.map +1 -1
  188. package/out/build/align.d.ts +26 -0
  189. package/out/build/align.d.ts.map +1 -1
  190. package/out/build/align.js +35 -2
  191. package/out/build/align.js.map +1 -1
  192. package/out/build/budget.d.ts +9 -26
  193. package/out/build/budget.d.ts.map +1 -1
  194. package/out/build/budget.js +10 -31
  195. package/out/build/budget.js.map +1 -1
  196. package/out/build/checkpoint.d.ts +11 -0
  197. package/out/build/checkpoint.d.ts.map +1 -1
  198. package/out/build/checkpoint.js.map +1 -1
  199. package/out/build/component-check.d.ts +55 -1
  200. package/out/build/component-check.d.ts.map +1 -1
  201. package/out/build/component-check.js +65 -3
  202. package/out/build/component-check.js.map +1 -1
  203. package/out/build/manifest.d.ts.map +1 -1
  204. package/out/build/manifest.js +4 -0
  205. package/out/build/manifest.js.map +1 -1
  206. package/out/build/parallel.d.ts.map +1 -1
  207. package/out/build/parallel.js +8 -24
  208. package/out/build/parallel.js.map +1 -1
  209. package/out/build/region-names.d.ts +120 -0
  210. package/out/build/region-names.d.ts.map +1 -0
  211. package/out/build/region-names.js +430 -0
  212. package/out/build/region-names.js.map +1 -0
  213. package/out/build/source-record.d.ts.map +1 -1
  214. package/out/build/source-record.js +4 -0
  215. package/out/build/source-record.js.map +1 -1
  216. package/out/build/types.d.ts +20 -0
  217. package/out/build/types.d.ts.map +1 -1
  218. package/out/build/worker.js +3 -1
  219. package/out/build/worker.js.map +1 -1
  220. package/out/build.d.ts +0 -1
  221. package/out/build.d.ts.map +1 -1
  222. package/out/build.js +3 -5
  223. package/out/build.js.map +1 -1
  224. package/out/de/recipes/locale.d.ts.map +1 -1
  225. package/out/de/recipes/locale.js +3 -2
  226. package/out/de/recipes/locale.js.map +1 -1
  227. package/out/env.d.ts +0 -2
  228. package/out/env.d.ts.map +1 -1
  229. package/out/env.js +0 -5
  230. package/out/env.js.map +1 -1
  231. package/out/es/adapters/sanidad-centros-ap/adapter.d.ts +9 -0
  232. package/out/es/adapters/sanidad-centros-ap/adapter.d.ts.map +1 -0
  233. package/out/es/adapters/sanidad-centros-ap/adapter.js +36 -0
  234. package/out/es/adapters/sanidad-centros-ap/adapter.js.map +1 -0
  235. package/out/es/evaluation/sanidad-centros-ap.d.ts +34 -0
  236. package/out/es/evaluation/sanidad-centros-ap.d.ts.map +1 -0
  237. package/out/es/evaluation/sanidad-centros-ap.js +128 -0
  238. package/out/es/evaluation/sanidad-centros-ap.js.map +1 -0
  239. package/out/evaluation/corpus-adapter.d.ts +60 -0
  240. package/out/evaluation/corpus-adapter.d.ts.map +1 -0
  241. package/out/evaluation/corpus-adapter.js +100 -0
  242. package/out/evaluation/corpus-adapter.js.map +1 -0
  243. package/out/evaluation/source.d.ts +134 -0
  244. package/out/evaluation/source.d.ts.map +1 -0
  245. package/out/evaluation/source.js +80 -0
  246. package/out/evaluation/source.js.map +1 -0
  247. package/out/evaluation/sources.d.ts +6 -0
  248. package/out/evaluation/sources.d.ts.map +1 -0
  249. package/out/evaluation/sources.js +22 -0
  250. package/out/evaluation/sources.js.map +1 -0
  251. package/out/fr/adapters/laposte-poincont/adapter.d.ts +110 -0
  252. package/out/fr/adapters/laposte-poincont/adapter.d.ts.map +1 -0
  253. package/out/fr/adapters/laposte-poincont/adapter.js +315 -0
  254. package/out/fr/adapters/laposte-poincont/adapter.js.map +1 -0
  255. package/out/fr/recipes/unit-line-guideline.d.ts.map +1 -1
  256. package/out/fr/recipes/unit-line-guideline.js +8 -4
  257. package/out/fr/recipes/unit-line-guideline.js.map +1 -1
  258. package/out/fr/structures/laposte.d.ts +27 -0
  259. package/out/fr/structures/laposte.d.ts.map +1 -0
  260. package/out/fr/structures/laposte.js +96 -0
  261. package/out/fr/structures/laposte.js.map +1 -0
  262. package/out/fr/tools/fetch/laposte-poincont.d.ts +95 -0
  263. package/out/fr/tools/fetch/laposte-poincont.d.ts.map +1 -0
  264. package/out/fr/tools/fetch/laposte-poincont.js +135 -0
  265. package/out/fr/tools/fetch/laposte-poincont.js.map +1 -0
  266. package/out/it/adapters/miur-scuole/adapter.d.ts +9 -0
  267. package/out/it/adapters/miur-scuole/adapter.d.ts.map +1 -0
  268. package/out/it/adapters/miur-scuole/adapter.js +35 -0
  269. package/out/it/adapters/miur-scuole/adapter.js.map +1 -0
  270. package/out/it/evaluation/miur-scuole.d.ts +53 -0
  271. package/out/it/evaluation/miur-scuole.d.ts.map +1 -0
  272. package/out/it/evaluation/miur-scuole.js +68 -0
  273. package/out/it/evaluation/miur-scuole.js.map +1 -0
  274. package/out/jp/adapters/wof-admin/adapter.js +4 -4
  275. package/out/nc/adapters/opt-nc/adapter.d.ts +84 -0
  276. package/out/nc/adapters/opt-nc/adapter.d.ts.map +1 -0
  277. package/out/nc/adapters/opt-nc/adapter.js +173 -0
  278. package/out/nc/adapters/opt-nc/adapter.js.map +1 -0
  279. package/out/nc/structures/opt-nc.d.ts +12 -0
  280. package/out/nc/structures/opt-nc.d.ts.map +1 -0
  281. package/out/nc/structures/opt-nc.js +64 -0
  282. package/out/nc/structures/opt-nc.js.map +1 -0
  283. package/out/nc/tools/fetch/opt-nc.d.ts +81 -0
  284. package/out/nc/tools/fetch/opt-nc.d.ts.map +1 -0
  285. package/out/nc/tools/fetch/opt-nc.js +162 -0
  286. package/out/nc/tools/fetch/opt-nc.js.map +1 -0
  287. package/out/nz/adapters/charities-register/adapter.d.ts +9 -0
  288. package/out/nz/adapters/charities-register/adapter.d.ts.map +1 -0
  289. package/out/nz/adapters/charities-register/adapter.js +36 -0
  290. package/out/nz/adapters/charities-register/adapter.js.map +1 -0
  291. package/out/nz/evaluation/charities-register.d.ts +60 -0
  292. package/out/nz/evaluation/charities-register.d.ts.map +1 -0
  293. package/out/nz/evaluation/charities-register.js +84 -0
  294. package/out/nz/evaluation/charities-register.js.map +1 -0
  295. package/out/recipes/bare/postcode.d.ts +2 -1
  296. package/out/recipes/bare/postcode.d.ts.map +1 -1
  297. package/out/recipes/bare/postcode.js +14 -11
  298. package/out/recipes/bare/postcode.js.map +1 -1
  299. package/out/recipes/deepseek/batches.d.ts +11 -1
  300. package/out/recipes/deepseek/batches.d.ts.map +1 -1
  301. package/out/recipes/deepseek/batches.js +8 -7
  302. package/out/recipes/deepseek/batches.js.map +1 -1
  303. package/out/recipes/po/box/cedex/recipe.d.ts.map +1 -1
  304. package/out/recipes/po/box/cedex/recipe.js +12 -1
  305. package/out/recipes/po/box/cedex/recipe.js.map +1 -1
  306. package/out/recipes/po/box/cedex/us.d.ts +12 -0
  307. package/out/recipes/po/box/cedex/us.d.ts.map +1 -1
  308. package/out/recipes/po/box/cedex/us.js +36 -2
  309. package/out/recipes/po/box/cedex/us.js.map +1 -1
  310. package/out/recipes/scaffold.d.ts +1 -1
  311. package/out/recipes/sources.d.ts.map +1 -1
  312. package/out/recipes/sources.js +16 -0
  313. package/out/recipes/sources.js.map +1 -1
  314. package/out/recipes.d.ts.map +1 -1
  315. package/out/recipes.js +2 -0
  316. package/out/recipes.js.map +1 -1
  317. package/out/registers.d.ts +28 -2
  318. package/out/registers.d.ts.map +1 -1
  319. package/out/registers.js +28 -2
  320. package/out/registers.js.map +1 -1
  321. package/out/{post-offices → structures}/source.d.ts +34 -16
  322. package/out/structures/source.d.ts.map +1 -0
  323. package/out/structures/source.js +39 -0
  324. package/out/structures/source.js.map +1 -0
  325. package/out/structures/sources.d.ts +6 -0
  326. package/out/structures/sources.d.ts.map +1 -0
  327. package/out/structures/sources.js +23 -0
  328. package/out/structures/sources.js.map +1 -0
  329. package/out/synthesizers/house-venue.d.ts.map +1 -1
  330. package/out/synthesizers/house-venue.js +2 -1
  331. package/out/synthesizers/house-venue.js.map +1 -1
  332. package/out/synthesizers/tail.d.ts +15 -1
  333. package/out/synthesizers/tail.d.ts.map +1 -1
  334. package/out/synthesizers/tail.js +8 -3
  335. package/out/synthesizers/tail.js.map +1 -1
  336. package/out/tools/audit.js +1 -1
  337. package/out/tools/audit.js.map +1 -1
  338. package/out/tools/fetch/storage.d.ts +10 -2
  339. package/out/tools/fetch/storage.d.ts.map +1 -1
  340. package/out/tools/fetch/storage.js +18 -4
  341. package/out/tools/fetch/storage.js.map +1 -1
  342. package/out/tools/fetch.d.ts +10 -2
  343. package/out/tools/fetch.d.ts.map +1 -1
  344. package/out/tools/fetch.js +10 -2
  345. package/out/tools/fetch.js.map +1 -1
  346. package/out/tools/overlay/kryptonite.d.ts.map +1 -1
  347. package/out/tools/overlay/kryptonite.js +5 -2
  348. package/out/tools/overlay/kryptonite.js.map +1 -1
  349. package/out/tools/overlay/split/attribute.d.ts +7 -1
  350. package/out/tools/overlay/split/attribute.d.ts.map +1 -1
  351. package/out/tools/overlay/split/attribute.js +4 -1
  352. package/out/tools/overlay/split/attribute.js.map +1 -1
  353. package/out/tools/overlay/split/overlay.d.ts +10 -0
  354. package/out/tools/overlay/split/overlay.d.ts.map +1 -1
  355. package/out/tools/overlay/split/overlay.js +17 -4
  356. package/out/tools/overlay/split/overlay.js.map +1 -1
  357. package/out/tools/postcode/triples.js +3 -3
  358. package/out/tools/postcode/triples.js.map +1 -1
  359. package/out/tools/region-slot-census.run.d.ts +2 -0
  360. package/out/tools/region-slot-census.run.d.ts.map +1 -0
  361. package/out/tools/region-slot-census.run.js +134 -0
  362. package/out/tools/region-slot-census.run.js.map +1 -0
  363. package/out/training/config/load.d.ts.map +1 -1
  364. package/out/training/config/load.js +10 -0
  365. package/out/training/config/load.js.map +1 -1
  366. package/out/training/config/schema.d.ts +13 -0
  367. package/out/training/config/schema.d.ts.map +1 -1
  368. package/out/training/config/schema.js +6 -0
  369. package/out/training/config/schema.js.map +1 -1
  370. package/out/tw/registers.d.ts +9 -0
  371. package/out/tw/registers.d.ts.map +1 -1
  372. package/out/tw/registers.js +11 -4
  373. package/out/tw/registers.js.map +1 -1
  374. package/out/tw/structures/chunghwa-post.d.ts +39 -0
  375. package/out/tw/structures/chunghwa-post.d.ts.map +1 -0
  376. package/out/tw/structures/chunghwa-post.js +150 -0
  377. package/out/tw/structures/chunghwa-post.js.map +1 -0
  378. package/out/tw/tools/fetch/chunghwa-post.d.ts +55 -0
  379. package/out/tw/tools/fetch/chunghwa-post.d.ts.map +1 -0
  380. package/out/tw/tools/fetch/chunghwa-post.js +110 -0
  381. package/out/tw/tools/fetch/chunghwa-post.js.map +1 -0
  382. package/out/us/adapters/state/ny-notaries/adapter.d.ts.map +1 -1
  383. package/out/us/adapters/state/ny-notaries/adapter.js +7 -2
  384. package/out/us/adapters/state/ny-notaries/adapter.js.map +1 -1
  385. package/out/us/adapters/state/tx-notaries/adapter.d.ts +42 -0
  386. package/out/us/adapters/state/tx-notaries/adapter.d.ts.map +1 -1
  387. package/out/us/adapters/state/tx-notaries/adapter.js +92 -19
  388. package/out/us/adapters/state/tx-notaries/adapter.js.map +1 -1
  389. package/out/us/adapters/usgov/nad/adapter.d.ts +35 -2
  390. package/out/us/adapters/usgov/nad/adapter.d.ts.map +1 -1
  391. package/out/us/adapters/usgov/nad/adapter.js +90 -27
  392. package/out/us/adapters/usgov/nad/adapter.js.map +1 -1
  393. package/out/us/adapters/usgov/nppes/adapter.d.ts.map +1 -1
  394. package/out/us/adapters/usgov/nppes/adapter.js +8 -11
  395. package/out/us/adapters/usgov/nppes/adapter.js.map +1 -1
  396. package/out/us/adapters/usgov/usgs-structures/adapter.d.ts +87 -0
  397. package/out/us/adapters/usgov/usgs-structures/adapter.d.ts.map +1 -0
  398. package/out/us/adapters/usgov/{usgs-post-offices → usgs-structures}/adapter.js +36 -27
  399. package/out/us/adapters/usgov/usgs-structures/adapter.js.map +1 -0
  400. package/out/us/recipes/county.d.ts +124 -0
  401. package/out/us/recipes/county.d.ts.map +1 -0
  402. package/out/us/recipes/county.js +295 -0
  403. package/out/us/recipes/county.js.map +1 -0
  404. package/out/us/street-unit.d.ts +10 -3
  405. package/out/us/street-unit.d.ts.map +1 -1
  406. package/out/us/street-unit.js +14 -6
  407. package/out/us/street-unit.js.map +1 -1
  408. package/out/us/structures/usgs/layers.d.ts +57 -0
  409. package/out/us/structures/usgs/layers.d.ts.map +1 -0
  410. package/out/us/structures/usgs/layers.js +121 -0
  411. package/out/us/structures/usgs/layers.js.map +1 -0
  412. package/out/us/structures/usgs/national-map.d.ts +14 -0
  413. package/out/us/structures/usgs/national-map.d.ts.map +1 -0
  414. package/out/us/{post-offices/usgs-national-map.js → structures/usgs/national-map.js} +16 -14
  415. package/out/us/structures/usgs/national-map.js.map +1 -0
  416. package/out/us/tools/fetch/usgs/gnis.d.ts +118 -0
  417. package/out/us/tools/fetch/usgs/gnis.d.ts.map +1 -0
  418. package/out/us/tools/fetch/usgs/gnis.js +177 -0
  419. package/out/us/tools/fetch/usgs/gnis.js.map +1 -0
  420. package/out/us/tools/fetch/usgs/structures.d.ts +99 -0
  421. package/out/us/tools/fetch/usgs/structures.d.ts.map +1 -0
  422. package/out/us/tools/fetch/usgs/structures.js +233 -0
  423. package/out/us/tools/fetch/usgs/structures.js.map +1 -0
  424. package/out/utils/align.js.map +1 -1
  425. package/out/utils/evaluation-groups.d.ts +98 -0
  426. package/out/utils/evaluation-groups.d.ts.map +1 -0
  427. package/out/utils/evaluation-groups.js +92 -0
  428. package/out/utils/evaluation-groups.js.map +1 -0
  429. package/out/utils/split.d.ts +26 -1
  430. package/out/utils/split.d.ts.map +1 -1
  431. package/out/utils/split.js +28 -3
  432. package/out/utils/split.js.map +1 -1
  433. package/out/utils/tokenize.d.ts +3 -3
  434. package/out/utils/tokenize.d.ts.map +1 -1
  435. package/out/utils/tokenize.js.map +1 -1
  436. package/out/utils/validation-groups.d.ts +168 -0
  437. package/out/utils/validation-groups.d.ts.map +1 -0
  438. package/out/utils/validation-groups.js +135 -0
  439. package/out/utils/validation-groups.js.map +1 -0
  440. package/out/utils/wof-json.d.ts +31 -57
  441. package/out/utils/wof-json.d.ts.map +1 -1
  442. package/out/utils/wof-json.js +81 -98
  443. package/out/utils/wof-json.js.map +1 -1
  444. package/package.json +18 -18
  445. package/lib/adapters/wof/record-cache.ts +0 -118
  446. package/lib/build/heap.ts +0 -60
  447. package/lib/post-offices/sources.ts +0 -18
  448. package/lib/us/post-offices/usgs-national-map.ts +0 -89
  449. package/lib/us/tools/fetch/usgs-post-offices.ts +0 -362
  450. package/out/adapters/wof/record-cache.d.ts +0 -22
  451. package/out/adapters/wof/record-cache.d.ts.map +0 -1
  452. package/out/adapters/wof/record-cache.js +0 -89
  453. package/out/adapters/wof/record-cache.js.map +0 -1
  454. package/out/build/heap.d.ts +0 -26
  455. package/out/build/heap.d.ts.map +0 -1
  456. package/out/build/heap.js +0 -52
  457. package/out/build/heap.js.map +0 -1
  458. package/out/post-offices/source.d.ts.map +0 -1
  459. package/out/post-offices/source.js +0 -21
  460. package/out/post-offices/source.js.map +0 -1
  461. package/out/post-offices/sources.d.ts +0 -13
  462. package/out/post-offices/sources.d.ts.map +0 -1
  463. package/out/post-offices/sources.js +0 -8
  464. package/out/post-offices/sources.js.map +0 -1
  465. package/out/us/adapters/usgov/usgs-post-offices/adapter.d.ts +0 -66
  466. package/out/us/adapters/usgov/usgs-post-offices/adapter.d.ts.map +0 -1
  467. package/out/us/adapters/usgov/usgs-post-offices/adapter.js.map +0 -1
  468. package/out/us/post-offices/usgs-national-map.d.ts +0 -14
  469. package/out/us/post-offices/usgs-national-map.d.ts.map +0 -1
  470. package/out/us/post-offices/usgs-national-map.js.map +0 -1
  471. package/out/us/tools/fetch/usgs-post-offices.d.ts +0 -99
  472. package/out/us/tools/fetch/usgs-post-offices.d.ts.map +0 -1
  473. package/out/us/tools/fetch/usgs-post-offices.js +0 -246
  474. package/out/us/tools/fetch/usgs-post-offices.js.map +0 -1
@@ -0,0 +1,144 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * `au-acnc-register`: the Australian Charities and Not-for-profits Commission's register of charities
6
+ * (`ACNC Registered Charities`, data.gov.au dataset `acnc-register`), read by the evaluation
7
+ * source and by the `au-acnc-register` corpus adapter through {@linkcode readACNCCharities}.
8
+ *
9
+ * Each row is one registered charity with up to three address lines, a town, a state and a postcode.
10
+ * Every row's `Address_Type` reads `Business`.
11
+ *
12
+ * A charity whose address the ACNC withholds has empty address columns and yields no record.
13
+ *
14
+ * The rows read only the address, never the charity's name, because a small
15
+ * charity's name can be a person's.
16
+ * A record is kept only where its address is one street line with a house number,
17
+ * so a unit line or a post-office box line yields none.
18
+ *
19
+ * ## License
20
+ *
21
+ * The dataset record on data.gov.au (`package_show?id=acnc-register`), whose organization
22
+ * is `acnc`, states `license_title: Creative Commons Attribution 3.0 Australia`
23
+ * (`http://creativecommons.org/licenses/by/3.0/au/`), whose clause 3A grants the right to « create
24
+ * and Reproduce one or more Derivative Works » (`data/licenses/au-acnc-cc-by-3.0-au.md`).
25
+ */
26
+
27
+ import type { PathBuilder, PathBuilderLike } from "path-ts"
28
+ import { CSVSpliterator } from "spliterator"
29
+
30
+ import {
31
+ type EvaluationRecordReading,
32
+ type EvaluationSource,
33
+ evaluationSourceRead,
34
+ evaluationStreetLine,
35
+ fetchEvaluationFile,
36
+ readEvaluationFetch,
37
+ } from "#evaluation/source"
38
+
39
+ /**
40
+ * The register's CSV distribution on data.gov.au, updated weekly.
41
+ */
42
+ export const AU_ACNC_REGISTER_URL =
43
+ "https://data.gov.au/data/dataset/b050b242-4487-4306-abf5-07ca073e5594/resource/8fb32972-24e9-4c95-885e-7140be51be8a/download/datadotgov_main.csv"
44
+
45
+ /**
46
+ * The file the fetch writes and the reader reads, under the publisher's own name.
47
+ */
48
+ export const AU_ACNC_REGISTER_FILENAME = "datadotgov_main.csv"
49
+
50
+ /**
51
+ * The eight states and territories, the values `State` takes on an Australian address.
52
+ */
53
+ const STATES = new Set(["NSW", "VIC", "QLD", "WA", "SA", "TAS", "ACT", "NT"])
54
+
55
+ interface ACNCRow {
56
+ abn?: string
57
+ address_line_1?: string
58
+ address_line_2?: string
59
+ address_line_3?: string
60
+ town_city?: string
61
+ state?: string
62
+ postcode?: string
63
+ country?: string
64
+ }
65
+
66
+ function value(text: string | undefined): string {
67
+ return (text ?? "").replaceAll(/\s+/gu, " ").trim()
68
+ }
69
+
70
+ /**
71
+ * One register row as an address record, or the reason it yields none.
72
+ */
73
+ export function readACNCCharity(row: ACNCRow): EvaluationRecordReading {
74
+ const id = value(row.abn)
75
+ const state = value(row.state)
76
+ const postcode = value(row.postcode)
77
+ const locality = value(row.town_city)
78
+ const line = value(row.address_line_1)
79
+
80
+ if (!id) return { refused: "row:identifier-absent" }
81
+
82
+ if (!line) return { refused: "row:address-withheld" }
83
+
84
+ if (value(row.country) && value(row.country).toLowerCase() !== "australia") return { refused: "row:overseas" }
85
+
86
+ if (value(row.address_line_2) || value(row.address_line_3)) return { refused: "row:several-lines" }
87
+
88
+ if (!STATES.has(state.toUpperCase())) return { refused: "row:state-absent" }
89
+
90
+ if (!/^\d{4}$/u.test(postcode)) return { refused: "row:postcode-absent" }
91
+
92
+ if (!locality) return { refused: "row:locality-absent" }
93
+
94
+ if (/\b(?:p\.?\s?o\.?\s*box|gpo box|locked bag|private bag)\b/iu.test(line)) return { refused: "row:post-box" }
95
+
96
+ const street = evaluationStreetLine(line, "AU")
97
+
98
+ if ("refused" in street) return street
99
+
100
+ return {
101
+ id,
102
+ stratum: state.toUpperCase(),
103
+ components: {
104
+ house_number: street.house_number,
105
+ street: street.street,
106
+ locality,
107
+ region: state,
108
+ postcode,
109
+ },
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Australia's evaluation source, the ACNC charity register.
115
+ */
116
+ export const auACNCRegisterSource: EvaluationSource = {
117
+ id: "au-acnc-register",
118
+ country: "AU",
119
+ publisher: "Australian Charities and Not-for-profits Commission",
120
+ attribution:
121
+ "Australian Charities and Not-for-profits Commission, ACNC Registered Charities, data.gov.au, CC BY 3.0 AU",
122
+ license: "Creative Commons Attribution 3.0 Australia",
123
+ registerSource: "au-charity-nonprofit-1",
124
+
125
+ fetch: (directory, report) => fetchEvaluationFile(directory, AU_ACNC_REGISTER_URL, AU_ACNC_REGISTER_FILENAME, report),
126
+
127
+ async read(directory: PathBuilder) {
128
+ const fetched = await readEvaluationFetch(directory)
129
+
130
+ return evaluationSourceRead(
131
+ `fetched ${fetched.downloaded_at.slice(0, 10)}`,
132
+ readACNCCharities(directory(AU_ACNC_REGISTER_FILENAME))
133
+ )
134
+ },
135
+ }
136
+
137
+ /**
138
+ * Every row of the register CSV at `path`, read by {@linkcode readACNCCharity}.
139
+ */
140
+ export async function* readACNCCharities(path: PathBuilderLike): AsyncGenerator<EvaluationRecordReading> {
141
+ for await (const row of CSVSpliterator.fromAsync<ACNCRow>(path, { normalizeKeys: true })) {
142
+ yield readACNCCharity(row)
143
+ }
144
+ }
@@ -22,10 +22,12 @@ import { stringifyJSON } from "@mailwoman/core/json"
22
22
  import { PathBuilder, type PathBuilderLike } from "path-ts"
23
23
  import { JSONSpliterator } from "spliterator"
24
24
 
25
+ import { createUnitSplitter } from "#adapters/street/unit"
25
26
  import { alignSettings, createRowAligner, emptyAlignResult, type AlignTally } from "#build/align"
26
27
  import { alignTotalsOf, serializeAlignTotals, type AlignTotalsRecord } from "#build/align/totals"
27
28
  import type { AlignSettings } from "#build/checkpoint"
28
29
  import { createIneligibilityReader } from "#build/eligibility"
30
+ import { tryReadDefaultRegionNames } from "#build/region-names"
29
31
  import type { BuildProfile } from "#build/types"
30
32
  import { flushStream, once } from "#runner"
31
33
  import type { CanonicalRow } from "#types"
@@ -191,6 +193,11 @@ export async function reusableAlignRange(
191
193
 
192
194
  if (stringifyJSON(record.settings) !== stringifyJSON(settings)) return null
193
195
 
196
+ // A record from before the per-source component counts can't supply them to the manifest.
197
+ if (!Array.isArray(record.totals.component_findings_by_source)) return null
198
+
199
+ if (!Array.isArray(record.totals.unchecked_component_rules)) return null
200
+
194
201
  for (const name of ALIGN_RANGE_OUTPUTS) {
195
202
  if ((await tryStat(dir(name)))?.size !== record.outputs[name]) return null
196
203
  }
@@ -237,6 +244,8 @@ export async function runAlignRange(opts: AlignRangeOptions): Promise<AlignRange
237
244
  holdouts: opts.holdouts,
238
245
  licenses,
239
246
  ineligibility,
247
+ units: await createUnitSplitter(),
248
+ regions: await tryReadDefaultRegionNames(),
240
249
  result,
241
250
  tally,
242
251
  sinks: {
@@ -14,6 +14,7 @@
14
14
  */
15
15
 
16
16
  import type { AlignPhaseResult, AlignTally } from "#build/align"
17
+ import type { ComponentFindingCounts, ComponentRule } from "#build/component-check"
17
18
  import type { LicenseRefusalKind } from "#utils/license"
18
19
  import type { SplitName } from "#utils/split"
19
20
 
@@ -31,6 +32,8 @@ export interface AlignTotals extends AlignTally {
31
32
  * Every license value the policy refused, with its refusal kind.
32
33
  */
33
34
  refusedValues: Map<string, LicenseRefusalKind>
35
+ componentFindingsBySource: ComponentFindingCounts
36
+ uncheckedComponentRules: Set<ComponentRule>
34
37
  }
35
38
 
36
39
  /**
@@ -49,6 +52,8 @@ export interface AlignTotalsRecord {
49
52
  rows_by_source: [string, { rows: number; license: string }][]
50
53
  ineligible_sources: [string, readonly string[]][]
51
54
  refused_license_values: [string, LicenseRefusalKind][]
55
+ component_findings_by_source: [string, [ComponentRule, number][]][]
56
+ unchecked_component_rules: ComponentRule[]
52
57
  }
53
58
 
54
59
  /**
@@ -68,6 +73,8 @@ export function alignTotalsOf(result: AlignPhaseResult): AlignTotals {
68
73
  rowsBySource: result.rowsBySource,
69
74
  ineligibleSources: result.ineligibleSources,
70
75
  refusedValues: result.licenses.refusedValues(),
76
+ componentFindingsBySource: result.componentFindingsBySource,
77
+ uncheckedComponentRules: result.uncheckedComponentRules,
71
78
  }
72
79
  }
73
80
 
@@ -85,6 +92,8 @@ export function serializeAlignTotals(totals: AlignTotals): AlignTotalsRecord {
85
92
  rows_by_source: [...totals.rowsBySource],
86
93
  ineligible_sources: [...totals.ineligibleSources],
87
94
  refused_license_values: [...totals.refusedValues],
95
+ component_findings_by_source: [...totals.componentFindingsBySource].map(([source, rules]) => [source, [...rules]]),
96
+ unchecked_component_rules: [...totals.uncheckedComponentRules],
88
97
  }
89
98
  }
90
99
 
@@ -125,6 +134,8 @@ export function mergeAlignTotals(records: readonly AlignTotalsRecord[]): AlignTo
125
134
  rowsBySource: new Map(),
126
135
  ineligibleSources: new Map(),
127
136
  refusedValues: new Map(),
137
+ componentFindingsBySource: new Map(),
138
+ uncheckedComponentRules: new Set(),
128
139
  }
129
140
 
130
141
  for (const record of records) {
@@ -150,6 +161,18 @@ export function mergeAlignTotals(records: readonly AlignTotalsRecord[]): AlignTo
150
161
 
151
162
  keepFirst(totals.ineligibleSources, record.ineligible_sources)
152
163
  keepFirst(totals.refusedValues, record.refused_license_values)
164
+
165
+ for (const [source, rules] of record.component_findings_by_source) {
166
+ const into = totals.componentFindingsBySource.get(source) ?? new Map<ComponentRule, number>()
167
+
168
+ totals.componentFindingsBySource.set(source, into)
169
+ addCounts(into, rules)
170
+ }
171
+
172
+ // A rule one record couldn't check leaves the merged counts short, so it stays unchecked for the whole.
173
+ for (const rule of record.unchecked_component_rules) {
174
+ totals.uncheckedComponentRules.add(rule)
175
+ }
153
176
  }
154
177
 
155
178
  return totals
@@ -15,6 +15,7 @@ import { sha256Hex } from "@mailwoman/core/hash"
15
15
  import { stringifyJSON } from "@mailwoman/core/json"
16
16
  import type { PathBuilder } from "path-ts"
17
17
 
18
+ import { createUnitSplitter, type UnitSplitter } from "#adapters/street/unit"
18
19
  import {
19
20
  ALIGN_OUTPUTS,
20
21
  readAlignCheckpoint,
@@ -23,8 +24,15 @@ import {
23
24
  type AlignOutputName,
24
25
  type AlignSettings,
25
26
  } from "#build/checkpoint"
26
- import { componentFindings, ENFORCED_COMPONENT_RULES } from "#build/component-check"
27
+ import {
28
+ componentFindings,
29
+ componentFindingsRecord,
30
+ ComponentRule,
31
+ ENFORCED_COMPONENT_RULES,
32
+ type ComponentFindingCounts,
33
+ } from "#build/component-check"
27
34
  import { createIneligibilityReader } from "#build/eligibility"
35
+ import { tryReadDefaultRegionNames, type RegionNames } from "#build/region-names"
28
36
  import { streamJSONL } from "#build/rows"
29
37
  import type { BuildProfile, BuildStage } from "#build/types"
30
38
  import { flushStream, once, type AdapterRunManifest } from "#runner"
@@ -108,6 +116,19 @@ export interface AlignPhaseResult {
108
116
  excludedByEligibility: number
109
117
  rowsBySource: Map<string, { rows: number; license: string }>
110
118
  ineligibleSources: Map<string, readonly string[]>
119
+ /**
120
+ * Base rows failing each component rule, per `source` then rule (#2898).
121
+ *
122
+ * Every rule is counted, whether the build quarantines a row for it
123
+ * (`ENFORCED_COMPONENT_RULES`) or only reports it.
124
+ */
125
+ componentFindingsBySource: ComponentFindingCounts
126
+ /**
127
+ * The component rules this phase couldn't check, because the data they read wasn't on the host.
128
+ *
129
+ * Their counts in {@linkcode AlignPhaseResult.componentFindingsBySource} are absent rather than zero.
130
+ */
131
+ uncheckedComponentRules: Set<ComponentRule>
111
132
 
112
133
  /**
113
134
  * The source-id lists this phase wrote, or `null` when it wrote none.
@@ -173,6 +194,24 @@ function restoreTally(checkpoint: AlignCheckpoint, result: AlignPhaseResult): Al
173
194
  result.rowsBySource.set(source, contributed)
174
195
  }
175
196
 
197
+ // A checkpoint from before the per-source component counts would leave them short by every aligned adapter.
198
+ if (!checkpoint.component_findings_by_source) {
199
+ throw new Error(
200
+ `resume refused: the align checkpoint after ${checkpoint.completed_adapters.join(", ")} records no ` +
201
+ `component_findings_by_source, so the manifest's per-source component counts would miss those adapters. ` +
202
+ `Rebuild with --fresh.`
203
+ )
204
+ }
205
+
206
+ for (const [source, rules] of Object.entries(checkpoint.component_findings_by_source)) {
207
+ result.componentFindingsBySource.set(source, new Map(Object.entries(rules) as [ComponentRule, number][]))
208
+ }
209
+
210
+ // A checkpoint that records no list was written before `region:unknown` existed, so its rows went unchecked.
211
+ for (const rule of checkpoint.unchecked_component_rules ?? [ComponentRule.RegionUnknown]) {
212
+ result.uncheckedComponentRules.add(rule as ComponentRule)
213
+ }
214
+
176
215
  return {
177
216
  aligned: checkpoint.aligned,
178
217
  quarantined: checkpoint.quarantined,
@@ -225,6 +264,16 @@ export interface RowAlignerOptions {
225
264
  retention?: SplitRetention
226
265
  licenses: LicenseVerdictCache
227
266
  ineligibility: ReturnType<typeof createIneligibilityReader>
267
+ /**
268
+ * The unit vocabulary the component check's `street:trailing-unit` rule reads, from `createUnitSplitter`.
269
+ */
270
+ units: UnitSplitter
271
+ /**
272
+ * The region forms the `region:unknown` rule reads, or `null` when the WOF database isn't on the host.
273
+ *
274
+ * A `null` records the rule in `result.uncheckedComponentRules`.
275
+ */
276
+ regions: RegionNames | null
228
277
  /**
229
278
  * The accumulators the aligner adds each row to.
230
279
  */
@@ -244,6 +293,11 @@ export interface RowAlignerOptions {
244
293
  */
245
294
  export function createRowAligner(opts: RowAlignerOptions): (row: CanonicalRow) => void {
246
295
  const { result, tally, sinks, licenses, ineligibility } = opts
296
+ const context = { units: opts.units, regions: opts.regions }
297
+
298
+ if (!opts.regions) {
299
+ result.uncheckedComponentRules.add(ComponentRule.RegionUnknown)
300
+ }
247
301
 
248
302
  const quarantine = (row: CanonicalRow, reason: string): void => {
249
303
  sinks.quarantine(`${stringifyJSON({ row, reason })}\n`)
@@ -290,9 +344,19 @@ export function createRowAligner(opts: RowAlignerOptions): (row: CanonicalRow) =
290
344
 
291
345
  // A row whose values fail its country's rules or contradict each other (#2898) is
292
346
  // quarantined before augmentation, so no variant inherits the wrong value.
293
- const invalid = componentFindings(row.components, row.country).filter((finding) =>
294
- ENFORCED_COMPONENT_RULES.has(finding.rule)
295
- )
347
+ const findings = componentFindings(row.components, row.country, context)
348
+
349
+ if (findings.length) {
350
+ const bySource = result.componentFindingsBySource.get(row.source) ?? new Map<ComponentRule, number>()
351
+
352
+ result.componentFindingsBySource.set(row.source, bySource)
353
+
354
+ for (const finding of findings) {
355
+ bySource.set(finding.rule, (bySource.get(finding.rule) ?? 0) + 1)
356
+ }
357
+ }
358
+
359
+ const invalid = findings.filter((finding) => ENFORCED_COMPONENT_RULES.has(finding.rule))
296
360
 
297
361
  if (invalid.length) {
298
362
  quarantine(row, invalid.map((finding) => `component-invalid:${finding.rule}`).join("; "))
@@ -373,6 +437,8 @@ export function emptyAlignResult(
373
437
  refusedBySource: new Map(),
374
438
  rowsBySource: new Map(),
375
439
  ineligibleSources,
440
+ componentFindingsBySource: new Map(),
441
+ uncheckedComponentRules: new Set(),
376
442
  sourceIDPaths: null,
377
443
  licenses,
378
444
  }
@@ -472,6 +538,8 @@ export async function runAlignPhase(opts: AlignPhaseOptions): Promise<AlignPhase
472
538
  retention: opts.retention,
473
539
  licenses,
474
540
  ineligibility,
541
+ units: await createUnitSplitter(),
542
+ regions: await tryReadDefaultRegionNames(),
475
543
  result,
476
544
  tally,
477
545
  sinks: {
@@ -520,6 +588,8 @@ export async function runAlignPhase(opts: AlignPhaseOptions): Promise<AlignPhase
520
588
  admitted_unresolved_license_rows: tally.admittedUnresolved,
521
589
  excluded_by_eligibility: tally.excludedByEligibility,
522
590
  rows_by_source: Object.fromEntries(result.rowsBySource),
591
+ component_findings_by_source: componentFindingsRecord(result.componentFindingsBySource),
592
+ unchecked_component_rules: [...result.uncheckedComponentRules],
523
593
  written_at: new Date().toISOString(),
524
594
  })
525
595
  }
@@ -16,8 +16,6 @@
16
16
 
17
17
  import { availableParallelism, totalMemoryBytes } from "@mailwoman/core/utils/system"
18
18
 
19
- import { isResidentRecordAdapter } from "#build/heap"
20
-
21
19
  const GiB = 1024 ** 3
22
20
 
23
21
  /**
@@ -43,16 +41,15 @@ export interface WorkerResources {
43
41
  }
44
42
 
45
43
  /**
46
- * The two worker classes.
44
+ * The worker classes.
47
45
  *
48
- * `standard` runs every task except a resident-record adapter: an adapter,
49
- * an align range, or a source's sort and parquet write.
50
- * `resident` runs `wof-admin` or `wof-postalcode`, whose run holds every source record in memory
51
- * (`#build/heap`), with a 16 GiB heap above the 15 GiB floor `assertHeapForAdapters` enforces.
46
+ * `standard` runs every task: an adapter, an align range, or a source's sort and parquet write.
47
+ * The WOF adapters read the WOF record store and peaked at 1,862 MiB
48
+ * (`wof-admin`, 79,116,868 rows) and 636 MiB (`wof-postalcode`, 5,240,681 rows) by
49
+ * kernel `maxRSS` over the lab's full clone set, inside the standard heap.
52
50
  */
53
51
  export const WORKER_CLASSES = {
54
52
  standard: { heapBytes: 6 * GiB, duckdbBytes: 1.5 * GiB, duckdbThreads: 1 },
55
- resident: { heapBytes: 16 * GiB, duckdbBytes: 0, duckdbThreads: 1 },
56
53
  } as const satisfies Record<string, WorkerResources>
57
54
 
58
55
  export type WorkerClass = keyof typeof WORKER_CLASSES
@@ -78,13 +75,6 @@ export function workerReservationBytes(workerClass: WorkerClass): number {
78
75
  return resources.heapBytes + resources.duckdbBytes + WORKER_NATIVE_ALLOWANCE_BYTES
79
76
  }
80
77
 
81
- /**
82
- * The class a source's adapter task runs in.
83
- */
84
- export function adapterWorkerClass(adapterID: string): WorkerClass {
85
- return isResidentRecordAdapter(adapterID) ? "resident" : "standard"
86
- }
87
-
88
78
  /**
89
79
  * A parallel build's memory plan.
90
80
  */
@@ -100,37 +90,23 @@ const gib = (bytes: number): string => `${(bytes / GiB).toFixed(1)} GiB`
100
90
  * The `--jobs` a build takes when none is given: the most standard workers the
101
91
  * host's budget holds, capped at the host's CPU count.
102
92
  *
103
- * Returns 1 for a serial build when fewer than two workers fit or when a configured resident
104
- * adapter cannot fit in the budget. {@linkcode planWorkerBudget} refuses that configuration.
93
+ * Returns 1 for a serial build when fewer than two workers fit.
105
94
  */
106
- export function defaultBuildJobs(opts: { adapterIDs: readonly string[]; hostMemoryBytes?: number }): number {
95
+ export function defaultBuildJobs(opts: { hostMemoryBytes?: number } = {}): number {
107
96
  const hostMemoryBytes = opts.hostMemoryBytes ?? totalMemoryBytes()
108
97
  const budgetBytes = hostMemoryBytes - HOST_RESERVE_BYTES
109
-
110
- const residentFits =
111
- !opts.adapterIDs.some(isResidentRecordAdapter) || workerReservationBytes("resident") <= budgetBytes
112
-
113
98
  const fits = Math.min(availableParallelism(), Math.floor(budgetBytes / workerReservationBytes("standard")))
114
99
 
115
- return residentFits && fits >= 2 ? fits : 1
100
+ return fits >= 2 ? fits : 1
116
101
  }
117
102
 
118
103
  /**
119
- * Check that `jobs` standard workers fit in the host budget and that a resident
120
- * adapter fits when it runs by itself.
104
+ * Check that `jobs` standard workers fit in the host budget.
121
105
  *
122
- * A resident adapter runs one at a time and beside the standard workers that fit,
123
- * so it lowers the build's concurrency while it runs rather than raising its demand.
124
- *
125
- * @throws When `jobs` standard workers exceed the budget, or a configured resident
126
- * adapter exceeds the budget when it runs by itself.
106
+ * @throws When `jobs` standard workers exceed the budget.
127
107
  * The error lists each reservation and the largest `--jobs` that fits.
128
108
  */
129
- export function planWorkerBudget(opts: {
130
- jobs: number
131
- adapterIDs: readonly string[]
132
- hostMemoryBytes?: number
133
- }): WorkerBudget {
109
+ export function planWorkerBudget(opts: { jobs: number; hostMemoryBytes?: number }): WorkerBudget {
134
110
  const hostMemoryBytes = opts.hostMemoryBytes ?? totalMemoryBytes()
135
111
  const budgetBytes = hostMemoryBytes - HOST_RESERVE_BYTES
136
112
  const standard = workerReservationBytes("standard")
@@ -148,15 +124,5 @@ export function planWorkerBudget(opts: {
148
124
  )
149
125
  }
150
126
 
151
- const resident = opts.adapterIDs.filter(isResidentRecordAdapter)
152
-
153
- if (resident.length && workerReservationBytes("resident") > budgetBytes) {
154
- throw new Error(
155
- `corpus build refused: ${resident.join(", ")} ${resident.length === 1 ? "runs" : "run"} in a worker reserving ` +
156
- `${gib(workerReservationBytes("resident"))} (heap ${gib(WORKER_CLASSES.resident.heapBytes)}), and ${sizes}. ` +
157
- `Run with --jobs 1 on a host that can hold it, or leave ${resident.join(", ")} out of --inputs.`
158
- )
159
- }
160
-
161
127
  return { jobs: opts.jobs, hostMemoryBytes, budgetBytes }
162
128
  }
@@ -91,6 +91,17 @@ export interface AlignCheckpoint {
91
91
  admitted_unresolved_license_rows: number
92
92
  excluded_by_eligibility: number
93
93
  rows_by_source: Record<string, { rows: number; license: string }>
94
+ /**
95
+ * Base rows failing each component rule, per source then rule.
96
+ *
97
+ * Absent from a checkpoint written before the counts existed.
98
+ * A resume refuses such a checkpoint.
99
+ */
100
+ component_findings_by_source?: Record<string, Record<string, number>>
101
+ /**
102
+ * The component rules the aligned adapters' rows weren't checked against.
103
+ */
104
+ unchecked_component_rules?: string[]
94
105
  written_at: string
95
106
  }
96
107
 
@@ -10,8 +10,11 @@
10
10
  * per-country data or the row itself, so the same rules hold in every country.
11
11
  */
12
12
 
13
- import { acceptPostcode, postcodeSyntax } from "@mailwoman/postcode/country-formats"
13
+ import { acceptPostcode, statesPostcodeSyntax } from "@mailwoman/postcode/country-formats"
14
14
 
15
+ import type { UnitSplitter } from "#adapters/street/unit"
16
+ import { writtenSubdivisionCode } from "#adapters/wof/admin/json/region-codes"
17
+ import type { RegionNames } from "#build/region-names"
15
18
  import type { CanonicalRow } from "#types"
16
19
 
17
20
  /**
@@ -35,6 +38,25 @@ export const ComponentRule = {
35
38
  * the city with the street line.
36
39
  */
37
40
  LocalityHoldsStreet: "locality:holds-street",
41
+ /**
42
+ * The postcode is the row's own region (`1811 Hayes Avenue, Hull, IA IA`).
43
+ */
44
+ PostcodeRepeatsRegion: "postcode:repeats-region",
45
+ /**
46
+ * The locality is the code the row's country writes for the row's own region
47
+ * (`BELLVILLE, TX, TX 77418` read with `TX` as the city).
48
+ */
49
+ LocalityRepeatsRegion: "locality:repeats-region",
50
+ /**
51
+ * The street still ends in a unit designator and identifier of the row's
52
+ * country (`Avenue des Armieres Entree 13`).
53
+ */
54
+ StreetTrailingUnit: "street:trailing-unit",
55
+ /**
56
+ * The region is no name or abbreviation of a region or macroregion of the row's country
57
+ * in the WOF admin database, in a country where that database holds regions.
58
+ */
59
+ RegionUnknown: "region:unknown",
38
60
  } as const
39
61
 
40
62
  export type ComponentRule = (typeof ComponentRule)[keyof typeof ComponentRule]
@@ -46,11 +68,22 @@ export type ComponentRule = (typeof ComponentRule)[keyof typeof ComponentRule]
46
68
  * The v0.8.9 dry run (#2898) found 522,089 rows failing it, among them legitimate partial
47
69
  * postcodes (WOF's Dutch `3704`) and spaced written forms (`31 261` in Kraków), beside the defects
48
70
  * it is meant for (NAD's 425,667 short ZIP Codes and Overture Brazil's dropped leading zeros).
71
+ *
72
+ * `locality:repeats-region` is reported but not enforced, because a publisher's own `NY` for
73
+ * New York City (`150 E 71 ST, NY, NY 10021`) fails it beside the rows whose city was lost.
74
+ *
75
+ * `street:trailing-unit` is reported but not enforced, because some streets end in a
76
+ * word a country also writes as a unit (`Morning Side`, `Skijor Steppe Upper`).
77
+ *
78
+ * `region:unknown` is reported but not enforced, because neither source holds every
79
+ * form addresses write: Swiss canton codes (`TG`), Latvia's post-2021 municipalities
80
+ * (`Valmieras nov.`), Bangkok's short `กรุงเทพ`.
49
81
  */
50
82
  export const ENFORCED_COMPONENT_RULES: ReadonlySet<ComponentRule> = new Set([
51
83
  ComponentRule.StreetRepeatsPostcode,
52
84
  ComponentRule.StreetHoldsPlace,
53
85
  ComponentRule.LocalityHoldsStreet,
86
+ ComponentRule.PostcodeRepeatsRegion,
54
87
  ])
55
88
 
56
89
  /**
@@ -61,6 +94,18 @@ export interface ComponentFinding {
61
94
  values: string[]
62
95
  }
63
96
 
97
+ /**
98
+ * Rows failing each rule, per `source` then rule.
99
+ */
100
+ export type ComponentFindingCounts = Map<string, Map<ComponentRule, number>>
101
+
102
+ /**
103
+ * {@linkcode ComponentFindingCounts} as a JSON object, in the order each source and rule was first counted.
104
+ */
105
+ export function componentFindingsRecord(counts: ComponentFindingCounts): Record<string, Record<string, number>> {
106
+ return Object.fromEntries([...counts].map(([source, rules]) => [source, Object.fromEntries(rules)]))
107
+ }
108
+
64
109
  /**
65
110
  * The fewest digits a street's ending needs before it is compared with the row's postcode.
66
111
  */
@@ -73,14 +118,34 @@ const fold = (text: string) =>
73
118
  .replaceAll(/[\s,.]+/gu, " ")
74
119
  .trim()
75
120
 
121
+ /**
122
+ * What the rules read beyond the row.
123
+ */
124
+ export interface ComponentCheckContext {
125
+ /**
126
+ * The unit vocabulary `street:trailing-unit` reads.
127
+ * Without it the rule isn't checked.
128
+ */
129
+ units?: UnitSplitter | null
130
+ /**
131
+ * The WOF region names `region:unknown` reads.
132
+ * Without them the rule isn't checked.
133
+ */
134
+ regions?: RegionNames | null
135
+ }
136
+
76
137
  /**
77
138
  * The rules `components` fails for a row of `country`, in rule order.
78
139
  */
79
- export function componentFindings(components: CanonicalRow["components"], country: string): ComponentFinding[] {
140
+ export function componentFindings(
141
+ components: CanonicalRow["components"],
142
+ country: string,
143
+ context: ComponentCheckContext = {}
144
+ ): ComponentFinding[] {
80
145
  const findings: ComponentFinding[] = []
81
146
  const { postcode, street, locality, region } = components
82
147
 
83
- if (postcode && postcodeSyntax(country) && acceptPostcode(postcode, country) == null) {
148
+ if (postcode && statesPostcodeSyntax(country) && acceptPostcode(postcode, country) == null) {
84
149
  findings.push({ rule: ComponentRule.PostcodeFormat, values: [postcode] })
85
150
  }
86
151
 
@@ -121,5 +186,36 @@ export function componentFindings(components: CanonicalRow["components"], countr
121
186
  }
122
187
  }
123
188
 
189
+ if (postcode && region && fold(postcode) === fold(region)) {
190
+ findings.push({ rule: ComponentRule.PostcodeRepeatsRegion, values: [postcode, region] })
191
+ }
192
+
193
+ // A city may share its region's name (`Berlin, Berlin`, `أبو ظبي, أبو ظبي`),
194
+ // but no city is written as its region's code. libaddressinput's keys and ISO ids state
195
+ // which codes a country's addresses write.
196
+ if (locality && region) {
197
+ const regionCode = writtenSubdivisionCode(country, region)
198
+
199
+ if (regionCode != null && fold(locality) === fold(regionCode)) {
200
+ findings.push({ rule: ComponentRule.LocalityRepeatsRegion, values: [locality, region] })
201
+ }
202
+ }
203
+
204
+ if (street && context.units) {
205
+ const trailing = context.units.trailingUnit(street, {
206
+ country,
207
+ ...(locality ? { locality } : {}),
208
+ ...(postcode ? { postcode } : {}),
209
+ })
210
+
211
+ if (trailing) {
212
+ findings.push({ rule: ComponentRule.StreetTrailingUnit, values: [street, trailing.unit] })
213
+ }
214
+ }
215
+
216
+ if (region && context.regions?.holds(country, region) === false) {
217
+ findings.push({ rule: ComponentRule.RegionUnknown, values: [region] })
218
+ }
219
+
124
220
  return findings
125
221
  }