@mailwoman/kind-classifier 9.4.0 → 10.1.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.
@@ -1,282 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * ROAD_TO_V9 §4 — the query-INTENT rules. Same contract as `rules.ts` (a `(input, shape) => number`
7
- * in [0, 1], 0 when the rule does not fire) and the same bitter-lesson invariant: universal
8
- * structural patterns and bounded linguistic categories only, never a place-name dictionary. The
9
- * one lexicon these kinds consult — the POI synonym table — is INJECTED, exactly as `poi.ts`
10
- * already does it.
11
- *
12
- * ## Why two of these three deliberately lose
13
- *
14
- * `bare_toponym` and `route_pair` are scored BELOW the structural kind that already owns their
15
- * population (`locality_only`, 0.85). They therefore surface in `QueryKindResult.alternatives` and
16
- * never as the top kind. That is not timidity — it is the D-rule discharge. The top kind is the
17
- * only thing the coordinator routes on (`deriveInputMode`, `canShortCircuit`, the POI branch), so
18
- * pinning it is what makes these additions provably answer-neutral on the bare-city-name register,
19
- * which is the single largest population in map search. The intent they carry travels on the
20
- * marker instead, where it is advisory by construction.
21
- *
22
- * `near_me` DOES win its top slot (0.91), because there is no incumbent worth preserving: a query
23
- * ending "near me" is not a locality and answering it as one is the bug.
24
- */
25
- import { isDisqualifyingStreetSuffix, MAX_LOCALITY_ONLY_LENGTH, wordsOf } from "#rules";
26
- /**
27
- * `locality_only` scores 0.85. Both refinement kinds sit under it by a whole confidence step so no float-comparison
28
- * accident can flip the top slot, and so the gap reads as deliberate to the next person.
29
- */
30
- const BARE_TOPONYM_CONFIDENCE = 0.84;
31
- /**
32
- * Lower still, and for a second reason on top of the ranking discipline: a route pair is a HYPOTHESIS about a query
33
- * whose competing reading (locality + region) is more common in this corpus. The number states that.
34
- */
35
- const ROUTE_PAIR_CONFIDENCE = 0.55;
36
- /**
37
- * Above `landmark`'s venue ceiling (0.88) and above `poi_query`'s anchored band (0.90), because a deictic tail is a
38
- * stronger signal than either shape heuristic: nothing else in the vocabulary explains why "me" is at the end of the
39
- * string.
40
- */
41
- const NEAR_ME_CONFIDENCE = 0.91;
42
- /**
43
- * Word ceiling for a single bare toponym. Four covers the long tail that actually exists as one place name ("Newcastle
44
- * upon Tyne", "Sault Sainte Marie", "Las Palmas de Gran Canaria"); past it the input is carrying more than a name.
45
- */
46
- const MAX_BARE_TOPONYM_WORDS = 4;
47
- /**
48
- * Toponymic HEAD particles — the bounded linguistic category that makes a multi-token string ONE place name.
49
- *
50
- * Same justification, and the same boundary, as `@mailwoman/phrase-grouper`'s `PLACE_NAME_PARTICLES` (which covers the
51
- * INFIX glue: `de`, `am`, `aan den`). This set covers the PREFIX heads, and it exists for exactly one job: keeping
52
- * `route_pair` off "New York", "San Francisco", "Fort Worth" and their kin. It is a closed morphological class, not a
53
- * gazetteer — growing it with actual place names is the wrong move, and the pressure for that belongs on the resolver.
54
- *
55
- * Case-folded on read, because lowercase is the primary user register and "new york" is the same query.
56
- */
57
- const TOPONYM_HEAD_PARTICLES = new Set([
58
- // English
59
- "new",
60
- "old",
61
- "fort",
62
- "ft",
63
- "port",
64
- "lake",
65
- "mount",
66
- "mt",
67
- "north",
68
- "south",
69
- "east",
70
- "west",
71
- "upper",
72
- "lower",
73
- "great",
74
- "little",
75
- "saint",
76
- "st",
77
- "st.",
78
- // Romance
79
- "san",
80
- "santa",
81
- "santo",
82
- "são",
83
- "sao",
84
- "los",
85
- "las",
86
- "el",
87
- "la",
88
- "le",
89
- "les",
90
- "villa",
91
- "rio",
92
- "nueva",
93
- "nuevo",
94
- "puerto",
95
- "ciudad",
96
- "campo",
97
- "monte",
98
- "castel",
99
- "borgo",
100
- // Germanic / Nordic
101
- "bad",
102
- "sankt",
103
- "neu",
104
- "alt",
105
- "groß",
106
- "gross",
107
- "klein",
108
- "ober",
109
- "unter",
110
- "nieuw",
111
- "oud",
112
- "ny",
113
- "stor",
114
- "lille",
115
- "sint",
116
- // Definite article as a head — "The Valley" (Anguilla), "The Hague", "The Bottom".
117
- "the",
118
- // Generic toponymic heads outside the Latin/Germanic families, added because the 306-case corpus MEASURED them
119
- // (see `mailwoman/test/kind-intent-invariance.test.ts`): each is a common noun in its own language — Semitic "tel"
120
- // (mound), Malay "kuala" (confluence), Khmer "phnom" (hill) — that heads a place name the way "mount" does.
121
- "tel",
122
- "kuala",
123
- "phnom",
124
- "cape",
125
- "isle",
126
- "isla",
127
- "ilha",
128
- ]);
129
- /**
130
- * Generic toponymic TAIL nouns — the other half of the same bounded morphological class. "Belize City", "George Town",
131
- * "Cape Town", "Palm Springs": a place name whose last token is a settlement/landform generic is ONE name, not two.
132
- *
133
- * Measured additions, same as the heads above: `city`, `town` and `valley` each came off a real corpus row that was
134
- * forking wrongly.
135
- */
136
- const TOPONYM_TAIL_NOUNS = new Set([
137
- "city",
138
- "town",
139
- "ville",
140
- "village",
141
- "borough",
142
- "springs",
143
- "falls",
144
- "beach",
145
- "heights",
146
- "valley",
147
- "island",
148
- "islands",
149
- "bay",
150
- "harbour",
151
- "harbor",
152
- "park",
153
- "hills",
154
- "river",
155
- "creek",
156
- "point",
157
- "stadt",
158
- "burg",
159
- ]);
160
- /**
161
- * Deictic locator tails — "near me", "nearby", "around here", "in my area".
162
- *
163
- * The class is `preposition + a reference to the ASKER`, which is why it is bounded and why it is safe: `me`, `here`,
164
- * `my <noun>` are function words, not places. Anchored to the END of the string (`$`) on purpose — the whole point of
165
- * the kind is that the query names no anchor, so anything AFTER the locator is an anchor and disqualifies it.
166
- *
167
- * Linear by construction: every alternative begins with a required literal, and the only quantifiers are bounded `\s+`
168
- * runs BETWEEN two required literals or trailing before `$`. No unbounded-whitespace-then-literal prefix, which is the
169
- * `js/polynomial-redos` shape (see the `ANCHOR_SEPARATOR` docstring in `poi.ts` for the same analysis).
170
- */
171
- const DEICTIC_LOCATOR_TAIL = /\b(?:near|close\s+to|next\s+to|around|by|closest\s+to|nearest\s+to)\s+(?:me|us|here|my\s+(?:location|position|area|place|house|home))\s*$/;
172
- /**
173
- * The adverbial half of the same class — no preposition, the deixis is baked into the word.
174
- */
175
- const DEICTIC_ADVERB_TAIL = /\b(?:nearby|near\s?by|close\s+by|around\s+here|in\s+my\s+(?:area|neighborhood|neighbourhood))\s*$/;
176
- /**
177
- * True when the input carries a deictic locator tail in EITHER form.
178
- */
179
- function hasDeicticTail(lowercased) {
180
- return DEICTIC_LOCATOR_TAIL.test(lowercased) || DEICTIC_ADVERB_TAIL.test(lowercased);
181
- }
182
- /**
183
- * The conditions `bare_toponym` and `route_pair` share: no address grammar of any kind, one segment, alpha throughout.
184
- *
185
- * Returns the word list when the input clears them, `null` when it does not. Deliberately a SUPERSET of
186
- * `scoreLocalityOnly`'s conditions (which admit two segments), so `bare_toponym` is a strict refinement of
187
- * `locality_only` and can never fire where `locality_only` did not — the property `intent-rules.test.ts` asserts and
188
- * the reason the ranking discipline above is enough to keep the top kind pinned.
189
- */
190
- function bareNameWords(input, shape) {
191
- const text = input.normalized.trim();
192
- if (!text || text.length > MAX_LOCALITY_ONLY_LENGTH)
193
- return null;
194
- // A recognized postcode/known format IS address grammar. Nothing bare survives this.
195
- if (shape.knownFormats.length)
196
- return null;
197
- // `alpha` excludes every house number and every postcode by construction — the cheapest available statement of
198
- // "no address grammar", and it costs no lexicon.
199
- if (shape.characterClass !== "alpha")
200
- return null;
201
- // A comma is the admin-context marker ("Paris, FR"). One segment, or the name is not bare.
202
- if ((shape.segments?.length ?? 1) !== 1)
203
- return null;
204
- const lowercased = text.toLowerCase();
205
- if (hasDeicticTail(lowercased))
206
- return null;
207
- const words = wordsOf(text);
208
- if (!words.length || words.length > MAX_BARE_TOPONYM_WORDS)
209
- return null;
210
- for (const word of words) {
211
- if (isDisqualifyingStreetSuffix(word))
212
- return null;
213
- }
214
- return words;
215
- }
216
- /**
217
- * `bare_toponym` rule: a single coherent place-name carrying no address grammar.
218
- *
219
- * Feeds the declared-ambiguity path. The rule itself asserts nothing about WHICH place — that is the resolver's
220
- * question, and `mailwoman/query-intent.ts` is where the answer's dominance margin decides whether the ambiguity gets
221
- * declared.
222
- */
223
- export function scoreBareToponym(input, shape) {
224
- return bareNameWords(input, shape) ? BARE_TOPONYM_CONFIDENCE : 0;
225
- }
226
- /**
227
- * `route_pair` rule: exactly two toponym-shaped tokens with nothing between them.
228
- *
229
- * **The known confound is structural and unfixable here.** "Paris London" and "Moscow Idaho" are the same string shape
230
- * — two bare capitalized words — and separating them needs to know that Idaho is a region, which is a gazetteer fact,
231
- * not a structural one. The hard-slice board's 18 `comma_free` rows are that population, and they fire this rule. That
232
- * is the reason ROAD_TO_V9 §4.3 specifies **classification + a declared fork, never a router**: both readings are named
233
- * in the marker, neither wins, and the resolver keeps answering exactly as it did.
234
- *
235
- * The one class that IS separable structurally is the two-token SINGLE name — "New York", "Fort Worth", "San Francisco"
236
- * — because those carry a toponymic head particle. That guard is what keeps the fork off the common case.
237
- */
238
- export function scoreRoutePair(input, shape) {
239
- const words = bareNameWords(input, shape);
240
- if (!words || words.length !== 2)
241
- return 0;
242
- const [first, second] = [words[0].toLowerCase(), words[1].toLowerCase()];
243
- // Reduplication — "Pago Pago", "Baden-Baden", "Walla Walla", "Bora Bora". Nobody travels from a place to itself,
244
- // so a repeated token is a universal single-name signal and needs no lexicon at all.
245
- if (first === second)
246
- return 0;
247
- if (TOPONYM_HEAD_PARTICLES.has(first) || TOPONYM_HEAD_PARTICLES.has(second))
248
- return 0;
249
- if (TOPONYM_TAIL_NOUNS.has(second))
250
- return 0;
251
- return ROUTE_PAIR_CONFIDENCE;
252
- }
253
- /**
254
- * `near_me` rule: a subject plus a deictic locator, with no anchor.
255
- *
256
- * Requires a non-empty subject before the locator, so a bare "near me" stays with the `landmark` leaders rule rather
257
- * than claiming to be a category search with a missing focus point.
258
- */
259
- export function scoreNearMe(input, _shape) {
260
- const lowercased = input.normalized.trim().toLowerCase();
261
- if (!hasDeicticTail(lowercased))
262
- return 0;
263
- // The subject is everything before the locator. `hasDeicticTail` already anchored the match to the end, so the
264
- // first match index is where the subject stops.
265
- const match = DEICTIC_LOCATOR_TAIL.exec(lowercased) ?? DEICTIC_ADVERB_TAIL.exec(lowercased);
266
- if (!match)
267
- return 0;
268
- return lowercased.slice(0, match.index).trim() ? NEAR_ME_CONFIDENCE : 0;
269
- }
270
- /**
271
- * The subject of a `near_me` query — the category or thing the asker wants, with the locator stripped. Empty string
272
- * when the rule would not have fired. Used to build the marker's evidence, never to route.
273
- */
274
- export function nearMeSubject(input) {
275
- const trimmed = input.normalized.trim();
276
- const lowercased = trimmed.toLowerCase();
277
- const match = DEICTIC_LOCATOR_TAIL.exec(lowercased) ?? DEICTIC_ADVERB_TAIL.exec(lowercased);
278
- if (!match)
279
- return "";
280
- return trimmed.slice(0, match.index).trim();
281
- }
282
- //# sourceMappingURL=intent-rules.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"intent-rules.js","sourceRoot":"","sources":["../lib/intent-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,OAAO,EAAE,2BAA2B,EAAE,wBAAwB,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACvF;;;GAGG;AACH,MAAM,uBAAuB,GAAG,IAAI,CAAA;AAEpC;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,CAAA;AAElC;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAE/B;;;GAGG;AACH,MAAM,sBAAsB,GAAG,CAAC,CAAA;AAEhC;;;;;;;;;GASG;AACH,MAAM,sBAAsB,GAAwB,IAAI,GAAG,CAAC;IAC3D,UAAU;IACV,KAAK;IACL,KAAK;IACL,MAAM;IACN,IAAI;IACJ,MAAM;IACN,MAAM;IACN,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,QAAQ;IACR,OAAO;IACP,IAAI;IACJ,KAAK;IAC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