@mailwoman/core 7.2.0 → 7.3.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 (150) hide show
  1. package/api/APIClient.ts +175 -0
  2. package/api/headless.ts +23 -0
  3. package/api/index.ts +11 -0
  4. package/api/responses.ts +135 -0
  5. package/coarse-placer/coarse-placer.ts +300 -0
  6. package/coarse-placer/featurize.ts +171 -0
  7. package/coarse-placer/tools/build-dataset.ts +223 -0
  8. package/coarse-placer/tools/build-outlier-exposure.ts +172 -0
  9. package/coarse-placer/tools/build-outlier-latin.ts +200 -0
  10. package/coarse-placer/tools/build-outlier-oa.ts +231 -0
  11. package/coarse-placer/tools/eval-latin-offmap.ts +140 -0
  12. package/coarse-placer/tools/eval-openset.ts +519 -0
  13. package/coarse-placer/tools/eval-quant-compare.ts +151 -0
  14. package/coarse-placer/tools/eval.ts +187 -0
  15. package/coarse-placer/tools/fnv-hash.ts +24 -0
  16. package/coarse-placer/tools/index.ts +23 -0
  17. package/coarse-placer/tools/probe-frontier.ts +216 -0
  18. package/coarse-placer/tools/quantize.ts +116 -0
  19. package/coarse-placer/tools/train.ts +244 -0
  20. package/collections.ts +134 -0
  21. package/db/schema.ts +21 -0
  22. package/decoder/build-tree.ts +228 -0
  23. package/decoder/calibration.ts +101 -0
  24. package/decoder/containment.ts +87 -0
  25. package/decoder/index.ts +17 -0
  26. package/decoder/proposals-to-tree.ts +83 -0
  27. package/decoder/resolve-proposal-overlaps.ts +79 -0
  28. package/decoder/serialize-json.ts +70 -0
  29. package/decoder/serialize-tuples.ts +61 -0
  30. package/decoder/serialize-xml.ts +209 -0
  31. package/decoder/types.ts +159 -0
  32. package/decoder/unknown-spans.ts +103 -0
  33. package/decoder/validate-tree.ts +100 -0
  34. package/env/index.ts +42 -0
  35. package/env/load.ts +14 -0
  36. package/env/paths.ts +40 -0
  37. package/env/schema.ts +125 -0
  38. package/errors/index.ts +9 -0
  39. package/errors/schema.ts +155 -0
  40. package/fs/node.ts +38 -0
  41. package/identifiers.ts +58 -0
  42. package/index.ts +13 -0
  43. package/kysley/adapter.ts +29 -0
  44. package/kysley/client.ts +30 -0
  45. package/kysley/dialect-config.ts +30 -0
  46. package/kysley/dialect.ts +67 -0
  47. package/kysley/driver.ts +175 -0
  48. package/layers/index.ts +12 -0
  49. package/layers/manifest.ts +154 -0
  50. package/layers/schema.ts +105 -0
  51. package/locale/index.ts +9 -0
  52. package/locale/locale.ts +49 -0
  53. package/locale/profiles/en-us.ts +69 -0
  54. package/locale/profiles/fr-fr.ts +75 -0
  55. package/locale/profiles/index.ts +9 -0
  56. package/locale/profiles/ja-jp.ts +33 -0
  57. package/locale/registry.ts +68 -0
  58. package/logging/index.ts +8 -0
  59. package/logging/shared.ts +145 -0
  60. package/logging/utils.ts +46 -0
  61. package/objects.ts +211 -0
  62. package/out/api/APIClient.d.ts.map +1 -1
  63. package/out/api/APIClient.js +2 -2
  64. package/out/api/APIClient.js.map +1 -1
  65. package/out/pipeline/types.d.ts +13 -0
  66. package/out/pipeline/types.d.ts.map +1 -1
  67. package/out/pipeline/types.js.map +1 -1
  68. package/out/scripting/utils/index.d.ts.map +1 -1
  69. package/out/scripting/utils/index.js +3 -5
  70. package/out/scripting/utils/index.js.map +1 -1
  71. package/package.json +190 -107
  72. package/pipeline/index.ts +46 -0
  73. package/pipeline/reconcile-lookups.ts +108 -0
  74. package/pipeline/reconcile.ts +542 -0
  75. package/pipeline/runtime-pipeline.ts +732 -0
  76. package/pipeline/span-logit-aggregation.ts +151 -0
  77. package/pipeline/span-proposer.ts +587 -0
  78. package/pipeline/types.ts +357 -0
  79. package/policy/defaults.ts +35 -0
  80. package/policy/index.ts +10 -0
  81. package/policy/policy.ts +60 -0
  82. package/policy/proposal-collection.ts +64 -0
  83. package/policy/registry.ts +149 -0
  84. package/resolver/index.ts +29 -0
  85. package/resolver/types.ts +584 -0
  86. package/resources/LocaleIndex.ts +124 -0
  87. package/resources/ResourceMapCache.ts +126 -0
  88. package/resources/collections.ts +93 -0
  89. package/resources/debugging.ts +19 -0
  90. package/resources/git.ts +54 -0
  91. package/resources/index.ts +17 -0
  92. package/resources/languages/index.ts +49 -0
  93. package/resources/languages/types.gen.ts +1368 -0
  94. package/resources/libaddressinput.ts +105 -0
  95. package/resources/libpostal.ts +182 -0
  96. package/resources/locale.ts +23 -0
  97. package/resources/set.ts +179 -0
  98. package/resources/whosonfirst/DataSourceCache.ts +72 -0
  99. package/resources/whosonfirst/PlacetypeDataSource.ts +199 -0
  100. package/resources/whosonfirst/index.ts +10 -0
  101. package/resources/whosonfirst/loader.ts +157 -0
  102. package/resources/whosonfirst/placetypes/Placetype.ts +438 -0
  103. package/resources/whosonfirst/placetypes/admin.ts +173 -0
  104. package/resources/whosonfirst/placetypes/definition.ts +135 -0
  105. package/resources/whosonfirst/placetypes/graph.ts +0 -0
  106. package/resources/whosonfirst/placetypes/index.ts +12 -0
  107. package/resources/whosonfirst/placetypes/mermaid.ts +168 -0
  108. package/resources/whosonfirst/placetypes/tree.ts +46 -0
  109. package/routing/index.ts +208 -0
  110. package/scripting/index.ts +40 -0
  111. package/scripting/utils/index.ts +103 -0
  112. package/tokenization/Graph.ts +50 -0
  113. package/tokenization/Span.ts +297 -0
  114. package/tokenization/index.ts +9 -0
  115. package/tokenization/normalizer.ts +123 -0
  116. package/tools/download-libpostal-resources.ts +98 -0
  117. package/tools/download-ssl-address.ts +99 -0
  118. package/tools/generate-language-types.ts +194 -0
  119. package/tools/index.ts +13 -0
  120. package/types/Classification.ts +211 -0
  121. package/types/classifier.ts +133 -0
  122. package/types/component.ts +75 -0
  123. package/types/index.ts +10 -0
  124. package/types/mapping.ts +81 -0
  125. package/utils/data-root.ts +56 -0
  126. package/utils/hash.ts +27 -0
  127. package/utils/index.ts +14 -0
  128. package/utils/jsonl.ts +43 -0
  129. package/utils/python-json.ts +105 -0
  130. package/utils/python-random.ts +90 -0
  131. package/utils/repo.ts +118 -0
  132. package/utils/sealed-db.ts +85 -0
  133. package/utils/stats.ts +32 -0
  134. package/vitest.config.ts +53 -0
  135. package/out/lifecycle/ServiceSymbol.d.ts +0 -57
  136. package/out/lifecycle/ServiceSymbol.d.ts.map +0 -1
  137. package/out/lifecycle/ServiceSymbol.js +0 -60
  138. package/out/lifecycle/ServiceSymbol.js.map +0 -1
  139. package/out/lifecycle/index.d.ts +0 -11
  140. package/out/lifecycle/index.d.ts.map +0 -1
  141. package/out/lifecycle/index.js +0 -11
  142. package/out/lifecycle/index.js.map +0 -1
  143. package/out/lifecycle/lru-cache.d.ts +0 -22
  144. package/out/lifecycle/lru-cache.d.ts.map +0 -1
  145. package/out/lifecycle/lru-cache.js +0 -31
  146. package/out/lifecycle/lru-cache.js.map +0 -1
  147. package/out/lifecycle/services.d.ts +0 -144
  148. package/out/lifecycle/services.d.ts.map +0 -1
  149. package/out/lifecycle/services.js +0 -191
  150. package/out/lifecycle/services.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mailwoman/core",
3
- "version": "7.2.0",
3
+ "version": "7.3.0",
4
4
  "description": "Mailwoman core: tokenization, decoder, formatter, resources, filters, utils.",
5
5
  "license": "AGPL-3.0-only OR LicenseRef-Commercial",
6
6
  "repository": {
@@ -14,176 +14,260 @@
14
14
  "out/**/*.d.ts",
15
15
  "out/**/*.d.ts.map",
16
16
  "data/**/*",
17
- "THIRD_PARTY_NOTICES.md"
17
+ "THIRD_PARTY_NOTICES.md",
18
+ "*.ts",
19
+ "*.tsx",
20
+ "**/*.ts",
21
+ "**/*.tsx",
22
+ "!*.test.ts",
23
+ "!*.test.tsx",
24
+ "!**/*.test.ts",
25
+ "!**/*.test.tsx"
18
26
  ],
19
27
  "type": "module",
20
28
  "exports": {
21
29
  "./package.json": "./package.json",
22
30
  ".": {
23
- "node": "./index.ts",
24
- "default": "./out/index.js",
25
- "types": "./out/index.d.ts"
31
+ "types": "./out/index.d.ts",
32
+ "default": "./out/index.js"
26
33
  },
27
34
  "./coarse-placer": {
28
- "node": "./coarse-placer/coarse-placer.ts",
29
- "default": "./out/coarse-placer/coarse-placer.js",
30
- "types": "./out/coarse-placer/coarse-placer.d.ts"
35
+ "types": "./out/coarse-placer/coarse-placer.d.ts",
36
+ "default": "./out/coarse-placer/coarse-placer.js"
31
37
  },
32
38
  "./coarse-placer/tools": {
33
- "node": "./coarse-placer/tools/index.ts",
34
- "default": "./out/coarse-placer/tools/index.js",
35
- "types": "./out/coarse-placer/tools/index.d.ts"
39
+ "types": "./out/coarse-placer/tools/index.d.ts",
40
+ "default": "./out/coarse-placer/tools/index.js"
36
41
  },
37
42
  "./tokenization": {
38
- "node": "./tokenization/index.ts",
39
- "default": "./out/tokenization/index.js",
40
- "types": "./out/tokenization/index.d.ts"
43
+ "types": "./out/tokenization/index.d.ts",
44
+ "default": "./out/tokenization/index.js"
41
45
  },
42
46
  "./types": {
43
- "node": "./types/index.ts",
44
- "default": "./out/types/index.js",
45
- "types": "./out/types/index.d.ts"
47
+ "types": "./out/types/index.d.ts",
48
+ "default": "./out/types/index.js"
46
49
  },
47
50
  "./decoder": {
48
- "node": "./decoder/index.ts",
49
- "default": "./out/decoder/index.js",
50
- "types": "./out/decoder/index.d.ts"
51
+ "types": "./out/decoder/index.d.ts",
52
+ "default": "./out/decoder/index.js"
51
53
  },
52
54
  "./env": {
53
- "node": "./env/index.ts",
54
- "default": "./out/env/index.js",
55
- "types": "./out/env/index.d.ts"
55
+ "types": "./out/env/index.d.ts",
56
+ "default": "./out/env/index.js"
56
57
  },
57
58
  "./layers": {
58
- "node": "./layers/index.ts",
59
- "default": "./out/layers/index.js",
60
- "types": "./out/layers/index.d.ts"
59
+ "types": "./out/layers/index.d.ts",
60
+ "default": "./out/layers/index.js"
61
61
  },
62
62
  "./resources": {
63
- "node": "./resources/index.ts",
64
- "default": "./out/resources/index.js",
65
- "types": "./out/resources/index.d.ts"
63
+ "types": "./out/resources/index.d.ts",
64
+ "default": "./out/resources/index.js"
66
65
  },
67
66
  "./resources/languages": {
68
- "node": "./resources/languages/index.ts",
69
- "default": "./out/resources/languages/index.js",
70
- "types": "./out/resources/languages/index.d.ts"
67
+ "types": "./out/resources/languages/index.d.ts",
68
+ "default": "./out/resources/languages/index.js"
71
69
  },
72
70
  "./resources/whosonfirst": {
73
- "node": "./resources/whosonfirst/index.ts",
74
- "default": "./out/resources/whosonfirst/index.js",
75
- "types": "./out/resources/whosonfirst/index.d.ts"
76
- },
77
- "./resources/libpostal": {
78
- "node": "./resources/libpostal/index.ts",
79
- "default": "./out/resources/libpostal/index.js",
80
- "types": "./out/resources/libpostal/index.d.ts"
71
+ "types": "./out/resources/whosonfirst/index.d.ts",
72
+ "default": "./out/resources/whosonfirst/index.js"
81
73
  },
82
74
  "./utils": {
83
- "node": "./utils/index.ts",
84
- "default": "./out/utils/index.js",
85
- "types": "./out/utils/index.d.ts"
75
+ "types": "./out/utils/index.d.ts",
76
+ "default": "./out/utils/index.js"
86
77
  },
87
78
  "./fs": {
88
- "node": "./fs/node.ts",
89
- "default": "./out/fs/node.js",
90
- "types": "./out/fs/node.d.ts"
79
+ "types": "./out/fs/node.d.ts",
80
+ "default": "./out/fs/node.js"
91
81
  },
92
82
  "./scripting": {
93
- "node": "./scripting/index.ts",
94
- "default": "./out/scripting/index.js",
95
- "types": "./out/scripting/index.d.ts"
83
+ "types": "./out/scripting/index.d.ts",
84
+ "default": "./out/scripting/index.js"
96
85
  },
97
86
  "./scripting/utils": {
98
- "node": "./scripting/utils/index.ts",
99
- "default": "./out/scripting/utils/index.js",
100
- "types": "./out/scripting/utils/index.d.ts"
101
- },
102
- "./lifecycle": {
103
- "node": "./lifecycle/index.ts",
104
- "default": "./out/lifecycle/index.js",
105
- "types": "./out/lifecycle/index.d.ts"
106
- },
107
- "./identifiers": {
108
- "node": "./identifiers/index.ts",
109
- "default": "./out/identifiers/index.js",
110
- "types": "./out/identifiers/index.d.ts"
87
+ "types": "./out/scripting/utils/index.d.ts",
88
+ "default": "./out/scripting/utils/index.js"
111
89
  },
112
90
  "./objects": {
113
- "node": "./objects.ts",
114
- "default": "./out/objects.js",
115
- "types": "./out/objects.d.ts"
91
+ "types": "./out/objects.d.ts",
92
+ "default": "./out/objects.js"
116
93
  },
117
94
  "./locale": {
118
- "node": "./locale/index.ts",
119
- "default": "./out/locale/index.js",
120
- "types": "./out/locale/index.d.ts"
95
+ "types": "./out/locale/index.d.ts",
96
+ "default": "./out/locale/index.js"
121
97
  },
122
98
  "./api": {
123
- "node": "./api/index.ts",
124
- "default": "./out/api/index.js",
125
- "types": "./out/api/index.d.ts"
99
+ "types": "./out/api/index.d.ts",
100
+ "default": "./out/api/index.js"
126
101
  },
127
102
  "./logging": {
128
- "node": "./logging/index.ts",
129
- "default": "./out/logging/index.js",
130
- "types": "./out/logging/index.d.ts"
103
+ "types": "./out/logging/index.d.ts",
104
+ "default": "./out/logging/index.js"
131
105
  },
132
106
  "./policy": {
133
- "node": "./policy/index.ts",
134
- "default": "./out/policy/index.js",
135
- "types": "./out/policy/index.d.ts"
107
+ "types": "./out/policy/index.d.ts",
108
+ "default": "./out/policy/index.js"
136
109
  },
137
110
  "./pipeline": {
138
- "node": "./pipeline/index.ts",
139
- "default": "./out/pipeline/index.js",
140
- "types": "./out/pipeline/index.d.ts"
111
+ "types": "./out/pipeline/index.d.ts",
112
+ "default": "./out/pipeline/index.js"
141
113
  },
142
114
  "./resolver": {
143
- "node": "./resolver/index.ts",
144
- "default": "./out/resolver/index.js",
145
- "types": "./out/resolver/index.d.ts"
115
+ "types": "./out/resolver/index.d.ts",
116
+ "default": "./out/resolver/index.js"
146
117
  },
147
118
  "./kysley/client": {
148
- "node": "./kysley/client.ts",
149
- "default": "./out/kysley/client.js",
150
- "types": "./out/kysley/client.d.ts"
119
+ "types": "./out/kysley/client.d.ts",
120
+ "default": "./out/kysley/client.js"
151
121
  },
152
122
  "./kysley/dialect": {
153
- "node": "./kysley/dialect.ts",
154
- "default": "./out/kysley/dialect.js",
155
- "types": "./out/kysley/dialect.d.ts"
123
+ "types": "./out/kysley/dialect.d.ts",
124
+ "default": "./out/kysley/dialect.js"
156
125
  },
157
126
  "./kysley/dialect-config": {
158
- "node": "./kysley/dialect-config.ts",
159
- "default": "./out/kysley/dialect-config.js",
160
- "types": "./out/kysley/dialect-config.d.ts"
127
+ "types": "./out/kysley/dialect-config.d.ts",
128
+ "default": "./out/kysley/dialect-config.js"
161
129
  },
162
130
  "./errors": {
163
- "node": "./errors/index.ts",
164
- "default": "./out/errors/index.js",
165
- "types": "./out/errors/index.d.ts"
131
+ "types": "./out/errors/index.d.ts",
132
+ "default": "./out/errors/index.js"
166
133
  },
167
134
  "./routing": {
168
- "node": "./routing/index.ts",
169
- "default": "./out/routing/index.js",
170
- "types": "./out/routing/index.d.ts"
135
+ "types": "./out/routing/index.d.ts",
136
+ "default": "./out/routing/index.js"
171
137
  },
172
138
  "./filters/*": {
173
- "node": "./filters/*.ts",
174
- "default": "./out/filters/*.js",
175
- "types": "./out/filters/*.d.ts"
139
+ "types": "./out/filters/*.d.ts",
140
+ "default": "./out/filters/*.js"
176
141
  },
177
142
  "./tools": {
178
- "node": "./tools/index.ts",
179
- "default": "./out/tools/index.js",
180
- "types": "./out/tools/index.d.ts"
143
+ "types": "./out/tools/index.d.ts",
144
+ "default": "./out/tools/index.js"
181
145
  }
182
146
  },
183
147
  "publishConfig": {
184
- "access": "public"
148
+ "access": "public",
149
+ "exports": {
150
+ "./package.json": "./package.json",
151
+ ".": {
152
+ "types": "./out/index.d.ts",
153
+ "default": "./out/index.js"
154
+ },
155
+ "./coarse-placer": {
156
+ "types": "./out/coarse-placer/coarse-placer.d.ts",
157
+ "default": "./out/coarse-placer/coarse-placer.js"
158
+ },
159
+ "./coarse-placer/tools": {
160
+ "types": "./out/coarse-placer/tools/index.d.ts",
161
+ "default": "./out/coarse-placer/tools/index.js"
162
+ },
163
+ "./tokenization": {
164
+ "types": "./out/tokenization/index.d.ts",
165
+ "default": "./out/tokenization/index.js"
166
+ },
167
+ "./types": {
168
+ "types": "./out/types/index.d.ts",
169
+ "default": "./out/types/index.js"
170
+ },
171
+ "./decoder": {
172
+ "types": "./out/decoder/index.d.ts",
173
+ "default": "./out/decoder/index.js"
174
+ },
175
+ "./env": {
176
+ "types": "./out/env/index.d.ts",
177
+ "default": "./out/env/index.js"
178
+ },
179
+ "./layers": {
180
+ "types": "./out/layers/index.d.ts",
181
+ "default": "./out/layers/index.js"
182
+ },
183
+ "./resources": {
184
+ "types": "./out/resources/index.d.ts",
185
+ "default": "./out/resources/index.js"
186
+ },
187
+ "./resources/languages": {
188
+ "types": "./out/resources/languages/index.d.ts",
189
+ "default": "./out/resources/languages/index.js"
190
+ },
191
+ "./resources/whosonfirst": {
192
+ "types": "./out/resources/whosonfirst/index.d.ts",
193
+ "default": "./out/resources/whosonfirst/index.js"
194
+ },
195
+ "./utils": {
196
+ "types": "./out/utils/index.d.ts",
197
+ "default": "./out/utils/index.js"
198
+ },
199
+ "./fs": {
200
+ "types": "./out/fs/node.d.ts",
201
+ "default": "./out/fs/node.js"
202
+ },
203
+ "./scripting": {
204
+ "types": "./out/scripting/index.d.ts",
205
+ "default": "./out/scripting/index.js"
206
+ },
207
+ "./scripting/utils": {
208
+ "types": "./out/scripting/utils/index.d.ts",
209
+ "default": "./out/scripting/utils/index.js"
210
+ },
211
+ "./objects": {
212
+ "types": "./out/objects.d.ts",
213
+ "default": "./out/objects.js"
214
+ },
215
+ "./locale": {
216
+ "types": "./out/locale/index.d.ts",
217
+ "default": "./out/locale/index.js"
218
+ },
219
+ "./api": {
220
+ "types": "./out/api/index.d.ts",
221
+ "default": "./out/api/index.js"
222
+ },
223
+ "./logging": {
224
+ "types": "./out/logging/index.d.ts",
225
+ "default": "./out/logging/index.js"
226
+ },
227
+ "./policy": {
228
+ "types": "./out/policy/index.d.ts",
229
+ "default": "./out/policy/index.js"
230
+ },
231
+ "./pipeline": {
232
+ "types": "./out/pipeline/index.d.ts",
233
+ "default": "./out/pipeline/index.js"
234
+ },
235
+ "./resolver": {
236
+ "types": "./out/resolver/index.d.ts",
237
+ "default": "./out/resolver/index.js"
238
+ },
239
+ "./kysley/client": {
240
+ "types": "./out/kysley/client.d.ts",
241
+ "default": "./out/kysley/client.js"
242
+ },
243
+ "./kysley/dialect": {
244
+ "types": "./out/kysley/dialect.d.ts",
245
+ "default": "./out/kysley/dialect.js"
246
+ },
247
+ "./kysley/dialect-config": {
248
+ "types": "./out/kysley/dialect-config.d.ts",
249
+ "default": "./out/kysley/dialect-config.js"
250
+ },
251
+ "./errors": {
252
+ "types": "./out/errors/index.d.ts",
253
+ "default": "./out/errors/index.js"
254
+ },
255
+ "./routing": {
256
+ "types": "./out/routing/index.d.ts",
257
+ "default": "./out/routing/index.js"
258
+ },
259
+ "./filters/*": {
260
+ "types": "./out/filters/*.d.ts",
261
+ "default": "./out/filters/*.js"
262
+ },
263
+ "./tools": {
264
+ "types": "./out/tools/index.d.ts",
265
+ "default": "./out/tools/index.js"
266
+ }
267
+ }
185
268
  },
186
269
  "dependencies": {
270
+ "async-init": "^1.0.0",
187
271
  "axios": "^1.18.1",
188
272
  "axios-cache-interceptor": "^1.12.0",
189
273
  "change-case": "^5.4.4",
@@ -193,7 +277,6 @@
193
277
  "http-status-codes": "^2.3.0",
194
278
  "json-colorizer": "^3.0.1",
195
279
  "kysely": "^0.29.3",
196
- "lru-cache": "^11.5.2",
197
280
  "path-ts": "^2.1.0",
198
281
  "pino": "^10.3.1",
199
282
  "pino-pretty": "^13.1.3",
@@ -205,7 +288,7 @@
205
288
  },
206
289
  "devDependencies": {
207
290
  "@duckdb/node-api": "1.5.3-r.3",
208
- "@mailwoman/codex": "7.2.0",
291
+ "@mailwoman/codex": "7.3.0",
209
292
  "@types/d3-color": "^3.1.3",
210
293
  "@types/d3-scale-chromatic": "^3.1.0"
211
294
  }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Runtime pipeline coordinator — see `STAGES.md` for the full contract.
7
+ */
8
+
9
+ export { reconcileSpans } from "./reconcile.ts"
10
+ export type {
11
+ ClassifierCandidate,
12
+ ParentChainLookup,
13
+ ParseTree,
14
+ ReconcileInputs,
15
+ ReconcileOpts,
16
+ ResolverCandidatesLookup,
17
+ ScoreBreakdown,
18
+ } from "./reconcile.ts"
19
+ export { HARD_PLACE_COUNTRY_SAFELIST, hardCountryFor, isBareLocalityTree, runPipeline } from "./runtime-pipeline.ts"
20
+ export { aggregateSpanLogits } from "./span-logit-aggregation.ts"
21
+ export type { SpanBounds, TokenPiece } from "./span-logit-aggregation.ts"
22
+ export { EMPTY_SPAN_PROPOSER_LEXICON, proposeSpans } from "./span-proposer.ts"
23
+ export type { ProposedSpan, ProposedSpanKind, SpanProposerLexicon } from "./span-proposer.ts"
24
+ export { WORD_CONSISTENCY_SHIP_DEFAULT } from "./types.ts"
25
+ export type {
26
+ AddressClassifier,
27
+ ClassifierOpts,
28
+ FSTMatcherLike,
29
+ LocaleHint,
30
+ LocaleTag,
31
+ NormalizedInputLite,
32
+ PhraseGrouper,
33
+ PhraseKind,
34
+ PhraseProposal,
35
+ PipelineOpts,
36
+ PipelineResult,
37
+ PipelineTiming,
38
+ POIIntent,
39
+ POIIntentOutcome,
40
+ POIResult,
41
+ QueryKind,
42
+ QueryKindResult,
43
+ QueryShapeLite,
44
+ RuntimePipelineStages,
45
+ UserLocation,
46
+ } from "./types.ts"
@@ -0,0 +1,108 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Pre-fetch adapters that wire a `ResolverBackend` into the reconciler's concordance axes (#478
7
+ * step 2, re-scoped): `reconcileSpans` already implements resolver-candidate and parent-chain
8
+ * scoring but the runtime pipeline never passed the lookups — the axes were dormant, exercised
9
+ * only by Map-backed test fixtures.
10
+ *
11
+ * The reconciler's beam search is SYNCHRONOUS; the backend is async. So this module does one
12
+ * bounded async pre-fetch pass — `findPlace` per (phrase-span × top-k tag) pair, `ancestors` per
13
+ * fetched place — and returns Map-backed lookups with the contract the reconciler expects. Query
14
+ * count is capped (`maxLookups`, default 12) the same way `resolveTree` caps its walk; pairs are
15
+ * visited in classifier-score order so the budget goes to the likeliest spans.
16
+ */
17
+
18
+ import type { ResolvedPlace, ResolverBackend } from "../resolver/types.ts"
19
+ import type { ClassifierCandidate, ParentChainLookup, ResolverCandidatesLookup } from "./reconcile.ts"
20
+
21
+ const RESOLVABLE_TAGS = new Set(["country", "region", "locality", "dependent_locality", "county", "subregion"])
22
+
23
+ export interface ReconcileLookups {
24
+ resolverCandidates: ResolverCandidatesLookup
25
+ parentChain: ParentChainLookup
26
+ }
27
+
28
+ /**
29
+ * Build the reconciler's concordance lookups from one bounded pre-fetch pass over the backend.
30
+ *
31
+ * @param backend The gazetteer backend (Stage 6's `WOFSqlitePlaceLookup.asResolverBackend()` in production; any
32
+ * structural match in tests).
33
+ * @param raw The normalized input text — span bounds index into this.
34
+ * @param classifierTopK The aggregated per-span tag candidates (score-descending preferred; the budget follows this
35
+ * order).
36
+ * @param opts.maxLookups Hard cap on `findPlace` calls (default 12).
37
+ * @param opts.candidatesPerPair Max places retained per (span, tag) pair (default 3).
38
+ */
39
+ export async function prefetchReconcileLookups(
40
+ backend: ResolverBackend,
41
+ raw: string,
42
+ classifierTopK: ReadonlyArray<ClassifierCandidate>,
43
+ opts?: { maxLookups?: number; candidatesPerPair?: number; defaultCountry?: string }
44
+ ): Promise<ReconcileLookups> {
45
+ const maxLookups = opts?.maxLookups ?? 12
46
+ const perPair = opts?.candidatesPerPair ?? 3
47
+
48
+ const candidateTable = new Map<string, ResolvedPlace[]>()
49
+ const chainTable = new Map<number | string, ResolvedPlace[]>()
50
+ const pairKey = (span: { start: number; end: number }, tag: string) => `${span.start}:${span.end}:${tag}`
51
+
52
+ let budget = maxLookups
53
+
54
+ for (const candidate of classifierTopK) {
55
+ if (budget <= 0) break
56
+
57
+ if (!RESOLVABLE_TAGS.has(candidate.tag)) continue
58
+ const key = pairKey(candidate.span, candidate.tag)
59
+
60
+ if (candidateTable.has(key)) continue
61
+ const text = raw.slice(candidate.span.start, candidate.span.end).trim()
62
+
63
+ if (!text) continue
64
+ budget--
65
+ let places: ResolvedPlace[] = []
66
+
67
+ try {
68
+ places = await backend.findPlace({
69
+ text,
70
+ placetype: candidate.tag,
71
+ ...(opts?.defaultCountry ? { country: opts.defaultCountry } : {}),
72
+ limit: perPair,
73
+ })
74
+ } catch {
75
+ // A backend failure degrades to "no concordance evidence for this pair" — the
76
+ // reconciler scores without it, identical to today's behavior.
77
+ }
78
+ candidateTable.set(key, places.slice(0, perPair))
79
+
80
+ // Ancestors are synchronous + memoized backend-side; chain them now so parentsOf is a
81
+ // pure Map read during the beam search.
82
+ if (backend.ancestors) {
83
+ for (const place of places) {
84
+ if (chainTable.has(place.id)) continue
85
+ const chain = backend.ancestors(place.id) ?? []
86
+ // The reconciler's concordance check is MEMBERSHIP-ONLY (by id) — Ancestor carries no
87
+ // coordinates, and none are needed; zeroes satisfy the ResolvedPlace shape.
88
+ chainTable.set(
89
+ place.id,
90
+ chain.map((a) => ({ id: a.id, name: a.name, placetype: a.placetype, lat: 0, lon: 0 }) as ResolvedPlace)
91
+ )
92
+ }
93
+ }
94
+ }
95
+
96
+ return {
97
+ resolverCandidates: {
98
+ candidatesFor(span, tag) {
99
+ return candidateTable.get(pairKey(span, tag)) ?? []
100
+ },
101
+ },
102
+ parentChain: {
103
+ parentsOf(place) {
104
+ return chainTable.get(place.id) ?? []
105
+ },
106
+ },
107
+ }
108
+ }