@mailwoman/corpus 11.3.0 → 11.5.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 (352) hide show
  1. package/data/PROVENANCE.md +3 -4
  2. package/data/address-source-register.json +12 -4
  3. package/data/builds/v0.8.22-nz-overlay/OVERLAY_PLAN.json +19 -0
  4. package/data/builds/v0.8.23-overlay/OVERLAY_PLAN.json +3656 -0
  5. package/data/builds/v0.8.23-prominent-overlay/OVERLAY_PLAN.json +42 -0
  6. package/data/builds/v0.8.23-rebuild/inputs.json +141 -0
  7. package/data/builds/v0.8.24-rebuild/inputs.json +111 -0
  8. package/data/corpus-source-inputs.json +95 -1
  9. package/data/holdout/evaluation-groups.v0.8.24.json +222158 -0
  10. package/data/license-decisions.json +14 -1
  11. package/data/region-slot-second-level.json +1 -1
  12. package/data/training-configs/v8.11.0-base-c6-90k-v0823-s42.yaml +920 -0
  13. package/data/training-configs/v8.12.0-base-c6-wofreps-v0823-s42.yaml +944 -0
  14. package/data/training-configs/v8.13.0-base-c6-wofreps-v0822-s42.yaml +918 -0
  15. package/data/training-configs/v8.14.0-base-c6-wofreps-cursor-v0822-s42.yaml +926 -0
  16. package/data/training-configs/v8.15.0-base-c6-wofreps-cursor-emit-v0822-s42.yaml +973 -0
  17. package/data/training-configs/v8.16.0-base-c6-wofreps-positions-v0822-s42.yaml +988 -0
  18. package/data/training-configs/v8.19.0-nz-v0822-s42.yaml +870 -0
  19. package/data/training-manifests/v0.8.22-nz-overlay.effective.json +2556 -0
  20. package/data/training-manifests/v0.8.22-nz-overlay.json +9000 -0
  21. package/lib/adapters/cordis/adapter.ts +3 -2
  22. package/lib/adapters/gleif/adapter.ts +123 -20
  23. package/lib/adapters/openaddresses/adapter.ts +2 -2
  24. package/lib/adapters/osm/adapter.ts +62 -4
  25. package/lib/adapters/overture/adapter.ts +97 -15
  26. package/lib/adapters/overture/address-key.ts +89 -0
  27. package/lib/adapters/overture/places-in/adapter.ts +258 -0
  28. package/lib/adapters/street/convention.ts +49 -0
  29. package/lib/adapters/street/country-line.ts +65 -0
  30. package/lib/adapters/wof/admin/json/adapter.ts +4 -4
  31. package/lib/adapters/wof/admin/json/region-codes.ts +98 -0
  32. package/lib/adapters/wof/json-rows.ts +2 -2
  33. package/lib/adapters.ts +2 -0
  34. package/lib/build/align/range.ts +21 -11
  35. package/lib/build/align/totals.ts +20 -0
  36. package/lib/build/align.ts +218 -20
  37. package/lib/build/budget.ts +55 -20
  38. package/lib/build/checkpoint.ts +9 -0
  39. package/lib/build/component-check.ts +97 -3
  40. package/lib/build/inputs.ts +122 -31
  41. package/lib/build/manifest.ts +1 -0
  42. package/lib/build/parallel.ts +140 -23
  43. package/lib/build/{region-names.ts → region/names.ts} +16 -4
  44. package/lib/build/region/recount.ts +153 -0
  45. package/lib/build/reuse.ts +112 -0
  46. package/lib/build/settings.ts +84 -3
  47. package/lib/build/source-record.ts +45 -8
  48. package/lib/build/types.ts +26 -0
  49. package/lib/build/worker.ts +75 -10
  50. package/lib/build.ts +2 -1
  51. package/lib/de/recipes/locale.ts +9 -3
  52. package/lib/evaluation/corpus-adapter.ts +2 -2
  53. package/lib/fi/adapters/ryhti/adapter.ts +2 -2
  54. package/lib/fo/adapters/adressur/adapter.ts +2 -2
  55. package/lib/fr/recipes/lieudit.ts +3 -4
  56. package/lib/in/street-line/segment.ts +370 -0
  57. package/lib/international/recipes/locale.ts +6 -3
  58. package/lib/li/adapters/llv/adapter.ts +2 -2
  59. package/lib/lu/adapters/bd-adresses/adapter.ts +2 -2
  60. package/lib/no/adapters/matrikkelen/adapter.ts +2 -2
  61. package/lib/parquet/streams.ts +18 -3
  62. package/lib/parquet/writers.ts +161 -29
  63. package/lib/recipes/country-balanced.ts +32 -18
  64. package/lib/recipes/fragment-assay/build.ts +8 -5
  65. package/lib/recipes/fragment-assay/rows.ts +4 -4
  66. package/lib/recipes/house/venue.ts +2 -1
  67. package/lib/recipes/postal/guideline/leg.ts +3 -2
  68. package/lib/recipes/prominent/places.ts +4 -4
  69. package/lib/runner.ts +139 -20
  70. package/lib/sg/recipes/register.ts +6 -1
  71. package/lib/source-register/row-license.ts +12 -2
  72. package/lib/surfaces/corpus-row.ts +84 -0
  73. package/lib/surfaces/locale.ts +20 -24
  74. package/lib/synthesizers/house-venue.ts +33 -40
  75. package/lib/synthesizers/no-street.ts +2 -2
  76. package/lib/synthesizers/po-box.ts +3 -3
  77. package/lib/synthesizers/tail.ts +3 -2
  78. package/lib/synthesizers/utils.ts +95 -56
  79. package/lib/test-kit.ts +50 -1
  80. package/lib/tools/fetch/overture-places-in.ts +118 -0
  81. package/lib/tools/fetch/storage.ts +3 -0
  82. package/lib/tools/fetch.ts +2 -0
  83. package/lib/tools/overlay/manifest.ts +36 -5
  84. package/lib/tools/region-slot-census.run.ts +2 -2
  85. package/lib/training/config/schema.ts +17 -0
  86. package/lib/types.ts +39 -0
  87. package/lib/us/adapters/state/tx-notaries/adapter.ts +2 -1
  88. package/lib/us/adapters/usgov/imls-pls/adapter.ts +2 -1
  89. package/lib/us/adapters/usgov/nad/adapter.ts +40 -7
  90. package/lib/us/adapters/usgov/nad/address-key.ts +8 -47
  91. package/lib/us/adapters/usgov/nppes/adapter.ts +2 -1
  92. package/lib/utils/address-key.ts +57 -0
  93. package/lib/utils/align.ts +22 -10
  94. package/lib/utils/evaluation-groups.ts +13 -6
  95. package/lib/utils/split.ts +24 -3
  96. package/out/adapters/cordis/adapter.d.ts.map +1 -1
  97. package/out/adapters/cordis/adapter.js +3 -2
  98. package/out/adapters/cordis/adapter.js.map +1 -1
  99. package/out/adapters/gleif/adapter.d.ts +4 -0
  100. package/out/adapters/gleif/adapter.d.ts.map +1 -1
  101. package/out/adapters/gleif/adapter.js +100 -20
  102. package/out/adapters/gleif/adapter.js.map +1 -1
  103. package/out/adapters/openaddresses/adapter.js +2 -2
  104. package/out/adapters/openaddresses/adapter.js.map +1 -1
  105. package/out/adapters/osm/adapter.d.ts +9 -0
  106. package/out/adapters/osm/adapter.d.ts.map +1 -1
  107. package/out/adapters/osm/adapter.js +55 -13
  108. package/out/adapters/osm/adapter.js.map +1 -1
  109. package/out/adapters/overture/adapter.d.ts +6 -0
  110. package/out/adapters/overture/adapter.d.ts.map +1 -1
  111. package/out/adapters/overture/adapter.js +72 -9
  112. package/out/adapters/overture/adapter.js.map +1 -1
  113. package/out/adapters/overture/address-key.d.ts +39 -0
  114. package/out/adapters/overture/address-key.d.ts.map +1 -0
  115. package/out/adapters/overture/address-key.js +75 -0
  116. package/out/adapters/overture/address-key.js.map +1 -0
  117. package/out/adapters/overture/places-in/adapter.d.ts +20 -0
  118. package/out/adapters/overture/places-in/adapter.d.ts.map +1 -0
  119. package/out/adapters/overture/places-in/adapter.js +191 -0
  120. package/out/adapters/overture/places-in/adapter.js.map +1 -0
  121. package/out/adapters/street/convention.d.ts +11 -0
  122. package/out/adapters/street/convention.d.ts.map +1 -0
  123. package/out/adapters/street/convention.js +40 -0
  124. package/out/adapters/street/convention.js.map +1 -0
  125. package/out/adapters/street/country-line.d.ts +31 -0
  126. package/out/adapters/street/country-line.d.ts.map +1 -0
  127. package/out/adapters/street/country-line.js +31 -0
  128. package/out/adapters/street/country-line.js.map +1 -0
  129. package/out/adapters/wof/admin/json/adapter.js +4 -4
  130. package/out/adapters/wof/admin/json/adapter.js.map +1 -1
  131. package/out/adapters/wof/admin/json/region-codes.d.ts +5 -0
  132. package/out/adapters/wof/admin/json/region-codes.d.ts.map +1 -1
  133. package/out/adapters/wof/admin/json/region-codes.js +83 -0
  134. package/out/adapters/wof/admin/json/region-codes.js.map +1 -1
  135. package/out/adapters/wof/json-rows.d.ts.map +1 -1
  136. package/out/adapters/wof/json-rows.js +2 -2
  137. package/out/adapters/wof/json-rows.js.map +1 -1
  138. package/out/adapters.d.ts.map +1 -1
  139. package/out/adapters.js +2 -0
  140. package/out/adapters.js.map +1 -1
  141. package/out/build/align/range.d.ts +7 -3
  142. package/out/build/align/range.d.ts.map +1 -1
  143. package/out/build/align/range.js +17 -9
  144. package/out/build/align/range.js.map +1 -1
  145. package/out/build/align/totals.d.ts +12 -0
  146. package/out/build/align/totals.d.ts.map +1 -1
  147. package/out/build/align/totals.js +8 -0
  148. package/out/build/align/totals.js.map +1 -1
  149. package/out/build/align.d.ts +60 -5
  150. package/out/build/align.d.ts.map +1 -1
  151. package/out/build/align.js +136 -12
  152. package/out/build/align.js.map +1 -1
  153. package/out/build/budget.d.ts +35 -11
  154. package/out/build/budget.d.ts.map +1 -1
  155. package/out/build/budget.js +52 -20
  156. package/out/build/budget.js.map +1 -1
  157. package/out/build/checkpoint.d.ts +9 -0
  158. package/out/build/checkpoint.d.ts.map +1 -1
  159. package/out/build/checkpoint.js.map +1 -1
  160. package/out/build/component-check.d.ts +29 -1
  161. package/out/build/component-check.d.ts.map +1 -1
  162. package/out/build/component-check.js +57 -2
  163. package/out/build/component-check.js.map +1 -1
  164. package/out/build/inputs.d.ts +58 -0
  165. package/out/build/inputs.d.ts.map +1 -1
  166. package/out/build/inputs.js +57 -20
  167. package/out/build/inputs.js.map +1 -1
  168. package/out/build/manifest.d.ts.map +1 -1
  169. package/out/build/manifest.js +1 -0
  170. package/out/build/manifest.js.map +1 -1
  171. package/out/build/parallel.d.ts +19 -1
  172. package/out/build/parallel.d.ts.map +1 -1
  173. package/out/build/parallel.js +92 -11
  174. package/out/build/parallel.js.map +1 -1
  175. package/out/build/{region-names.d.ts → region/names.d.ts} +10 -1
  176. package/out/build/region/names.d.ts.map +1 -0
  177. package/out/build/{region-names.js → region/names.js} +16 -5
  178. package/out/build/region/names.js.map +1 -0
  179. package/out/build/region/recount.d.ts +47 -0
  180. package/out/build/region/recount.d.ts.map +1 -0
  181. package/out/build/region/recount.js +105 -0
  182. package/out/build/region/recount.js.map +1 -0
  183. package/out/build/reuse.d.ts +31 -0
  184. package/out/build/reuse.d.ts.map +1 -0
  185. package/out/build/reuse.js +50 -0
  186. package/out/build/reuse.js.map +1 -0
  187. package/out/build/settings.d.ts +38 -0
  188. package/out/build/settings.d.ts.map +1 -1
  189. package/out/build/settings.js +67 -3
  190. package/out/build/settings.js.map +1 -1
  191. package/out/build/source-record.d.ts +32 -7
  192. package/out/build/source-record.d.ts.map +1 -1
  193. package/out/build/source-record.js +17 -4
  194. package/out/build/source-record.js.map +1 -1
  195. package/out/build/types.d.ts +24 -0
  196. package/out/build/types.d.ts.map +1 -1
  197. package/out/build/worker.d.ts +17 -0
  198. package/out/build/worker.d.ts.map +1 -1
  199. package/out/build/worker.js +44 -9
  200. package/out/build/worker.js.map +1 -1
  201. package/out/build.d.ts.map +1 -1
  202. package/out/build.js +2 -1
  203. package/out/build.js.map +1 -1
  204. package/out/de/recipes/locale.d.ts.map +1 -1
  205. package/out/de/recipes/locale.js +9 -3
  206. package/out/de/recipes/locale.js.map +1 -1
  207. package/out/evaluation/corpus-adapter.d.ts +14 -0
  208. package/out/evaluation/corpus-adapter.d.ts.map +1 -1
  209. package/out/evaluation/corpus-adapter.js +2 -16
  210. package/out/evaluation/corpus-adapter.js.map +1 -1
  211. package/out/fi/adapters/ryhti/adapter.js +2 -2
  212. package/out/fi/adapters/ryhti/adapter.js.map +1 -1
  213. package/out/fo/adapters/adressur/adapter.js +2 -2
  214. package/out/fo/adapters/adressur/adapter.js.map +1 -1
  215. package/out/fr/recipes/lieudit.d.ts.map +1 -1
  216. package/out/fr/recipes/lieudit.js +3 -3
  217. package/out/fr/recipes/lieudit.js.map +1 -1
  218. package/out/in/street-line/segment.d.ts +75 -0
  219. package/out/in/street-line/segment.d.ts.map +1 -0
  220. package/out/in/street-line/segment.js +298 -0
  221. package/out/in/street-line/segment.js.map +1 -0
  222. package/out/international/recipes/locale.d.ts.map +1 -1
  223. package/out/international/recipes/locale.js +6 -3
  224. package/out/international/recipes/locale.js.map +1 -1
  225. package/out/li/adapters/llv/adapter.js +2 -2
  226. package/out/li/adapters/llv/adapter.js.map +1 -1
  227. package/out/lu/adapters/bd-adresses/adapter.js +2 -2
  228. package/out/lu/adapters/bd-adresses/adapter.js.map +1 -1
  229. package/out/no/adapters/matrikkelen/adapter.js +2 -2
  230. package/out/no/adapters/matrikkelen/adapter.js.map +1 -1
  231. package/out/parquet/streams.d.ts +9 -0
  232. package/out/parquet/streams.d.ts.map +1 -1
  233. package/out/parquet/streams.js +7 -3
  234. package/out/parquet/streams.js.map +1 -1
  235. package/out/parquet/writers.d.ts +55 -2
  236. package/out/parquet/writers.d.ts.map +1 -1
  237. package/out/parquet/writers.js +109 -27
  238. package/out/parquet/writers.js.map +1 -1
  239. package/out/recipes/country-balanced.d.ts.map +1 -1
  240. package/out/recipes/country-balanced.js +32 -15
  241. package/out/recipes/country-balanced.js.map +1 -1
  242. package/out/recipes/fragment-assay/build.d.ts +5 -2
  243. package/out/recipes/fragment-assay/build.d.ts.map +1 -1
  244. package/out/recipes/fragment-assay/build.js +8 -5
  245. package/out/recipes/fragment-assay/build.js.map +1 -1
  246. package/out/recipes/fragment-assay/rows.d.ts +2 -2
  247. package/out/recipes/fragment-assay/rows.js +4 -4
  248. package/out/recipes/fragment-assay/rows.js.map +1 -1
  249. package/out/recipes/house/venue.d.ts.map +1 -1
  250. package/out/recipes/house/venue.js +2 -1
  251. package/out/recipes/house/venue.js.map +1 -1
  252. package/out/recipes/postal/guideline/leg.d.ts.map +1 -1
  253. package/out/recipes/postal/guideline/leg.js +2 -7
  254. package/out/recipes/postal/guideline/leg.js.map +1 -1
  255. package/out/recipes/prominent/places.js +4 -4
  256. package/out/recipes/prominent/places.js.map +1 -1
  257. package/out/runner.d.ts +28 -0
  258. package/out/runner.d.ts.map +1 -1
  259. package/out/runner.js +85 -18
  260. package/out/runner.js.map +1 -1
  261. package/out/sg/recipes/register.d.ts.map +1 -1
  262. package/out/sg/recipes/register.js +6 -1
  263. package/out/sg/recipes/register.js.map +1 -1
  264. package/out/source-register/row-license.d.ts +8 -0
  265. package/out/source-register/row-license.d.ts.map +1 -1
  266. package/out/source-register/row-license.js +10 -2
  267. package/out/source-register/row-license.js.map +1 -1
  268. package/out/surfaces/corpus-row.d.ts +32 -0
  269. package/out/surfaces/corpus-row.d.ts.map +1 -0
  270. package/out/surfaces/corpus-row.js +70 -0
  271. package/out/surfaces/corpus-row.js.map +1 -0
  272. package/out/surfaces/locale.d.ts.map +1 -1
  273. package/out/surfaces/locale.js +16 -22
  274. package/out/surfaces/locale.js.map +1 -1
  275. package/out/synthesizers/house-venue.d.ts +9 -4
  276. package/out/synthesizers/house-venue.d.ts.map +1 -1
  277. package/out/synthesizers/house-venue.js +25 -35
  278. package/out/synthesizers/house-venue.js.map +1 -1
  279. package/out/synthesizers/no-street.js +2 -9
  280. package/out/synthesizers/no-street.js.map +1 -1
  281. package/out/synthesizers/po-box.js +3 -7
  282. package/out/synthesizers/po-box.js.map +1 -1
  283. package/out/synthesizers/tail.d.ts.map +1 -1
  284. package/out/synthesizers/tail.js +2 -2
  285. package/out/synthesizers/tail.js.map +1 -1
  286. package/out/synthesizers/utils.d.ts +20 -3
  287. package/out/synthesizers/utils.d.ts.map +1 -1
  288. package/out/synthesizers/utils.js +74 -57
  289. package/out/synthesizers/utils.js.map +1 -1
  290. package/out/test-kit.d.ts +11 -0
  291. package/out/test-kit.d.ts.map +1 -1
  292. package/out/test-kit.js +30 -1
  293. package/out/test-kit.js.map +1 -1
  294. package/out/tools/fetch/overture-places-in.d.ts +14 -0
  295. package/out/tools/fetch/overture-places-in.d.ts.map +1 -0
  296. package/out/tools/fetch/overture-places-in.js +82 -0
  297. package/out/tools/fetch/overture-places-in.js.map +1 -0
  298. package/out/tools/fetch/storage.d.ts +2 -0
  299. package/out/tools/fetch/storage.d.ts.map +1 -1
  300. package/out/tools/fetch/storage.js +3 -0
  301. package/out/tools/fetch/storage.js.map +1 -1
  302. package/out/tools/fetch.d.ts +2 -0
  303. package/out/tools/fetch.d.ts.map +1 -1
  304. package/out/tools/fetch.js +2 -0
  305. package/out/tools/fetch.js.map +1 -1
  306. package/out/tools/overlay/manifest.d.ts.map +1 -1
  307. package/out/tools/overlay/manifest.js +29 -5
  308. package/out/tools/overlay/manifest.js.map +1 -1
  309. package/out/tools/region-slot-census.run.js +2 -2
  310. package/out/training/config/schema.d.ts +46 -0
  311. package/out/training/config/schema.d.ts.map +1 -1
  312. package/out/training/config/schema.js +13 -0
  313. package/out/training/config/schema.js.map +1 -1
  314. package/out/types.d.ts +41 -0
  315. package/out/types.d.ts.map +1 -1
  316. package/out/types.js.map +1 -1
  317. package/out/us/adapters/state/tx-notaries/adapter.d.ts.map +1 -1
  318. package/out/us/adapters/state/tx-notaries/adapter.js +2 -1
  319. package/out/us/adapters/state/tx-notaries/adapter.js.map +1 -1
  320. package/out/us/adapters/usgov/imls-pls/adapter.d.ts.map +1 -1
  321. package/out/us/adapters/usgov/imls-pls/adapter.js +2 -1
  322. package/out/us/adapters/usgov/imls-pls/adapter.js.map +1 -1
  323. package/out/us/adapters/usgov/nad/adapter.d.ts +19 -0
  324. package/out/us/adapters/usgov/nad/adapter.d.ts.map +1 -1
  325. package/out/us/adapters/usgov/nad/adapter.js +29 -6
  326. package/out/us/adapters/usgov/nad/adapter.js.map +1 -1
  327. package/out/us/adapters/usgov/nad/address-key.d.ts +1 -5
  328. package/out/us/adapters/usgov/nad/address-key.d.ts.map +1 -1
  329. package/out/us/adapters/usgov/nad/address-key.js +8 -33
  330. package/out/us/adapters/usgov/nad/address-key.js.map +1 -1
  331. package/out/us/adapters/usgov/nppes/adapter.d.ts.map +1 -1
  332. package/out/us/adapters/usgov/nppes/adapter.js +2 -1
  333. package/out/us/adapters/usgov/nppes/adapter.js.map +1 -1
  334. package/out/utils/address-key.d.ts +23 -0
  335. package/out/utils/address-key.d.ts.map +1 -0
  336. package/out/utils/address-key.js +43 -0
  337. package/out/utils/address-key.js.map +1 -0
  338. package/out/utils/align.d.ts +7 -0
  339. package/out/utils/align.d.ts.map +1 -1
  340. package/out/utils/align.js +18 -8
  341. package/out/utils/align.js.map +1 -1
  342. package/out/utils/evaluation-groups.d.ts +5 -1
  343. package/out/utils/evaluation-groups.d.ts.map +1 -1
  344. package/out/utils/evaluation-groups.js +12 -1
  345. package/out/utils/evaluation-groups.js.map +1 -1
  346. package/out/utils/split.d.ts +11 -0
  347. package/out/utils/split.d.ts.map +1 -1
  348. package/out/utils/split.js +18 -3
  349. package/out/utils/split.js.map +1 -1
  350. package/package.json +19 -19
  351. package/out/build/region-names.d.ts.map +0 -1
  352. package/out/build/region-names.js.map +0 -1
@@ -0,0 +1,89 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * @file The address key that joins an Overture row to every other rendering of the same address.
6
+ *
7
+ * An Overture row's `source_id` is a hash of its aligned components (`stableSourceID`).
8
+ * A re-run that adds the region or writes the postcode in another grouping gives the same address a new id,
9
+ * and the record id the split groups by doesn't hold across the re-run (#3457).
10
+ * The key reads the postcode, the locality, the house number, the street and the unit, each folded.
11
+ * It leaves out the region and the country, the two components a re-run adds to some rows and not others.
12
+ * A postcode keeps only its letters and digits, so `K7K6R2` and `K7K 6R2`, `54420-240` and `54420240` are
13
+ * one postcode.
14
+ *
15
+ * The key's text comes from Overture's own fields.
16
+ * The adapter writes `street`, `number`, `unit` and `locality` verbatim and regroups only the postcode.
17
+ */
18
+
19
+ import { type AddressKeyRow, aliasedSpanSQL, foldKeyText, labeledSpanText } from "#utils/address-key"
20
+
21
+ /**
22
+ * The street tags whose spans make up the street.
23
+ *
24
+ * The affix relabel may split a street keyword into its own span,
25
+ * and the joined text is the same either way.
26
+ */
27
+ const STREET_TAGS: ReadonlySet<string> = new Set(["street_prefix", "street", "street_suffix"])
28
+
29
+ const POSTCODE_TAGS: ReadonlySet<string> = new Set(["postcode"])
30
+
31
+ const HOUSE_NUMBER_TAGS: ReadonlySet<string> = new Set(["house_number"])
32
+
33
+ /**
34
+ * A postcode's letters and digits, lower case.
35
+ */
36
+ function foldPostcode(text: string): string {
37
+ return foldKeyText(text).replaceAll(" ", "")
38
+ }
39
+
40
+ /**
41
+ * The folded postcode and the house number's digits, the part of the key a column scan can compute.
42
+ *
43
+ * @returns null when the row holds neither a postcode nor a locality.
44
+ * The adapter writes no such row.
45
+ */
46
+ export function overtureAddressBlock(row: AddressKeyRow): string | null {
47
+ const postcode = foldPostcode(labeledSpanText(row, POSTCODE_TAGS))
48
+ const number = labeledSpanText(row, HOUSE_NUMBER_TAGS).replaceAll(/\D/gu, "")
49
+
50
+ if (!postcode && !row.span_tags.includes("locality")) return null
51
+
52
+ return `${postcode}|${number}`
53
+ }
54
+
55
+ /**
56
+ * {@linkcode overtureAddressBlock} as a DuckDB expression over a corpus file aliased `alias`.
57
+ *
58
+ * `lower` and the ASCII class agree with the JavaScript fold for the postcodes
59
+ * Overture writes in Brazil, Mexico and Canada.
60
+ * Those hold only ASCII letters, digits, a space and a hyphen.
61
+ */
62
+ export function overtureAddressBlockSQL(alias: string): string {
63
+ const text = (tag: string) => `coalesce(${aliasedSpanSQL(alias, tag)}, '')`
64
+
65
+ return (
66
+ `(regexp_replace(lower(${text("postcode")}), '[^0-9a-z]', '', 'g') || '|' || ` +
67
+ `regexp_replace(${text("house_number")}, '[^0-9]', '', 'g'))`
68
+ )
69
+ }
70
+
71
+ /**
72
+ * The address key of one Overture row, `<postcode>|<locality>|<house number>|<street>|<unit>`.
73
+ *
74
+ * A row without a house number keys by its street within its postcode and locality.
75
+ *
76
+ * @returns null when the row has no street, or neither a postcode nor a locality.
77
+ */
78
+ export function overtureAddressKey(row: AddressKeyRow): string | null {
79
+ const street = foldKeyText(labeledSpanText(row, STREET_TAGS))
80
+ const postcode = foldPostcode(labeledSpanText(row, POSTCODE_TAGS))
81
+ const locality = foldKeyText(labeledSpanText(row, new Set(["locality"])))
82
+
83
+ if (!street || (!postcode && !locality)) return null
84
+
85
+ const number = foldKeyText(labeledSpanText(row, HOUSE_NUMBER_TAGS))
86
+ const unit = foldKeyText(labeledSpanText(row, new Set(["unit"])))
87
+
88
+ return `${postcode}|${locality}|${number}|${street}|${unit}`
89
+ }
@@ -0,0 +1,258 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * `overture-places-in`: the street addresses of Indian places in the Overture Maps places theme.
6
+ *
7
+ * Input is the parquet file `#tools/fetch/overture-places-in` copies out of one Overture release.
8
+ * It holds each Indian place's first address as `freeform` (the street line),
9
+ * `locality`, `region` and `postcode`, with the dataset Overture took the place from
10
+ * (Microsoft, Meta, Foursquare, AllThePlaces, DAC, PinMeTo).
11
+ *
12
+ * ## The rendered order
13
+ *
14
+ * Each row renders through the IN layout in `@mailwoman/codex/address/layouts`.
15
+ * The share `WRITTEN_LAYOUTS` records renders through the written order, with the state before the PIN.
16
+ *
17
+ * India Post's UPU description (`https://www.upu.int/UPU/media/upu/PostalEntitiesFiles/addressingUnit/indEn.pdf`,
18
+ * 01/2013, sha256 `f8ac2ed37a59ecece8cd11e2ac5088411148b1e3d69304c118e655e275fa2a3e`) writes the
19
+ * premise number, a comma and the street (`4, Amrita Shergill Road`, `32/1, 2nd Main Road`).
20
+ * The sub-locality (`Jayanagar`), the locality, the state and the PIN
21
+ * follow (`Bangalore / Karnataka / 560082`).
22
+ *
23
+ * A hash of the Overture id draws between the two orders, so a rebuild renders each place the same way.
24
+ *
25
+ * ## What a row holds
26
+ *
27
+ * `segmentINStreetLine` (`#in/street-line/segment`) labels the street line,
28
+ * and keeps a line only where each part has one reading.
29
+ * The place's own name is never read, because a Meta or Foursquare listing can be
30
+ * a person's (`HDFC ERGO Insurance Agent: <name>`).
31
+ *
32
+ * A state is kept only where Who's On First or GeoNames holds it as one of India's
33
+ * first-level divisions, and only in a written-out form.
34
+ * AllThePlaces writes districts there (`Erode`, `Palakkad`), and DAC and Meta write
35
+ * ISO 3166-2 suffixes (`MH`), which Indian addresses spell out.
36
+ *
37
+ * A PIN is six digits, and a locality is letters without a comma.
38
+ *
39
+ * ## License
40
+ *
41
+ * Overture's places theme is CDLA Permissive 2.0 for Meta, Microsoft, DAC and PinMeTo,
42
+ * Apache 2.0 for Foursquare and CC0 1.0 for AllThePlaces, as the register's elected
43
+ * decision for `us-geodata-aggregate-1` records.
44
+ */
45
+
46
+ import { formatAddressRow } from "@mailwoman/codex/address/format"
47
+ import { writtenLayoutForCountry } from "@mailwoman/codex/address/layouts"
48
+ import { foldName } from "@mailwoman/codex/names/normalize"
49
+ import { sha256Hex } from "@mailwoman/core/crypto/hash"
50
+ import { mulberry32 } from "@mailwoman/core/math/random"
51
+
52
+ import { type RegionNames, tryReadDefaultRegionNames } from "#build/region/names"
53
+ import { INStreetLineRefusal, isINSubProvince, segmentINStreetLine } from "#in/street-line/segment"
54
+ import { openParquetRowStream } from "#parquet/streams"
55
+ import { SourceRegister } from "#registers"
56
+ import { AddressRole, type AdapterOptions, type CanonicalRow, type CorpusAdapter, SurfaceOrigin } from "#types"
57
+
58
+ /**
59
+ * Registry id for this adapter, stamped as the `source` of every row it emits.
60
+ */
61
+ const OVERTURE_PLACES_IN_ADAPTER_ID = "overture-places-in"
62
+
63
+ /**
64
+ * The license stamped on each row: the places theme's license for the CDLA datasets.
65
+ *
66
+ * The register decision records the Apache 2.0 and CC0 datasets.
67
+ */
68
+ const OVERTURE_PLACES_IN_DEFAULT_LICENSE = "CDLA-Permissive-2.0"
69
+
70
+ /**
71
+ * One row of the snapshot `#tools/fetch/overture-places-in` writes.
72
+ */
73
+ interface OverturePlaceINRecord {
74
+ id: string
75
+ freeform: string | null
76
+ locality: string | null
77
+ region: string | null
78
+ postcode: string | null
79
+ }
80
+
81
+ /**
82
+ * Why a record emitted no row: the street line's own refusals, and the fields beside it.
83
+ */
84
+ const OverturePlaceINRefusal = {
85
+ ...INStreetLineRefusal,
86
+ StreetLineAbsent: "street-line-absent",
87
+ LocalityUnread: "locality-unread",
88
+ PostcodeUnread: "postcode-unread",
89
+ } as const
90
+
91
+ type OverturePlaceINRefusal = (typeof OverturePlaceINRefusal)[keyof typeof OverturePlaceINRefusal]
92
+
93
+ /**
94
+ * A PIN code as the address writes it: six digits, the first one to eight,
95
+ * with an optional space after the third.
96
+ */
97
+ const PIN = /^([1-8]\d{2})\s?(\d{3})$/u
98
+
99
+ /**
100
+ * A locality written in letters, with the spaces, dots, hyphens and apostrophes a name holds.
101
+ */
102
+ const LOCALITY = /^[\p{L}\p{M}][\p{L}\p{M} .'-]*$/u
103
+
104
+ /**
105
+ * The longest region value read as an ISO 3166-2 suffix (`MH`, `UP`) rather than a state's written name.
106
+ */
107
+ const MAX_SUBDIVISION_CODE_LENGTH = 3
108
+
109
+ /**
110
+ * A uniform draw in `[0, 1)` fixed by the Overture id.
111
+ */
112
+ function drawFor(id: string): number {
113
+ return mulberry32(Number.parseInt(sha256Hex(id).slice(0, 8), 16))()
114
+ }
115
+
116
+ /**
117
+ * Read one record into a row's components, or the reason it holds none.
118
+ */
119
+ function readOverturePlaceIN(
120
+ record: OverturePlaceINRecord,
121
+ regionNames: Pick<RegionNames, "holds">
122
+ ): { components: CanonicalRow["components"] } | { refused: OverturePlaceINRefusal } {
123
+ const freeform = record.freeform?.trim()
124
+
125
+ if (!freeform) return { refused: OverturePlaceINRefusal.StreetLineAbsent }
126
+
127
+ const locality = record.locality?.trim() ?? ""
128
+
129
+ if (!LOCALITY.test(locality) || isINSubProvince(locality)) return { refused: OverturePlaceINRefusal.LocalityUnread }
130
+
131
+ const pin = PIN.exec(record.postcode?.trim() ?? "")
132
+
133
+ if (!pin) return { refused: OverturePlaceINRefusal.PostcodeUnread }
134
+
135
+ const postcode = `${pin[1]}${pin[2]}`
136
+ const regionValue = record.region?.trim() ?? ""
137
+
138
+ const region =
139
+ regionValue.length > MAX_SUBDIVISION_CODE_LENGTH &&
140
+ foldName(regionValue) !== foldName(locality) &&
141
+ regionNames.holds("IN", regionValue)
142
+ ? regionValue
143
+ : undefined
144
+
145
+ const line = segmentINStreetLine(freeform, { locality, region: regionValue })
146
+
147
+ if ("refused" in line) return { refused: line.refused }
148
+
149
+ const { omitted: _omitted, ...parts } = line
150
+
151
+ if (parts.dependent_locality && foldName(parts.dependent_locality) === foldName(locality)) {
152
+ delete parts.dependent_locality
153
+ }
154
+
155
+ return {
156
+ components: {
157
+ ...parts,
158
+ locality,
159
+ ...(region ? { region } : {}),
160
+ postcode,
161
+ },
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Render one record as a corpus row, in the postal or the written order its id draws,
167
+ * or `null` when it holds none.
168
+ */
169
+ function renderOverturePlaceIN(
170
+ record: OverturePlaceINRecord,
171
+ regionNames: Pick<RegionNames, "holds">
172
+ ): CanonicalRow | null {
173
+ const reading = readOverturePlaceIN(record, regionNames)
174
+
175
+ if ("refused" in reading) return null
176
+
177
+ const layout = writtenLayoutForCountry("IN", drawFor(record.id))
178
+ const rendered = formatAddressRow(reading.components, "IN", { singleLine: true, ...(layout ? { layout } : {}) })
179
+
180
+ if (!rendered) return null
181
+
182
+ return {
183
+ raw: rendered.raw,
184
+ components: rendered.components,
185
+ country: "IN",
186
+ locale: "en-IN",
187
+ source: OVERTURE_PLACES_IN_ADAPTER_ID,
188
+ source_id: `${OVERTURE_PLACES_IN_ADAPTER_ID}-${record.id}`,
189
+ license: OVERTURE_PLACES_IN_DEFAULT_LICENSE,
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Options for {@link createOverturePlacesINAdapter}.
195
+ */
196
+ export interface OverturePlacesINAdapterOptions {
197
+ /**
198
+ * Reads India's first-level division names.
199
+ *
200
+ * Defaults to the Who's On First admin database with GeoNames' first-level names.
201
+ * The adapter refuses to run without one.
202
+ */
203
+ regionNames?: () => Promise<Pick<RegionNames, "holds"> | null>
204
+ }
205
+
206
+ export function createOverturePlacesINAdapter(options: OverturePlacesINAdapterOptions = {}): CorpusAdapter {
207
+ const loadRegionNames = options.regionNames ?? tryReadDefaultRegionNames
208
+
209
+ return {
210
+ id: OVERTURE_PLACES_IN_ADAPTER_ID,
211
+ defaultLicense: OVERTURE_PLACES_IN_DEFAULT_LICENSE,
212
+ addressRole: AddressRole.Facility,
213
+ register: SourceRegister.Overture,
214
+ surface: SurfaceOrigin.Rendered,
215
+ description:
216
+ "Overture Maps places in India — the street address of each place (CDLA Permissive 2.0 / Apache 2.0 / CC0), rendered in India Post's order.",
217
+
218
+ async *rows(opts: AdapterOptions): AsyncIterable<CanonicalRow> {
219
+ // A street-line reader for another country's Overture places would replace
220
+ // this refusal. country-branch: the street-line reader and the PIN
221
+ // and state checks follow India Post's conventions.
222
+ if (opts.country && opts.country !== "IN") {
223
+ throw new Error(`${OVERTURE_PLACES_IN_ADAPTER_ID} adapter: only IN supported, got country=${opts.country}`)
224
+ }
225
+
226
+ const regionNames = await loadRegionNames()
227
+
228
+ if (!regionNames) {
229
+ throw new Error(
230
+ `${OVERTURE_PLACES_IN_ADAPTER_ID} adapter: the Who's On First admin database that holds India's states isn't on this host`
231
+ )
232
+ }
233
+
234
+ let emitted = 0
235
+
236
+ for await (const record of openParquetRowStream<OverturePlaceINRecord>(opts.inputPath, {
237
+ columns: ["id", "freeform", "locality", "region", "postcode"],
238
+ })) {
239
+ if (opts.signal?.aborted) break
240
+
241
+ if (typeof opts.limit === "number" && emitted >= opts.limit) break
242
+
243
+ const row = renderOverturePlaceIN(record, regionNames)
244
+
245
+ if (!row) continue
246
+
247
+ yield row
248
+
249
+ emitted++
250
+ }
251
+ },
252
+ }
253
+ }
254
+
255
+ /**
256
+ * The configured adapter instance registered with the corpus builder.
257
+ */
258
+ export const overturePlacesINAdapter = createOverturePlacesINAdapter()
@@ -0,0 +1,49 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * A row's street components, written under its country's street span convention.
6
+ *
7
+ * `docs/engineering/reference/SCHEMA.mdx` labels a US street's directional
8
+ * and type as `street_prefix` and `street_suffix` spans.
9
+ * An adapter that reads one street line, such as the NPPES practice location
10
+ * or a notary register's address, emits the whole line as `street`.
11
+ *
12
+ * The model then learns both forms for one US street.
13
+ * The evaluation reads the whole form as an unlabeled affix.
14
+ */
15
+
16
+ import { streetSpanConventionFor } from "@mailwoman/codex/labels/street/convention"
17
+
18
+ import type { CanonicalRow } from "#types"
19
+ import { decomposeStreet } from "#us/adapters/tiger/street-decompose"
20
+
21
+ /**
22
+ * Returns `components` with a whole `street` split into `street_prefix`, `street`
23
+ * and `street_suffix` when `country`'s convention is `split` and the row labels no street affix.
24
+ *
25
+ * The split reads the dictionaries the TIGER adapter's {@linkcode decomposeStreet} reads,
26
+ * so every US source labels one street one way.
27
+ * A street with no directional or type keyword keeps its one span.
28
+ */
29
+ export function withConventionStreet(
30
+ components: CanonicalRow["components"],
31
+ country: string
32
+ ): CanonicalRow["components"] {
33
+ const street = components.street
34
+
35
+ if (!street || streetSpanConventionFor(country) !== "split") return components
36
+
37
+ if (components.street_prefix || components.street_suffix || components.street_prefix_particle) return components
38
+
39
+ const { prefix, street: name, suffix } = decomposeStreet(street)
40
+
41
+ if (!prefix && !suffix) return components
42
+
43
+ return {
44
+ ...components,
45
+ ...(prefix ? { street_prefix: prefix } : {}),
46
+ street: name,
47
+ ...(suffix ? { street_suffix: suffix } : {}),
48
+ }
49
+ }
@@ -0,0 +1,65 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * The street-line readers a country's own directory supplies, keyed by ISO 3166-1 alpha-2 code.
6
+ *
7
+ * A country whose free-text street line joins several comma-separated parts in an
8
+ * order its postal operator states gets a reader under `lib/<cc>/street-line/`,
9
+ * and an adapter reads a line of that country through this table.
10
+ * A country without an entry has no reader, and an adapter keeps its own split.
11
+ */
12
+
13
+ import { segmentINStreetLine } from "#in/street-line/segment"
14
+
15
+ /**
16
+ * The parts a country's reader labels in one street line.
17
+ */
18
+ export interface CountryStreetLineParts {
19
+ house_number?: string
20
+ street: string
21
+ dependent_locality?: string
22
+ /**
23
+ * A building or complex name written before the street (`Tagore Road Hostel`).
24
+ */
25
+ building?: string
26
+ }
27
+
28
+ /**
29
+ * The record fields beside the line.
30
+ * The line may repeat their values.
31
+ */
32
+ export interface CountryStreetLineContext {
33
+ locality?: string | null
34
+ region?: string | null
35
+ }
36
+
37
+ /**
38
+ * Reads one street line, or returns the reason it can't be labeled.
39
+ */
40
+ export type CountryStreetLineReader = (
41
+ line: string,
42
+ context: CountryStreetLineContext
43
+ ) => CountryStreetLineParts | { refused: string }
44
+
45
+ const COUNTRY_STREET_LINE_READERS: Readonly<Record<string, CountryStreetLineReader>> = {
46
+ IN: (line, context) => {
47
+ const parts = segmentINStreetLine(line, context)
48
+
49
+ if ("refused" in parts) return parts
50
+
51
+ return {
52
+ ...(parts.house_number ? { house_number: parts.house_number } : {}),
53
+ street: parts.street,
54
+ ...(parts.dependent_locality ? { dependent_locality: parts.dependent_locality } : {}),
55
+ ...(parts.venue ? { building: parts.venue } : {}),
56
+ }
57
+ },
58
+ }
59
+
60
+ /**
61
+ * The street-line reader of `country`, or `null` when its directory supplies none.
62
+ */
63
+ export function streetLineReaderFor(country: string): CountryStreetLineReader | null {
64
+ return COUNTRY_STREET_LINE_READERS[country.toUpperCase()] ?? null
65
+ }
@@ -46,7 +46,7 @@
46
46
 
47
47
  import { layoutForCountry, layoutPrintsLargestFirst, lineJoinForCountry } from "@mailwoman/codex/address/layouts"
48
48
  import type { ComponentTag } from "@mailwoman/codex/component"
49
- import { countrySurfaceForms } from "@mailwoman/codex/country/country"
49
+ import { countryRenderForms } from "@mailwoman/codex/country/country"
50
50
  import { OFFICIAL_LANGUAGES } from "@mailwoman/codex/country/official-languages"
51
51
  import { postalTownPlacetypeForCountry } from "@mailwoman/codex/labels/placetype-map"
52
52
  import { foldToken } from "@mailwoman/codex/names/normalize"
@@ -419,8 +419,8 @@ function isStructuralSlot(slot: NameSlot): boolean {
419
419
  /**
420
420
  * The forms one ancestor level is written in, its canonical form first.
421
421
  *
422
- * - A country is written in its OpenCage-canonical display name, then each
423
- * surface form the codex lists for it (`United States`, `USA`, `US`, `U.S.A.`),
422
+ * - A country is written in its OpenCage-canonical display name, then each surface form
423
+ * the codex lists for it except a two-letter code (`United States`, `USA`, `U.S.A.`),
424
424
  * or its own `wof:name` when the codex lists none.
425
425
  * - A region is written in its name, then in the code the country's addresses
426
426
  * write for it (`NY`), from libaddressinput.
@@ -442,7 +442,7 @@ function levelForms(level: ChainLevel, ancestor: WOFRecord, country: string): st
442
442
  if (level === "country") {
443
443
  add(COUNTRY_DISPLAY_NAME[ancestor.country] ?? ancestor.name)
444
444
 
445
- const curated = countrySurfaceForms(ancestor.country)
445
+ const curated = countryRenderForms(ancestor.country)
446
446
 
447
447
  if (curated.length) {
448
448
  curated.forEach(add)
@@ -15,8 +15,10 @@
15
15
  * AU, BR, CA, ES, HK, IT, KR, MX, SO and US in the vendored specs.
16
16
  */
17
17
 
18
+ import { layoutCitationForCountry, layoutForCountry, layoutPrintsTag } from "@mailwoman/codex/address/layouts"
18
19
  import { readLocalTextFileSync } from "@mailwoman/core/fs/readers"
19
20
  import { isFileSync } from "@mailwoman/core/fs/readers/stat"
21
+ import { escapeRegExp } from "@mailwoman/core/strings/regexp"
20
22
  import { tryParsingJSON } from "@mailwoman/core/values/json"
21
23
  import { isPresent } from "@mailwoman/core/values/objects"
22
24
  import { sslAddressSpecsPath } from "@mailwoman/dictionaries/paths"
@@ -132,6 +134,102 @@ function writtenCodesFor(country: string): ReadonlyMap<string, string> {
132
134
  return written
133
135
  }
134
136
 
137
+ /**
138
+ * ISO 3166-2 codes that replaced a code the vendored libaddressinput specs still list,
139
+ * keyed by the current code.
140
+ *
141
+ * ISO 3166-2:IN's change of 2023-11-23 ("Change of subdivision codes") moved Odisha
142
+ * from `IN-OR` to `IN-OD`, Chhattisgarh from `IN-CT` to `IN-CG`, Telangana from
143
+ * `IN-TG` to `IN-TS` and Uttarakhand from `IN-UT` to `IN-UK`.
144
+ * GLEIF's golden copy of 2026-10-03 writes the current codes.
145
+ *
146
+ * The libaddressinput spec and Who's On First's concordances hold the earlier ones.
147
+ */
148
+ const ISO_SUBDIVISION_CODES_REPLACED: Readonly<Record<string, string>> = {
149
+ "IN-CG": "IN-CT",
150
+ "IN-OD": "IN-OR",
151
+ "IN-TS": "IN-TG",
152
+ "IN-UK": "IN-UT",
153
+ }
154
+
155
+ /**
156
+ * The form `country`'s addresses write for the subdivision whose ISO 3166-2 code ends in `isoSuffix`:
157
+ * the libaddressinput key listed beside that ISO id, or `null` when the spec lists no such id.
158
+ *
159
+ * India keys Maharashtra by its name beside ISO id `MH`, so `IN`, `MH` returns `Maharashtra`.
160
+ * The United States keys New York as `NY`, so `US`, `NY` returns `NY`.
161
+ * The comparison ignores case.
162
+ */
163
+ function writtenSubdivisionForISO(country: string, isoSuffix: string): string | null {
164
+ const code = country.toUpperCase()
165
+ const spec = specFor(code)
166
+ const keys = spec?.sub_keys?.split("~") ?? []
167
+ const isoIDs = spec?.sub_isoids?.split("~") ?? []
168
+
169
+ if (isoIDs.length !== keys.length) return null
170
+
171
+ const suffix = isoSuffix.toUpperCase()
172
+ const listed = ISO_SUBDIVISION_CODES_REPLACED[`${code}-${suffix}`]?.slice(code.length + 1) ?? suffix
173
+ const at = isoIDs.findIndex((isoID) => isoID.toUpperCase() === listed)
174
+
175
+ return at === -1 ? null : keys[at]!
176
+ }
177
+
178
+ const CITED_KEY_FORM_BY_COUNTRY = new Map<string, boolean>()
179
+
180
+ /**
181
+ * Countries whose cited example matches a libaddressinput key on a line that
182
+ * isn't the region's, with the line.
183
+ *
184
+ * Suriname's one example writes `PARAMARIBO` as the locality.
185
+ * Paramaribo is also a district key, so the match is the city's name rather than a written region.
186
+ */
187
+ const CITED_KEY_MATCH_ON_ANOTHER_LINE: Readonly<Record<string, string>> = {
188
+ SR: "PARAMARIBO",
189
+ }
190
+
191
+ /**
192
+ * Whether `country`'s codex layout prints a region, has a primary citation, and one of
193
+ * the citation's example lines writes a libaddressinput key as a word of its own.
194
+ *
195
+ * libaddressinput is a compiled dataset, so its key is the written form only where the postal operator's
196
+ * own example agrees: Italy's description writes `00122 ROMA RM`, and its key for Rome is `RM`.
197
+ * Chile's writes `REGION METROPOLITANA`, which isn't a Chilean key, so Chile reads no key.
198
+ */
199
+ function citationWritesKeys(country: string): boolean {
200
+ const cached = CITED_KEY_FORM_BY_COUNTRY.get(country)
201
+
202
+ if (typeof cached === "boolean") return cached
203
+
204
+ const layout = layoutForCountry(country)
205
+ const citation = layoutCitationForCountry(country)
206
+ const keys = specFor(country)?.sub_keys?.split("~").filter(isPresent) ?? []
207
+ const otherLine = CITED_KEY_MATCH_ON_ANOTHER_LINE[country]
208
+ const lines = (citation?.examples.flat() ?? []).filter((line) => line !== otherLine)
209
+
210
+ const writes =
211
+ Boolean(layout && layoutPrintsTag(layout, "region")) &&
212
+ keys.some((key) => {
213
+ const word = new RegExp(`(?:^|[\\s,])${escapeRegExp(key)}(?:$|[\\s,])`, "iu")
214
+
215
+ return lines.some((line) => word.test(line))
216
+ })
217
+
218
+ CITED_KEY_FORM_BY_COUNTRY.set(country, writes)
219
+
220
+ return writes
221
+ }
222
+
223
+ /**
224
+ * {@link writtenSubdivisionForISO}, for a country whose cited layout writes libaddressinput's
225
+ * keys (`citationWritesKeys`), or `null` for any other country.
226
+ */
227
+ export function citedSubdivisionForISO(country: string, isoSuffix: string): string | null {
228
+ const code = country.toUpperCase()
229
+
230
+ return citationWritesKeys(code) ? writtenSubdivisionForISO(code, isoSuffix) : null
231
+ }
232
+
135
233
  /**
136
234
  * Every key and name libaddressinput lists for `country`'s subdivisions
137
235
  * (`TX`, `Texas`; `AE`, `Armed Forces (AE)`; `TO`, `Torino`), or none when it lists no subdivisions.
@@ -5,7 +5,6 @@
5
5
  * @file Deterministic canonical-row emission shared by WOF GeoJSON adapters.
6
6
  */
7
7
 
8
- import { formatAddressRow } from "@mailwoman/codex/address/format"
9
8
  import {
10
9
  adminRunJoinForCountry,
11
10
  isLargestFirstSystem,
@@ -17,6 +16,7 @@ import { isPresent } from "@mailwoman/core/values/objects"
17
16
  import { textScript } from "@mailwoman/recognizer/query-shape/script-run"
18
17
 
19
18
  import type { RowSampler, SampledRow } from "#adapters/wof/sample"
19
+ import { formatCorpusRow } from "#surfaces/corpus-row"
20
20
  import type { AdapterOptions, CanonicalRow } from "#types"
21
21
  import { nameValues, normalizeNameKey, type WOFRecord } from "#utils"
22
22
 
@@ -359,7 +359,7 @@ function* renderWOFRows<A extends object>(
359
359
  for (const variant of variantsFor(record, ancestors, slot)) {
360
360
  const rendered = variant.hierarchy
361
361
  ? renderHierarchy(variant.components, variant.layoutCountry ?? record.country)
362
- : formatAddressRow(variant.components, record.country, { singleLine: true })
362
+ : formatCorpusRow(variant.components, record.country, { singleLine: true })
363
363
 
364
364
  if (!rendered) continue
365
365
 
package/lib/adapters.ts CHANGED
@@ -54,6 +54,7 @@ import { gleifAdapter } from "#adapters/gleif/adapter"
54
54
  import { openaddressesAdapter } from "#adapters/openaddresses/adapter"
55
55
  import { osmAdapter } from "#adapters/osm/adapter"
56
56
  import { overtureAdapter } from "#adapters/overture/adapter"
57
+ import { overturePlacesINAdapter } from "#adapters/overture/places-in/adapter"
57
58
  import { defaultAdapterRegistry } from "#adapters/registry"
58
59
  import { wofAdminAdapter } from "#adapters/wof/admin/json/adapter"
59
60
  import { wofPostalcodeAdapter } from "#adapters/wof/postalcode-json/adapter"
@@ -155,6 +156,7 @@ export const BUILTIN_ADAPTERS: readonly CorpusAdapter[] = [
155
156
  tigerAdapter,
156
157
  openaddressesAdapter,
157
158
  overtureAdapter,
159
+ overturePlacesINAdapter,
158
160
  osmAdapter,
159
161
  gnafAdapter,
160
162
  fccBdcAdapter,