@mailwoman/codex 9.3.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/README.md +221 -75
  2. package/lib/address/format.ts +144 -0
  3. package/lib/address/key.ts +134 -0
  4. package/lib/address/layout.ts +189 -0
  5. package/lib/address/layouts/generated.ts +1576 -0
  6. package/lib/address/layouts/index.ts +213 -0
  7. package/lib/address/render.ts +176 -0
  8. package/lib/{address-system-conventions.ts → address/system-conventions.ts} +6 -5
  9. package/lib/component.ts +96 -0
  10. package/lib/country/index.ts +3 -2
  11. package/lib/country/{reference.ts → reference/index.ts} +1 -1
  12. package/lib/country/region-languages.ts +46 -0
  13. package/lib/es/co-official-languages.ts +62 -0
  14. package/lib/es/index.ts +1 -0
  15. package/lib/gb/index.ts +2 -2
  16. package/lib/index.ts +4 -2
  17. package/lib/jp/index.ts +1 -0
  18. package/lib/jp/municipality-register.ts +62 -0
  19. package/lib/kr/index.ts +10 -0
  20. package/lib/kr/sigungu-register.ts +294 -0
  21. package/lib/placetype-map.ts +157 -0
  22. package/lib/postcode/shapes.json +80 -0
  23. package/lib/postcode/shapes.ts +56 -0
  24. package/lib/{postcode-systems.ts → postcode/systems.ts} +8 -1
  25. package/lib/register-completion.ts +24 -0
  26. package/lib/us/index.ts +2 -2
  27. package/lib/us/po-box.ts +37 -10
  28. package/lib/us/{street-directional.ts → street/directional.ts} +1 -1
  29. package/lib/us/{street-suffix.ts → street/suffix.ts} +1 -1
  30. package/out/address/format.d.ts +87 -0
  31. package/out/address/format.d.ts.map +1 -0
  32. package/out/address/format.js +85 -0
  33. package/out/address/format.js.map +1 -0
  34. package/out/address/key.d.ts +67 -0
  35. package/out/address/key.d.ts.map +1 -0
  36. package/out/address/key.js +91 -0
  37. package/out/address/key.js.map +1 -0
  38. package/out/address/layout.d.ts +104 -0
  39. package/out/address/layout.d.ts.map +1 -0
  40. package/out/address/layout.js +123 -0
  41. package/out/address/layout.js.map +1 -0
  42. package/out/address/layouts/generated.d.ts +21 -0
  43. package/out/address/layouts/generated.d.ts.map +1 -0
  44. package/out/address/layouts/generated.js +1380 -0
  45. package/out/address/layouts/generated.js.map +1 -0
  46. package/out/address/layouts/index.d.ts +81 -0
  47. package/out/address/layouts/index.d.ts.map +1 -0
  48. package/out/address/layouts/index.js +184 -0
  49. package/out/address/layouts/index.js.map +1 -0
  50. package/out/address/render.d.ts +64 -0
  51. package/out/address/render.d.ts.map +1 -0
  52. package/out/address/render.js +115 -0
  53. package/out/address/render.js.map +1 -0
  54. package/out/{address-system-conventions.d.ts → address/system-conventions.d.ts} +6 -5
  55. package/out/address/system-conventions.d.ts.map +1 -0
  56. package/out/{address-system-conventions.js → address/system-conventions.js} +2 -2
  57. package/out/address/system-conventions.js.map +1 -0
  58. package/out/au/delivery-service.d.ts.map +1 -1
  59. package/out/au/level-designator.d.ts.map +1 -1
  60. package/out/au/state.d.ts.map +1 -1
  61. package/out/ca/province.d.ts.map +1 -1
  62. package/out/component.d.ts +50 -0
  63. package/out/component.d.ts.map +1 -0
  64. package/out/component.js +84 -0
  65. package/out/component.js.map +1 -0
  66. package/out/country/codes.d.ts +2 -2
  67. package/out/country/codes.d.ts.map +1 -1
  68. package/out/country/display-names.d.ts.map +1 -1
  69. package/out/country/display-names.js.map +1 -1
  70. package/out/country/index.d.ts +3 -2
  71. package/out/country/index.d.ts.map +1 -1
  72. package/out/country/index.js +3 -2
  73. package/out/country/index.js.map +1 -1
  74. package/out/country/{reference-data.d.ts → reference/data.d.ts} +1 -1
  75. package/out/country/reference/data.d.ts.map +1 -0
  76. package/out/country/{reference-data.js → reference/data.js} +1 -1
  77. package/out/country/reference/data.js.map +1 -0
  78. package/out/country/{reference.d.ts → reference/index.d.ts} +1 -1
  79. package/out/country/reference/index.d.ts.map +1 -0
  80. package/out/country/{reference.js → reference/index.js} +2 -2
  81. package/out/country/reference/index.js.map +1 -0
  82. package/out/country/region-languages.d.ts +25 -0
  83. package/out/country/region-languages.d.ts.map +1 -0
  84. package/out/country/region-languages.js +41 -0
  85. package/out/country/region-languages.js.map +1 -0
  86. package/out/de/bundesland.d.ts.map +1 -1
  87. package/out/de/postleitzahl.d.ts.map +1 -1
  88. package/out/de/street-type.d.ts.map +1 -1
  89. package/out/es/co-official-languages.d.ts +37 -0
  90. package/out/es/co-official-languages.d.ts.map +1 -0
  91. package/out/es/co-official-languages.js +61 -0
  92. package/out/es/co-official-languages.js.map +1 -0
  93. package/out/es/index.d.ts +1 -0
  94. package/out/es/index.d.ts.map +1 -1
  95. package/out/es/index.js +1 -0
  96. package/out/es/index.js.map +1 -1
  97. package/out/fr/departement.d.ts.map +1 -1
  98. package/out/fr/region.d.ts.map +1 -1
  99. package/out/gb/country.d.ts.map +1 -1
  100. package/out/gb/index.d.ts +2 -2
  101. package/out/gb/index.d.ts.map +1 -1
  102. package/out/gb/index.js +2 -2
  103. package/out/gb/index.js.map +1 -1
  104. package/out/gb/{postcode-area.d.ts → postcode/area.d.ts} +1 -1
  105. package/out/gb/postcode/area.d.ts.map +1 -0
  106. package/out/gb/{postcode-area.js → postcode/area.js} +1 -1
  107. package/out/gb/postcode/area.js.map +1 -0
  108. package/out/gb/{postcode.d.ts → postcode/index.d.ts} +1 -1
  109. package/out/gb/postcode/index.d.ts.map +1 -0
  110. package/out/gb/{postcode.js → postcode/index.js} +1 -1
  111. package/out/gb/postcode/index.js.map +1 -0
  112. package/out/gb/street-type.d.ts.map +1 -1
  113. package/out/index.d.ts +4 -2
  114. package/out/index.d.ts.map +1 -1
  115. package/out/index.js +4 -2
  116. package/out/index.js.map +1 -1
  117. package/out/jp/address-unit.d.ts.map +1 -1
  118. package/out/jp/index.d.ts +1 -0
  119. package/out/jp/index.d.ts.map +1 -1
  120. package/out/jp/index.js +1 -0
  121. package/out/jp/index.js.map +1 -1
  122. package/out/jp/municipality-register.d.ts +48 -0
  123. package/out/jp/municipality-register.d.ts.map +1 -0
  124. package/out/jp/municipality-register.js +41 -0
  125. package/out/jp/municipality-register.js.map +1 -0
  126. package/out/jp/prefecture.d.ts.map +1 -1
  127. package/out/kr/index.d.ts +10 -0
  128. package/out/kr/index.d.ts.map +1 -0
  129. package/out/kr/index.js +10 -0
  130. package/out/kr/index.js.map +1 -0
  131. package/out/kr/sigungu-register.d.ts +37 -0
  132. package/out/kr/sigungu-register.d.ts.map +1 -0
  133. package/out/kr/sigungu-register.js +283 -0
  134. package/out/kr/sigungu-register.js.map +1 -0
  135. package/out/level-semantics.d.ts.map +1 -1
  136. package/out/level-semantics.js.map +1 -1
  137. package/out/nz/delivery-service.d.ts.map +1 -1
  138. package/out/placetype-map.d.ts +83 -0
  139. package/out/placetype-map.d.ts.map +1 -0
  140. package/out/placetype-map.js +130 -0
  141. package/out/placetype-map.js.map +1 -0
  142. package/out/postcode/shapes.d.ts +47 -0
  143. package/out/postcode/shapes.d.ts.map +1 -0
  144. package/out/postcode/shapes.js +38 -0
  145. package/out/postcode/shapes.js.map +1 -0
  146. package/out/postcode/shapes.json +80 -0
  147. package/out/{postcode-systems.d.ts → postcode/systems.d.ts} +8 -1
  148. package/out/postcode/systems.d.ts.map +1 -0
  149. package/out/{postcode-systems.js → postcode/systems.js} +9 -2
  150. package/out/postcode/systems.js.map +1 -0
  151. package/out/register-completion.d.ts +14 -0
  152. package/out/register-completion.d.ts.map +1 -0
  153. package/out/register-completion.js +23 -0
  154. package/out/register-completion.js.map +1 -0
  155. package/out/us/floor-designator.d.ts.map +1 -1
  156. package/out/us/index.d.ts +2 -2
  157. package/out/us/index.js +2 -2
  158. package/out/us/military-address.d.ts.map +1 -1
  159. package/out/us/po-box.d.ts +6 -0
  160. package/out/us/po-box.d.ts.map +1 -1
  161. package/out/us/po-box.js +35 -10
  162. package/out/us/po-box.js.map +1 -1
  163. package/out/us/state.d.ts.map +1 -1
  164. package/out/us/{street-directional.d.ts → street/directional.d.ts} +1 -1
  165. package/out/us/street/directional.d.ts.map +1 -0
  166. package/out/us/{street-directional.js → street/directional.js} +2 -2
  167. package/out/us/street/directional.js.map +1 -0
  168. package/out/us/{street-suffix.d.ts → street/suffix.d.ts} +1 -1
  169. package/out/us/street/suffix.d.ts.map +1 -0
  170. package/out/us/{street-suffix.js → street/suffix.js} +2 -2
  171. package/out/us/street/suffix.js.map +1 -0
  172. package/out/us/zipcode.d.ts +1 -1
  173. package/out/us/zipcode.d.ts.map +1 -1
  174. package/package.json +120 -30
  175. package/lib/tools/build-country-surface-lexicon.ts +0 -177
  176. package/lib/tools/export-country-surfaces.ts +0 -48
  177. package/lib/tools/generate-country-population.ts +0 -142
  178. package/lib/tools/generate-country-reference.ts +0 -168
  179. package/lib/tools/generate-official-languages.ts +0 -210
  180. package/lib/tools/index.ts +0 -12
  181. package/out/address-system-conventions.d.ts.map +0 -1
  182. package/out/address-system-conventions.js.map +0 -1
  183. package/out/country/reference-data.d.ts.map +0 -1
  184. package/out/country/reference-data.js.map +0 -1
  185. package/out/country/reference.d.ts.map +0 -1
  186. package/out/country/reference.js.map +0 -1
  187. package/out/gb/postcode-area.d.ts.map +0 -1
  188. package/out/gb/postcode-area.js.map +0 -1
  189. package/out/gb/postcode.d.ts.map +0 -1
  190. package/out/gb/postcode.js.map +0 -1
  191. package/out/postcode-systems.d.ts.map +0 -1
  192. package/out/postcode-systems.js.map +0 -1
  193. package/out/tools/build-country-surface-lexicon.d.ts +0 -43
  194. package/out/tools/build-country-surface-lexicon.d.ts.map +0 -1
  195. package/out/tools/build-country-surface-lexicon.js +0 -149
  196. package/out/tools/build-country-surface-lexicon.js.map +0 -1
  197. package/out/tools/export-country-surfaces.d.ts +0 -15
  198. package/out/tools/export-country-surfaces.d.ts.map +0 -1
  199. package/out/tools/export-country-surfaces.js +0 -34
  200. package/out/tools/export-country-surfaces.js.map +0 -1
  201. package/out/tools/generate-country-population.d.ts +0 -42
  202. package/out/tools/generate-country-population.d.ts.map +0 -1
  203. package/out/tools/generate-country-population.js +0 -106
  204. package/out/tools/generate-country-population.js.map +0 -1
  205. package/out/tools/generate-country-reference.d.ts +0 -36
  206. package/out/tools/generate-country-reference.d.ts.map +0 -1
  207. package/out/tools/generate-country-reference.js +0 -107
  208. package/out/tools/generate-country-reference.js.map +0 -1
  209. package/out/tools/generate-official-languages.d.ts +0 -50
  210. package/out/tools/generate-official-languages.d.ts.map +0 -1
  211. package/out/tools/generate-official-languages.js +0 -149
  212. package/out/tools/generate-official-languages.js.map +0 -1
  213. package/out/tools/index.d.ts +0 -12
  214. package/out/tools/index.d.ts.map +0 -1
  215. package/out/tools/index.js +0 -12
  216. package/out/tools/index.js.map +0 -1
  217. package/out/us/street-directional.d.ts.map +0 -1
  218. package/out/us/street-directional.js.map +0 -1
  219. package/out/us/street-suffix.d.ts.map +0 -1
  220. package/out/us/street-suffix.js.map +0 -1
  221. /package/lib/country/{reference-data.ts → reference/data.ts} +0 -0
  222. /package/lib/gb/{postcode-area.ts → postcode/area.ts} +0 -0
  223. /package/lib/gb/{postcode.ts → postcode/index.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mailwoman/codex",
3
- "version": "9.3.0",
3
+ "version": "10.0.0",
4
4
  "description": "Per-address-system postal reference data + branded types (USPS street suffixes, US ZIP codes). Pure, zero-runtime-dep — the shared canonical home for postal-system primitives the parser, resolver, and synthesis layers all reach for.",
5
5
  "license": "AGPL-3.0-only OR LicenseRef-Commercial",
6
6
  "repository": {
@@ -23,6 +23,8 @@
23
23
  "!**/*.test.tsx",
24
24
  "lib/us/street-suffix.json",
25
25
  "out/us/street-suffix.json",
26
+ "lib/postcode/shapes.json",
27
+ "out/postcode/shapes.json",
26
28
  "!test/**"
27
29
  ],
28
30
  "type": "module",
@@ -85,10 +87,45 @@
85
87
  "node": "./out/nz/index.js",
86
88
  "default": "./out/nz/index.js"
87
89
  },
88
- "./tools": {
89
- "types": "./out/tools/index.d.ts",
90
- "node": "./out/tools/index.js",
91
- "default": "./out/tools/index.js"
90
+ "./address-layout": {
91
+ "types": "./out/address/layout.d.ts",
92
+ "node": "./out/address/layout.js",
93
+ "default": "./out/address/layout.js"
94
+ },
95
+ "./address-layouts": {
96
+ "types": "./out/address/layouts/index.d.ts",
97
+ "node": "./out/address/layouts/index.js",
98
+ "default": "./out/address/layouts/index.js"
99
+ },
100
+ "./address-layouts-generated": {
101
+ "types": "./out/address/layouts/generated.d.ts",
102
+ "node": "./out/address/layouts/generated.js",
103
+ "default": "./out/address/layouts/generated.js"
104
+ },
105
+ "./address-render": {
106
+ "types": "./out/address/render.d.ts",
107
+ "node": "./out/address/render.js",
108
+ "default": "./out/address/render.js"
109
+ },
110
+ "./address-format": {
111
+ "types": "./out/address/format.d.ts",
112
+ "node": "./out/address/format.js",
113
+ "default": "./out/address/format.js"
114
+ },
115
+ "./address-key": {
116
+ "types": "./out/address/key.d.ts",
117
+ "node": "./out/address/key.js",
118
+ "default": "./out/address/key.js"
119
+ },
120
+ "./component": {
121
+ "types": "./out/component.d.ts",
122
+ "node": "./out/component.js",
123
+ "default": "./out/component.js"
124
+ },
125
+ "./placetype-map": {
126
+ "types": "./out/placetype-map.d.ts",
127
+ "node": "./out/placetype-map.js",
128
+ "default": "./out/placetype-map.js"
92
129
  },
93
130
  "./normalize": {
94
131
  "types": "./out/normalize.d.ts",
@@ -106,19 +143,24 @@
106
143
  "default": "./out/it/index.js"
107
144
  },
108
145
  "./address-system-conventions": {
109
- "types": "./out/address-system-conventions.d.ts",
110
- "node": "./out/address-system-conventions.js",
111
- "default": "./out/address-system-conventions.js"
146
+ "types": "./out/address/system-conventions.d.ts",
147
+ "node": "./out/address/system-conventions.js",
148
+ "default": "./out/address/system-conventions.js"
112
149
  },
113
150
  "./level-semantics": {
114
151
  "types": "./out/level-semantics.d.ts",
115
152
  "node": "./out/level-semantics.js",
116
153
  "default": "./out/level-semantics.js"
117
154
  },
155
+ "./postcode-shapes": {
156
+ "types": "./out/postcode/shapes.d.ts",
157
+ "node": "./out/postcode/shapes.js",
158
+ "default": "./out/postcode/shapes.js"
159
+ },
118
160
  "./postcode-systems": {
119
- "types": "./out/postcode-systems.d.ts",
120
- "node": "./out/postcode-systems.js",
121
- "default": "./out/postcode-systems.js"
161
+ "types": "./out/postcode/systems.d.ts",
162
+ "node": "./out/postcode/systems.js",
163
+ "default": "./out/postcode/systems.js"
122
164
  },
123
165
  "./us/floor-designator": {
124
166
  "types": "./out/us/floor-designator.d.ts",
@@ -131,14 +173,19 @@
131
173
  "default": "./out/us/state.js"
132
174
  },
133
175
  "./us/street-suffix": {
134
- "types": "./out/us/street-suffix.d.ts",
135
- "node": "./out/us/street-suffix.js",
136
- "default": "./out/us/street-suffix.js"
176
+ "types": "./out/us/street/suffix.d.ts",
177
+ "node": "./out/us/street/suffix.js",
178
+ "default": "./out/us/street/suffix.js"
137
179
  },
138
180
  "./us/unit-designator": {
139
181
  "types": "./out/us/unit-designator.d.ts",
140
182
  "node": "./out/us/unit-designator.js",
141
183
  "default": "./out/us/unit-designator.js"
184
+ },
185
+ "./kr": {
186
+ "types": "./out/kr/index.d.ts",
187
+ "node": "./out/kr/index.js",
188
+ "default": "./out/kr/index.js"
142
189
  }
143
190
  },
144
191
  "publishConfig": {
@@ -195,10 +242,45 @@
195
242
  "node": "./out/nz/index.js",
196
243
  "default": "./out/nz/index.js"
197
244
  },
198
- "./tools": {
199
- "types": "./out/tools/index.d.ts",
200
- "node": "./out/tools/index.js",
201
- "default": "./out/tools/index.js"
245
+ "./address-layout": {
246
+ "types": "./out/address/layout.d.ts",
247
+ "node": "./out/address/layout.js",
248
+ "default": "./out/address/layout.js"
249
+ },
250
+ "./address-layouts": {
251
+ "types": "./out/address/layouts/index.d.ts",
252
+ "node": "./out/address/layouts/index.js",
253
+ "default": "./out/address/layouts/index.js"
254
+ },
255
+ "./address-layouts-generated": {
256
+ "types": "./out/address/layouts/generated.d.ts",
257
+ "node": "./out/address/layouts/generated.js",
258
+ "default": "./out/address/layouts/generated.js"
259
+ },
260
+ "./address-render": {
261
+ "types": "./out/address/render.d.ts",
262
+ "node": "./out/address/render.js",
263
+ "default": "./out/address/render.js"
264
+ },
265
+ "./address-format": {
266
+ "types": "./out/address/format.d.ts",
267
+ "node": "./out/address/format.js",
268
+ "default": "./out/address/format.js"
269
+ },
270
+ "./address-key": {
271
+ "types": "./out/address/key.d.ts",
272
+ "node": "./out/address/key.js",
273
+ "default": "./out/address/key.js"
274
+ },
275
+ "./component": {
276
+ "types": "./out/component.d.ts",
277
+ "node": "./out/component.js",
278
+ "default": "./out/component.js"
279
+ },
280
+ "./placetype-map": {
281
+ "types": "./out/placetype-map.d.ts",
282
+ "node": "./out/placetype-map.js",
283
+ "default": "./out/placetype-map.js"
202
284
  },
203
285
  "./normalize": {
204
286
  "types": "./out/normalize.d.ts",
@@ -216,19 +298,24 @@
216
298
  "default": "./out/it/index.js"
217
299
  },
218
300
  "./address-system-conventions": {
219
- "types": "./out/address-system-conventions.d.ts",
220
- "node": "./out/address-system-conventions.js",
221
- "default": "./out/address-system-conventions.js"
301
+ "types": "./out/address/system-conventions.d.ts",
302
+ "node": "./out/address/system-conventions.js",
303
+ "default": "./out/address/system-conventions.js"
222
304
  },
223
305
  "./level-semantics": {
224
306
  "types": "./out/level-semantics.d.ts",
225
307
  "node": "./out/level-semantics.js",
226
308
  "default": "./out/level-semantics.js"
227
309
  },
310
+ "./postcode-shapes": {
311
+ "types": "./out/postcode/shapes.d.ts",
312
+ "node": "./out/postcode/shapes.js",
313
+ "default": "./out/postcode/shapes.js"
314
+ },
228
315
  "./postcode-systems": {
229
- "types": "./out/postcode-systems.d.ts",
230
- "node": "./out/postcode-systems.js",
231
- "default": "./out/postcode-systems.js"
316
+ "types": "./out/postcode/systems.d.ts",
317
+ "node": "./out/postcode/systems.js",
318
+ "default": "./out/postcode/systems.js"
232
319
  },
233
320
  "./us/floor-designator": {
234
321
  "types": "./out/us/floor-designator.d.ts",
@@ -241,14 +328,19 @@
241
328
  "default": "./out/us/state.js"
242
329
  },
243
330
  "./us/street-suffix": {
244
- "types": "./out/us/street-suffix.d.ts",
245
- "node": "./out/us/street-suffix.js",
246
- "default": "./out/us/street-suffix.js"
331
+ "types": "./out/us/street/suffix.d.ts",
332
+ "node": "./out/us/street/suffix.js",
333
+ "default": "./out/us/street/suffix.js"
247
334
  },
248
335
  "./us/unit-designator": {
249
336
  "types": "./out/us/unit-designator.d.ts",
250
337
  "node": "./out/us/unit-designator.js",
251
338
  "default": "./out/us/unit-designator.js"
339
+ },
340
+ "./kr": {
341
+ "types": "./out/kr/index.d.ts",
342
+ "node": "./out/kr/index.js",
343
+ "default": "./out/kr/index.js"
252
344
  }
253
345
  },
254
346
  "imports": {
@@ -263,8 +355,6 @@
263
355
  "type-fest": "^5.9.0"
264
356
  },
265
357
  "devDependencies": {
266
- "@mailwoman/annotations": "9.3.0",
267
- "@mailwoman/core": "9.3.0",
268
- "path-ts": "^2.3.0"
358
+ "@mailwoman/annotations": "10.0.0"
269
359
  }
270
360
  }
@@ -1,177 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * Build the COUNTRY-SURFACE LEXICON for the country-lexicon soft-feed channel (#1104). This is the
7
- * third atlas channel, a sibling of the postcode anchor (#239/#240) and the gazetteer anchor
8
- * (#464): a per-token multi-hot clue the neural GRAMMAR conditions on but never obeys. Country is a
9
- * CLOSED, ENUMERABLE class (~250 surfaces) — atlas, not grammar — so a dictionary phrase-lookup
10
- * recovers the WOF-admin / resolver hierarchy case ("United States of America, Wyoming, <locality>")
11
- * the learned tagger reads as a leading STREET. Pelias handled the same class the same way
12
- * (`WhosOnFirstClassifier extends PhraseClassifier`); this is the model-first analogue.
13
- *
14
- * WHY A DEDICATED LEXICON (not just the gazetteer's `country` slot): the gazetteer already carries
15
- * these surfaces in slot 0, and the shipped model already consumes them — yet the WOF-admin case
16
- * still fails (model-card #1104: golden country recall 82.0% vs 88.6%). The country bit is one of a
17
- * 5-hot vector sharing ONE learned projection with region/po_box/cedex/homograph, and it is ZEROED
18
- * adjacent to a postcode by `suppress_gazetteer_near_postcode` (exactly where a trailing "…12345
19
- * USA" sits). A dedicated channel de-entangles the country signal (its own projection + confidence
20
- * weight) and is immune to that suppression. See
21
- * docs/superpowers/plans/2026-07-14-country-lexicon-channel.md.
22
- *
23
- * The matcher REUSES the gazetteer's phrase-scan (longest-first n-gram over whitespace words,
24
- * case-insensitive `entries` + uppercase-exact `code_entries`, char→piece projection) — one tested
25
- * algorithm, two vocabularies. Only the vocabulary + the emitted feature differ. The emitted
26
- * feature is 2-dim per piece: `[country_surface, country_ambiguous]`.
27
- *
28
- * - `country_surface` (bit 1): the piece is part of a recognized country surface phrase.
29
- * - `country_ambiguous` (bit 2): the SURFACE is a homograph (also a US region) or a common-word
30
- * name ("Georgia", "America", "England", "IN") — a SOFT version of Pelias's hard blacklist. The
31
- * model learns to trust `surface & !ambiguous` (unambiguous long/code forms) strongly and
32
- * `surface & ambiguous` weakly, using context — model-first, never a hard drop, so recall on
33
- * "Republic of Georgia" is preserved.
34
- *
35
- * Source of truth: `@mailwoman/codex` (COUNTRY_SURFACE_FORMS + ISO2_TO_NAME) — the SAME data the
36
- * corpus-python bridge `country-surfaces.json` is generated from (export-country-surfaces.ts), so
37
- * the channel and the corpus extract synthesizer cannot diverge on what a country surface IS.
38
- *
39
- * Output: data/gazetteer/country-surface-lexicon-v1.json (small, committed, provenance-tracked).
40
- * Regenerate: `node codex/tools/build-country-surface-lexicon.ts`
41
- */
42
-
43
- import { makeDirectories, writeLocalTextFile } from "@mailwoman/core/fs/writers"
44
- import { repoRootPath } from "@mailwoman/core/paths"
45
- import { dirname } from "path-ts"
46
-
47
- import { COUNTRY_SURFACE_FORMS, ISO2_TO_NAME } from "#country/country"
48
- import { wordNorm, wordNormLower } from "#normalize"
49
- import { US_STATE_ABBREVIATIONS, US_STATE_NAMES } from "#us/state"
50
-
51
- /**
52
- * Ambiguous entries printed before the list is truncated.
53
- */
54
- const MAX_LISTED_AMBIGUOUS = 12
55
-
56
- /**
57
- * Letters at or below which a token reads as an abbreviation rather than a word.
58
- */
59
- const MAX_ABBREVIATION_LETTERS = 3
60
-
61
- const BIT = { country_surface: 1, country_ambiguous: 2 }
62
- const SLOTS = ["country_surface", "country_ambiguous"]
63
-
64
- /**
65
- * Committed output path (a codex-derived artifact, like export-country-surfaces.ts — no argv, so the no-process-globals
66
- * lint policy holds; codex stays zero-runtime-dep).
67
- */
68
- const OUTPUT = repoRootPath("data", "gazetteer", "country-surface-lexicon-v1.json")
69
-
70
- /**
71
- * THE shared word-normalization rule (identical to build-gazetteer-anchor-lexicon.mjs and mirrored in
72
- * gazetteer_char_paint on both sides): per whitespace-word, strip LEADING/TRAILING characters that are not Unicode
73
- * letters or digits (keep internal ones: "u.s.a", "timor-leste"), rejoin single-spaced. Entry keys and scanned tokens
74
- * both pass through it, so "U.S.A." ≡ "u.s.a".
75
- */
76
- /**
77
- * Short alphabetic code (≤3 letters once punctuation is dropped) → exact-uppercase matching.
78
- */
79
- const isShortCode = (s: string): boolean => {
80
- const letters = s.replaceAll(/[^\p{L}]/gu, "")
81
-
82
- return letters.length > 0 && letters.length <= MAX_ABBREVIATION_LETTERS && /^[\p{L}.\s]+$/u.test(s)
83
- }
84
-
85
- // Homograph set: a single-word country surface that is ALSO a US region (name or abbreviation) reads
86
- // ambiguously (Georgia the country vs the state, IN = India vs Indiana). Computed from codex so it
87
- // tracks the US region table, never hand-maintained.
88
- const usStateNames = new Set(US_STATE_NAMES.map((n) => n.toLowerCase()))
89
- const usStateAbbrevs = new Set<string>(US_STATE_ABBREVIATIONS as readonly string[])
90
-
91
- /**
92
- * Curated common-word country surfaces — single tokens that appear far more often as ordinary street/venue/locality
93
- * words than as a trailing country. A SOFT flag (the model still decides), the model-first analogue of Pelias's
94
- * blacklist (north/south/east/west/street/city/king). Tunable.
95
- */
96
- const COMMON_WORD_AMBIGUOUS = new Set(["america", "england", "britain", "turkey", "chad", "jordan", "jersey", "guinea"])
97
-
98
- const isAmbiguousName = (lowerKey: string): boolean => usStateNames.has(lowerKey) || COMMON_WORD_AMBIGUOUS.has(lowerKey)
99
-
100
- // surface → bits, split across the two match-rule maps (mirrors the gazetteer builder).
101
- const entries = new Map<string, number>() // lowercase key
102
- const codeEntries = new Map<string, number>() // exact-uppercase key
103
- let maxNgram = 1
104
-
105
- function add(surface: string): void {
106
- const s = surface.trim()
107
-
108
- if (!s) return
109
-
110
- if (isShortCode(s)) {
111
- const key = wordNorm(s).toUpperCase()
112
-
113
- if (!key) return
114
- // A code that collides with a US-state abbreviation (CA/IN/AL/CO/…) is a homograph → ambiguous.
115
- const bits = BIT.country_surface | (usStateAbbrevs.has(key) ? BIT.country_ambiguous : 0)
116
- codeEntries.set(key, (codeEntries.get(key) ?? 0) | bits)
117
-
118
- return
119
- }
120
-
121
- const key = wordNormLower(s)
122
-
123
- if (!key) return
124
- const words = key.split(" ")
125
- maxNgram = Math.max(maxNgram, words.length)
126
- // Multi-word phrases are unambiguous by construction; single tokens consult the homograph +
127
- // common-word rule.
128
- const ambiguous = words.length === 1 && isAmbiguousName(key)
129
- const bits = BIT.country_surface | (ambiguous ? BIT.country_ambiguous : 0)
130
- entries.set(key, (entries.get(key) ?? 0) | bits)
131
- }
132
-
133
- // Curated rich surface forms first (US/GB/DE/… endonyms + abbreviations), then the canonical English
134
- // name for every remaining ISO 3166-1 alpha-2 — exactly the merge country-surfaces.json performs.
135
- for (const forms of Object.values(COUNTRY_SURFACE_FORMS)) {
136
- for (const f of forms) {
137
- add(f)
138
- }
139
- }
140
-
141
- for (const [, name] of ISO2_TO_NAME) {
142
- add(name)
143
- }
144
-
145
- const ambiguousEntries = [...entries, ...codeEntries].filter(([, b]) => b & BIT.country_ambiguous).map(([k]) => k)
146
-
147
- const lexicon = {
148
- version: 1,
149
- generated_by:
150
- "codex/tools/build-country-surface-lexicon.ts (source: @mailwoman/codex COUNTRY_SURFACE_FORMS + ISO2_TO_NAME)",
151
- feature_dim: SLOTS.length,
152
- slots: SLOTS,
153
- bits: BIT,
154
- max_ngram: maxNgram,
155
- rules: {
156
- word_norm:
157
- "per whitespace-word: strip leading/trailing chars that are not Unicode letters/digits " +
158
- "(keep internal: 'timor-leste', 'u.s.a'); rejoin single-spaced. Applied to BOTH entry keys and scanned tokens.",
159
- entries:
160
- "case-insensitive; key = word_norm lowercased. country_surface always set; country_ambiguous set for single-token homographs (US region) or curated common-word names.",
161
- code_entries:
162
- "case-SENSITIVE exact: word_norm(token) == key (keys uppercase; 'in' the word ≠ 'IN' India). n-gram length 1. country_ambiguous set when the code is also a US-state abbreviation.",
163
- scan: "longest-first n-gram over whitespace words, left to right, non-overlapping (shared with the gazetteer matcher)",
164
- feature:
165
- "emitted per-piece row = [country_surface, country_ambiguous] (the raw bits); confidence = 1.0 where country_surface fires.",
166
- },
167
- entries: Object.fromEntries([...entries].toSorted(([a], [b]) => a.localeCompare(b))),
168
- code_entries: Object.fromEntries([...codeEntries].toSorted(([a], [b]) => a.localeCompare(b))),
169
- }
170
-
171
- await makeDirectories(dirname(OUTPUT))
172
- await writeLocalTextFile(JSON.stringify(lexicon, null, 1) + "\n", OUTPUT)
173
-
174
- process.stderr.write(
175
- `wrote ${OUTPUT}: ${entries.size} entries + ${codeEntries.size} code_entries, ` +
176
- `max_ngram=${maxNgram}, ${ambiguousEntries.length} ambiguous: ${ambiguousEntries.slice(0, MAX_LISTED_AMBIGUOUS).join(", ")}${ambiguousEntries.length > MAX_LISTED_AMBIGUOUS ? ", …" : ""}\n`
177
- )
@@ -1,48 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * codex → corpus-python bridge: emit the authoritative country surface forms as JSON so the Python
7
- * extract generators can synthesize address tails ("…, USA" / "…, United States of America") without
8
- * re-deriving the country name/alias data. `@mailwoman/codex` stays the single source of truth
9
- * (COUNTRY_SURFACE_FORMS + ISO2_TO_NAME, salvaged from isp-nexus spatial/countries); this writes a
10
- * snapshot the language boundary can't import directly.
11
- *
12
- * Regenerate: `node codex/tools/export-country-surfaces.ts` (writes the corpus-python data file).
13
- */
14
-
15
- import { writeLocalTextFile } from "@mailwoman/core/fs/writers"
16
- import { repoRootPath } from "@mailwoman/core/paths"
17
-
18
- import { COUNTRY_SURFACE_FORMS, ISO2_TO_NAME } from "#country/country"
19
-
20
- // Merge: rich surface forms where the codex curates them, else the canonical English name for every
21
- // ISO 3166-1 alpha-2. Canonical-name-first (the codex's own ordering) so the common form leads.
22
- const surfaces: Record<string, string[]> = {}
23
-
24
- for (const [iso2, forms] of Object.entries(COUNTRY_SURFACE_FORMS)) {
25
- surfaces[iso2] = [...forms]
26
- }
27
-
28
- for (const [iso2, name] of ISO2_TO_NAME) {
29
- if (!surfaces[iso2]) {
30
- surfaces[iso2] = [name]
31
- }
32
- }
33
-
34
- const out = repoRootPath("corpus-python", "src", "mailwoman_train", "data", "country-surfaces.json")
35
-
36
- await writeLocalTextFile(
37
- JSON.stringify(
38
- {
39
- _generated: "codex/tools/export-country-surfaces.ts from @mailwoman/codex COUNTRY_SURFACE_FORMS + ISO2_TO_NAME",
40
- surfaces,
41
- },
42
- null,
43
- 2
44
- ) + "\n",
45
- out
46
- )
47
-
48
- process.stderr.write(`wrote ${Object.keys(surfaces).length} countries → ${out}\n`)
@@ -1,142 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * Regenerate `codex/country/population.ts` — the per-country population table — from GeoNames
7
- * `countryInfo.txt` (https://download.geonames.org/export/dump/countryInfo.txt, CC-BY-4.0). The
8
- * output is committed; this tool makes it reproducible (provenance), not a hand-typed dictionary.
9
- *
10
- * Why it exists (#1650): WOF carries no readable population for 147 of 237 country records
11
- * (measured against the 2026-08-18 candidate build), so those countries entered every prominence
12
- * race at an asserted ZERO — ranked below any namesake hamlet. The magnitude is what a fame race
13
- * reads, so a census-vintage figure is entirely sufficient; currency of the estimate is not the
14
- * point.
15
- *
16
- * Rows whose GeoNames population is 0 are DROPPED rather than emitted: an entry in this table is a
17
- * positive claim, and the consumer's absence branch (`?? undefined`) must stay reachable for
18
- * territories GeoNames itself declines to estimate (the meaning-of-zero rule).
19
- *
20
- * Usage: mailwoman dev generate country-population
21
- */
22
-
23
- import { APIClient, pluckResponseData } from "@mailwoman/core/api"
24
- import { writeLocalTextFile } from "@mailwoman/core/fs/writers"
25
- import { resolvePackagePath } from "@mailwoman/core/module/resolvers"
26
-
27
- const SOURCE = "https://download.geonames.org/export/dump/countryInfo.txt"
28
-
29
- /**
30
- * The committed output path, resolved relative to this module (codex/tools/ → codex/country/). See
31
- * `generate-country-reference.ts` for why this is `import.meta.url` rather than a `core` path helper (codex is
32
- * zero-runtime-dep and `core` already references `codex` — importing core here would cycle the project graph).
33
- */
34
- const DEFAULT_OUT = resolvePackagePath("@mailwoman/codex", "lib", "country", "population.ts")
35
-
36
- /**
37
- * Tab positions this tool reads from `countryInfo.txt`'s 19-column rows. Named so the parse states which columns it
38
- * believes in; a GeoNames format change fails the count guard below rather than silently reading the wrong column.
39
- */
40
- const COLUMN_ISO2 = 0
41
- const COLUMN_POPULATION = 7
42
- const MINIMUM_COLUMNS = 8
43
-
44
- /**
45
- * GeoNames publishes ~250 countries/territories; a parse recovering fewer than this read the wrong column or a
46
- * truncated body, and the guard fails loudly instead of committing a hollow table.
47
- */
48
- const MINIMUM_PLAUSIBLE_COUNTRIES = 200
49
-
50
- /**
51
- * Numbers below five digits are emitted bare — the house numeric-separator style groups by three and only from five
52
- * digits up (`8450`, not `8_450`).
53
- */
54
- const SEPARATOR_MINIMUM = 10_000
55
-
56
- /**
57
- * Options for {@linkcode generateCountryPopulation}.
58
- */
59
- export interface GenerateCountryPopulationOptions {
60
- /**
61
- * Output path override. Default: `codex/country/population.ts` (the committed table).
62
- */
63
- out?: string
64
- }
65
-
66
- /**
67
- * Summary returned by {@linkcode generateCountryPopulation}.
68
- */
69
- export interface GenerateCountryPopulationSummary {
70
- countries: number
71
- outPath: string
72
- }
73
-
74
- /**
75
- * Fetch GeoNames `countryInfo.txt` and regenerate the committed `COUNTRY_POPULATION` table.
76
- */
77
- export async function generateCountryPopulation(
78
- options: GenerateCountryPopulationOptions = {},
79
- report?: (line: string) => void
80
- ): Promise<GenerateCountryPopulationSummary> {
81
- const outPath = options.out ?? DEFAULT_OUT
82
-
83
- // `responseType: "text"` because the source is a tab-separated dump, not JSON.
84
- const text = await new APIClient({ displayName: "geonames-country-info", retry: true })
85
- .fetch<string>({ url: SOURCE, responseType: "text" })
86
- .then(pluckResponseData)
87
-
88
- const rows: Record<string, number> = {}
89
-
90
- // oxlint-disable-next-line mailwoman/prefer-spliterator -- countryInfo.txt is ~35 kB and bounded (~300 rows)
91
- for (const line of text.split("\n")) {
92
- if (!line || line.startsWith("#")) continue
93
- // oxlint-disable-next-line mailwoman/prefer-spliterator -- one 19-column row
94
- const columns = line.split("\t")
95
-
96
- if (columns.length < MINIMUM_COLUMNS) continue
97
- const alpha2 = columns[COLUMN_ISO2]!.trim()
98
- const population = Number(columns[COLUMN_POPULATION])
99
-
100
- if (!/^[A-Z]{2}$/.test(alpha2)) continue
101
-
102
- if (!Number.isFinite(population) || population <= 0) continue
103
-
104
- rows[alpha2] = population
105
- }
106
-
107
- if (Object.keys(rows).length < MINIMUM_PLAUSIBLE_COUNTRIES) {
108
- throw new Error(`generateCountryPopulation: only ${Object.keys(rows).length} rows parsed — format drift?`)
109
- }
110
-
111
- const body = Object.keys(rows)
112
- .toSorted()
113
- .map((k) => {
114
- const n = rows[k]!
115
- const literal = n >= SEPARATOR_MINIMUM ? n.toLocaleString("en-US").replaceAll(",", "_") : String(n)
116
-
117
- return `\t${k}: ${literal},`
118
- })
119
- .join("\n")
120
-
121
- const header = `/**
122
- * @copyright Sister Software
123
- * @license AGPL-3.0
124
- * @author Teffen Ellis, et al.
125
- *
126
- * GENERATED — do not edit by hand. Per-country population, derived from GeoNames countryInfo.txt
127
- * (https://download.geonames.org/export/dump/countryInfo.txt, CC-BY-4.0). Estimates are
128
- * census-vintage; a prominence race reads the magnitude, not the currency. Countries GeoNames
129
- * declines to estimate are ABSENT, never zero.
130
- * Regenerate with: mailwoman dev generate country-population
131
- */
132
-
133
- /**
134
- * ISO 3166-1 alpha-2 → population estimate.
135
- */
136
- export const COUNTRY_POPULATION: Readonly<Record<string, number>> = {`
137
-
138
- await writeLocalTextFile(`${header}\n${body}\n}\n`, outPath)
139
- report?.(`wrote ${outPath} (${Object.keys(rows).length} countries)`)
140
-
141
- return { countries: Object.keys(rows).length, outPath }
142
- }