cspell-trie-lib 6.1.0 → 6.1.3-alpha.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/lib/TrieBuilder.js +7 -10
- package/dist/lib/compoundWalker.js +2 -4
- package/dist/lib/convertToTrieRefNodes.js +2 -4
- package/dist/lib/distance/distanceAStar.js +1 -2
- package/dist/lib/distance/weightedMaps.js +3 -4
- package/dist/lib/find.js +10 -16
- package/dist/lib/io/importExportV2.js +1 -2
- package/dist/lib/io/importExportV3.js +4 -8
- package/dist/lib/mappers/mapDictionaryInfo.js +2 -2
- package/dist/lib/mappers/mapHunspellInformation.js +1 -1
- package/dist/lib/suggestions/genSuggestionsOptions.js +1 -2
- package/dist/lib/suggestions/suggestAStar.js +10 -16
- package/dist/lib/suggestions/suggestCollector.js +2 -2
- package/dist/lib/suggestions/walker/hintedWalker.js +3 -4
- package/dist/lib/trie-util.js +1 -1
- package/dist/lib/trie.js +6 -7
- package/dist/lib/utils/PairingHeap.js +1 -2
- package/dist/lib/utils/memorizer.js +2 -4
- package/dist/lib/utils/secondChanceCache.js +1 -2
- package/dist/lib/utils/timer.js +1 -1
- package/package.json +7 -7
package/dist/lib/TrieBuilder.js
CHANGED
|
@@ -100,20 +100,18 @@ class TrieBuilder {
|
|
|
100
100
|
return n;
|
|
101
101
|
}
|
|
102
102
|
storeTransform(src, s, result) {
|
|
103
|
-
var _a;
|
|
104
103
|
if (!Object.isFrozen(result) || !Object.isFrozen(src))
|
|
105
104
|
return;
|
|
106
|
-
const t =
|
|
105
|
+
const t = this.transforms.get(src) ?? new Map();
|
|
107
106
|
t.set(s, result);
|
|
108
107
|
this.transforms.set(src, t);
|
|
109
108
|
}
|
|
110
109
|
addChild(node, head, child) {
|
|
111
|
-
|
|
112
|
-
if (((_a = node.c) === null || _a === void 0 ? void 0 : _a.get(head)) !== child) {
|
|
110
|
+
if (node.c?.get(head) !== child) {
|
|
113
111
|
if (!node.c || Object.isFrozen(node)) {
|
|
114
|
-
node = { ...node, c: new Map(
|
|
112
|
+
node = { ...node, c: new Map(node.c ?? []) };
|
|
115
113
|
}
|
|
116
|
-
|
|
114
|
+
node.c?.set(head, child);
|
|
117
115
|
}
|
|
118
116
|
return Object.isFrozen(child) ? this.tryToCache(node) : node;
|
|
119
117
|
}
|
|
@@ -134,10 +132,9 @@ class TrieBuilder {
|
|
|
134
132
|
return cachedNode;
|
|
135
133
|
}
|
|
136
134
|
_insert(node, s, d) {
|
|
137
|
-
var _a, _b;
|
|
138
135
|
const orig = node;
|
|
139
136
|
if (Object.isFrozen(node)) {
|
|
140
|
-
const n =
|
|
137
|
+
const n = this.transforms.get(node)?.get(s);
|
|
141
138
|
if (n) {
|
|
142
139
|
return this.tryCacheFrozen(n);
|
|
143
140
|
}
|
|
@@ -154,7 +151,7 @@ class TrieBuilder {
|
|
|
154
151
|
}
|
|
155
152
|
const head = s[0];
|
|
156
153
|
const tail = s.slice(1);
|
|
157
|
-
const cNode =
|
|
154
|
+
const cNode = node.c?.get(head);
|
|
158
155
|
const child = cNode ? this._insert(cNode, tail, d + 1) : this.buildTail(tail);
|
|
159
156
|
node = this.addChild(node, head, child);
|
|
160
157
|
this.storeTransform(orig, s, node);
|
|
@@ -165,7 +162,7 @@ class TrieBuilder {
|
|
|
165
162
|
let d = 1;
|
|
166
163
|
for (const s of word.split('')) {
|
|
167
164
|
const p = this.lastPath[d];
|
|
168
|
-
if (
|
|
165
|
+
if (p?.s !== s)
|
|
169
166
|
break;
|
|
170
167
|
d++;
|
|
171
168
|
}
|
|
@@ -10,12 +10,10 @@ exports.compoundWords = exports.compoundWalker = void 0;
|
|
|
10
10
|
* @param trie the compound Trie to walk
|
|
11
11
|
*/
|
|
12
12
|
function* compoundWalker(trie, caseSensitive = true) {
|
|
13
|
-
var _a;
|
|
14
13
|
const { compoundCharacter: cc, forbiddenWordPrefix: forbidden, stripCaseAndAccentsPrefix } = trie.options;
|
|
15
14
|
const blockNode = new Set([cc, forbidden, stripCaseAndAccentsPrefix]);
|
|
16
|
-
const root = (!caseSensitive &&
|
|
15
|
+
const root = (!caseSensitive && trie.root.c?.get(stripCaseAndAccentsPrefix)) || trie.root;
|
|
17
16
|
function* walk(n, s, c, d) {
|
|
18
|
-
var _a;
|
|
19
17
|
const deeper = yield { n, s, c, d };
|
|
20
18
|
if (deeper !== false && n.c) {
|
|
21
19
|
for (const [k, cn] of n.c) {
|
|
@@ -24,7 +22,7 @@ function* compoundWalker(trie, caseSensitive = true) {
|
|
|
24
22
|
yield* walk(cn, s + k, false, d);
|
|
25
23
|
}
|
|
26
24
|
if (n.c.has(cc)) {
|
|
27
|
-
const compoundNodes =
|
|
25
|
+
const compoundNodes = root.c?.get(cc);
|
|
28
26
|
if (compoundNodes) {
|
|
29
27
|
yield* walk(compoundNodes, s, true, d + 1);
|
|
30
28
|
}
|
|
@@ -15,7 +15,6 @@ function convertToTrieRefNodes(root) {
|
|
|
15
15
|
const cached = new Map();
|
|
16
16
|
const rollupTally = new Map();
|
|
17
17
|
function tally(n) {
|
|
18
|
-
var _a;
|
|
19
18
|
if (n.f && !n.c) {
|
|
20
19
|
tallies.set(eow, (tallies.get(eow) || 0) + 1);
|
|
21
20
|
return;
|
|
@@ -26,7 +25,7 @@ function convertToTrieRefNodes(root) {
|
|
|
26
25
|
return;
|
|
27
26
|
}
|
|
28
27
|
tallies.set(n, 1);
|
|
29
|
-
for (const c of
|
|
28
|
+
for (const c of n.c?.values() || []) {
|
|
30
29
|
tally(c);
|
|
31
30
|
}
|
|
32
31
|
}
|
|
@@ -51,7 +50,6 @@ function convertToTrieRefNodes(root) {
|
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
function* walkByRollup(n) {
|
|
54
|
-
var _a;
|
|
55
53
|
if (cached.has(n))
|
|
56
54
|
return;
|
|
57
55
|
if (n.f && !n.c) {
|
|
@@ -59,7 +57,7 @@ function convertToTrieRefNodes(root) {
|
|
|
59
57
|
cached.set(n, cached.get(eow));
|
|
60
58
|
return;
|
|
61
59
|
}
|
|
62
|
-
const children = [...(
|
|
60
|
+
const children = [...(n.c?.values() || [])].sort((a, b) => (rollupTally.get(b) || 0) - (rollupTally.get(a) || 0));
|
|
63
61
|
for (const c of children) {
|
|
64
62
|
yield* walkByRollup(c);
|
|
65
63
|
}
|
|
@@ -8,7 +8,6 @@ const PairingHeap_1 = require("../utils/PairingHeap");
|
|
|
8
8
|
* Using basic weights, this algorithm has the same results as the Damerau-Levenshtein algorithm.
|
|
9
9
|
*/
|
|
10
10
|
function distanceAStar(a, b) {
|
|
11
|
-
var _a;
|
|
12
11
|
const aN = a.length;
|
|
13
12
|
const bN = b.length;
|
|
14
13
|
const cost = 100;
|
|
@@ -49,7 +48,7 @@ function distanceAStar(a, b) {
|
|
|
49
48
|
opDel(best);
|
|
50
49
|
opSub(best);
|
|
51
50
|
}
|
|
52
|
-
return
|
|
51
|
+
return best?.c ?? -1;
|
|
53
52
|
}
|
|
54
53
|
exports.distanceAStar = distanceAStar;
|
|
55
54
|
function compare(a, b) {
|
|
@@ -272,19 +272,18 @@ function prettyPrintWeightMap(map) {
|
|
|
272
272
|
}
|
|
273
273
|
exports.prettyPrintWeightMap = prettyPrintWeightMap;
|
|
274
274
|
function lookupReplaceCost(map, a, b) {
|
|
275
|
-
var _a, _b;
|
|
276
275
|
const trie = map.replace;
|
|
277
276
|
let tt = trie;
|
|
278
277
|
for (let ai = 0; ai < a.length && tt; ++ai) {
|
|
279
|
-
tt =
|
|
278
|
+
tt = tt.n?.[a[ai]];
|
|
280
279
|
}
|
|
281
280
|
if (!tt)
|
|
282
281
|
return undefined;
|
|
283
282
|
let t = tt.t;
|
|
284
283
|
for (let bi = 0; bi < b.length && t; ++bi) {
|
|
285
|
-
t =
|
|
284
|
+
t = t.n?.[b[bi]];
|
|
286
285
|
}
|
|
287
|
-
return t
|
|
286
|
+
return t?.c;
|
|
288
287
|
}
|
|
289
288
|
exports.lookupReplaceCost = lookupReplaceCost;
|
|
290
289
|
function normalizeDef(def) {
|
package/dist/lib/find.js
CHANGED
|
@@ -52,10 +52,9 @@ function _findWord(root, word, options) {
|
|
|
52
52
|
* @param options
|
|
53
53
|
*/
|
|
54
54
|
function _findWordNode(root, word, options) {
|
|
55
|
-
var _a, _b;
|
|
56
55
|
const compoundMode = knownCompoundModes.get(options.compoundMode) || _defaultFindOptions.compoundMode;
|
|
57
|
-
const compoundPrefix = options.compoundMode === 'compound' ?
|
|
58
|
-
const ignoreCasePrefix = options.matchCase ? '' :
|
|
56
|
+
const compoundPrefix = options.compoundMode === 'compound' ? root.compoundCharacter ?? options.compoundFix : '';
|
|
57
|
+
const ignoreCasePrefix = options.matchCase ? '' : root.stripCaseAndAccentsPrefix ?? options.caseInsensitivePrefix;
|
|
59
58
|
function __findCompound() {
|
|
60
59
|
const f = findCompoundWord(root, word, compoundPrefix, ignoreCasePrefix);
|
|
61
60
|
const result = { ...f };
|
|
@@ -97,7 +96,6 @@ function findLegacyCompound(root, word, options) {
|
|
|
97
96
|
}
|
|
98
97
|
exports.findLegacyCompound = findLegacyCompound;
|
|
99
98
|
function findCompoundNode(root, word, compoundCharacter, ignoreCasePrefix) {
|
|
100
|
-
var _a, _b, _c;
|
|
101
99
|
// Approach - do a depth first search for the matching word.
|
|
102
100
|
const stack = [
|
|
103
101
|
// { n: root, compoundPrefix: '', cr: undefined, caseMatched: true },
|
|
@@ -107,12 +105,11 @@ function findCompoundNode(root, word, compoundCharacter, ignoreCasePrefix) {
|
|
|
107
105
|
const possibleCompoundPrefix = ignoreCasePrefix && compoundCharacter ? ignoreCasePrefix + compoundCharacter : '';
|
|
108
106
|
const w = word.normalize();
|
|
109
107
|
function determineRoot(s) {
|
|
110
|
-
var _a;
|
|
111
108
|
const prefix = s.compoundPrefix;
|
|
112
109
|
let r = root;
|
|
113
110
|
let i;
|
|
114
111
|
for (i = 0; i < prefix.length && r; ++i) {
|
|
115
|
-
r =
|
|
112
|
+
r = r.c?.get(prefix[i]);
|
|
116
113
|
}
|
|
117
114
|
const caseMatched = s.caseMatched && prefix[0] !== ignoreCasePrefix;
|
|
118
115
|
return {
|
|
@@ -131,7 +128,7 @@ function findCompoundNode(root, word, compoundCharacter, ignoreCasePrefix) {
|
|
|
131
128
|
const s = stack[i];
|
|
132
129
|
const h = w[i++];
|
|
133
130
|
const n = s.cr || s.n;
|
|
134
|
-
const c =
|
|
131
|
+
const c = n?.c?.get(h);
|
|
135
132
|
if (c && i < word.length) {
|
|
136
133
|
// Go deeper.
|
|
137
134
|
caseMatched = s.caseMatched;
|
|
@@ -141,7 +138,7 @@ function findCompoundNode(root, word, compoundCharacter, ignoreCasePrefix) {
|
|
|
141
138
|
// Remember the first matching node for possible auto completion.
|
|
142
139
|
node = node || c;
|
|
143
140
|
// We did not find the word backup and take the first unused compound branch
|
|
144
|
-
while (--i > 0 && (!stack[i].compoundPrefix || !
|
|
141
|
+
while (--i > 0 && (!stack[i].compoundPrefix || !stack[i].n?.c?.has(compoundCharacter))) {
|
|
145
142
|
/* empty */
|
|
146
143
|
}
|
|
147
144
|
if (i >= 0 && stack[i].compoundPrefix) {
|
|
@@ -186,22 +183,20 @@ function findWordExact(root, word) {
|
|
|
186
183
|
}
|
|
187
184
|
exports.findWordExact = findWordExact;
|
|
188
185
|
function isEndOfWordNode(n) {
|
|
189
|
-
return
|
|
186
|
+
return n?.f === TrieNode_1.FLAG_WORD;
|
|
190
187
|
}
|
|
191
188
|
exports.isEndOfWordNode = isEndOfWordNode;
|
|
192
189
|
function walk(root, word) {
|
|
193
|
-
var _a;
|
|
194
190
|
const w = word;
|
|
195
191
|
let n = root;
|
|
196
192
|
let i = 0;
|
|
197
193
|
while (n && i < word.length) {
|
|
198
194
|
const h = w[i++];
|
|
199
|
-
n =
|
|
195
|
+
n = n.c?.get(h);
|
|
200
196
|
}
|
|
201
197
|
return n;
|
|
202
198
|
}
|
|
203
199
|
function findLegacyCompoundNode(roots, word, minCompoundLength) {
|
|
204
|
-
var _a, _b;
|
|
205
200
|
const root = roots[0];
|
|
206
201
|
const numRoots = roots.length;
|
|
207
202
|
// Approach - do a depth first search for the matching word.
|
|
@@ -219,7 +214,7 @@ function findLegacyCompoundNode(roots, word, minCompoundLength) {
|
|
|
219
214
|
const s = stack[i];
|
|
220
215
|
const h = w[i++];
|
|
221
216
|
const n = s.cr || s.n;
|
|
222
|
-
const c =
|
|
217
|
+
const c = n?.c?.get(h);
|
|
223
218
|
if (c && i < wLen) {
|
|
224
219
|
// Go deeper.
|
|
225
220
|
stack[i] = {
|
|
@@ -236,7 +231,7 @@ function findLegacyCompoundNode(roots, word, minCompoundLength) {
|
|
|
236
231
|
while (--i > 0) {
|
|
237
232
|
const s = stack[i];
|
|
238
233
|
if (s.usedRoots < numRoots &&
|
|
239
|
-
|
|
234
|
+
s.n?.f &&
|
|
240
235
|
(s.subLength >= minCompoundLength || !s.subLength) &&
|
|
241
236
|
wLen - i >= minCompoundLength) {
|
|
242
237
|
break;
|
|
@@ -284,8 +279,7 @@ function findLegacyCompoundWord(roots, word, minCompoundLength) {
|
|
|
284
279
|
return { found, compoundUsed, caseMatched };
|
|
285
280
|
}
|
|
286
281
|
function isForbiddenWord(root, word, forbiddenPrefix) {
|
|
287
|
-
|
|
288
|
-
return findWordExact((_a = root === null || root === void 0 ? void 0 : root.c) === null || _a === void 0 ? void 0 : _a.get(forbiddenPrefix), word);
|
|
282
|
+
return findWordExact(root?.c?.get(forbiddenPrefix), word);
|
|
289
283
|
}
|
|
290
284
|
exports.isForbiddenWord = isForbiddenWord;
|
|
291
285
|
function createFindOptions(options) {
|
|
@@ -8,9 +8,8 @@ const EOW = '*';
|
|
|
8
8
|
exports.DATA = '__DATA__';
|
|
9
9
|
function leaves(node) {
|
|
10
10
|
function toRefNode(node, k) {
|
|
11
|
-
var _a;
|
|
12
11
|
const refNode = node;
|
|
13
|
-
refNode.s =
|
|
12
|
+
refNode.s = refNode.s ?? k;
|
|
14
13
|
return refNode;
|
|
15
14
|
}
|
|
16
15
|
function* walk(node, k, p) {
|
|
@@ -148,13 +148,12 @@ function parseStream(radix) {
|
|
|
148
148
|
function parseReference(acc, _) {
|
|
149
149
|
let ref = '';
|
|
150
150
|
function parser(acc, s) {
|
|
151
|
-
var _a;
|
|
152
151
|
if (s === EOR) {
|
|
153
152
|
const { root, nodes, stack } = acc;
|
|
154
153
|
const r = parseInt(ref, radix);
|
|
155
154
|
const top = stack[stack.length - 1];
|
|
156
155
|
const p = stack[stack.length - 2].node;
|
|
157
|
-
|
|
156
|
+
p.c?.set(top.s, nodes[r]);
|
|
158
157
|
return { root, nodes, stack, parser: undefined };
|
|
159
158
|
}
|
|
160
159
|
ref = ref + s;
|
|
@@ -180,12 +179,11 @@ function parseStream(radix) {
|
|
|
180
179
|
return { ...acc, parser };
|
|
181
180
|
}
|
|
182
181
|
function parseCharacter(acc, s) {
|
|
183
|
-
var _a;
|
|
184
182
|
const parser = undefined;
|
|
185
183
|
const { root, nodes, stack } = acc;
|
|
186
184
|
const top = stack[stack.length - 1];
|
|
187
185
|
const node = top.node;
|
|
188
|
-
node.c =
|
|
186
|
+
node.c = node.c ?? new Map();
|
|
189
187
|
const n = { f: undefined, c: undefined, n: nodes.length };
|
|
190
188
|
node.c.set(s, n);
|
|
191
189
|
stack.push({ node: n, s });
|
|
@@ -193,7 +191,6 @@ function parseStream(radix) {
|
|
|
193
191
|
return { root, nodes, stack, parser };
|
|
194
192
|
}
|
|
195
193
|
function parseEOW(acc, _) {
|
|
196
|
-
var _a;
|
|
197
194
|
const parser = parseBack;
|
|
198
195
|
const { root, nodes, stack } = acc;
|
|
199
196
|
const top = stack[stack.length - 1];
|
|
@@ -202,7 +199,7 @@ function parseStream(radix) {
|
|
|
202
199
|
if (!node.c) {
|
|
203
200
|
top.node = eow;
|
|
204
201
|
const p = stack[stack.length - 2].node;
|
|
205
|
-
|
|
202
|
+
p.c?.set(top.s, eow);
|
|
206
203
|
nodes.pop();
|
|
207
204
|
}
|
|
208
205
|
stack.pop();
|
|
@@ -232,8 +229,7 @@ function parseStream(radix) {
|
|
|
232
229
|
[LF, parseIgnore],
|
|
233
230
|
]);
|
|
234
231
|
function parserMain(acc, s) {
|
|
235
|
-
|
|
236
|
-
const parser = (_b = (_a = acc.parser) !== null && _a !== void 0 ? _a : parsers.get(s)) !== null && _b !== void 0 ? _b : parseCharacter;
|
|
232
|
+
const parser = acc.parser ?? parsers.get(s) ?? parseCharacter;
|
|
237
233
|
return parser(acc, s);
|
|
238
234
|
}
|
|
239
235
|
return parserMain;
|
|
@@ -10,7 +10,7 @@ const mapToSuggestionCostDef_1 = require("./mapToSuggestionCostDef");
|
|
|
10
10
|
function mapDictionaryInformation(dictInfo) {
|
|
11
11
|
const _locale = dictInfo.locale;
|
|
12
12
|
const locale = _locale ? (0, locale_1.parseLocale)(_locale).filter((loc) => loc.isValid()) : undefined;
|
|
13
|
-
const locales = locale
|
|
13
|
+
const locales = locale?.map((loc) => loc.locale);
|
|
14
14
|
const costs = (0, mapCosts_1.mapEditCosts)(dictInfo.costs);
|
|
15
15
|
const defsEC = dictInfo.suggestionEditCosts || [];
|
|
16
16
|
const defsHI = dictInfo.hunspellInformation
|
|
@@ -32,7 +32,7 @@ function processAlphabet(alphabet, locale, editCost) {
|
|
|
32
32
|
];
|
|
33
33
|
}
|
|
34
34
|
function toCharSets(cs, defaultValue, cost, penalty) {
|
|
35
|
-
cs = cs
|
|
35
|
+
cs = cs ?? defaultValue;
|
|
36
36
|
if (!cs)
|
|
37
37
|
return [];
|
|
38
38
|
if (typeof cs === 'string') {
|
|
@@ -37,7 +37,7 @@ function hunspellInformationToSuggestionCostDef(hunInfo, locales) {
|
|
|
37
37
|
}
|
|
38
38
|
exports.hunspellInformationToSuggestionCostDef = hunspellInformationToSuggestionCostDef;
|
|
39
39
|
function calcCosts(costs = {}, locale) {
|
|
40
|
-
const useLocale =
|
|
40
|
+
const useLocale = locale?.length ? locale.map((loc) => loc.locale) : undefined;
|
|
41
41
|
const hunCosts = (0, mapCosts_1.mapHunspellCosts)(costs);
|
|
42
42
|
const c = {
|
|
43
43
|
...hunCosts,
|
|
@@ -44,7 +44,6 @@ function createSuggestionOptions(...opts) {
|
|
|
44
44
|
}
|
|
45
45
|
exports.createSuggestionOptions = createSuggestionOptions;
|
|
46
46
|
function assign(dest, src, k) {
|
|
47
|
-
|
|
48
|
-
dest[k] = (_a = src[k]) !== null && _a !== void 0 ? _a : dest[k];
|
|
47
|
+
dest[k] = src[k] ?? dest[k];
|
|
49
48
|
}
|
|
50
49
|
//# sourceMappingURL=genSuggestionsOptions.js.map
|
|
@@ -150,14 +150,12 @@ function* genCompoundableSuggestions(root, word, options) {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
function opCompoundWord(best) {
|
|
153
|
-
|
|
154
|
-
if (!((_a = best.n.c) === null || _a === void 0 ? void 0 : _a.get(compoundIndicator)))
|
|
153
|
+
if (!best.n.c?.get(compoundIndicator))
|
|
155
154
|
return;
|
|
156
155
|
const i = best.i;
|
|
157
156
|
const s = '';
|
|
158
157
|
nodes.forEach((node) => {
|
|
159
|
-
|
|
160
|
-
const n = (_a = node.c) === null || _a === void 0 ? void 0 : _a.get(compoundIndicator);
|
|
158
|
+
const n = node.c?.get(compoundIndicator);
|
|
161
159
|
if (!n)
|
|
162
160
|
return;
|
|
163
161
|
const e = { p: best, n, i, s, c: opCosts.wordBreak, a: Action.CompoundWord };
|
|
@@ -189,9 +187,8 @@ function* genCompoundableSuggestions(root, word, options) {
|
|
|
189
187
|
return addEdge(best, e);
|
|
190
188
|
}
|
|
191
189
|
function opIdentity(best) {
|
|
192
|
-
var _a;
|
|
193
190
|
const s = word[best.i];
|
|
194
|
-
const n =
|
|
191
|
+
const n = best.n.c?.get(s);
|
|
195
192
|
if (!n)
|
|
196
193
|
return;
|
|
197
194
|
const i = best.i + 1;
|
|
@@ -216,7 +213,6 @@ function* genCompoundableSuggestions(root, word, options) {
|
|
|
216
213
|
}
|
|
217
214
|
}
|
|
218
215
|
function opSwap(best) {
|
|
219
|
-
var _a, _b;
|
|
220
216
|
const children = best.n.c;
|
|
221
217
|
const i = best.i;
|
|
222
218
|
const i2 = i + 1;
|
|
@@ -226,8 +222,8 @@ function* genCompoundableSuggestions(root, word, options) {
|
|
|
226
222
|
const wc2 = word[i2];
|
|
227
223
|
if (wc1 === wc2)
|
|
228
224
|
return;
|
|
229
|
-
const n =
|
|
230
|
-
const n2 =
|
|
225
|
+
const n = best.n.c?.get(wc2);
|
|
226
|
+
const n2 = n?.c?.get(wc1);
|
|
231
227
|
if (!n || !n2)
|
|
232
228
|
return;
|
|
233
229
|
const e = {
|
|
@@ -242,7 +238,6 @@ function* genCompoundableSuggestions(root, word, options) {
|
|
|
242
238
|
addEdge(best, e);
|
|
243
239
|
}
|
|
244
240
|
function opDuplicate(best) {
|
|
245
|
-
var _a, _b;
|
|
246
241
|
const children = best.n.c;
|
|
247
242
|
const i = best.i;
|
|
248
243
|
const i2 = i + 1;
|
|
@@ -250,7 +245,7 @@ function* genCompoundableSuggestions(root, word, options) {
|
|
|
250
245
|
return;
|
|
251
246
|
const wc1 = word[i];
|
|
252
247
|
const wc2 = word[i2];
|
|
253
|
-
const n =
|
|
248
|
+
const n = best.n.c?.get(wc1);
|
|
254
249
|
if (!n)
|
|
255
250
|
return;
|
|
256
251
|
if (wc1 === wc2) {
|
|
@@ -259,7 +254,7 @@ function* genCompoundableSuggestions(root, word, options) {
|
|
|
259
254
|
addEdge(best, e);
|
|
260
255
|
return;
|
|
261
256
|
}
|
|
262
|
-
const n2 =
|
|
257
|
+
const n2 = n?.c?.get(wc1);
|
|
263
258
|
if (!n2)
|
|
264
259
|
return;
|
|
265
260
|
// convert single to double letter
|
|
@@ -278,9 +273,8 @@ function* genCompoundableSuggestions(root, word, options) {
|
|
|
278
273
|
}
|
|
279
274
|
}
|
|
280
275
|
function resolveEdge({ edge, suffixes }) {
|
|
281
|
-
var _a;
|
|
282
276
|
const { p, s: es, c: ec } = edge;
|
|
283
|
-
if (!
|
|
277
|
+
if (!p.r?.has(edge))
|
|
284
278
|
return;
|
|
285
279
|
const edgeSuffixes = suffixes.map((sfx) => ({ s: es + sfx.s, c: ec + sfx.c }));
|
|
286
280
|
for (const { s, c } of edgeSuffixes) {
|
|
@@ -292,7 +286,7 @@ function* genCompoundableSuggestions(root, word, options) {
|
|
|
292
286
|
}
|
|
293
287
|
p.r.delete(edge);
|
|
294
288
|
const location = pathToLocation.get(p);
|
|
295
|
-
if (
|
|
289
|
+
if (location?.p === p) {
|
|
296
290
|
location.sfx = location.sfx.concat(edgeSuffixes);
|
|
297
291
|
if (!p.r.size) {
|
|
298
292
|
location.sbc = p.g;
|
|
@@ -416,7 +410,7 @@ function determineInitialNodes(root, ignoreCase) {
|
|
|
416
410
|
const noCaseNodes = ignoreCase
|
|
417
411
|
? roots
|
|
418
412
|
.filter((r) => r.stripCaseAndAccentsPrefix)
|
|
419
|
-
.map((n) =>
|
|
413
|
+
.map((n) => n.c?.get(n.stripCaseAndAccentsPrefix))
|
|
420
414
|
.filter(isDefined)
|
|
421
415
|
: [];
|
|
422
416
|
const nodes = rootNodes.concat(noCaseNodes);
|
|
@@ -101,7 +101,7 @@ function suggestionCollector(wordToMatch, options) {
|
|
|
101
101
|
*/
|
|
102
102
|
function collect(src, timeout, filter) {
|
|
103
103
|
let stop = false;
|
|
104
|
-
timeout = timeout
|
|
104
|
+
timeout = timeout ?? timeRemaining;
|
|
105
105
|
timeout = Math.min(timeout, timeRemaining);
|
|
106
106
|
if (timeout < 0)
|
|
107
107
|
return;
|
|
@@ -202,7 +202,7 @@ function impersonateCollector(collector, word) {
|
|
|
202
202
|
exports.impersonateCollector = impersonateCollector;
|
|
203
203
|
function isSuggestionResult(s) {
|
|
204
204
|
const r = s;
|
|
205
|
-
return
|
|
205
|
+
return r?.cost !== undefined && r.word != undefined;
|
|
206
206
|
}
|
|
207
207
|
exports.isSuggestionResult = isSuggestionResult;
|
|
208
208
|
//# sourceMappingURL=suggestCollector.js.map
|
|
@@ -12,21 +12,20 @@ exports.hintedWalker = hintedWalker;
|
|
|
12
12
|
* next(goDeeper: boolean):
|
|
13
13
|
*/
|
|
14
14
|
function* hintedWalkerNext(root, ignoreCase, hint, compoundingMethod, emitWordSeparator = '') {
|
|
15
|
-
const _compoundingMethod = compoundingMethod
|
|
15
|
+
const _compoundingMethod = compoundingMethod ?? walkerTypes_1.CompoundWordsMethod.NONE;
|
|
16
16
|
const compoundCharacter = root.compoundCharacter;
|
|
17
17
|
const noCaseCharacter = root.stripCaseAndAccentsPrefix;
|
|
18
18
|
const rawRoots = [root, ignoreCase ? root.c.get(noCaseCharacter) : undefined].filter(trie_util_1.isDefined);
|
|
19
19
|
const specialRootsPrefix = existMap([compoundCharacter, noCaseCharacter, root.forbiddenWordPrefix]);
|
|
20
20
|
function filterRoot(root) {
|
|
21
|
-
|
|
22
|
-
const children = (_a = root.c) === null || _a === void 0 ? void 0 : _a.entries();
|
|
21
|
+
const children = root.c?.entries();
|
|
23
22
|
const c = children && [...children].filter(([v]) => !(v in specialRootsPrefix));
|
|
24
23
|
return {
|
|
25
24
|
c: c && new Map(c),
|
|
26
25
|
};
|
|
27
26
|
}
|
|
28
27
|
const roots = rawRoots.map(filterRoot);
|
|
29
|
-
const compoundRoots = rawRoots.map((r) =>
|
|
28
|
+
const compoundRoots = rawRoots.map((r) => r.c?.get(compoundCharacter)).filter(trie_util_1.isDefined);
|
|
30
29
|
const setOfCompoundRoots = new Set(compoundRoots);
|
|
31
30
|
const rootsForCompoundMethods = roots.concat(compoundRoots);
|
|
32
31
|
const compoundMethodRoots = {
|
package/dist/lib/trie-util.js
CHANGED
|
@@ -175,7 +175,7 @@ function mergeDefaults(value, defaultValue) {
|
|
|
175
175
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
176
176
|
for (const [k, v] of Object.entries(value)) {
|
|
177
177
|
if (k in result) {
|
|
178
|
-
result[k] = v
|
|
178
|
+
result[k] = v ?? result[k];
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
}
|
package/dist/lib/trie.js
CHANGED
|
@@ -35,8 +35,7 @@ class Trie {
|
|
|
35
35
|
* Number of words in the Trie
|
|
36
36
|
*/
|
|
37
37
|
size() {
|
|
38
|
-
|
|
39
|
-
this.count = (_a = this.count) !== null && _a !== void 0 ? _a : (0, trie_util_1.countWords)(this.root);
|
|
38
|
+
this.count = this.count ?? (0, trie_util_1.countWords)(this.root);
|
|
40
39
|
return this.count;
|
|
41
40
|
}
|
|
42
41
|
isSizeKnown() {
|
|
@@ -96,7 +95,7 @@ class Trie {
|
|
|
96
95
|
return !!f.found && !f.forbidden;
|
|
97
96
|
}
|
|
98
97
|
findWord(word, options) {
|
|
99
|
-
if (options
|
|
98
|
+
if (options?.useLegacyWordCompounds) {
|
|
100
99
|
const len = options.useLegacyWordCompounds !== true
|
|
101
100
|
? options.useLegacyWordCompounds
|
|
102
101
|
: defaultLegacyMinCompoundLength;
|
|
@@ -106,7 +105,7 @@ class Trie {
|
|
|
106
105
|
});
|
|
107
106
|
return (0, find_1.findLegacyCompound)(this.root, word, findOptions);
|
|
108
107
|
}
|
|
109
|
-
const findOptions = this.createFindOptions({ matchCase: options
|
|
108
|
+
const findOptions = this.createFindOptions({ matchCase: options?.caseSensitive });
|
|
110
109
|
return (0, find_1.findWord)(this.root, word, findOptions);
|
|
111
110
|
}
|
|
112
111
|
/**
|
|
@@ -185,9 +184,9 @@ class Trie {
|
|
|
185
184
|
}
|
|
186
185
|
calcIsLegacy() {
|
|
187
186
|
const c = this.root.c;
|
|
188
|
-
return !(
|
|
189
|
-
|
|
190
|
-
|
|
187
|
+
return !(c?.get(this._options.compoundCharacter) ||
|
|
188
|
+
c?.get(this._options.stripCaseAndAccentsPrefix) ||
|
|
189
|
+
c?.get(this._options.forbiddenWordPrefix));
|
|
191
190
|
}
|
|
192
191
|
static create(words, options) {
|
|
193
192
|
const root = (0, trie_util_1.createTriFromList)(words, options);
|
|
@@ -5,20 +5,18 @@ exports.memorizer = void 0;
|
|
|
5
5
|
function memorizer(fn) {
|
|
6
6
|
const r = {};
|
|
7
7
|
function find(p) {
|
|
8
|
-
var _a;
|
|
9
8
|
let n = r;
|
|
10
9
|
for (const k of p) {
|
|
11
10
|
if (!n)
|
|
12
11
|
break;
|
|
13
|
-
n =
|
|
12
|
+
n = n.c?.get(k);
|
|
14
13
|
}
|
|
15
14
|
return n;
|
|
16
15
|
}
|
|
17
16
|
function set(p, v) {
|
|
18
|
-
var _a;
|
|
19
17
|
let n = r;
|
|
20
18
|
for (const k of p) {
|
|
21
|
-
const c =
|
|
19
|
+
const c = n.c?.get(k);
|
|
22
20
|
if (c) {
|
|
23
21
|
n = c;
|
|
24
22
|
continue;
|
|
@@ -18,8 +18,7 @@ class SecondChanceCache {
|
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
20
|
get(key) {
|
|
21
|
-
|
|
22
|
-
return (_a = this.map0.get(key)) !== null && _a !== void 0 ? _a : this.get1(key);
|
|
21
|
+
return this.map0.get(key) ?? this.get1(key);
|
|
23
22
|
}
|
|
24
23
|
set(key, value) {
|
|
25
24
|
if (this.map0.size >= this.maxL0Size && !this.map0.has(key)) {
|
package/dist/lib/utils/timer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.polyHrTime = exports.toMilliseconds = exports.createTimer = void 0;
|
|
4
|
-
const _hrTime =
|
|
4
|
+
const _hrTime = process?.hrtime || polyHrTime;
|
|
5
5
|
function createTimer(hrTimeFn = _hrTime) {
|
|
6
6
|
let start = hrTimeFn();
|
|
7
7
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-trie-lib",
|
|
3
|
-
"version": "6.1.0",
|
|
3
|
+
"version": "6.1.3-alpha.0",
|
|
4
4
|
"description": "Trie Data Structure to support cspell.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/streetsidesoftware/cspell#readme",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@cspell/cspell-pipe": "^6.1.0",
|
|
40
|
+
"@cspell/cspell-pipe": "^6.1.3-alpha.0",
|
|
41
41
|
"fs-extra": "^10.1.0",
|
|
42
42
|
"gensequence": "^3.1.1"
|
|
43
43
|
},
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"node": ">=14"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@cspell/cspell-types": "^6.1.0",
|
|
49
|
-
"@cspell/dict-en_us": "^2.2.
|
|
48
|
+
"@cspell/cspell-types": "^6.1.3-alpha.0",
|
|
49
|
+
"@cspell/dict-en_us": "^2.2.6",
|
|
50
50
|
"@cspell/dict-es-es": "^2.2.0",
|
|
51
51
|
"@types/fs-extra": "^9.0.13",
|
|
52
|
-
"@types/node": "^17.0.
|
|
53
|
-
"jest": "^28.1.
|
|
52
|
+
"@types/node": "^17.0.43",
|
|
53
|
+
"jest": "^28.1.1",
|
|
54
54
|
"rimraf": "^3.0.2"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "b3cde7e463fd8a6f2c03f990adc70b913239baeb"
|
|
57
57
|
}
|