@mailwoman/codex 9.4.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.
- package/README.md +221 -75
- package/lib/address/format.ts +144 -0
- package/lib/address/key.ts +134 -0
- package/lib/address/layout.ts +189 -0
- package/lib/address/layouts/generated.ts +1576 -0
- package/lib/address/layouts/index.ts +213 -0
- package/lib/address/render.ts +176 -0
- package/lib/{address-system-conventions.ts → address/system-conventions.ts} +6 -5
- package/lib/component.ts +96 -0
- package/lib/country/index.ts +3 -2
- package/lib/country/{reference.ts → reference/index.ts} +1 -1
- package/lib/country/region-languages.ts +46 -0
- package/lib/es/co-official-languages.ts +62 -0
- package/lib/es/index.ts +1 -0
- package/lib/gb/index.ts +2 -2
- package/lib/index.ts +4 -2
- package/lib/placetype-map.ts +157 -0
- package/lib/postcode/shapes.json +80 -0
- package/lib/postcode/shapes.ts +56 -0
- package/lib/{postcode-systems.ts → postcode/systems.ts} +8 -1
- package/lib/us/index.ts +2 -2
- package/lib/us/po-box.ts +37 -10
- package/lib/us/{street-directional.ts → street/directional.ts} +1 -1
- package/lib/us/{street-suffix.ts → street/suffix.ts} +1 -1
- package/out/address/format.d.ts +87 -0
- package/out/address/format.d.ts.map +1 -0
- package/out/address/format.js +85 -0
- package/out/address/format.js.map +1 -0
- package/out/address/key.d.ts +67 -0
- package/out/address/key.d.ts.map +1 -0
- package/out/address/key.js +91 -0
- package/out/address/key.js.map +1 -0
- package/out/address/layout.d.ts +104 -0
- package/out/address/layout.d.ts.map +1 -0
- package/out/address/layout.js +123 -0
- package/out/address/layout.js.map +1 -0
- package/out/address/layouts/generated.d.ts +21 -0
- package/out/address/layouts/generated.d.ts.map +1 -0
- package/out/address/layouts/generated.js +1380 -0
- package/out/address/layouts/generated.js.map +1 -0
- package/out/address/layouts/index.d.ts +81 -0
- package/out/address/layouts/index.d.ts.map +1 -0
- package/out/address/layouts/index.js +184 -0
- package/out/address/layouts/index.js.map +1 -0
- package/out/address/render.d.ts +64 -0
- package/out/address/render.d.ts.map +1 -0
- package/out/address/render.js +115 -0
- package/out/address/render.js.map +1 -0
- package/out/{address-system-conventions.d.ts → address/system-conventions.d.ts} +6 -5
- package/out/address/system-conventions.d.ts.map +1 -0
- package/out/{address-system-conventions.js → address/system-conventions.js} +2 -2
- package/out/address/system-conventions.js.map +1 -0
- package/out/au/delivery-service.d.ts.map +1 -1
- package/out/au/level-designator.d.ts.map +1 -1
- package/out/au/state.d.ts.map +1 -1
- package/out/ca/province.d.ts.map +1 -1
- package/out/component.d.ts +50 -0
- package/out/component.d.ts.map +1 -0
- package/out/component.js +84 -0
- package/out/component.js.map +1 -0
- package/out/country/codes.d.ts +2 -2
- package/out/country/codes.d.ts.map +1 -1
- package/out/country/display-names.d.ts.map +1 -1
- package/out/country/display-names.js.map +1 -1
- package/out/country/index.d.ts +3 -2
- package/out/country/index.d.ts.map +1 -1
- package/out/country/index.js +3 -2
- package/out/country/index.js.map +1 -1
- package/out/country/{reference-data.d.ts → reference/data.d.ts} +1 -1
- package/out/country/reference/data.d.ts.map +1 -0
- package/out/country/{reference-data.js → reference/data.js} +1 -1
- package/out/country/reference/data.js.map +1 -0
- package/out/country/{reference.d.ts → reference/index.d.ts} +1 -1
- package/out/country/reference/index.d.ts.map +1 -0
- package/out/country/{reference.js → reference/index.js} +2 -2
- package/out/country/reference/index.js.map +1 -0
- package/out/country/region-languages.d.ts +25 -0
- package/out/country/region-languages.d.ts.map +1 -0
- package/out/country/region-languages.js +41 -0
- package/out/country/region-languages.js.map +1 -0
- package/out/de/bundesland.d.ts.map +1 -1
- package/out/de/postleitzahl.d.ts.map +1 -1
- package/out/de/street-type.d.ts.map +1 -1
- package/out/es/co-official-languages.d.ts +37 -0
- package/out/es/co-official-languages.d.ts.map +1 -0
- package/out/es/co-official-languages.js +61 -0
- package/out/es/co-official-languages.js.map +1 -0
- package/out/es/index.d.ts +1 -0
- package/out/es/index.d.ts.map +1 -1
- package/out/es/index.js +1 -0
- package/out/es/index.js.map +1 -1
- package/out/fr/departement.d.ts.map +1 -1
- package/out/fr/region.d.ts.map +1 -1
- package/out/gb/country.d.ts.map +1 -1
- package/out/gb/index.d.ts +2 -2
- package/out/gb/index.d.ts.map +1 -1
- package/out/gb/index.js +2 -2
- package/out/gb/index.js.map +1 -1
- package/out/gb/{postcode-area.d.ts → postcode/area.d.ts} +1 -1
- package/out/gb/postcode/area.d.ts.map +1 -0
- package/out/gb/{postcode-area.js → postcode/area.js} +1 -1
- package/out/gb/postcode/area.js.map +1 -0
- package/out/gb/{postcode.d.ts → postcode/index.d.ts} +1 -1
- package/out/gb/postcode/index.d.ts.map +1 -0
- package/out/gb/{postcode.js → postcode/index.js} +1 -1
- package/out/gb/postcode/index.js.map +1 -0
- package/out/gb/street-type.d.ts.map +1 -1
- package/out/index.d.ts +4 -2
- package/out/index.d.ts.map +1 -1
- package/out/index.js +4 -2
- package/out/index.js.map +1 -1
- package/out/jp/address-unit.d.ts.map +1 -1
- package/out/jp/prefecture.d.ts.map +1 -1
- package/out/level-semantics.d.ts.map +1 -1
- package/out/level-semantics.js.map +1 -1
- package/out/nz/delivery-service.d.ts.map +1 -1
- package/out/placetype-map.d.ts +83 -0
- package/out/placetype-map.d.ts.map +1 -0
- package/out/placetype-map.js +130 -0
- package/out/placetype-map.js.map +1 -0
- package/out/postcode/shapes.d.ts +47 -0
- package/out/postcode/shapes.d.ts.map +1 -0
- package/out/postcode/shapes.js +38 -0
- package/out/postcode/shapes.js.map +1 -0
- package/out/postcode/shapes.json +80 -0
- package/out/{postcode-systems.d.ts → postcode/systems.d.ts} +8 -1
- package/out/postcode/systems.d.ts.map +1 -0
- package/out/{postcode-systems.js → postcode/systems.js} +9 -2
- package/out/postcode/systems.js.map +1 -0
- package/out/us/floor-designator.d.ts.map +1 -1
- package/out/us/index.d.ts +2 -2
- package/out/us/index.js +2 -2
- package/out/us/military-address.d.ts.map +1 -1
- package/out/us/po-box.d.ts +6 -0
- package/out/us/po-box.d.ts.map +1 -1
- package/out/us/po-box.js +35 -10
- package/out/us/po-box.js.map +1 -1
- package/out/us/state.d.ts.map +1 -1
- package/out/us/{street-directional.d.ts → street/directional.d.ts} +1 -1
- package/out/us/street/directional.d.ts.map +1 -0
- package/out/us/{street-directional.js → street/directional.js} +2 -2
- package/out/us/street/directional.js.map +1 -0
- package/out/us/{street-suffix.d.ts → street/suffix.d.ts} +1 -1
- package/out/us/street/suffix.d.ts.map +1 -0
- package/out/us/{street-suffix.js → street/suffix.js} +2 -2
- package/out/us/street/suffix.js.map +1 -0
- package/out/us/zipcode.d.ts +1 -1
- package/out/us/zipcode.d.ts.map +1 -1
- package/package.json +110 -30
- package/lib/tools/build-country-surface-lexicon.ts +0 -177
- package/lib/tools/export-country-surfaces.ts +0 -48
- package/lib/tools/generate-country-population.ts +0 -142
- package/lib/tools/generate-country-reference.ts +0 -168
- package/lib/tools/generate-official-languages.ts +0 -210
- package/lib/tools/index.ts +0 -12
- package/out/address-system-conventions.d.ts.map +0 -1
- package/out/address-system-conventions.js.map +0 -1
- package/out/country/reference-data.d.ts.map +0 -1
- package/out/country/reference-data.js.map +0 -1
- package/out/country/reference.d.ts.map +0 -1
- package/out/country/reference.js.map +0 -1
- package/out/gb/postcode-area.d.ts.map +0 -1
- package/out/gb/postcode-area.js.map +0 -1
- package/out/gb/postcode.d.ts.map +0 -1
- package/out/gb/postcode.js.map +0 -1
- package/out/postcode-systems.d.ts.map +0 -1
- package/out/postcode-systems.js.map +0 -1
- package/out/tools/build-country-surface-lexicon.d.ts +0 -43
- package/out/tools/build-country-surface-lexicon.d.ts.map +0 -1
- package/out/tools/build-country-surface-lexicon.js +0 -149
- package/out/tools/build-country-surface-lexicon.js.map +0 -1
- package/out/tools/export-country-surfaces.d.ts +0 -15
- package/out/tools/export-country-surfaces.d.ts.map +0 -1
- package/out/tools/export-country-surfaces.js +0 -34
- package/out/tools/export-country-surfaces.js.map +0 -1
- package/out/tools/generate-country-population.d.ts +0 -42
- package/out/tools/generate-country-population.d.ts.map +0 -1
- package/out/tools/generate-country-population.js +0 -106
- package/out/tools/generate-country-population.js.map +0 -1
- package/out/tools/generate-country-reference.d.ts +0 -36
- package/out/tools/generate-country-reference.d.ts.map +0 -1
- package/out/tools/generate-country-reference.js +0 -107
- package/out/tools/generate-country-reference.js.map +0 -1
- package/out/tools/generate-official-languages.d.ts +0 -50
- package/out/tools/generate-official-languages.d.ts.map +0 -1
- package/out/tools/generate-official-languages.js +0 -149
- package/out/tools/generate-official-languages.js.map +0 -1
- package/out/tools/index.d.ts +0 -12
- package/out/tools/index.d.ts.map +0 -1
- package/out/tools/index.js +0 -12
- package/out/tools/index.js.map +0 -1
- package/out/us/street-directional.d.ts.map +0 -1
- package/out/us/street-directional.js.map +0 -1
- package/out/us/street-suffix.d.ts.map +0 -1
- package/out/us/street-suffix.js.map +0 -1
- /package/lib/country/{reference-data.ts → reference/data.ts} +0 -0
- /package/lib/gb/{postcode-area.ts → postcode/area.ts} +0 -0
- /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": "
|
|
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
|
-
"./
|
|
89
|
-
"types": "./out/
|
|
90
|
-
"node": "./out/
|
|
91
|
-
"default": "./out/
|
|
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
|
|
110
|
-
"node": "./out/address
|
|
111
|
-
"default": "./out/address
|
|
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
|
|
120
|
-
"node": "./out/postcode
|
|
121
|
-
"default": "./out/postcode
|
|
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,9 +173,9 @@
|
|
|
131
173
|
"default": "./out/us/state.js"
|
|
132
174
|
},
|
|
133
175
|
"./us/street-suffix": {
|
|
134
|
-
"types": "./out/us/street
|
|
135
|
-
"node": "./out/us/street
|
|
136
|
-
"default": "./out/us/street
|
|
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",
|
|
@@ -200,10 +242,45 @@
|
|
|
200
242
|
"node": "./out/nz/index.js",
|
|
201
243
|
"default": "./out/nz/index.js"
|
|
202
244
|
},
|
|
203
|
-
"./
|
|
204
|
-
"types": "./out/
|
|
205
|
-
"node": "./out/
|
|
206
|
-
"default": "./out/
|
|
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"
|
|
207
284
|
},
|
|
208
285
|
"./normalize": {
|
|
209
286
|
"types": "./out/normalize.d.ts",
|
|
@@ -221,19 +298,24 @@
|
|
|
221
298
|
"default": "./out/it/index.js"
|
|
222
299
|
},
|
|
223
300
|
"./address-system-conventions": {
|
|
224
|
-
"types": "./out/address
|
|
225
|
-
"node": "./out/address
|
|
226
|
-
"default": "./out/address
|
|
301
|
+
"types": "./out/address/system-conventions.d.ts",
|
|
302
|
+
"node": "./out/address/system-conventions.js",
|
|
303
|
+
"default": "./out/address/system-conventions.js"
|
|
227
304
|
},
|
|
228
305
|
"./level-semantics": {
|
|
229
306
|
"types": "./out/level-semantics.d.ts",
|
|
230
307
|
"node": "./out/level-semantics.js",
|
|
231
308
|
"default": "./out/level-semantics.js"
|
|
232
309
|
},
|
|
310
|
+
"./postcode-shapes": {
|
|
311
|
+
"types": "./out/postcode/shapes.d.ts",
|
|
312
|
+
"node": "./out/postcode/shapes.js",
|
|
313
|
+
"default": "./out/postcode/shapes.js"
|
|
314
|
+
},
|
|
233
315
|
"./postcode-systems": {
|
|
234
|
-
"types": "./out/postcode
|
|
235
|
-
"node": "./out/postcode
|
|
236
|
-
"default": "./out/postcode
|
|
316
|
+
"types": "./out/postcode/systems.d.ts",
|
|
317
|
+
"node": "./out/postcode/systems.js",
|
|
318
|
+
"default": "./out/postcode/systems.js"
|
|
237
319
|
},
|
|
238
320
|
"./us/floor-designator": {
|
|
239
321
|
"types": "./out/us/floor-designator.d.ts",
|
|
@@ -246,9 +328,9 @@
|
|
|
246
328
|
"default": "./out/us/state.js"
|
|
247
329
|
},
|
|
248
330
|
"./us/street-suffix": {
|
|
249
|
-
"types": "./out/us/street
|
|
250
|
-
"node": "./out/us/street
|
|
251
|
-
"default": "./out/us/street
|
|
331
|
+
"types": "./out/us/street/suffix.d.ts",
|
|
332
|
+
"node": "./out/us/street/suffix.js",
|
|
333
|
+
"default": "./out/us/street/suffix.js"
|
|
252
334
|
},
|
|
253
335
|
"./us/unit-designator": {
|
|
254
336
|
"types": "./out/us/unit-designator.d.ts",
|
|
@@ -273,8 +355,6 @@
|
|
|
273
355
|
"type-fest": "^5.9.0"
|
|
274
356
|
},
|
|
275
357
|
"devDependencies": {
|
|
276
|
-
"@mailwoman/annotations": "
|
|
277
|
-
"@mailwoman/core": "9.4.0",
|
|
278
|
-
"path-ts": "^2.3.0"
|
|
358
|
+
"@mailwoman/annotations": "10.0.0"
|
|
279
359
|
}
|
|
280
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
|
-
}
|