@shobyde/boaz 0.8.5 → 0.9.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/dist/match/aliases.d.ts +35 -0
- package/dist/match/aliases.d.ts.map +1 -0
- package/dist/match/aliases.js +141 -0
- package/dist/match/aliases.js.map +1 -0
- package/dist/match/index.d.ts +84 -0
- package/dist/match/index.d.ts.map +1 -0
- package/dist/match/index.js +218 -0
- package/dist/match/index.js.map +1 -0
- package/package.json +21 -17
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface AliasSource {
|
|
2
|
+
/** The entity's canonical name, as the app prints it. */
|
|
3
|
+
name: string;
|
|
4
|
+
/** The clauses the app holds about this entity. */
|
|
5
|
+
documents: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface DerivedAlias {
|
|
8
|
+
alias: string;
|
|
9
|
+
entity: string;
|
|
10
|
+
kind: 'mechanical' | 'learned';
|
|
11
|
+
/** How discriminating the term is: entity share minus global share. */
|
|
12
|
+
score?: number;
|
|
13
|
+
}
|
|
14
|
+
/** Spelling aliases for one name: same word, different punctuation or number. */
|
|
15
|
+
export declare function mechanicalAliases(name: string): string[];
|
|
16
|
+
export interface DeriveOptions {
|
|
17
|
+
/** Minimum share of an entity's clauses a learned alias must appear in. */
|
|
18
|
+
minEntityShare?: number;
|
|
19
|
+
/** Maximum share of all other entities' clauses it may appear in. */
|
|
20
|
+
maxGlobalShare?: number;
|
|
21
|
+
/** Ignore entities with fewer clauses than this: one sentence is not a habit. */
|
|
22
|
+
minDocuments?: number;
|
|
23
|
+
/** Words that belong to the schema, not to any entity ("role", "sla"). */
|
|
24
|
+
exclude?: string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Derives aliases for every entity in one pass.
|
|
28
|
+
*
|
|
29
|
+
* const aliases = deriveAliases([{ name: 'Groundglass', documents: [...] }]);
|
|
30
|
+
* // -> [{ alias: 'conformance', entity: 'Groundglass', kind: 'learned', ... }]
|
|
31
|
+
*/
|
|
32
|
+
export declare function deriveAliases(sources: AliasSource[], options?: DeriveOptions): DerivedAlias[];
|
|
33
|
+
/** The aliases as a name→aliases map, which is what a resolver wants. */
|
|
34
|
+
export declare function aliasMap(aliases: DerivedAlias[]): Record<string, string[]>;
|
|
35
|
+
//# sourceMappingURL=aliases.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aliases.d.ts","sourceRoot":"","sources":["../../src/match/aliases.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,WAAW;IAC1B,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,YAAY,GAAG,SAAS,CAAC;IAC/B,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA0BD,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CA4BxD;AAED,MAAM,WAAW,aAAa;IAC5B,2EAA2E;IAC3E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qEAAqE;IACrE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iFAAiF;IACjF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,OAAO,GAAE,aAAkB,GAAG,YAAY,EAAE,CAsDjG;AAED,yEAAyE;AACzE,wBAAgB,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAM1E"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Aliases, derived at build time instead of hand-written by the app.
|
|
2
|
+
//
|
|
3
|
+
// Two tiers, and the difference matters:
|
|
4
|
+
//
|
|
5
|
+
// mechanical: things that are the same name written differently. A camel-case
|
|
6
|
+
// word, a hyphen, a plural, an acronym, a ".com". These are safe because they
|
|
7
|
+
// are spelling, not meaning, and every one is reversible by inspection.
|
|
8
|
+
//
|
|
9
|
+
// learned: words that this entity's own clauses use and other entities do not.
|
|
10
|
+
// "conformance" describes Groundglass and nothing else on the page, so a
|
|
11
|
+
// visitor who types it means Groundglass. These are accepted only when they
|
|
12
|
+
// discriminate: common inside the entity, rare outside it, and never a word
|
|
13
|
+
// from the entity's own name.
|
|
14
|
+
const STOP = new Set([
|
|
15
|
+
'the', 'and', 'for', 'with', 'that', 'this', 'from', 'into', 'over', 'under', 'than', 'then', 'them', 'they',
|
|
16
|
+
'their', 'there', 'here', 'when', 'what', 'which', 'while', 'your', 'you', 'our', 'its', 'it', 'is', 'are',
|
|
17
|
+
'was', 'were', 'has', 'have', 'had', 'not', 'but', 'all', 'any', 'can', 'will', 'would', 'could', 'should',
|
|
18
|
+
'one', 'two', 'each', 'every', 'more', 'most', 'some', 'such', 'own', 'same', 'only', 'also', 'because',
|
|
19
|
+
]);
|
|
20
|
+
const words = (text) => String(text)
|
|
21
|
+
.toLowerCase()
|
|
22
|
+
.replace(/[^a-z0-9+#]+/g, ' ')
|
|
23
|
+
.split(' ')
|
|
24
|
+
.filter(Boolean);
|
|
25
|
+
const stem = (word) => word.replace(/(ies)$/, 'y').replace(/(es|s)$/, '');
|
|
26
|
+
function splitCamel(name) {
|
|
27
|
+
return String(name)
|
|
28
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
29
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
|
|
30
|
+
.split(/[\s._-]+/)
|
|
31
|
+
.filter(Boolean);
|
|
32
|
+
}
|
|
33
|
+
/** Spelling aliases for one name: same word, different punctuation or number. */
|
|
34
|
+
export function mechanicalAliases(name) {
|
|
35
|
+
const out = new Set();
|
|
36
|
+
const parts = splitCamel(name);
|
|
37
|
+
const joined = parts.join('');
|
|
38
|
+
out.add(joined);
|
|
39
|
+
out.add(parts.join(' '));
|
|
40
|
+
out.add(parts.join('-'));
|
|
41
|
+
out.add(parts.join('_'));
|
|
42
|
+
// A dotted product name is typed with a space, a dot, or neither.
|
|
43
|
+
if (/\./.test(name)) {
|
|
44
|
+
out.add(name.replace(/\./g, ' '));
|
|
45
|
+
out.add(name.replace(/\./g, ''));
|
|
46
|
+
out.add(name.replace(/\.com$/, ''));
|
|
47
|
+
}
|
|
48
|
+
// Plural and singular of the last word.
|
|
49
|
+
const last = parts[parts.length - 1] ?? '';
|
|
50
|
+
if (last.endsWith('s') && last.length > 3)
|
|
51
|
+
out.add([...parts.slice(0, -1), last.slice(0, -1)].join(''));
|
|
52
|
+
else if (last)
|
|
53
|
+
out.add([...parts.slice(0, -1), `${last}s`].join(''));
|
|
54
|
+
// An acronym, when the name is two or more words.
|
|
55
|
+
if (parts.length >= 2)
|
|
56
|
+
out.add(parts.map((part) => part[0]).join(''));
|
|
57
|
+
const acronym = parts.length >= 2 ? parts.map((part) => part[0]).join('') : '';
|
|
58
|
+
out.delete('');
|
|
59
|
+
out.delete(String(name).toLowerCase());
|
|
60
|
+
// Aliases are compared, not printed: lowercase them once here so every caller
|
|
61
|
+
// does not have to remember. An acronym can be two letters and still count.
|
|
62
|
+
return [...out]
|
|
63
|
+
.map((alias) => alias.toLowerCase())
|
|
64
|
+
.filter((alias) => alias.length >= 3 || alias === acronym.toLowerCase());
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Derives aliases for every entity in one pass.
|
|
68
|
+
*
|
|
69
|
+
* const aliases = deriveAliases([{ name: 'Groundglass', documents: [...] }]);
|
|
70
|
+
* // -> [{ alias: 'conformance', entity: 'Groundglass', kind: 'learned', ... }]
|
|
71
|
+
*/
|
|
72
|
+
export function deriveAliases(sources, options = {}) {
|
|
73
|
+
const minEntityShare = options.minEntityShare ?? 0.5;
|
|
74
|
+
const maxGlobalShare = options.maxGlobalShare ?? 0.25;
|
|
75
|
+
const minDocuments = options.minDocuments ?? 2;
|
|
76
|
+
// A fact table's attribute names appear in every entity's clauses, so they look
|
|
77
|
+
// discriminating per entity and are worthless as aliases. The app knows its
|
|
78
|
+
// schema; it passes the words here.
|
|
79
|
+
const excluded = new Set((options.exclude ?? []).flatMap((word) => words(word)));
|
|
80
|
+
const prepared = sources.map((source) => ({
|
|
81
|
+
name: source.name,
|
|
82
|
+
tokens: source.documents.map((document) => new Set(words(document))),
|
|
83
|
+
}));
|
|
84
|
+
const totals = new Map();
|
|
85
|
+
for (const entity of prepared)
|
|
86
|
+
for (const set of entity.tokens)
|
|
87
|
+
for (const word of set)
|
|
88
|
+
totals.set(word, (totals.get(word) ?? 0) + 1);
|
|
89
|
+
const totalDocuments = prepared.reduce((sum, entity) => sum + entity.tokens.length, 0) || 1;
|
|
90
|
+
const result = [];
|
|
91
|
+
const seen = new Set();
|
|
92
|
+
for (const entity of prepared) {
|
|
93
|
+
const nameWords = new Set(words(entity.name));
|
|
94
|
+
for (const alias of mechanicalAliases(entity.name)) {
|
|
95
|
+
const key = `${alias}:${entity.name}`;
|
|
96
|
+
if (seen.has(key))
|
|
97
|
+
continue;
|
|
98
|
+
seen.add(key);
|
|
99
|
+
result.push({ alias, entity: entity.name, kind: 'mechanical' });
|
|
100
|
+
}
|
|
101
|
+
if (entity.tokens.length < minDocuments)
|
|
102
|
+
continue;
|
|
103
|
+
const counts = new Map();
|
|
104
|
+
for (const set of entity.tokens)
|
|
105
|
+
for (const word of set)
|
|
106
|
+
counts.set(word, (counts.get(word) ?? 0) + 1);
|
|
107
|
+
for (const [word, count] of counts) {
|
|
108
|
+
if (word.length < 4 || STOP.has(word) || excluded.has(word) || /^\d+$/.test(word))
|
|
109
|
+
continue;
|
|
110
|
+
if (nameWords.has(word) || [...nameWords].some((nameWord) => stem(nameWord) === stem(word)))
|
|
111
|
+
continue;
|
|
112
|
+
const entityShare = count / entity.tokens.length;
|
|
113
|
+
if (entityShare < minEntityShare)
|
|
114
|
+
continue;
|
|
115
|
+
const global = (totals.get(word) ?? 0) - count;
|
|
116
|
+
const globalShare = global / Math.max(1, totalDocuments - entity.tokens.length);
|
|
117
|
+
if (globalShare > maxGlobalShare)
|
|
118
|
+
continue;
|
|
119
|
+
const key = `${word}:${entity.name}`;
|
|
120
|
+
if (seen.has(key))
|
|
121
|
+
continue;
|
|
122
|
+
seen.add(key);
|
|
123
|
+
result.push({
|
|
124
|
+
alias: word,
|
|
125
|
+
entity: entity.name,
|
|
126
|
+
kind: 'learned',
|
|
127
|
+
score: Math.round((entityShare - globalShare) * 100) / 100,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return result.sort((a, b) => (a.entity === b.entity ? (b.score ?? 0) - (a.score ?? 0) : a.entity.localeCompare(b.entity)));
|
|
132
|
+
}
|
|
133
|
+
/** The aliases as a name→aliases map, which is what a resolver wants. */
|
|
134
|
+
export function aliasMap(aliases) {
|
|
135
|
+
const map = {};
|
|
136
|
+
for (const { alias, entity } of aliases) {
|
|
137
|
+
map[alias] = [...new Set([...(map[alias] ?? []), entity])];
|
|
138
|
+
}
|
|
139
|
+
return map;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=aliases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aliases.js","sourceRoot":"","sources":["../../src/match/aliases.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,EAAE;AACF,yCAAyC;AACzC,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,0EAA0E;AAC1E,EAAE;AACF,iFAAiF;AACjF,2EAA2E;AAC3E,8EAA8E;AAC9E,8EAA8E;AAC9E,gCAAgC;AAiBhC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC;IACnB,KAAK,EAAE,KAAK,EAAE,KAAK,EA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AC,OAAuB;IAC9C,MAAM,GAAG,GAA6B,EAAE,CAAC;IACzC,KAAK,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,OAAO,EAAE,CAAC;QACxC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export interface ResolverMatch {
|
|
2
|
+
/** The spelling the visitor typed. */
|
|
3
|
+
from: string;
|
|
4
|
+
/** The canonical name it resolved to. */
|
|
5
|
+
to: string;
|
|
6
|
+
/** Edit distance between the compacted forms. */
|
|
7
|
+
edits: number;
|
|
8
|
+
/** 1 for an exact match, lower for a fuzzier one. */
|
|
9
|
+
confidence: number;
|
|
10
|
+
}
|
|
11
|
+
export interface ResolvedQuestion {
|
|
12
|
+
text: string;
|
|
13
|
+
matches: ResolverMatch[];
|
|
14
|
+
}
|
|
15
|
+
/** Bounded Damerau-Levenshtein: enough for a typo, cheap enough to run per span. */
|
|
16
|
+
export declare function editDistance(a: string, b: string, limit?: number): number;
|
|
17
|
+
/** A phonetic key. Two spellings of the same name usually agree on it. */
|
|
18
|
+
export declare function phoneticKey(word: string): string;
|
|
19
|
+
export interface EntityResolverOptions {
|
|
20
|
+
/** The names the app can be asked about, in the spelling it wants back. */
|
|
21
|
+
names: string[];
|
|
22
|
+
/** Longest span to try, in words. "hob knob" is two. */
|
|
23
|
+
maxSpan?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Rewrites near-miss names to the canonical one, before routing.
|
|
27
|
+
*
|
|
28
|
+
* const resolver = createEntityResolver({ names: ['Hobnob', 'Readback'] });
|
|
29
|
+
* resolver.resolve('what stack does hob knob use').text
|
|
30
|
+
* // 'what stack does Hobnob use'
|
|
31
|
+
*
|
|
32
|
+
* Two signals must agree for a fuzzy match, unless the spelling is exact: the
|
|
33
|
+
* phonetic key, or the first three letters. One signal alone matches too much:
|
|
34
|
+
* "boas" is one edit from "boaz" and also from "bias".
|
|
35
|
+
*/
|
|
36
|
+
export declare function createEntityResolver(options: EntityResolverOptions): {
|
|
37
|
+
names: string[];
|
|
38
|
+
resolve: (input: string) => ResolvedQuestion;
|
|
39
|
+
};
|
|
40
|
+
export type EntityResolver = ReturnType<typeof createEntityResolver>;
|
|
41
|
+
export interface EvidenceDocument {
|
|
42
|
+
/** Stable id for the clause, so a caller can name what it quoted. */
|
|
43
|
+
id: string;
|
|
44
|
+
/** One sentence or fact, in the app's own words. */
|
|
45
|
+
text: string;
|
|
46
|
+
/** Optional subject, for asking "what does X say about Y". */
|
|
47
|
+
subject?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface EvidenceHit {
|
|
50
|
+
document: EvidenceDocument;
|
|
51
|
+
score: number;
|
|
52
|
+
/** Words the clause and the question share. */
|
|
53
|
+
shared: string[];
|
|
54
|
+
/** True when the clause asserts absence ("no model", "never uploads"). */
|
|
55
|
+
denial: boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface EvidenceOptions {
|
|
58
|
+
/** A clause must cover this share of the question's weight. */
|
|
59
|
+
minScore?: number;
|
|
60
|
+
}
|
|
61
|
+
export declare const contentWords: (text: string) => string[];
|
|
62
|
+
/**
|
|
63
|
+
* Weighted evidence over the app's own clauses.
|
|
64
|
+
*
|
|
65
|
+
* const index = createEvidenceIndex(kb.clauses);
|
|
66
|
+
* index.find('does hobnob label speakers', { subject: 'Hobnob' })
|
|
67
|
+
*
|
|
68
|
+
* A word's weight is inverse document frequency in this corpus, so "speaker"
|
|
69
|
+
* outranks "project". The head noun (the last content word of the question) has
|
|
70
|
+
* to appear: sharing a verb is not evidence. A clause that asserts absence is
|
|
71
|
+
* returned as a denial, which is an answer, not a miss.
|
|
72
|
+
*/
|
|
73
|
+
export declare function createEvidenceIndex(documents: EvidenceDocument[], options?: EvidenceOptions): {
|
|
74
|
+
size: number;
|
|
75
|
+
find: (question: string, findOptions?: {
|
|
76
|
+
subject?: string;
|
|
77
|
+
}) => EvidenceHit | undefined;
|
|
78
|
+
/** For diagnostics: the words the corpus makes expensive. */
|
|
79
|
+
weight: (word: string) => number;
|
|
80
|
+
};
|
|
81
|
+
export type EvidenceIndex = ReturnType<typeof createEvidenceIndex>;
|
|
82
|
+
export { aliasMap, deriveAliases, mechanicalAliases } from './aliases.js';
|
|
83
|
+
export type { AliasSource, DeriveOptions, DerivedAlias } from './aliases.js';
|
|
84
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/match/index.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,aAAa;IAC5B,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAKD,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,MAAM,CAepE;AAED,0EAA0E;AAC1E,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAchD;AAED,MAAM,WAAW,qBAAqB;IACpC,2EAA2E;IAC3E,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB;;qBAKzC,MAAM,KAAG,gBAAgB;EAgFlD;AAED,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAIrE,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAC;IACX,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,0EAA0E;IAC1E,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAQD,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,MAAM,EAKO,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,gBAAgB,EAAE,EAAE,OAAO,GAAE,eAAoB;;qBAUtE,MAAM,gBAAe;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,KAAQ,WAAW,GAAG,SAAS;IAiC9F,6DAA6D;mBAnCzC,MAAM;EAsC7B;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAGnE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC1E,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// Matching, as a library concern: names that are nearly right, and evidence
|
|
2
|
+
// that is weighted by how rare a word is.
|
|
3
|
+
//
|
|
4
|
+
// Neither function knows what the app is about. The app supplies the names, the
|
|
5
|
+
// clauses and the vocabulary; this decides which name the words meant and which
|
|
6
|
+
// clause carries the question.
|
|
7
|
+
const compact = (text) => String(text).toLowerCase().replace(/[^a-z0-9]+/g, '');
|
|
8
|
+
const words = (text) => String(text).toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim().split(/\s+/).filter(Boolean);
|
|
9
|
+
/** Bounded Damerau-Levenshtein: enough for a typo, cheap enough to run per span. */
|
|
10
|
+
export function editDistance(a, b, limit = 3) {
|
|
11
|
+
if (a === b)
|
|
12
|
+
return 0;
|
|
13
|
+
if (Math.abs(a.length - b.length) > limit)
|
|
14
|
+
return limit;
|
|
15
|
+
const rows = Array.from({ length: a.length + 1 }, (_, index) => [index, ...Array(b.length).fill(0)]);
|
|
16
|
+
for (let column = 1; column <= b.length; column += 1)
|
|
17
|
+
rows[0][column] = column;
|
|
18
|
+
for (let row = 1; row <= a.length; row += 1) {
|
|
19
|
+
for (let column = 1; column <= b.length; column += 1) {
|
|
20
|
+
const cost = a[row - 1] === b[column - 1] ? 0 : 1;
|
|
21
|
+
rows[row][column] = Math.min(rows[row - 1][column] + 1, rows[row][column - 1] + 1, rows[row - 1][column - 1] + cost);
|
|
22
|
+
if (row > 1 && column > 1 && a[row - 1] === b[column - 2] && a[row - 2] === b[column - 1]) {
|
|
23
|
+
rows[row][column] = Math.min(rows[row][column], rows[row - 2][column - 2] + cost);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return rows[a.length][b.length];
|
|
28
|
+
}
|
|
29
|
+
/** A phonetic key. Two spellings of the same name usually agree on it. */
|
|
30
|
+
export function phoneticKey(word) {
|
|
31
|
+
const key = String(word).toUpperCase().replace(/[^A-Z]/g, '');
|
|
32
|
+
if (!key)
|
|
33
|
+
return '';
|
|
34
|
+
const map = {
|
|
35
|
+
B: 1, F: 1, P: 1, V: 1, C: 2, G: 2, J: 2, K: 2, Q: 2, S: 2, X: 2, Z: 2, D: 3, T: 3, L: 4, M: 5, N: 5, R: 6,
|
|
36
|
+
};
|
|
37
|
+
let tail = '';
|
|
38
|
+
let last = map[key[0]] ?? 0;
|
|
39
|
+
for (const char of key.slice(1)) {
|
|
40
|
+
const code = map[char] ?? 0;
|
|
41
|
+
if (code && code !== last)
|
|
42
|
+
tail += String(code);
|
|
43
|
+
last = code || last;
|
|
44
|
+
}
|
|
45
|
+
return `${key[0]}${tail.padEnd(3, '0').slice(0, 3)}`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Rewrites near-miss names to the canonical one, before routing.
|
|
49
|
+
*
|
|
50
|
+
* const resolver = createEntityResolver({ names: ['Hobnob', 'Readback'] });
|
|
51
|
+
* resolver.resolve('what stack does hob knob use').text
|
|
52
|
+
* // 'what stack does Hobnob use'
|
|
53
|
+
*
|
|
54
|
+
* Two signals must agree for a fuzzy match, unless the spelling is exact: the
|
|
55
|
+
* phonetic key, or the first three letters. One signal alone matches too much:
|
|
56
|
+
* "boas" is one edit from "boaz" and also from "bias".
|
|
57
|
+
*/
|
|
58
|
+
export function createEntityResolver(options) {
|
|
59
|
+
const names = [...new Set(options.names.filter(Boolean))];
|
|
60
|
+
const maxSpan = options.maxSpan ?? 3;
|
|
61
|
+
const targets = names.map((name) => ({ name, compact: compact(name), phonetic: phoneticKey(name) }));
|
|
62
|
+
function resolve(input) {
|
|
63
|
+
const original = String(input);
|
|
64
|
+
const tokens = words(original.replace(/\bdot\b/gi, ' '));
|
|
65
|
+
if (!tokens.length)
|
|
66
|
+
return { text: original, matches: [] };
|
|
67
|
+
const hits = [];
|
|
68
|
+
for (const target of targets) {
|
|
69
|
+
if (target.compact.length < 4)
|
|
70
|
+
continue;
|
|
71
|
+
const allowed = target.compact.length >= 8 ? 2 : 1;
|
|
72
|
+
for (let span = 1; span <= maxSpan; span += 1) {
|
|
73
|
+
for (let start = 0; start + span <= tokens.length; start += 1) {
|
|
74
|
+
// Three tokens joined is usually a phrase, not a name; cap the bytes.
|
|
75
|
+
const candidate = tokens.slice(start, start + span).join('');
|
|
76
|
+
if (candidate.length < 4 || candidate.length > target.compact.length + 3)
|
|
77
|
+
continue;
|
|
78
|
+
const edits = editDistance(candidate, target.compact, 3);
|
|
79
|
+
if (edits > 2)
|
|
80
|
+
continue;
|
|
81
|
+
const phonetic = phoneticKey(candidate) === target.phonetic;
|
|
82
|
+
const prefix = candidate.slice(0, 3) === target.compact.slice(0, 3);
|
|
83
|
+
const exact = candidate === target.compact;
|
|
84
|
+
if (!exact && !(edits <= allowed && (phonetic || prefix)))
|
|
85
|
+
continue;
|
|
86
|
+
hits.push({
|
|
87
|
+
from: tokens.slice(start, start + span).join(' '),
|
|
88
|
+
to: target.name,
|
|
89
|
+
edits,
|
|
90
|
+
confidence: exact ? 1 : Math.round((1 - edits / Math.max(4, target.compact.length)) * 100) / 100,
|
|
91
|
+
start,
|
|
92
|
+
span,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!hits.length)
|
|
98
|
+
return { text: original, matches: [] };
|
|
99
|
+
// Non-overlapping, best first, then apply every accepted hit right to left so
|
|
100
|
+
// the earlier indices stay valid.
|
|
101
|
+
hits.sort((a, b) => a.edits - b.edits || b.span - a.span);
|
|
102
|
+
const chosen = [];
|
|
103
|
+
for (const hit of hits) {
|
|
104
|
+
if (chosen.some((other) => hit.start < other.start + other.span && other.start < hit.start + hit.span))
|
|
105
|
+
continue;
|
|
106
|
+
chosen.push(hit);
|
|
107
|
+
}
|
|
108
|
+
let text = original;
|
|
109
|
+
for (const hit of [...chosen].sort((a, b) => b.start - a.start)) {
|
|
110
|
+
const parts = text.split(/(\s+)/);
|
|
111
|
+
const out = [];
|
|
112
|
+
let index = -1;
|
|
113
|
+
let skip = 0;
|
|
114
|
+
for (const part of parts) {
|
|
115
|
+
if (/^\s+$/.test(part)) {
|
|
116
|
+
out.push(part);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
index += 1;
|
|
120
|
+
if (index < hit.start) {
|
|
121
|
+
out.push(part);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (index === hit.start) {
|
|
125
|
+
out.push(hit.to);
|
|
126
|
+
skip = hit.span - 1;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (skip > 0) {
|
|
130
|
+
skip -= 1;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
out.push(part);
|
|
134
|
+
}
|
|
135
|
+
text = out.join('').replace(/\s{2,}/g, ' ');
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
text,
|
|
139
|
+
matches: chosen.map(({ from, to, edits, confidence }) => ({ from, to, edits, confidence })),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return { names, resolve };
|
|
143
|
+
}
|
|
144
|
+
const STOP = new Set([
|
|
145
|
+
'the', 'a', 'an', 'does', 'do', 'is', 'are', 'was', 'were', 'can', 'could', 'it', 'its', 'this', 'that',
|
|
146
|
+
'with', 'for', 'and', 'or', 'to', 'in', 'on', 'of', 'any', 'have', 'has', 'had', 'be', 'by', 'from', 'as',
|
|
147
|
+
'at', 'about', 'support', 'supports', 'use', 'uses', 'using', 'work', 'works', 'need', 'needs',
|
|
148
|
+
]);
|
|
149
|
+
export const contentWords = (text) => String(text)
|
|
150
|
+
.toLowerCase()
|
|
151
|
+
.replace(/[^a-z0-9+#]+/g, ' ')
|
|
152
|
+
.split(' ')
|
|
153
|
+
.filter((word) => word.length > 2 && !STOP.has(word));
|
|
154
|
+
/**
|
|
155
|
+
* Weighted evidence over the app's own clauses.
|
|
156
|
+
*
|
|
157
|
+
* const index = createEvidenceIndex(kb.clauses);
|
|
158
|
+
* index.find('does hobnob label speakers', { subject: 'Hobnob' })
|
|
159
|
+
*
|
|
160
|
+
* A word's weight is inverse document frequency in this corpus, so "speaker"
|
|
161
|
+
* outranks "project". The head noun (the last content word of the question) has
|
|
162
|
+
* to appear: sharing a verb is not evidence. A clause that asserts absence is
|
|
163
|
+
* returned as a denial, which is an answer, not a miss.
|
|
164
|
+
*/
|
|
165
|
+
export function createEvidenceIndex(documents, options = {}) {
|
|
166
|
+
const minScore = options.minScore ?? 0.6;
|
|
167
|
+
const prepared = documents.map((document) => ({ document, words: new Set(contentWords(document.text)) }));
|
|
168
|
+
const documentFrequency = new Map();
|
|
169
|
+
for (const { words: set } of prepared) {
|
|
170
|
+
for (const word of set)
|
|
171
|
+
documentFrequency.set(word, (documentFrequency.get(word) ?? 0) + 1);
|
|
172
|
+
}
|
|
173
|
+
const total = Math.max(1, prepared.length);
|
|
174
|
+
const weight = (word) => Math.log(1 + total / (1 + (documentFrequency.get(word) ?? 0)));
|
|
175
|
+
function find(question, findOptions = {}) {
|
|
176
|
+
const subjectWords = new Set(contentWords(findOptions.subject ?? ''));
|
|
177
|
+
// Words the corpus has never seen cannot be evidence, and the subject's own
|
|
178
|
+
// name is not evidence either: it is the filter, not the question. Scoring
|
|
179
|
+
// over them would mark a correct clause as a miss.
|
|
180
|
+
const asked = contentWords(question).filter((word) => !subjectWords.has(word) && (documentFrequency.get(word) ?? 0) > 0);
|
|
181
|
+
if (!asked.length)
|
|
182
|
+
return undefined;
|
|
183
|
+
// The head noun is the last content word that is not a generic wrapper
|
|
184
|
+
// ("model file", "kind of thing"): "file" is not the subject of the question,
|
|
185
|
+
// "model" is.
|
|
186
|
+
const GENERIC = new Set(['file', 'thing', 'kind', 'type', 'way', 'feature', 'option', 'version']);
|
|
187
|
+
const head = [...asked].reverse().find((word) => !GENERIC.has(word)) ?? asked[asked.length - 1];
|
|
188
|
+
let best;
|
|
189
|
+
for (const { document, words: set } of prepared) {
|
|
190
|
+
if (findOptions.subject && document.subject && document.subject.toLowerCase() !== findOptions.subject.toLowerCase())
|
|
191
|
+
continue;
|
|
192
|
+
const shared = asked.filter((word) => set.has(word));
|
|
193
|
+
if (!shared.length)
|
|
194
|
+
continue;
|
|
195
|
+
// The head noun is the gate: a clause about "server" for a question about
|
|
196
|
+
// "quizzes" shares nothing that matters.
|
|
197
|
+
if (!set.has(head))
|
|
198
|
+
continue;
|
|
199
|
+
const totalWeight = asked.reduce((sum, word) => sum + weight(word), 0);
|
|
200
|
+
const sharedWeight = shared.reduce((sum, word) => sum + weight(word), 0);
|
|
201
|
+
const score = totalWeight ? sharedWeight / totalWeight : 0;
|
|
202
|
+
if (score < minScore)
|
|
203
|
+
continue;
|
|
204
|
+
const denial = /\b(no|not|never|without|nobody|nothing)\b/i.test(document.text);
|
|
205
|
+
if (!best || score > best.score)
|
|
206
|
+
best = { document, score: Math.round(score * 100) / 100, shared, denial };
|
|
207
|
+
}
|
|
208
|
+
return best;
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
size: prepared.length,
|
|
212
|
+
find,
|
|
213
|
+
/** For diagnostics: the words the corpus makes expensive. */
|
|
214
|
+
weight,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
export { aliasMap, deriveAliases, mechanicalAliases } from './aliases.js';
|
|
218
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/match/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,0CAA0C;AAC1C,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,+BAA+B;AAkB/B,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;AACxF,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAE3H,oFAAoF;AACpF,MAAM,UAAU,YAAY,CAAC,CAAS,EAAE,CAAS,EAA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;YACzC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,SAAS;YAC7B,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;YACvE,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;YACzE,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,YAAY,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,IAAI,KAAK,GAAG,QAAQ;gBAAE,SAAS;YAC/B,MAAM,MAAM,GAAG,4CAA4C,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAChF,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK;gBAAE,IAAI,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAC7G,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,IAAI,EAAE,QAAQ,CAAC,MAAM;QACrB,IAAI;QACJ,6DAA6D;QAC7D,MAAM;KACP,CAAC;AACJ,CAAC;AAKD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shobyde/boaz",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Declarative capabilities, a knowledge base with rules, and a deterministic answer engine for in-browser assistants: no model download, no API key, every reply traceable to a fact.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,38 +28,42 @@
|
|
|
28
28
|
"types": "./dist/core/index.d.ts",
|
|
29
29
|
"import": "./dist/core/index.js"
|
|
30
30
|
},
|
|
31
|
+
"./build": {
|
|
32
|
+
"types": "./dist/build/index.d.ts",
|
|
33
|
+
"import": "./dist/build/index.js"
|
|
34
|
+
},
|
|
31
35
|
"./core": {
|
|
32
36
|
"types": "./dist/core/index.d.ts",
|
|
33
37
|
"import": "./dist/core/index.js"
|
|
34
38
|
},
|
|
35
|
-
"./
|
|
36
|
-
"types": "./dist/
|
|
37
|
-
"import": "./dist/
|
|
39
|
+
"./dom": {
|
|
40
|
+
"types": "./dist/dom/index.d.ts",
|
|
41
|
+
"import": "./dist/dom/index.js"
|
|
38
42
|
},
|
|
39
|
-
"./
|
|
40
|
-
"types": "./dist/
|
|
41
|
-
"import": "./dist/
|
|
43
|
+
"./extract": {
|
|
44
|
+
"types": "./dist/extract/index.d.ts",
|
|
45
|
+
"import": "./dist/extract/index.js"
|
|
42
46
|
},
|
|
43
|
-
"./
|
|
44
|
-
"types": "./dist/
|
|
45
|
-
"import": "./dist/
|
|
47
|
+
"./match": {
|
|
48
|
+
"types": "./dist/match/index.d.ts",
|
|
49
|
+
"import": "./dist/match/index.js"
|
|
46
50
|
},
|
|
51
|
+
"./package.json": "./package.json",
|
|
47
52
|
"./probes": {
|
|
48
53
|
"types": "./dist/build/probes.d.ts",
|
|
49
54
|
"import": "./dist/build/probes.js"
|
|
50
55
|
},
|
|
51
|
-
"./
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
"import": "./dist/dom/index.js"
|
|
56
|
+
"./react": {
|
|
57
|
+
"types": "./dist/react/index.d.ts",
|
|
58
|
+
"import": "./dist/react/index.js"
|
|
55
59
|
},
|
|
56
60
|
"./rules": {
|
|
57
61
|
"types": "./dist/rules/index.d.ts",
|
|
58
62
|
"import": "./dist/rules/index.js"
|
|
59
63
|
},
|
|
60
|
-
"./
|
|
61
|
-
"types": "./dist/
|
|
62
|
-
"import": "./dist/
|
|
64
|
+
"./vite": {
|
|
65
|
+
"types": "./dist/vite/index.d.ts",
|
|
66
|
+
"import": "./dist/vite/index.js"
|
|
63
67
|
}
|
|
64
68
|
},
|
|
65
69
|
"bin": {
|