cspell-trie-lib 9.0.2 → 9.1.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/dist/index.d.ts +725 -665
- package/dist/index.js +9125 -7310
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,756 +1,801 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Operator } from "@cspell/cspell-pipe/sync";
|
|
2
|
+
import { DictionaryDefinitionAugmented, SuggestionCostMapDef } from "@cspell/cspell-types";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/distance/weightedMaps.d.ts
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
* Costs are minimized while penalties are maximized.
|
|
8
|
+
*/
|
|
8
9
|
interface Cost$1 {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The cost of an operation
|
|
12
|
+
* `c'' = min(c, c')`
|
|
13
|
+
*/
|
|
14
|
+
c?: number | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* The penalties applied
|
|
17
|
+
* `p'' = max(p, p')`
|
|
18
|
+
*/
|
|
19
|
+
p?: number | undefined;
|
|
19
20
|
}
|
|
20
21
|
interface TrieCost extends Cost$1 {
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
/** nested trie nodes */
|
|
23
|
+
n?: Record<string, TrieCost>;
|
|
23
24
|
}
|
|
24
25
|
interface TrieTrieCost {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
/** nested trie nodes */
|
|
27
|
+
n?: Record<string, TrieTrieCost>;
|
|
28
|
+
/** root of cost trie */
|
|
29
|
+
t?: Record<string, TrieCost>;
|
|
29
30
|
}
|
|
30
31
|
interface WeightMap {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
readonly insDel: TrieCost;
|
|
33
|
+
readonly replace: TrieTrieCost;
|
|
34
|
+
readonly swap: TrieTrieCost;
|
|
35
|
+
readonly adjustments: Map<string, PenaltyAdjustment>;
|
|
35
36
|
}
|
|
36
37
|
interface PenaltyAdjustment {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
38
|
+
/** Penalty Identifier */
|
|
39
|
+
id: string;
|
|
40
|
+
/** RegExp Pattern to match */
|
|
41
|
+
regexp: RegExp;
|
|
42
|
+
/** Penalty to apply */
|
|
43
|
+
penalty: number;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/lib/distance/distance.d.ts
|
|
45
47
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
* Calculate the edit distance between any two words.
|
|
49
|
+
* Use the Damerau–Levenshtein distance algorithm.
|
|
50
|
+
* @param wordA
|
|
51
|
+
* @param wordB
|
|
52
|
+
* @param editCost - the cost of each edit (defaults to 100)
|
|
53
|
+
* @returns the edit distance.
|
|
54
|
+
*/
|
|
53
55
|
declare function editDistance(wordA: string, wordB: string, editCost?: number): number;
|
|
54
56
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
* Calculate the weighted edit distance between any two words.
|
|
58
|
+
* @param wordA
|
|
59
|
+
* @param wordB
|
|
60
|
+
* @param weights - the weights to use
|
|
61
|
+
* @param editCost - the cost of each edit (defaults to 100)
|
|
62
|
+
* @returns the edit distance
|
|
63
|
+
*/
|
|
62
64
|
declare function editDistanceWeighted(wordA: string, wordB: string, weights: WeightMap, editCost?: number): number;
|
|
63
65
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
* Collect Map definitions into a single weighted map.
|
|
67
|
+
* @param defs - list of definitions
|
|
68
|
+
* @returns A Weighted Map to be used with distance calculations.
|
|
69
|
+
*/
|
|
68
70
|
declare function createWeightedMap(defs: SuggestionCostMapDef[]): WeightMap;
|
|
69
|
-
|
|
70
71
|
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
* Update a WeightedMap with a WeightedMapDef
|
|
73
|
+
* @param weightedMap - map to update
|
|
74
|
+
* @param def - the definition to use
|
|
75
|
+
*/
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/lib/types.d.ts
|
|
78
|
+
/**
|
|
79
|
+
* Make all properties in T optional and Possibly undefined
|
|
80
|
+
*/
|
|
81
|
+
type PartialWithUndefined<T> = { [P in keyof T]?: T[P] | undefined };
|
|
82
|
+
/**
|
|
83
|
+
* Make all fields mandatory
|
|
84
|
+
*/
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/lib/ITrieNode/TrieInfo.d.ts
|
|
77
87
|
interface TrieInfo {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
88
|
+
compoundCharacter: string;
|
|
89
|
+
stripCaseAndAccentsPrefix: string;
|
|
90
|
+
forbiddenWordPrefix: string;
|
|
91
|
+
isCaseAware: boolean;
|
|
82
92
|
}
|
|
83
93
|
interface TrieCharacteristics {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
hasForbiddenWords: boolean;
|
|
95
|
+
hasCompoundWords: boolean;
|
|
96
|
+
hasNonStrictWords: boolean;
|
|
87
97
|
}
|
|
88
98
|
type PartialTrieInfo = PartialWithUndefined<TrieInfo> | undefined;
|
|
89
|
-
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/lib/ITrieNode/ITrieNode.d.ts
|
|
90
101
|
interface FindResult$1 {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
found: string | false;
|
|
103
|
+
compoundUsed: boolean;
|
|
104
|
+
caseMatched: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Is the word explicitly forbidden.
|
|
107
|
+
* - `true` - word is in the forbidden list.
|
|
108
|
+
* - `false` - word is not in the forbidden list.
|
|
109
|
+
* - `undefined` - unknown - was not checked.
|
|
110
|
+
*/
|
|
111
|
+
forbidden?: boolean | undefined;
|
|
101
112
|
}
|
|
102
113
|
interface FindFullResult$1 extends FindResult$1 {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Is the word explicitly forbidden.
|
|
116
|
+
* - `true` - word is in the forbidden list.
|
|
117
|
+
* - `false` - word is not in the forbidden list.
|
|
118
|
+
* - `undefined` - unknown - was not checked.
|
|
119
|
+
*/
|
|
120
|
+
forbidden: boolean | undefined;
|
|
110
121
|
}
|
|
111
122
|
type ITrieNodeId = object | number | string;
|
|
112
123
|
type Entry = readonly [string, ITrieNode];
|
|
113
124
|
interface ITrieNode {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
125
|
+
/**
|
|
126
|
+
* ITrieNode instances are not unique. It is possible for multiple ITrieNode instances to
|
|
127
|
+
* represent the same node.
|
|
128
|
+
* `id` is used to see if two instances refer to the same node.
|
|
129
|
+
* The type is obscured because it is up the the backing structure to provide the best value.
|
|
130
|
+
* Note, only nodes from the same root are guaranteed to be unique. It is possible for two
|
|
131
|
+
* different ITrieNode instances to have the same `id` value if they come from different roots.
|
|
132
|
+
*/
|
|
133
|
+
readonly id: ITrieNodeId;
|
|
134
|
+
/** flag End of Word */
|
|
135
|
+
readonly eow: boolean;
|
|
136
|
+
/** get keys to children */
|
|
137
|
+
keys(): Iterable<string>;
|
|
138
|
+
/** get keys to children */
|
|
139
|
+
values(): Iterable<ITrieNode>;
|
|
140
|
+
/** get the children as key value pairs */
|
|
141
|
+
entries(): Iterable<Entry>;
|
|
142
|
+
/** get child ITrieNode */
|
|
143
|
+
get(char: string): ITrieNode | undefined;
|
|
144
|
+
/** get a nested child ITrieNode */
|
|
145
|
+
getNode?: (chars: string) => ITrieNode | undefined;
|
|
146
|
+
/** has child */
|
|
147
|
+
has(char: string): boolean;
|
|
148
|
+
/** `true` iff this node has children */
|
|
149
|
+
hasChildren(): boolean;
|
|
150
|
+
/** check if a word exists within this node. */
|
|
151
|
+
findExact?: ((word: string) => boolean) | undefined;
|
|
141
152
|
}
|
|
142
153
|
interface ITrieNodeRoot extends ITrieNode {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
154
|
+
readonly info: Readonly<TrieInfo>;
|
|
155
|
+
/**
|
|
156
|
+
* converts an `id` into a node.
|
|
157
|
+
* @param id an of a ITrieNode in this Trie
|
|
158
|
+
*/
|
|
159
|
+
resolveId(id: ITrieNodeId): ITrieNode;
|
|
160
|
+
findExact: ((word: string) => boolean) | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* Try to find a word.
|
|
163
|
+
* @param word - the normalized word to look up.
|
|
164
|
+
* @param strict - if `true` the case and accents must match.
|
|
165
|
+
* @returns undefined if it did not try to find the word, otherwise a FindResult.
|
|
166
|
+
*/
|
|
167
|
+
find?: ((word: string, strict: boolean) => FindResult$1 | undefined) | undefined;
|
|
168
|
+
isForbidden?: ((word: string) => boolean) | undefined;
|
|
169
|
+
readonly forbidPrefix: string;
|
|
170
|
+
readonly compoundFix: string;
|
|
171
|
+
readonly caseInsensitivePrefix: string;
|
|
172
|
+
readonly hasForbiddenWords: boolean;
|
|
173
|
+
readonly hasCompoundWords: boolean;
|
|
174
|
+
readonly hasNonStrictWords: boolean;
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/lib/ITrieNode/index.d.ts
|
|
166
178
|
type TrieOptions = TrieInfo;
|
|
167
179
|
type TrieOptionsRO = Readonly<TrieOptions>;
|
|
168
180
|
type PartialTrieOptions = PartialTrieInfo;
|
|
169
|
-
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/lib/TrieNode/TrieNode.d.ts
|
|
170
183
|
declare const FLAG_WORD = 1;
|
|
171
184
|
type ChildMap = Record<string, TrieNode>;
|
|
172
185
|
interface TrieNode {
|
|
173
|
-
|
|
174
|
-
|
|
186
|
+
f?: number | undefined;
|
|
187
|
+
c?: ChildMap | undefined;
|
|
175
188
|
}
|
|
176
189
|
interface TrieRoot extends TrieInfo {
|
|
177
|
-
|
|
190
|
+
c: ChildMap;
|
|
178
191
|
}
|
|
179
|
-
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/lib/walker/walkerTypes.d.ts
|
|
180
194
|
declare const JOIN_SEPARATOR = "+";
|
|
181
195
|
declare const WORD_SEPARATOR = " ";
|
|
182
|
-
interface YieldResult
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
196
|
+
interface YieldResult {
|
|
197
|
+
text: string;
|
|
198
|
+
node: TrieNode;
|
|
199
|
+
depth: number;
|
|
186
200
|
}
|
|
187
201
|
declare enum CompoundWordsMethod {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
type WalkerIterator
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
202
|
+
/**
|
|
203
|
+
* Do not compound words.
|
|
204
|
+
*/
|
|
205
|
+
NONE = 0,
|
|
206
|
+
/**
|
|
207
|
+
* Create word compounds separated by spaces.
|
|
208
|
+
*/
|
|
209
|
+
SEPARATE_WORDS = 1,
|
|
210
|
+
/**
|
|
211
|
+
* Create word compounds without separation.
|
|
212
|
+
*/
|
|
213
|
+
JOIN_WORDS = 2,
|
|
214
|
+
}
|
|
215
|
+
type WalkerIterator = Generator<YieldResult, void, boolean | undefined>;
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/lib/ITrieNode/walker/walkerTypes.d.ts
|
|
218
|
+
interface YieldResult$1 {
|
|
219
|
+
text: string;
|
|
220
|
+
node: ITrieNode;
|
|
221
|
+
depth: number;
|
|
207
222
|
}
|
|
208
223
|
type FalseToNotGoDeeper = boolean;
|
|
209
224
|
/**
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
type WalkerIterator = Generator<YieldResult, void, FalseToNotGoDeeper | undefined>;
|
|
214
|
-
|
|
225
|
+
* By default a Walker Iterator will go depth first. To prevent the
|
|
226
|
+
* walker from going deeper use `iterator.next(false)`.
|
|
227
|
+
*/
|
|
228
|
+
type WalkerIterator$1 = Generator<YieldResult$1, void, FalseToNotGoDeeper | undefined>;
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/lib/walker/hintedWalker.d.ts
|
|
215
231
|
/**
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
232
|
+
* Ask for the next result.
|
|
233
|
+
* goDeeper of true tells the walker to go deeper in the Trie if possible. Default is true.
|
|
234
|
+
* This can be used to limit the walker's depth.
|
|
235
|
+
*/
|
|
236
|
+
// next: (hinting?: Hinting) => IteratorResult<YieldResult>;
|
|
237
|
+
// [Symbol.iterator]: () => HintedWalkerIterator;
|
|
238
|
+
type HintedWalkerIterator = Generator<YieldResult, void, Hinting | undefined>;
|
|
221
239
|
declare function hintedWalker(root: TrieRoot, ignoreCase: boolean, hint: string, compoundingMethod: CompoundWordsMethod | undefined, emitWordSeparator?: string): HintedWalkerIterator;
|
|
240
|
+
/**
|
|
241
|
+
* Walks the Trie and yields a value at each node.
|
|
242
|
+
* next(goDeeper: boolean):
|
|
243
|
+
*/
|
|
244
|
+
|
|
222
245
|
interface Hinting {
|
|
223
|
-
|
|
246
|
+
goDeeper: boolean;
|
|
224
247
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/lib/walker/walker.d.ts
|
|
250
|
+
declare function walker(root: TrieNode, compoundingMethod?: CompoundWordsMethod): WalkerIterator;
|
|
251
|
+
/**
|
|
252
|
+
* Walks the Trie and yields each word.
|
|
253
|
+
*/
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/lib/suggestions/genSuggestionsOptions.d.ts
|
|
228
256
|
interface GenSuggestionOptionsStrict {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
257
|
+
/**
|
|
258
|
+
* Controls forcing compound words.
|
|
259
|
+
* @default CompoundWordsMethod.NONE
|
|
260
|
+
*/
|
|
261
|
+
compoundMethod?: CompoundWordsMethod;
|
|
262
|
+
/**
|
|
263
|
+
* ignore case when searching.
|
|
264
|
+
*/
|
|
265
|
+
ignoreCase: boolean;
|
|
266
|
+
/**
|
|
267
|
+
* Maximum number of "edits" allowed.
|
|
268
|
+
* 3 is a good number. Above 5 can be very slow.
|
|
269
|
+
*/
|
|
270
|
+
changeLimit: number;
|
|
271
|
+
/**
|
|
272
|
+
* Inserts a compound character between compounded word segments.
|
|
273
|
+
* @default ""
|
|
274
|
+
*/
|
|
275
|
+
compoundSeparator?: string;
|
|
248
276
|
}
|
|
249
277
|
type GenSuggestionOptionsStrictRO = Readonly<GenSuggestionOptionsStrict>;
|
|
250
278
|
type GenSuggestionOptions = Partial<GenSuggestionOptionsStrict>;
|
|
251
279
|
type GenSuggestionOptionsRO = Readonly<GenSuggestionOptions>;
|
|
252
280
|
interface SuggestionOptionsStrict extends GenSuggestionOptionsStrict {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
281
|
+
/**
|
|
282
|
+
* Maximum number of suggestions to make.
|
|
283
|
+
*/
|
|
284
|
+
numSuggestions: number;
|
|
285
|
+
/**
|
|
286
|
+
* Allow ties when making suggestions.
|
|
287
|
+
* if `true` it is possible to have more than `numSuggestions`.
|
|
288
|
+
*/
|
|
289
|
+
includeTies: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* Time alloted in milliseconds to generate suggestions.
|
|
292
|
+
*/
|
|
293
|
+
timeout: number;
|
|
294
|
+
/**
|
|
295
|
+
* Optional filter function.
|
|
296
|
+
* return true to keep the candidate.
|
|
297
|
+
*/
|
|
298
|
+
filter?: (word: string, cost: number) => boolean;
|
|
299
|
+
/**
|
|
300
|
+
* Apply weights to improve the suggestions.
|
|
301
|
+
*/
|
|
302
|
+
weightMap?: WeightMap | undefined;
|
|
275
303
|
}
|
|
276
304
|
type SuggestionOptions = Partial<SuggestionOptionsStrict>;
|
|
277
305
|
type SuggestionOptionsRO = Readonly<SuggestionOptions>;
|
|
278
|
-
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/lib/suggestions/SuggestionTypes.d.ts
|
|
279
308
|
type Cost = number;
|
|
280
309
|
type MaxCost = Cost;
|
|
281
310
|
interface SuggestionResultBase {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
311
|
+
/** The suggested word */
|
|
312
|
+
word: string;
|
|
313
|
+
/** The edit cost 100 = 1 edit */
|
|
314
|
+
cost: Cost;
|
|
315
|
+
/**
|
|
316
|
+
* This suggestion is the preferred suggestion.
|
|
317
|
+
* Setting this to `true` implies that an auto fix is possible.
|
|
318
|
+
*/
|
|
319
|
+
isPreferred?: boolean | undefined;
|
|
291
320
|
}
|
|
292
321
|
interface SuggestionResult extends SuggestionResultBase {
|
|
293
|
-
|
|
294
|
-
|
|
322
|
+
/** The suggested word with compound marks, generally a `•` */
|
|
323
|
+
compoundWord?: string | undefined;
|
|
295
324
|
}
|
|
296
325
|
interface Progress {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
326
|
+
type: "progress";
|
|
327
|
+
/** Number of Completed Tasks so far */
|
|
328
|
+
completed: number;
|
|
329
|
+
/**
|
|
330
|
+
* Number of tasks remaining, this number is allowed to increase over time since
|
|
331
|
+
* completed tasks can generate new tasks.
|
|
332
|
+
*/
|
|
333
|
+
remaining: number;
|
|
305
334
|
}
|
|
306
335
|
type GenerateNextParam = MaxCost | symbol | undefined;
|
|
307
336
|
type GenerateSuggestionResult = SuggestionResultBase | Progress | undefined;
|
|
308
337
|
/**
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
338
|
+
* Ask for the next result.
|
|
339
|
+
* maxCost - sets the max cost for following suggestions
|
|
340
|
+
* This is used to limit which suggestions are emitted.
|
|
341
|
+
* If the `iterator.next()` returns `undefined`, it is to request a value for maxCost.
|
|
342
|
+
*
|
|
343
|
+
* The SuggestionIterator is generally the
|
|
344
|
+
*/
|
|
316
345
|
type SuggestionGenerator = Generator<GenerateSuggestionResult, void, GenerateNextParam>;
|
|
317
|
-
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region src/lib/suggestions/suggestCollector.d.ts
|
|
318
348
|
type FilterWordFn = (word: string, cost: number) => boolean;
|
|
319
349
|
interface SuggestionCollector {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
345
|
-
interface SuggestionCollectorOptions extends Omit<GenSuggestionOptionsStrictRO,
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
350
|
+
/**
|
|
351
|
+
* Collection suggestions from a SuggestionIterator
|
|
352
|
+
* @param src - the SuggestionIterator used to generate suggestions.
|
|
353
|
+
* @param timeout - the amount of time in milliseconds to allow for suggestions.
|
|
354
|
+
* before sending `symbolStopProcessing`
|
|
355
|
+
* Iterator implementation:
|
|
356
|
+
* @example
|
|
357
|
+
* r = yield(suggestion);
|
|
358
|
+
* if (r === collector.symbolStopProcessing) // ...stop generating suggestions.
|
|
359
|
+
*/
|
|
360
|
+
collect: (src: SuggestionGenerator, timeout?: number, filter?: FilterWordFn) => void;
|
|
361
|
+
add: (suggestion: SuggestionResultBase) => SuggestionCollector;
|
|
362
|
+
readonly suggestions: SuggestionResult[];
|
|
363
|
+
readonly changeLimit: number;
|
|
364
|
+
readonly maxCost: number;
|
|
365
|
+
readonly word: string;
|
|
366
|
+
readonly maxNumSuggestions: number;
|
|
367
|
+
readonly includesTies: boolean;
|
|
368
|
+
readonly ignoreCase: boolean;
|
|
369
|
+
readonly genSuggestionOptions: GenSuggestionOptionsRO;
|
|
370
|
+
/**
|
|
371
|
+
* Possible value sent to the SuggestionIterator telling it to stop processing.
|
|
372
|
+
*/
|
|
373
|
+
readonly symbolStopProcessing: symbol;
|
|
374
|
+
}
|
|
375
|
+
interface SuggestionCollectorOptions extends Omit<GenSuggestionOptionsStrictRO, "ignoreCase" | "changeLimit"> {
|
|
376
|
+
/**
|
|
377
|
+
* number of best matching suggestions.
|
|
378
|
+
* @default 10
|
|
379
|
+
*/
|
|
380
|
+
numSuggestions: number;
|
|
381
|
+
/**
|
|
382
|
+
* An optional filter function that can be used to limit remove unwanted suggestions.
|
|
383
|
+
* I.E. to remove forbidden terms.
|
|
384
|
+
* @default () => true
|
|
385
|
+
*/
|
|
386
|
+
filter?: FilterWordFn | undefined;
|
|
387
|
+
/**
|
|
388
|
+
* The number of letters that can be changed when looking for a match
|
|
389
|
+
* @default 5
|
|
390
|
+
*/
|
|
391
|
+
changeLimit: number | undefined;
|
|
392
|
+
/**
|
|
393
|
+
* Include suggestions with tied cost even if the number is greater than `numSuggestions`.
|
|
394
|
+
* @default true
|
|
395
|
+
*/
|
|
396
|
+
includeTies?: boolean | undefined;
|
|
397
|
+
/**
|
|
398
|
+
* specify if case / accents should be ignored when looking for suggestions.
|
|
399
|
+
* @default true
|
|
400
|
+
*/
|
|
401
|
+
ignoreCase: boolean | undefined;
|
|
402
|
+
/**
|
|
403
|
+
* the total amount of time to allow for suggestions.
|
|
404
|
+
* @default 1000
|
|
405
|
+
*/
|
|
406
|
+
timeout?: number | undefined;
|
|
407
|
+
/**
|
|
408
|
+
* Used to improve the sorted results.
|
|
409
|
+
*/
|
|
410
|
+
weightMap?: WeightMap | undefined;
|
|
381
411
|
}
|
|
382
412
|
type SuggestionCollectorOptionsRO = Readonly<SuggestionCollectorOptions>;
|
|
383
413
|
declare function suggestionCollector(wordToMatch: string, options: SuggestionCollectorOptionsRO): SuggestionCollector;
|
|
384
414
|
/**
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
415
|
+
* Impersonating a Collector, allows searching for multiple variants on the same word.
|
|
416
|
+
* The collection is still in the original collector.
|
|
417
|
+
* @param collector - collector to impersonate
|
|
418
|
+
* @param word - word to present instead of `collector.word`.
|
|
419
|
+
* @returns a SuggestionCollector
|
|
420
|
+
*/
|
|
391
421
|
declare function impersonateCollector(collector: SuggestionCollector, word: string): SuggestionCollector;
|
|
392
|
-
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region src/lib/TrieData.d.ts
|
|
393
424
|
interface TrieData extends Readonly<TrieCharacteristics> {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
|
|
425
|
+
readonly info: Readonly<TrieInfo>;
|
|
426
|
+
/** Method used to split words into individual characters. */
|
|
427
|
+
wordToCharacters(word: string): readonly string[];
|
|
428
|
+
/** get an iterable for all the words in the dictionary. */
|
|
429
|
+
words(): Iterable<string>;
|
|
430
|
+
getRoot(): ITrieNodeRoot;
|
|
431
|
+
getNode(prefix: string): ITrieNode | undefined;
|
|
432
|
+
has(word: string): boolean;
|
|
433
|
+
isForbiddenWord(word: string): boolean;
|
|
434
|
+
readonly hasForbiddenWords: boolean;
|
|
435
|
+
readonly hasCompoundWords: boolean;
|
|
436
|
+
readonly hasNonStrictWords: boolean;
|
|
437
|
+
readonly size: number;
|
|
438
|
+
}
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region src/lib/ITrie.d.ts
|
|
409
441
|
interface ITrie {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
442
|
+
readonly data: TrieData;
|
|
443
|
+
/**
|
|
444
|
+
* Approximate number of words in the Trie, the first call to this method might be expensive.
|
|
445
|
+
* Use `size` to get the number of nodes.
|
|
446
|
+
*
|
|
447
|
+
* It does NOT count natural compound words. Natural compounds are words that are composed of appending
|
|
448
|
+
* multiple words to make a new word. This is common in languages like German and Dutch.
|
|
449
|
+
*/
|
|
450
|
+
numWords(): number;
|
|
451
|
+
/**
|
|
452
|
+
* Used to check if the number of words has been calculated.
|
|
453
|
+
*/
|
|
454
|
+
isNumWordsKnown(): boolean;
|
|
455
|
+
/**
|
|
456
|
+
* The number of nodes in the Trie. There is a rough corelation between the size and the number of words.
|
|
457
|
+
*/
|
|
458
|
+
readonly size: number;
|
|
459
|
+
readonly info: Readonly<TrieInfo>;
|
|
460
|
+
/**
|
|
461
|
+
* @param text - text to find in the Trie
|
|
462
|
+
*/
|
|
463
|
+
find(text: string): ITrieNode | undefined;
|
|
464
|
+
has(word: string): boolean;
|
|
465
|
+
has(word: string, minLegacyCompoundLength: boolean | number): boolean;
|
|
466
|
+
/**
|
|
467
|
+
* Determine if a word is in the dictionary.
|
|
468
|
+
* @param word - the exact word to search for - must be normalized.
|
|
469
|
+
* @param caseSensitive - false means also searching a dictionary where the words were normalized to lower case and accents removed.
|
|
470
|
+
* @returns true if the word was found and is not forbidden.
|
|
471
|
+
*/
|
|
472
|
+
hasWord(word: string, caseSensitive: boolean): boolean;
|
|
473
|
+
findWord(word: string, options?: FindWordOptions): FindFullResult$1;
|
|
474
|
+
/**
|
|
475
|
+
* Determine if a word is in the forbidden word list.
|
|
476
|
+
* @param word the word to lookup.
|
|
477
|
+
*/
|
|
478
|
+
isForbiddenWord(word: string): boolean;
|
|
479
|
+
/**
|
|
480
|
+
* Provides an ordered sequence of words with the prefix of text.
|
|
481
|
+
*/
|
|
482
|
+
completeWord(text: string): Iterable<string>;
|
|
483
|
+
/**
|
|
484
|
+
* Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
|
|
485
|
+
* @param text - the text to search for
|
|
486
|
+
* @param options - Controls the generated suggestions:
|
|
487
|
+
* - ignoreCase - Ignore Case and Accents
|
|
488
|
+
* - numSuggestions - the maximum number of suggestions to return.
|
|
489
|
+
* - compoundMethod - Use to control splitting words.
|
|
490
|
+
* - changeLimit - the maximum number of changes allowed to text. This is an approximate value, since some changes cost less than others.
|
|
491
|
+
* the lower the value, the faster results are returned. Values less than 4 are best.
|
|
492
|
+
*/
|
|
493
|
+
suggest(text: string, options: SuggestionOptions): string[];
|
|
494
|
+
/**
|
|
495
|
+
* Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
|
|
496
|
+
* The results include the word and adjusted edit cost. This is useful for merging results from multiple tries.
|
|
497
|
+
*/
|
|
498
|
+
suggestWithCost(text: string, options: SuggestionOptions): SuggestionResult[];
|
|
499
|
+
/**
|
|
500
|
+
* genSuggestions will generate suggestions and send them to `collector`. `collector` is responsible for returning the max acceptable cost.
|
|
501
|
+
* Costs are measured in weighted changes. A cost of 100 is the same as 1 edit. Some edits are considered cheaper.
|
|
502
|
+
* Returning a MaxCost < 0 will effectively cause the search for suggestions to stop.
|
|
503
|
+
*/
|
|
504
|
+
genSuggestions(collector: SuggestionCollector, compoundMethod?: CompoundWordsMethod): void;
|
|
505
|
+
/**
|
|
506
|
+
* Returns an iterator that can be used to get all words in the trie. For some dictionaries, this can result in millions of words.
|
|
507
|
+
*/
|
|
508
|
+
words(): Iterable<string>;
|
|
509
|
+
/**
|
|
510
|
+
* Allows iteration over the entire tree.
|
|
511
|
+
* On the returned Iterator, calling .next(goDeeper: boolean), allows for controlling the depth.
|
|
512
|
+
*/
|
|
513
|
+
iterate(): WalkerIterator$1;
|
|
514
|
+
readonly weightMap: WeightMap | undefined;
|
|
515
|
+
readonly isCaseAware: boolean;
|
|
516
|
+
readonly hasForbiddenWords: boolean;
|
|
517
|
+
readonly hasCompoundWords: boolean;
|
|
518
|
+
readonly hasNonStrictWords: boolean;
|
|
487
519
|
}
|
|
488
520
|
interface FindWordOptions {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
521
|
+
caseSensitive?: boolean;
|
|
522
|
+
useLegacyWordCompounds?: boolean | number;
|
|
523
|
+
checkForbidden?: boolean;
|
|
492
524
|
}
|
|
493
525
|
type FindWordOptionsRO = Readonly<FindWordOptions>;
|
|
494
|
-
|
|
526
|
+
//#endregion
|
|
527
|
+
//#region src/lib/buildITrie.d.ts
|
|
495
528
|
declare function buildITrieFromWords(words: Iterable<string>, info?: PartialTrieInfo): ITrie;
|
|
496
|
-
|
|
529
|
+
//#endregion
|
|
530
|
+
//#region src/lib/consolidate.d.ts
|
|
497
531
|
/**
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
532
|
+
* Consolidate to DAWG
|
|
533
|
+
* @param root the root of the Trie tree
|
|
534
|
+
*/
|
|
501
535
|
declare function consolidate(root: TrieRoot): TrieRoot;
|
|
502
|
-
|
|
536
|
+
//#endregion
|
|
537
|
+
//#region src/lib/constants.d.ts
|
|
503
538
|
declare const COMPOUND_FIX = "+";
|
|
504
539
|
declare const OPTIONAL_COMPOUND_FIX = "*";
|
|
505
540
|
declare const CASE_INSENSITIVE_PREFIX = "~";
|
|
506
541
|
declare const FORBID_PREFIX = "!";
|
|
507
542
|
declare const defaultTrieInfo: TrieInfo;
|
|
508
|
-
|
|
543
|
+
//#endregion
|
|
544
|
+
//#region src/lib/decodeTrie.d.ts
|
|
509
545
|
declare function decodeTrie(raw: string | Buffer): ITrie;
|
|
510
|
-
|
|
546
|
+
//#endregion
|
|
547
|
+
//#region src/lib/io/importExport.d.ts
|
|
511
548
|
interface ExportOptions {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
549
|
+
base?: number;
|
|
550
|
+
comment?: string;
|
|
551
|
+
version?: number;
|
|
552
|
+
addLineBreaksToImproveDiffs?: boolean;
|
|
516
553
|
}
|
|
517
554
|
/**
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
555
|
+
* Serialize a TrieNode.
|
|
556
|
+
* Note: This is destructive. The node will no longer be usable.
|
|
557
|
+
* Even though it is possible to preserve the trie, dealing with very large tries can consume a lot of memory.
|
|
558
|
+
* Considering this is the last step before exporting, it was decided to let this be destructive.
|
|
559
|
+
*/
|
|
523
560
|
declare function serializeTrie(root: TrieRoot, options?: ExportOptions | number): Iterable<string>;
|
|
524
561
|
declare function importTrie(input: Iterable<string> | IterableIterator<string> | string[] | string): TrieRoot;
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
562
|
+
//#endregion
|
|
563
|
+
//#region src/lib/models/DictionaryInformation.d.ts
|
|
564
|
+
type DictionaryInformation = Exclude<DictionaryDefinitionAugmented["dictionaryInformation"], undefined>;
|
|
565
|
+
//#endregion
|
|
566
|
+
//#region src/lib/mappers/mapDictionaryInfoToWeightMap.d.ts
|
|
528
567
|
declare function mapDictionaryInformationToWeightMap(dictInfo: DictionaryInformation): WeightMap;
|
|
529
|
-
|
|
568
|
+
//#endregion
|
|
569
|
+
//#region src/lib/TrieNode/find.d.ts
|
|
530
570
|
interface FindResult {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
571
|
+
found: string | false;
|
|
572
|
+
compoundUsed: boolean;
|
|
573
|
+
caseMatched: boolean;
|
|
534
574
|
}
|
|
535
575
|
interface FindFullResult extends FindResult {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
}
|
|
544
|
-
|
|
576
|
+
/**
|
|
577
|
+
* Is the word explicitly forbidden.
|
|
578
|
+
* - `true` - word is in the forbidden list.
|
|
579
|
+
* - `false` - word is not in the forbidden list.
|
|
580
|
+
* - `undefined` - unknown - was not checked.
|
|
581
|
+
* */
|
|
582
|
+
forbidden: boolean | undefined;
|
|
583
|
+
}
|
|
584
|
+
//#endregion
|
|
585
|
+
//#region src/lib/trie.d.ts
|
|
545
586
|
declare class Trie {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
}
|
|
619
|
-
|
|
587
|
+
readonly root: TrieRoot;
|
|
588
|
+
private count?;
|
|
589
|
+
private _options;
|
|
590
|
+
private _findOptionsDefaults;
|
|
591
|
+
private _findOptionsExact;
|
|
592
|
+
readonly isLegacy: boolean;
|
|
593
|
+
private hasForbidden;
|
|
594
|
+
constructor(root: TrieRoot, count?: number);
|
|
595
|
+
/**
|
|
596
|
+
* Number of words in the Trie
|
|
597
|
+
*/
|
|
598
|
+
size(): number;
|
|
599
|
+
isSizeKnown(): boolean;
|
|
600
|
+
get options(): Readonly<TrieInfo>;
|
|
601
|
+
/**
|
|
602
|
+
* @param text - text to find in the Trie
|
|
603
|
+
* @param minCompoundLength - deprecated - allows words to be glued together
|
|
604
|
+
*/
|
|
605
|
+
find(text: string, minCompoundLength?: boolean | number): TrieNode | undefined;
|
|
606
|
+
has(word: string, minLegacyCompoundLength?: boolean | number): boolean;
|
|
607
|
+
/**
|
|
608
|
+
* Determine if a word is in the dictionary.
|
|
609
|
+
* @param word - the exact word to search for - must be normalized.
|
|
610
|
+
* @param caseSensitive - false means also searching a dictionary where the words were normalized to lower case and accents removed.
|
|
611
|
+
* @returns true if the word was found and is not forbidden.
|
|
612
|
+
*/
|
|
613
|
+
hasWord(word: string, caseSensitive: boolean): boolean;
|
|
614
|
+
findWord(word: string, options?: FindWordOptionsRO): FindFullResult;
|
|
615
|
+
/**
|
|
616
|
+
* Determine if a word is in the forbidden word list.
|
|
617
|
+
* @param word the word to lookup.
|
|
618
|
+
*/
|
|
619
|
+
isForbiddenWord(word: string): boolean;
|
|
620
|
+
/**
|
|
621
|
+
* Provides an ordered sequence of words with the prefix of text.
|
|
622
|
+
*/
|
|
623
|
+
completeWord(text: string): Iterable<string>;
|
|
624
|
+
/**
|
|
625
|
+
* Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
|
|
626
|
+
* @param text - the text to search for
|
|
627
|
+
* @param maxNumSuggestions - the maximum number of suggestions to return.
|
|
628
|
+
* @param compoundMethod - Use to control splitting words.
|
|
629
|
+
* @param numChanges - the maximum number of changes allowed to text. This is an approximate value, since some changes cost less than others.
|
|
630
|
+
* the lower the value, the faster results are returned. Values less than 4 are best.
|
|
631
|
+
*/
|
|
632
|
+
suggest(text: string, options: SuggestionOptionsRO): string[];
|
|
633
|
+
/**
|
|
634
|
+
* Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
|
|
635
|
+
* The results include the word and adjusted edit cost. This is useful for merging results from multiple tries.
|
|
636
|
+
*/
|
|
637
|
+
suggestWithCost(text: string, options: SuggestionOptionsRO): SuggestionResult[];
|
|
638
|
+
/**
|
|
639
|
+
* genSuggestions will generate suggestions and send them to `collector`. `collector` is responsible for returning the max acceptable cost.
|
|
640
|
+
* Costs are measured in weighted changes. A cost of 100 is the same as 1 edit. Some edits are considered cheaper.
|
|
641
|
+
* Returning a MaxCost < 0 will effectively cause the search for suggestions to stop.
|
|
642
|
+
*/
|
|
643
|
+
genSuggestions(collector: SuggestionCollector, compoundMethod?: CompoundWordsMethod): void;
|
|
644
|
+
/**
|
|
645
|
+
* Returns an iterator that can be used to get all words in the trie. For some dictionaries, this can result in millions of words.
|
|
646
|
+
*/
|
|
647
|
+
words(): Iterable<string>;
|
|
648
|
+
/**
|
|
649
|
+
* Allows iteration over the entire tree.
|
|
650
|
+
* On the returned Iterator, calling .next(goDeeper: boolean), allows for controlling the depth.
|
|
651
|
+
*/
|
|
652
|
+
iterate(): WalkerIterator;
|
|
653
|
+
insert(word: string): this;
|
|
654
|
+
private calcIsLegacy;
|
|
655
|
+
static create(words: Iterable<string> | IterableIterator<string>, options?: PartialTrieInfo): Trie;
|
|
656
|
+
private createFindOptions;
|
|
657
|
+
private lastCreateFindOptionsMatchCaseMap;
|
|
658
|
+
private createFindOptionsMatchCase;
|
|
659
|
+
}
|
|
660
|
+
//#endregion
|
|
661
|
+
//#region src/lib/SimpleDictionaryParser.d.ts
|
|
620
662
|
interface ParseDictionaryOptions {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
663
|
+
compoundCharacter: string;
|
|
664
|
+
optionalCompoundCharacter: string;
|
|
665
|
+
forbiddenPrefix: string;
|
|
666
|
+
caseInsensitivePrefix: string;
|
|
667
|
+
/**
|
|
668
|
+
* Start of a single-line comment.
|
|
669
|
+
* @default "#"
|
|
670
|
+
*/
|
|
671
|
+
commentCharacter: string;
|
|
672
|
+
/**
|
|
673
|
+
* If word starts with prefix, do not strip case or accents.
|
|
674
|
+
* @default false;
|
|
675
|
+
*/
|
|
676
|
+
keepExactPrefix: string;
|
|
677
|
+
/**
|
|
678
|
+
* Tell the parser to automatically create case / accent insensitive forms.
|
|
679
|
+
* @default true
|
|
680
|
+
*/
|
|
681
|
+
stripCaseAndAccents: boolean;
|
|
682
|
+
/**
|
|
683
|
+
* Tell the parser to keep non-case/accent version in both forms.
|
|
684
|
+
* @default false
|
|
685
|
+
*/
|
|
686
|
+
stripCaseAndAccentsKeepDuplicate: boolean;
|
|
687
|
+
/**
|
|
688
|
+
* Tell the parser to keep non-case/accent version in both forms.
|
|
689
|
+
* @default false
|
|
690
|
+
*/
|
|
691
|
+
stripCaseAndAccentsOnForbidden: boolean;
|
|
692
|
+
/**
|
|
693
|
+
* Tell the parser to split into words along spaces.
|
|
694
|
+
* @default false
|
|
695
|
+
*/
|
|
696
|
+
split: boolean;
|
|
697
|
+
/**
|
|
698
|
+
* When splitting tells the parser to output both the split and non-split versions of the line.
|
|
699
|
+
* @default false
|
|
700
|
+
*/
|
|
701
|
+
splitKeepBoth: boolean;
|
|
702
|
+
/**
|
|
703
|
+
* Specify the separator for splitting words.
|
|
704
|
+
*/
|
|
705
|
+
splitSeparator: RegExp | string;
|
|
706
|
+
/**
|
|
707
|
+
* Do not normalize the compound character.
|
|
708
|
+
*/
|
|
709
|
+
keepOptionalCompoundCharacter: boolean;
|
|
668
710
|
}
|
|
669
711
|
/**
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
712
|
+
* Normalizes a dictionary words based upon prefix / suffixes.
|
|
713
|
+
* Case insensitive versions are also generated.
|
|
714
|
+
* @param options - defines prefixes used when parsing lines.
|
|
715
|
+
* @returns words that have been normalized.
|
|
716
|
+
*/
|
|
675
717
|
declare function createDictionaryLineParserMapper(options?: Partial<ParseDictionaryOptions>): Operator<string>;
|
|
676
718
|
/**
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
719
|
+
* Normalizes a dictionary words based upon prefix / suffixes.
|
|
720
|
+
* Case insensitive versions are also generated.
|
|
721
|
+
* @param lines - one word per line
|
|
722
|
+
* @param _options - defines prefixes used when parsing lines.
|
|
723
|
+
* @returns words that have been normalized.
|
|
724
|
+
*/
|
|
683
725
|
declare function parseDictionaryLines(lines: Iterable<string> | string, options?: Partial<ParseDictionaryOptions>): Iterable<string>;
|
|
684
726
|
declare function parseDictionaryLegacy(text: string | string[], options?: Partial<ParseDictionaryOptions>): Trie;
|
|
685
727
|
declare function parseDictionary(text: string | Iterable<string>, options?: Partial<ParseDictionaryOptions>): ITrie;
|
|
686
|
-
|
|
728
|
+
//#endregion
|
|
729
|
+
//#region src/lib/TrieBuilder.d.ts
|
|
687
730
|
/**
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
731
|
+
* Builds an optimized Trie from a Iterable<string>. It attempts to reduce the size of the trie
|
|
732
|
+
* by finding common endings.
|
|
733
|
+
* @param words Iterable set of words -- no processing is done on the words, they are inserted as is.
|
|
734
|
+
* @param trieOptions options for the Trie
|
|
735
|
+
*/
|
|
693
736
|
declare function buildTrie(words: Iterable<string>, trieOptions?: PartialTrieOptions): Trie;
|
|
694
737
|
/**
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
738
|
+
* Builds a Trie from a Iterable<string>. NO attempt a reducing the size of the Trie is done.
|
|
739
|
+
* @param words Iterable set of words -- no processing is done on the words, they are inserted as is.
|
|
740
|
+
* @param trieOptions options for the Trie
|
|
741
|
+
*/
|
|
699
742
|
declare function buildTrieFast(words: Iterable<string>, trieOptions?: PartialTrieOptions): Trie;
|
|
700
743
|
declare class TrieBuilder {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
744
|
+
private count;
|
|
745
|
+
private readonly signatures;
|
|
746
|
+
private readonly cached;
|
|
747
|
+
private readonly transforms;
|
|
748
|
+
private _eow;
|
|
749
|
+
/** position 0 of lastPath is always the root */
|
|
750
|
+
private lastPath;
|
|
751
|
+
private tails;
|
|
752
|
+
trieOptions: TrieOptions;
|
|
753
|
+
private numWords;
|
|
754
|
+
private _debug_lastWordsInserted;
|
|
755
|
+
// private _debug_mode = true;
|
|
756
|
+
private _debug_mode;
|
|
757
|
+
constructor(words?: Iterable<string>, trieOptions?: PartialTrieOptions);
|
|
758
|
+
private get _root();
|
|
759
|
+
private signature;
|
|
760
|
+
private _canBeCached;
|
|
761
|
+
private tryCacheFrozen;
|
|
762
|
+
private freeze;
|
|
763
|
+
private tryToCache;
|
|
764
|
+
private storeTransform;
|
|
765
|
+
private addChild;
|
|
766
|
+
private buildTail;
|
|
767
|
+
private _insert;
|
|
768
|
+
insertWord(word: string): void;
|
|
769
|
+
insert(words: Iterable<string>): void;
|
|
770
|
+
/**
|
|
771
|
+
* Resets the builder
|
|
772
|
+
*/
|
|
773
|
+
reset(): void;
|
|
774
|
+
build(consolidateSuffixes?: boolean): Trie;
|
|
775
|
+
private debugStack;
|
|
776
|
+
private debNodeInfo;
|
|
777
|
+
private logDebug;
|
|
778
|
+
private runDebug;
|
|
779
|
+
private copyIfFrozen;
|
|
780
|
+
private createNodeFrozen;
|
|
781
|
+
private createNode;
|
|
782
|
+
}
|
|
783
|
+
//#endregion
|
|
784
|
+
//#region src/lib/TrieNode/trie-util.d.ts
|
|
740
785
|
declare function insert(word: string, root?: TrieNode): TrieNode;
|
|
741
786
|
declare function isWordTerminationNode(node: TrieNode): boolean;
|
|
742
787
|
/**
|
|
743
|
-
|
|
744
|
-
|
|
788
|
+
* Sorts the nodes in a trie in place.
|
|
789
|
+
*/
|
|
745
790
|
declare function orderTrie(node: TrieNode): void;
|
|
746
791
|
/**
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
declare function walk(node: TrieNode): Iterable<YieldResult
|
|
792
|
+
* Generator an iterator that will walk the Trie parent then children in a depth first fashion that preserves sorted order.
|
|
793
|
+
*/
|
|
794
|
+
declare function walk(node: TrieNode): Iterable<YieldResult>;
|
|
750
795
|
declare const iterateTrie: typeof walk;
|
|
751
796
|
/**
|
|
752
|
-
|
|
753
|
-
|
|
797
|
+
* Generate a Iterator that can walk a Trie and yield the words.
|
|
798
|
+
*/
|
|
754
799
|
declare function iteratorTrieWords(node: TrieNode): Iterable<string>;
|
|
755
800
|
declare function createTrieRoot(options: PartialTrieInfo): TrieRoot;
|
|
756
801
|
declare function createTrieRootFromList(words: Iterable<string>, options?: PartialTrieInfo): TrieRoot;
|
|
@@ -760,54 +805,69 @@ declare function countNodes(root: TrieNode): number;
|
|
|
760
805
|
declare function countWords(root: TrieNode): number;
|
|
761
806
|
declare function isCircular(root: TrieNode): boolean;
|
|
762
807
|
declare function trieNodeToRoot(node: TrieNode, options: PartialTrieInfo): TrieRoot;
|
|
763
|
-
|
|
808
|
+
//#endregion
|
|
809
|
+
//#region src/lib/utils/isDefined.d.ts
|
|
764
810
|
declare function isDefined<T>(t: T | undefined): t is T;
|
|
765
|
-
|
|
811
|
+
//#endregion
|
|
812
|
+
//#region src/lib/utils/mergeDefaults.d.ts
|
|
766
813
|
/**
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
814
|
+
* Creates a new object of type T based upon the field values from `value`.
|
|
815
|
+
* n[k] = value[k] ?? default[k] where k must be a field in default.
|
|
816
|
+
* Note: it will remove fields not in defaultValue!
|
|
817
|
+
* @param value
|
|
818
|
+
* @param defaultValue
|
|
819
|
+
*/
|
|
773
820
|
declare function mergeDefaults<T extends object>(value: Readonly<PartialWithUndefined<T>> | undefined, defaultValue: T): T;
|
|
774
|
-
|
|
821
|
+
//#endregion
|
|
822
|
+
//#region src/lib/utils/mergeOptionalWithDefaults.d.ts
|
|
775
823
|
type ROPartialTrieOptions = Readonly<PartialTrieInfo>;
|
|
776
824
|
declare function mergeOptionalWithDefaults(options: ROPartialTrieOptions): TrieInfo;
|
|
777
825
|
declare function mergeOptionalWithDefaults(options: ROPartialTrieOptions, ...moreOptions: ROPartialTrieOptions[]): TrieInfo;
|
|
778
|
-
|
|
826
|
+
//#endregion
|
|
827
|
+
//#region src/lib/utils/normalizeWord.d.ts
|
|
779
828
|
/**
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
829
|
+
* Normalize word unicode.
|
|
830
|
+
* @param text - text to normalize
|
|
831
|
+
* @returns returns a word normalized to `NFC`
|
|
832
|
+
*/
|
|
784
833
|
declare const normalizeWord: (text: string) => string;
|
|
785
834
|
/**
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
835
|
+
* converts text to lower case and removes any accents.
|
|
836
|
+
* @param text - text to convert
|
|
837
|
+
* @returns lowercase word without accents
|
|
838
|
+
* @deprecated true
|
|
839
|
+
*/
|
|
791
840
|
declare const normalizeWordToLowercase: (text: string) => string;
|
|
792
841
|
/**
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
842
|
+
* generate case insensitive forms of a word
|
|
843
|
+
* @param text - text to convert
|
|
844
|
+
* @returns the forms of the word.
|
|
845
|
+
*/
|
|
797
846
|
declare const normalizeWordForCaseInsensitive: (text: string) => string[];
|
|
798
|
-
|
|
847
|
+
//#endregion
|
|
848
|
+
//#region src/lib/utils/text.d.ts
|
|
799
849
|
/**
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
850
|
+
* Expand a line into a set of characters.
|
|
851
|
+
*
|
|
852
|
+
* Example:
|
|
853
|
+
* - `a-c` -> `<a,b,c>`
|
|
854
|
+
* - `ac-` -> `<a,c,->`
|
|
855
|
+
* - `-abz` -> `<-,a,b,z>`
|
|
856
|
+
* - `\u0300-\u0308` -> `<accents>`
|
|
857
|
+
*
|
|
858
|
+
* @param line - set of characters
|
|
859
|
+
* @param rangeChar - the character to indicate ranges, set to empty to not have ranges.
|
|
860
|
+
*/
|
|
811
861
|
declare function expandCharacterSet(line: string, rangeChar?: string): Set<string>;
|
|
812
|
-
|
|
813
|
-
|
|
862
|
+
/**
|
|
863
|
+
* Expands a range between two characters.
|
|
864
|
+
* - `a <= b` -- `[a, b]`
|
|
865
|
+
* - `a > b` -- `[]`
|
|
866
|
+
* @param a - staring character
|
|
867
|
+
* @param b - ending character
|
|
868
|
+
* @returns array of unicode characters.
|
|
869
|
+
*/
|
|
870
|
+
|
|
871
|
+
//#endregion
|
|
872
|
+
export { CASE_INSENSITIVE_PREFIX, COMPOUND_FIX, ChildMap, CompoundWordsMethod, ExportOptions, FLAG_WORD, FORBID_PREFIX, FindFullResult, FindWordOptions, HintedWalkerIterator, Hinting, ITrie, JOIN_SEPARATOR, MaxCost, OPTIONAL_COMPOUND_FIX, PartialTrieOptions, SuggestionCollector, SuggestionCostMapDef, SuggestionResult, Trie, TrieBuilder, TrieNode, TrieOptions, TrieOptionsRO, TrieRoot, WORD_SEPARATOR, WalkerIterator, WeightMap, YieldResult, buildITrieFromWords, buildTrie, buildTrieFast, consolidate, countNodes, countWords, createDictionaryLineParserMapper as createDictionaryLineParser, createTrieRoot, createTrieRootFromList, createWeightedMap, decodeTrie, defaultTrieInfo, defaultTrieInfo as defaultTrieOptions, editDistance, editDistanceWeighted, expandCharacterSet, findNode, has, hintedWalker, impersonateCollector, importTrie, insert, isCircular, isDefined, isWordTerminationNode, iterateTrie, iteratorTrieWords, mapDictionaryInformationToWeightMap, mergeDefaults, mergeOptionalWithDefaults, normalizeWord, normalizeWordForCaseInsensitive, normalizeWordToLowercase, orderTrie, parseDictionary, parseDictionaryLegacy, parseDictionaryLines, serializeTrie, suggestionCollector, trieNodeToRoot, walk, walker };
|
|
873
|
+
//# sourceMappingURL=index.d.ts.map
|