@mailwoman/kind-classifier 10.1.0 → 10.2.1
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/lib/classify.ts +1 -0
- package/lib/index.ts +1 -1
- package/lib/intent/markers.ts +1 -1
- package/lib/poi.ts +51 -53
- package/out/classify.d.ts.map +1 -1
- package/out/classify.js +1 -0
- package/out/classify.js.map +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.d.ts.map +1 -1
- package/out/intent/markers.js +1 -1
- package/out/intent/markers.js.map +1 -1
- package/out/poi.d.ts +38 -35
- package/out/poi.d.ts.map +1 -1
- package/out/poi.js +12 -9
- package/out/poi.js.map +1 -1
- package/package.json +4 -4
package/lib/classify.ts
CHANGED
package/lib/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { deriveIntentMarkers } from "#intent/markers"
|
|
|
12
12
|
export type { IntentMarkerContext } from "#intent/markers"
|
|
13
13
|
export { nearMeSubject, scoreBareToponym, scoreNearMe, scoreRoutePair } from "#intent/rules"
|
|
14
14
|
export { matchPOICategory, matchPOISubject } from "#poi"
|
|
15
|
-
export type { POIPhraseMatch, POIPhraseLookup, POIQuerySpan,
|
|
15
|
+
export type { POIPhraseMatch, POIPhraseReading, POIPhraseLookup, POIQuerySpan, POISubjectMatch } from "#poi"
|
|
16
16
|
|
|
17
17
|
export {
|
|
18
18
|
scoreIntersection,
|
package/lib/intent/markers.ts
CHANGED
|
@@ -96,7 +96,7 @@ export function deriveIntentMarkers(
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
if (fired.has("poi_category") && ctx.poiLexicon) {
|
|
99
|
-
const match = matchPOICategory(ctx.input.normalized, ctx.locale ?? ctx.input.appliedLocale, ctx.poiLexicon)
|
|
99
|
+
const match = matchPOICategory(ctx.input.normalized, ctx.locale ?? ctx.input.appliedLocale ?? null, ctx.poiLexicon)
|
|
100
100
|
|
|
101
101
|
if (match) {
|
|
102
102
|
markers.push({
|
package/lib/poi.ts
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* Spec §3.1.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import type {
|
|
12
|
+
import type { POISpatialRelation } from "@mailwoman/core/pipeline"
|
|
13
|
+
import type { NormalizedInputLite, QueryShapeSegmentsView as QueryShapeLike, TextSpan } from "@mailwoman/query-shape"
|
|
13
14
|
/**
|
|
14
15
|
* Comma-segment ceiling for a POI-led query.
|
|
15
16
|
*
|
|
@@ -30,20 +31,26 @@ export interface POIPhraseMatch {
|
|
|
30
31
|
categoryID: string
|
|
31
32
|
matchedPhrase: string
|
|
32
33
|
confidence: number
|
|
33
|
-
mechanism?: "exact" | "locale_normalized" | "typo"
|
|
34
|
-
inputPhrase?: string
|
|
35
34
|
/**
|
|
36
|
-
*
|
|
35
|
+
* How the phrase matched, or `null` when the lookup does not report it.
|
|
37
36
|
*/
|
|
38
|
-
|
|
37
|
+
mechanism: "exact" | "locale_normalized" | "typo" | null
|
|
38
|
+
/**
|
|
39
|
+
* The phrase the lookup received, or `null` when the lookup does not report it.
|
|
40
|
+
*/
|
|
41
|
+
inputPhrase: string | null
|
|
42
|
+
/**
|
|
43
|
+
* What `categoryID` identifies.
|
|
44
|
+
*/
|
|
45
|
+
kind: "category" | "brand" | "name"
|
|
39
46
|
/**
|
|
40
47
|
* Wikidata QID when known, `kind: "brand"` only.
|
|
41
|
-
*
|
|
48
|
+
*
|
|
49
|
+
* It is `null` when a brand resolved using its name only, and for other kinds.
|
|
42
50
|
*/
|
|
43
|
-
wikidata
|
|
51
|
+
wikidata: string | null
|
|
44
52
|
/**
|
|
45
|
-
*
|
|
46
|
-
* rather than one candidate in a preference list.
|
|
53
|
+
* How the caller reads several hits for one phrase.
|
|
47
54
|
*
|
|
48
55
|
* A lookup returning several hits means two different things: a phrase index
|
|
49
56
|
* returns the categories one typed phrase could name, the curated reading first
|
|
@@ -51,16 +58,15 @@ export interface POIPhraseMatch {
|
|
|
51
58
|
* rung returns every entity kind that affords one activity in a stable enumeration.
|
|
52
59
|
* The enumeration does not express a preference.
|
|
53
60
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* Absent, the committed lexicon's shape, keeps the first-hit reading.
|
|
61
|
+
* - `"preference"`: the hits are a preference list; {@link matchPOISubject} keeps the first.
|
|
62
|
+
* The committed lexicon's shape.
|
|
63
|
+
* - `"set"`: this hit is one member of a set the caller must search together,
|
|
64
|
+
* so {@link matchPOISubject} returns them all and the POI branch searches their union.
|
|
59
65
|
*/
|
|
60
|
-
|
|
66
|
+
reading: POIPhraseReading
|
|
61
67
|
/**
|
|
62
68
|
* ISO 3166-1 alpha-2 countries the authority behind this hit scopes its claim to.
|
|
63
|
-
*
|
|
69
|
+
* `null` means the claim is true in every country.
|
|
64
70
|
*
|
|
65
71
|
* A scope is a statement about establishments, so it is judged against the country of
|
|
66
72
|
* the place being searched rather than the caller's locale: the locale is the lens the
|
|
@@ -68,29 +74,26 @@ export interface POIPhraseMatch {
|
|
|
68
74
|
* `matchPOISubject` returns the value unchanged.
|
|
69
75
|
* The POI intent stage binds it once the anchor has resolved.
|
|
70
76
|
*/
|
|
71
|
-
countryScope
|
|
77
|
+
countryScope: readonly string[] | null
|
|
72
78
|
}
|
|
73
79
|
|
|
80
|
+
/**
|
|
81
|
+
* How several hits for one phrase are read, as {@link POIPhraseMatch.reading} describes.
|
|
82
|
+
*/
|
|
83
|
+
export type POIPhraseReading = "preference" | "set"
|
|
84
|
+
|
|
74
85
|
/**
|
|
75
86
|
* Injected phrase→category lookup, exact-phrase and locale-aware, returning `[]` on miss.
|
|
76
87
|
*/
|
|
77
88
|
export type POIPhraseLookup = (phrase: string, locale?: string) => ReadonlyArray<POIPhraseMatch>
|
|
78
89
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Half-open character offsets into the normalized input.
|
|
85
|
-
*/
|
|
86
|
-
start: number
|
|
87
|
-
end: number
|
|
88
|
-
}
|
|
90
|
+
/**
|
|
91
|
+
* A span of the normalized input, with half-open character offsets.
|
|
92
|
+
*/
|
|
93
|
+
export type POIQuerySpan = TextSpan
|
|
89
94
|
|
|
90
95
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* Category lookups set `"category"` as the backward-compatible default.
|
|
96
|
+
* The subject phrase {@link matchPOISubject} chose and the lexicon hits for it.
|
|
94
97
|
*/
|
|
95
98
|
export interface POISubjectMatch {
|
|
96
99
|
/**
|
|
@@ -101,7 +104,7 @@ export interface POISubjectMatch {
|
|
|
101
104
|
match: POIPhraseMatch
|
|
102
105
|
/**
|
|
103
106
|
* Every category the subject reaches, `match` first: one entry unless the lookup
|
|
104
|
-
* returned a {@link POIPhraseMatch.
|
|
107
|
+
* returned a `"set"` {@link POIPhraseMatch.reading}, in which case it holds the
|
|
105
108
|
* whole set and the POI branch searches their union.
|
|
106
109
|
* The order is the lookup's and states no preference.
|
|
107
110
|
*/
|
|
@@ -111,13 +114,13 @@ export interface POISubjectMatch {
|
|
|
111
114
|
/**
|
|
112
115
|
* The relation crossing from the subject span to the anchor span.
|
|
113
116
|
*/
|
|
114
|
-
relation
|
|
115
|
-
relationSpan
|
|
117
|
+
relation: POISpatialRelation | null
|
|
118
|
+
relationSpan: POIQuerySpan | null
|
|
116
119
|
/**
|
|
117
120
|
* The anchor remainder after the separator; `""` when the whole input matched.
|
|
118
121
|
*/
|
|
119
122
|
remainder: string
|
|
120
|
-
anchorSpan
|
|
123
|
+
anchorSpan: POIQuerySpan | null
|
|
121
124
|
}
|
|
122
125
|
|
|
123
126
|
/**
|
|
@@ -146,15 +149,15 @@ const ANCHOR_SEPARATOR = /,\s*|\s(near|in|at|around|to)\s+/gi
|
|
|
146
149
|
const MAX_SUBJECT_TOKENS = 8
|
|
147
150
|
|
|
148
151
|
/**
|
|
149
|
-
* The categories one candidate subject reaches: the whole array when the first hit
|
|
150
|
-
*
|
|
152
|
+
* The categories one candidate subject reaches: the whole array when the first hit reads
|
|
153
|
+
* as a `"set"` ({@link POIPhraseMatch.reading}), preserved as the lookup returned it
|
|
151
154
|
* and never filtered, so a rung that flagged only some members keeps every member.
|
|
152
155
|
*
|
|
153
156
|
* The inconsistency stays visible.
|
|
154
157
|
* Otherwise, use only the first hit.
|
|
155
158
|
*/
|
|
156
159
|
function reachedMatches(hits: ReadonlyArray<POIPhraseMatch>): POIPhraseMatch[] {
|
|
157
|
-
return hits[0]!.
|
|
160
|
+
return hits[0]!.reading === "set" ? [...hits] : [hits[0]!]
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
/**
|
|
@@ -168,17 +171,13 @@ function reachedMatches(hits: ReadonlyArray<POIPhraseMatch>): POIPhraseMatch[] {
|
|
|
168
171
|
*
|
|
169
172
|
* The winning candidate's hits are listed per {@link reachedMatches}.
|
|
170
173
|
*/
|
|
171
|
-
export function matchPOISubject(
|
|
172
|
-
text: string,
|
|
173
|
-
locale: string | undefined,
|
|
174
|
-
lookup: POIPhraseLookup
|
|
175
|
-
): POISubjectMatch | null {
|
|
174
|
+
export function matchPOISubject(text: string, locale: string | null, lookup: POIPhraseLookup): POISubjectMatch | null {
|
|
176
175
|
const trimmed = text.trim()
|
|
177
176
|
const inputStart = text.indexOf(trimmed)
|
|
178
177
|
|
|
179
178
|
if (!trimmed) return null
|
|
180
179
|
|
|
181
|
-
const whole = lookup(trimmed, locale)
|
|
180
|
+
const whole = lookup(trimmed, locale ?? undefined)
|
|
182
181
|
|
|
183
182
|
if (whole.length) {
|
|
184
183
|
const matches = reachedMatches(whole)
|
|
@@ -188,7 +187,10 @@ export function matchPOISubject(
|
|
|
188
187
|
matches,
|
|
189
188
|
subject: trimmed,
|
|
190
189
|
subjectSpan: { text: trimmed, start: inputStart, end: inputStart + trimmed.length },
|
|
190
|
+
relation: null,
|
|
191
|
+
relationSpan: null,
|
|
191
192
|
remainder: "",
|
|
193
|
+
anchorSpan: null,
|
|
192
194
|
}
|
|
193
195
|
}
|
|
194
196
|
|
|
@@ -201,7 +203,7 @@ export function matchPOISubject(
|
|
|
201
203
|
// Whitespace-only split rather than `wordsOf`, because a comma inside a subject is real content.
|
|
202
204
|
if (subject.split(/\s+/).length > MAX_SUBJECT_TOKENS) break
|
|
203
205
|
|
|
204
|
-
const hits = lookup(subject, locale)
|
|
206
|
+
const hits = lookup(subject, locale ?? undefined)
|
|
205
207
|
|
|
206
208
|
if (!hits.length) continue
|
|
207
209
|
|
|
@@ -255,7 +257,7 @@ export function createScorePOIQuery(
|
|
|
255
257
|
locale?: string
|
|
256
258
|
): (input: NormalizedInputLite, shape: QueryShapeLike) => number {
|
|
257
259
|
return (input, shape) => {
|
|
258
|
-
const matched = matchPOISubject(input.normalized, locale ?? input.appliedLocale, lookup)
|
|
260
|
+
const matched = matchPOISubject(input.normalized, locale ?? input.appliedLocale ?? null, lookup)
|
|
259
261
|
|
|
260
262
|
if (!matched) return 0
|
|
261
263
|
|
|
@@ -297,11 +299,11 @@ export function createScorePOICategory(
|
|
|
297
299
|
locale?: string
|
|
298
300
|
): (input: NormalizedInputLite, shape: QueryShapeLike) => number {
|
|
299
301
|
return (input, _shape) => {
|
|
300
|
-
const matched = matchPOISubject(input.normalized, locale ?? input.appliedLocale, lookup)
|
|
302
|
+
const matched = matchPOISubject(input.normalized, locale ?? input.appliedLocale ?? null, lookup)
|
|
301
303
|
|
|
302
304
|
if (!matched || matched.remainder !== "") return 0
|
|
303
305
|
|
|
304
|
-
if (
|
|
306
|
+
if (matched.match.kind !== "category") return 0
|
|
305
307
|
|
|
306
308
|
return POI_CATEGORY_CONFIDENCE * matched.match.confidence
|
|
307
309
|
}
|
|
@@ -312,16 +314,12 @@ export function createScorePOICategory(
|
|
|
312
314
|
* `null` when the input is not a bare category, under the same conditions as
|
|
313
315
|
* {@link createScorePOICategory} so the two cannot disagree.
|
|
314
316
|
*/
|
|
315
|
-
export function matchPOICategory(
|
|
316
|
-
text: string,
|
|
317
|
-
locale: string | undefined,
|
|
318
|
-
lookup: POIPhraseLookup
|
|
319
|
-
): POIPhraseMatch | null {
|
|
317
|
+
export function matchPOICategory(text: string, locale: string | null, lookup: POIPhraseLookup): POIPhraseMatch | null {
|
|
320
318
|
const matched = matchPOISubject(text, locale, lookup)
|
|
321
319
|
|
|
322
320
|
if (!matched || matched.remainder !== "") return null
|
|
323
321
|
|
|
324
|
-
if (
|
|
322
|
+
if (matched.match.kind !== "category") return null
|
|
325
323
|
|
|
326
324
|
return matched.match
|
|
327
325
|
}
|
package/out/classify.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../lib/classify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAgC,eAAe,EAAE,MAAM,0BAA0B,CAAA;AACzG,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,IAAI,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAI3G,OAAO,EAA+C,KAAK,eAAe,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../lib/classify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAgC,eAAe,EAAE,MAAM,0BAA0B,CAAA;AACzG,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,IAAI,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAI3G,OAAO,EAA+C,KAAK,eAAe,EAAE,MAAM,MAAM,CAAA;AA6ExF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,cAAc,GAAG,eAAe,CAMnG;AAED;;;GAGG;AACH,wBAAsB,YAAY,CACjC,KAAK,EAAE,mBAAmB,EAC1B,KAAK,EAAE,cAAc,EACrB,OAAO,CAAC,EAAE,UAAU,GAClB,OAAO,CAAC,eAAe,CAAC,CAE1B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,eAAe,CAAA;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CACnC,IAAI,GAAE,kBAAuB,GAC3B,CAAC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,UAAU,KAAK,OAAO,CAAC,eAAe,CAAC,CAgCtG"}
|
package/out/classify.js
CHANGED
package/out/classify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classify.js","sourceRoot":"","sources":["../lib/classify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC7E,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAwB,MAAM,MAAM,CAAA;AACxF,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,iBAAiB,EACjB,sBAAsB,EACtB,UAAU,EACV,kBAAkB,GAClB,MAAM,QAAQ,CAAA;AAOf,MAAM,OAAO,GAA8B;IAC1C,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE;IACrC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;IAC9F,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,iBAAiB,EAAE;IAClD,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,iBAAiB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E;QAC5E,sCAAsC;QACtC,MAAM,MAAM,GAAmD;YAC9D,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE;YAChD,GAAG,IAAI,CAAC,YAAY;SACpB,CAAA;QAED,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC,CAAA;QAC9D,CAAC;QAED,IAAI,kBAAkB,GAAG,CAAC,EAAE,CAAC;YAC5B,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,kBAAkB,EAAE,CAAC,CAAA;QACtE,CAAC;QAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,CAAA;IACrE,CAAC,CAAA;AACF,CAAC"}
|
package/out/index.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ export { deriveIntentMarkers } from "#intent/markers";
|
|
|
11
11
|
export type { IntentMarkerContext } from "#intent/markers";
|
|
12
12
|
export { nearMeSubject, scoreBareToponym, scoreNearMe, scoreRoutePair } from "#intent/rules";
|
|
13
13
|
export { matchPOICategory, matchPOISubject } from "#poi";
|
|
14
|
-
export type { POIPhraseMatch, POIPhraseLookup, POIQuerySpan,
|
|
14
|
+
export type { POIPhraseMatch, POIPhraseReading, POIPhraseLookup, POIQuerySpan, POISubjectMatch } from "#poi";
|
|
15
15
|
export { scoreIntersection, scoreLandmark, scoreLocalityOnly, scorePoBox, scorePostcodeOnly, scoreStructuredAddress, scoreVague, scoreVenueLandmark, } from "#rules";
|
|
16
16
|
//# sourceMappingURL=index.d.ts.map
|
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAChF,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC5F,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AACxD,YAAY,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAChF,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC5F,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AACxD,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,eAAe,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AAE5G,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,iBAAiB,EACjB,sBAAsB,EACtB,UAAU,EACV,kBAAkB,GAClB,MAAM,QAAQ,CAAA"}
|
package/out/intent/markers.js
CHANGED
|
@@ -68,7 +68,7 @@ export function deriveIntentMarkers(kinds, ctx) {
|
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
if (fired.has("poi_category") && ctx.poiLexicon) {
|
|
71
|
-
const match = matchPOICategory(ctx.input.normalized, ctx.locale ?? ctx.input.appliedLocale, ctx.poiLexicon);
|
|
71
|
+
const match = matchPOICategory(ctx.input.normalized, ctx.locale ?? ctx.input.appliedLocale ?? null, ctx.poiLexicon);
|
|
72
72
|
if (match) {
|
|
73
73
|
markers.push({
|
|
74
74
|
kind: "poi_category",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markers.js","sourceRoot":"","sources":["../../lib/intent/markers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAwB,MAAM,MAAM,CAAA;AAiB7D;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAClC,KAA6D,EAC7D,GAAwB;IAExB,MAAM,KAAK,GAAG,IAAI,GAAG,CAAY,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;IAC1D,MAAM,OAAO,GAAwB,EAAE,CAAA;IAEvC,IAAI,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;QAC7B,+EAA+E;QAC/E,qFAAqF;QACrF,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAEvD,OAAO,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,eAAe;YACrB,SAAS,EAAE,iBAAiB;YAC5B,OAAO,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,2HAA2H;YACxJ,QAAQ,EAAE;gBACT,MAAM;gBACN;;;;;;mBAMG;gBACH,eAAe,EAAE,CAAC,cAAc,EAAE,6BAA6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;gBACzH,QAAQ,EAAE;oBACT,UAAU,EAAE,KAAK,CAAC,UAAU;oBAC5B,aAAa,EAAE,KAAK,CAAC,aAAa;oBAClC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACvD;aACD,CAAC,CAAA;QACH,CAAC;IACF,CAAC;IAED,OAAO,OAAO,CAAA;AACf,CAAC"}
|
package/out/poi.d.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* `@mailwoman/poi-taxonomy` and is wired in by `createRuntimePipeline` behind the `poiQueryKind` flag.
|
|
9
9
|
* Spec §3.1.
|
|
10
10
|
*/
|
|
11
|
-
import type {
|
|
11
|
+
import type { POISpatialRelation } from "@mailwoman/core/pipeline";
|
|
12
|
+
import type { NormalizedInputLite, QueryShapeSegmentsView as QueryShapeLike, TextSpan } from "@mailwoman/query-shape";
|
|
12
13
|
/**
|
|
13
14
|
* One lexicon hit for a candidate subject phrase.
|
|
14
15
|
*/
|
|
@@ -21,20 +22,26 @@ export interface POIPhraseMatch {
|
|
|
21
22
|
categoryID: string;
|
|
22
23
|
matchedPhrase: string;
|
|
23
24
|
confidence: number;
|
|
24
|
-
mechanism?: "exact" | "locale_normalized" | "typo";
|
|
25
|
-
inputPhrase?: string;
|
|
26
25
|
/**
|
|
27
|
-
*
|
|
26
|
+
* How the phrase matched, or `null` when the lookup does not report it.
|
|
28
27
|
*/
|
|
29
|
-
|
|
28
|
+
mechanism: "exact" | "locale_normalized" | "typo" | null;
|
|
29
|
+
/**
|
|
30
|
+
* The phrase the lookup received, or `null` when the lookup does not report it.
|
|
31
|
+
*/
|
|
32
|
+
inputPhrase: string | null;
|
|
33
|
+
/**
|
|
34
|
+
* What `categoryID` identifies.
|
|
35
|
+
*/
|
|
36
|
+
kind: "category" | "brand" | "name";
|
|
30
37
|
/**
|
|
31
38
|
* Wikidata QID when known, `kind: "brand"` only.
|
|
32
|
-
*
|
|
39
|
+
*
|
|
40
|
+
* It is `null` when a brand resolved using its name only, and for other kinds.
|
|
33
41
|
*/
|
|
34
|
-
wikidata
|
|
42
|
+
wikidata: string | null;
|
|
35
43
|
/**
|
|
36
|
-
*
|
|
37
|
-
* rather than one candidate in a preference list.
|
|
44
|
+
* How the caller reads several hits for one phrase.
|
|
38
45
|
*
|
|
39
46
|
* A lookup returning several hits means two different things: a phrase index
|
|
40
47
|
* returns the categories one typed phrase could name, the curated reading first
|
|
@@ -42,16 +49,15 @@ export interface POIPhraseMatch {
|
|
|
42
49
|
* rung returns every entity kind that affords one activity in a stable enumeration.
|
|
43
50
|
* The enumeration does not express a preference.
|
|
44
51
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* Absent, the committed lexicon's shape, keeps the first-hit reading.
|
|
52
|
+
* - `"preference"`: the hits are a preference list; {@link matchPOISubject} keeps the first.
|
|
53
|
+
* The committed lexicon's shape.
|
|
54
|
+
* - `"set"`: this hit is one member of a set the caller must search together,
|
|
55
|
+
* so {@link matchPOISubject} returns them all and the POI branch searches their union.
|
|
50
56
|
*/
|
|
51
|
-
|
|
57
|
+
reading: POIPhraseReading;
|
|
52
58
|
/**
|
|
53
59
|
* ISO 3166-1 alpha-2 countries the authority behind this hit scopes its claim to.
|
|
54
|
-
*
|
|
60
|
+
* `null` means the claim is true in every country.
|
|
55
61
|
*
|
|
56
62
|
* A scope is a statement about establishments, so it is judged against the country of
|
|
57
63
|
* the place being searched rather than the caller's locale: the locale is the lens the
|
|
@@ -59,25 +65,22 @@ export interface POIPhraseMatch {
|
|
|
59
65
|
* `matchPOISubject` returns the value unchanged.
|
|
60
66
|
* The POI intent stage binds it once the anchor has resolved.
|
|
61
67
|
*/
|
|
62
|
-
countryScope
|
|
68
|
+
countryScope: readonly string[] | null;
|
|
63
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* How several hits for one phrase are read, as {@link POIPhraseMatch.reading} describes.
|
|
72
|
+
*/
|
|
73
|
+
export type POIPhraseReading = "preference" | "set";
|
|
64
74
|
/**
|
|
65
75
|
* Injected phrase→category lookup, exact-phrase and locale-aware, returning `[]` on miss.
|
|
66
76
|
*/
|
|
67
77
|
export type POIPhraseLookup = (phrase: string, locale?: string) => ReadonlyArray<POIPhraseMatch>;
|
|
68
|
-
export type POISpatialRelation = "comma" | "near" | "in" | "at" | "around" | "to";
|
|
69
|
-
export interface POIQuerySpan {
|
|
70
|
-
text: string;
|
|
71
|
-
/**
|
|
72
|
-
* Half-open character offsets into the normalized input.
|
|
73
|
-
*/
|
|
74
|
-
start: number;
|
|
75
|
-
end: number;
|
|
76
|
-
}
|
|
77
78
|
/**
|
|
78
|
-
*
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
* A span of the normalized input, with half-open character offsets.
|
|
80
|
+
*/
|
|
81
|
+
export type POIQuerySpan = TextSpan;
|
|
82
|
+
/**
|
|
83
|
+
* The subject phrase {@link matchPOISubject} chose and the lexicon hits for it.
|
|
81
84
|
*/
|
|
82
85
|
export interface POISubjectMatch {
|
|
83
86
|
/**
|
|
@@ -88,7 +91,7 @@ export interface POISubjectMatch {
|
|
|
88
91
|
match: POIPhraseMatch;
|
|
89
92
|
/**
|
|
90
93
|
* Every category the subject reaches, `match` first: one entry unless the lookup
|
|
91
|
-
* returned a {@link POIPhraseMatch.
|
|
94
|
+
* returned a `"set"` {@link POIPhraseMatch.reading}, in which case it holds the
|
|
92
95
|
* whole set and the POI branch searches their union.
|
|
93
96
|
* The order is the lookup's and states no preference.
|
|
94
97
|
*/
|
|
@@ -98,13 +101,13 @@ export interface POISubjectMatch {
|
|
|
98
101
|
/**
|
|
99
102
|
* The relation crossing from the subject span to the anchor span.
|
|
100
103
|
*/
|
|
101
|
-
relation
|
|
102
|
-
relationSpan
|
|
104
|
+
relation: POISpatialRelation | null;
|
|
105
|
+
relationSpan: POIQuerySpan | null;
|
|
103
106
|
/**
|
|
104
107
|
* The anchor remainder after the separator; `""` when the whole input matched.
|
|
105
108
|
*/
|
|
106
109
|
remainder: string;
|
|
107
|
-
anchorSpan
|
|
110
|
+
anchorSpan: POIQuerySpan | null;
|
|
108
111
|
}
|
|
109
112
|
/**
|
|
110
113
|
* Match a POI subject: the whole input, or the text before the first anchor
|
|
@@ -117,7 +120,7 @@ export interface POISubjectMatch {
|
|
|
117
120
|
*
|
|
118
121
|
* The winning candidate's hits are listed per {@link reachedMatches}.
|
|
119
122
|
*/
|
|
120
|
-
export declare function matchPOISubject(text: string, locale: string |
|
|
123
|
+
export declare function matchPOISubject(text: string, locale: string | null, lookup: POIPhraseLookup): POISubjectMatch | null;
|
|
121
124
|
/**
|
|
122
125
|
* `poi_query` scorer over an injected lexicon, with confidence bands: a whole-input lexicon hit
|
|
123
126
|
* scores 0.92 (above venue-landmark's 0.88 ceiling, because an exact phrase beats a shape heuristic)
|
|
@@ -143,5 +146,5 @@ export declare function createScorePOICategory(lookup: POIPhraseLookup, locale?:
|
|
|
143
146
|
* `null` when the input is not a bare category, under the same conditions as
|
|
144
147
|
* {@link createScorePOICategory} so the two cannot disagree.
|
|
145
148
|
*/
|
|
146
|
-
export declare function matchPOICategory(text: string, locale: string |
|
|
149
|
+
export declare function matchPOICategory(text: string, locale: string | null, lookup: POIPhraseLookup): POIPhraseMatch | null;
|
|
147
150
|
//# sourceMappingURL=poi.d.ts.map
|
package/out/poi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poi.d.ts","sourceRoot":"","sources":["../lib/poi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,IAAI,cAAc,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"poi.d.ts","sourceRoot":"","sources":["../lib/poi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE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OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,YAAY,GAAG,IAAI,CAAA;CAC/B;AAuCD;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,eAAe,GAAG,IAAI,CAuEpH;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,eAAe,EACvB,MAAM,CAAC,EAAE,MAAM,GACb,CAAC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,cAAc,KAAK,MAAM,CAiB/D;AAYD;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACrC,MAAM,EAAE,eAAe,EACvB,MAAM,CAAC,EAAE,MAAM,GACb,CAAC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,cAAc,KAAK,MAAM,CAU/D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,cAAc,GAAG,IAAI,CAQpH"}
|
package/out/poi.js
CHANGED
|
@@ -39,15 +39,15 @@ const ANCHOR_SEPARATOR = /,\s*|\s(near|in|at|around|to)\s+/gi;
|
|
|
39
39
|
*/
|
|
40
40
|
const MAX_SUBJECT_TOKENS = 8;
|
|
41
41
|
/**
|
|
42
|
-
* The categories one candidate subject reaches: the whole array when the first hit
|
|
43
|
-
*
|
|
42
|
+
* The categories one candidate subject reaches: the whole array when the first hit reads
|
|
43
|
+
* as a `"set"` ({@link POIPhraseMatch.reading}), preserved as the lookup returned it
|
|
44
44
|
* and never filtered, so a rung that flagged only some members keeps every member.
|
|
45
45
|
*
|
|
46
46
|
* The inconsistency stays visible.
|
|
47
47
|
* Otherwise, use only the first hit.
|
|
48
48
|
*/
|
|
49
49
|
function reachedMatches(hits) {
|
|
50
|
-
return hits[0].
|
|
50
|
+
return hits[0].reading === "set" ? [...hits] : [hits[0]];
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* Match a POI subject: the whole input, or the text before the first anchor
|
|
@@ -65,7 +65,7 @@ export function matchPOISubject(text, locale, lookup) {
|
|
|
65
65
|
const inputStart = text.indexOf(trimmed);
|
|
66
66
|
if (!trimmed)
|
|
67
67
|
return null;
|
|
68
|
-
const whole = lookup(trimmed, locale);
|
|
68
|
+
const whole = lookup(trimmed, locale ?? undefined);
|
|
69
69
|
if (whole.length) {
|
|
70
70
|
const matches = reachedMatches(whole);
|
|
71
71
|
return {
|
|
@@ -73,7 +73,10 @@ export function matchPOISubject(text, locale, lookup) {
|
|
|
73
73
|
matches,
|
|
74
74
|
subject: trimmed,
|
|
75
75
|
subjectSpan: { text: trimmed, start: inputStart, end: inputStart + trimmed.length },
|
|
76
|
+
relation: null,
|
|
77
|
+
relationSpan: null,
|
|
76
78
|
remainder: "",
|
|
79
|
+
anchorSpan: null,
|
|
77
80
|
};
|
|
78
81
|
}
|
|
79
82
|
for (const separator of trimmed.matchAll(ANCHOR_SEPARATOR)) {
|
|
@@ -84,7 +87,7 @@ export function matchPOISubject(text, locale, lookup) {
|
|
|
84
87
|
// Whitespace-only split rather than `wordsOf`, because a comma inside a subject is real content.
|
|
85
88
|
if (subject.split(/\s+/).length > MAX_SUBJECT_TOKENS)
|
|
86
89
|
break;
|
|
87
|
-
const hits = lookup(subject, locale);
|
|
90
|
+
const hits = lookup(subject, locale ?? undefined);
|
|
88
91
|
if (!hits.length)
|
|
89
92
|
continue;
|
|
90
93
|
const remainder = trimmed.slice(separator.index + separator[0].length).trim();
|
|
@@ -130,7 +133,7 @@ export function matchPOISubject(text, locale, lookup) {
|
|
|
130
133
|
*/
|
|
131
134
|
export function createScorePOIQuery(lookup, locale) {
|
|
132
135
|
return (input, shape) => {
|
|
133
|
-
const matched = matchPOISubject(input.normalized, locale ?? input.appliedLocale, lookup);
|
|
136
|
+
const matched = matchPOISubject(input.normalized, locale ?? input.appliedLocale ?? null, lookup);
|
|
134
137
|
if (!matched)
|
|
135
138
|
return 0;
|
|
136
139
|
if (matched.remainder === "")
|
|
@@ -165,10 +168,10 @@ const POI_CATEGORY_CONFIDENCE = 0.93;
|
|
|
165
168
|
*/
|
|
166
169
|
export function createScorePOICategory(lookup, locale) {
|
|
167
170
|
return (input, _shape) => {
|
|
168
|
-
const matched = matchPOISubject(input.normalized, locale ?? input.appliedLocale, lookup);
|
|
171
|
+
const matched = matchPOISubject(input.normalized, locale ?? input.appliedLocale ?? null, lookup);
|
|
169
172
|
if (!matched || matched.remainder !== "")
|
|
170
173
|
return 0;
|
|
171
|
-
if (
|
|
174
|
+
if (matched.match.kind !== "category")
|
|
172
175
|
return 0;
|
|
173
176
|
return POI_CATEGORY_CONFIDENCE * matched.match.confidence;
|
|
174
177
|
};
|
|
@@ -182,7 +185,7 @@ export function matchPOICategory(text, locale, lookup) {
|
|
|
182
185
|
const matched = matchPOISubject(text, locale, lookup);
|
|
183
186
|
if (!matched || matched.remainder !== "")
|
|
184
187
|
return null;
|
|
185
|
-
if (
|
|
188
|
+
if (matched.match.kind !== "category")
|
|
186
189
|
return null;
|
|
187
190
|
return matched.match;
|
|
188
191
|
}
|
package/out/poi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poi.js","sourceRoot":"","sources":["../lib/poi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"poi.js","sourceRoot":"","sources":["../lib/poi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,CAAC,CAAA;AA0G1B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,gBAAgB,GAAG,oCAAoC,CAAA;AAE7D;;;GAGG;AACH,MAAM,kBAAkB,GAAG,CAAC,CAAA;AAE5B;;;;;;;GAOG;AACH,SAAS,cAAc,CAAC,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B,CACrC,MAAuB,EACvB,MAAe;IAEf,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QACxB,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,IAAI,EAAE,MAAM,CAAC,CAAA;QAEhG,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,SAAS,KAAK,EAAE;YAAE,OAAO,CAAC,CAAA;QAElD,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU;YAAE,OAAO,CAAC,CAAA;QAE/C,OAAO,uBAAuB,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAA;IAC1D,CAAC,CAAA;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,MAAqB,EAAE,MAAuB;IAC5F,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IAErD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,SAAS,KAAK,EAAE;QAAE,OAAO,IAAI,CAAA;IAErD,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO,IAAI,CAAA;IAElD,OAAO,OAAO,CAAC,KAAK,CAAA;AACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mailwoman/kind-classifier",
|
|
3
|
-
"version": "10.1
|
|
3
|
+
"version": "10.2.1",
|
|
4
4
|
"description": "Stage 2.5 of the runtime pipeline — categorize inputs by query shape (postcode_only / locality_only / structured_address / intersection / po_box / landmark / vague). Rule-based for v1.",
|
|
5
5
|
"license": "AGPL-3.0-only OR LicenseRef-Commercial",
|
|
6
6
|
"repository": {
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@mailwoman/codex": "10.1
|
|
68
|
-
"@mailwoman/core": "10.1
|
|
69
|
-
"@mailwoman/query-shape": "10.1
|
|
67
|
+
"@mailwoman/codex": "10.2.1",
|
|
68
|
+
"@mailwoman/core": "10.2.1",
|
|
69
|
+
"@mailwoman/query-shape": "10.2.1"
|
|
70
70
|
}
|
|
71
71
|
}
|