cspell-trie-lib 10.0.1 → 10.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 +418 -419
- package/dist/index.js +39 -33
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
import { DictionaryDefinitionAugmented, SuggestionCostMapDef } from "@cspell/cspell-types";
|
|
2
|
-
|
|
3
2
|
//#region src/lib/BuildOptions.d.ts
|
|
4
3
|
interface BuildOptions {
|
|
5
4
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
* Optimize the trie for size by merging duplicate sub-tries and using a String Table.
|
|
6
|
+
* @default false
|
|
7
|
+
*/
|
|
9
8
|
optimize?: boolean | undefined;
|
|
10
9
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
* Use a string table to reduce memory usage.
|
|
11
|
+
* @default false
|
|
12
|
+
*/
|
|
14
13
|
useStringTable?: boolean | undefined;
|
|
15
14
|
}
|
|
16
15
|
//#endregion
|
|
17
16
|
//#region src/lib/distance/weightedMaps.d.ts
|
|
18
17
|
/**
|
|
19
|
-
* Costs are minimized while penalties are maximized.
|
|
20
|
-
*/
|
|
18
|
+
* Costs are minimized while penalties are maximized.
|
|
19
|
+
*/
|
|
21
20
|
interface Cost$1 {
|
|
22
21
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
* The cost of an operation
|
|
23
|
+
* `c'' = min(c, c')`
|
|
24
|
+
*/
|
|
26
25
|
c?: number | undefined;
|
|
27
26
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
* The penalties applied
|
|
28
|
+
* `p'' = max(p, p')`
|
|
29
|
+
*/
|
|
31
30
|
p?: number | undefined;
|
|
32
31
|
}
|
|
33
32
|
interface TrieCost extends Cost$1 {
|
|
@@ -57,35 +56,35 @@ interface PenaltyAdjustment {
|
|
|
57
56
|
//#endregion
|
|
58
57
|
//#region src/lib/distance/distance.d.ts
|
|
59
58
|
/**
|
|
60
|
-
* Calculate the edit distance between any two words.
|
|
61
|
-
* Use the Damerau–Levenshtein distance algorithm.
|
|
62
|
-
* @param wordA
|
|
63
|
-
* @param wordB
|
|
64
|
-
* @param editCost - the cost of each edit (defaults to 100)
|
|
65
|
-
* @returns the edit distance.
|
|
66
|
-
*/
|
|
59
|
+
* Calculate the edit distance between any two words.
|
|
60
|
+
* Use the Damerau–Levenshtein distance algorithm.
|
|
61
|
+
* @param wordA
|
|
62
|
+
* @param wordB
|
|
63
|
+
* @param editCost - the cost of each edit (defaults to 100)
|
|
64
|
+
* @returns the edit distance.
|
|
65
|
+
*/
|
|
67
66
|
declare function editDistance(wordA: string, wordB: string, editCost?: number): number;
|
|
68
67
|
/**
|
|
69
|
-
* Calculate the weighted edit distance between any two words.
|
|
70
|
-
* @param wordA
|
|
71
|
-
* @param wordB
|
|
72
|
-
* @param weights - the weights to use
|
|
73
|
-
* @param editCost - the cost of each edit (defaults to 100)
|
|
74
|
-
* @returns the edit distance
|
|
75
|
-
*/
|
|
68
|
+
* Calculate the weighted edit distance between any two words.
|
|
69
|
+
* @param wordA
|
|
70
|
+
* @param wordB
|
|
71
|
+
* @param weights - the weights to use
|
|
72
|
+
* @param editCost - the cost of each edit (defaults to 100)
|
|
73
|
+
* @returns the edit distance
|
|
74
|
+
*/
|
|
76
75
|
declare function editDistanceWeighted(wordA: string, wordB: string, weights: WeightMap, editCost?: number): number;
|
|
77
76
|
/**
|
|
78
|
-
* Collect Map definitions into a single weighted map.
|
|
79
|
-
* @param defs - list of definitions
|
|
80
|
-
* @returns A Weighted Map to be used with distance calculations.
|
|
81
|
-
*/
|
|
77
|
+
* Collect Map definitions into a single weighted map.
|
|
78
|
+
* @param defs - list of definitions
|
|
79
|
+
* @returns A Weighted Map to be used with distance calculations.
|
|
80
|
+
*/
|
|
82
81
|
declare function createWeightedMap(defs: SuggestionCostMapDef[]): WeightMap;
|
|
83
82
|
//#endregion
|
|
84
83
|
//#region src/lib/types.d.ts
|
|
85
84
|
/**
|
|
86
|
-
* Make all properties in T optional and Possibly undefined
|
|
87
|
-
*/
|
|
88
|
-
type PartialWithUndefined<T> = { [P in keyof T]?: T[P] | undefined };
|
|
85
|
+
* Make all properties in T optional and Possibly undefined
|
|
86
|
+
*/
|
|
87
|
+
type PartialWithUndefined<T> = { [P in keyof T]?: T[P] | undefined; };
|
|
89
88
|
//#endregion
|
|
90
89
|
//#region src/lib/ITrieNode/TrieInfo.d.ts
|
|
91
90
|
interface TrieInfo {
|
|
@@ -109,41 +108,41 @@ interface FindResult$1 {
|
|
|
109
108
|
compoundUsed: boolean;
|
|
110
109
|
caseMatched: boolean;
|
|
111
110
|
/**
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
* Is the word explicitly forbidden.
|
|
112
|
+
* - `true` - word is in the forbidden list.
|
|
113
|
+
* - `false` - word is not in the forbidden list.
|
|
114
|
+
* - `undefined` - unknown - was not checked.
|
|
115
|
+
*/
|
|
117
116
|
forbidden: boolean | undefined;
|
|
118
117
|
}
|
|
119
118
|
interface FindFullResult$1 extends FindResult$1 {
|
|
120
119
|
/**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
* Is the word explicitly forbidden.
|
|
121
|
+
* - `true` - word is in the forbidden list.
|
|
122
|
+
* - `false` - word is not in the forbidden list.
|
|
123
|
+
* - `undefined` - unknown - was not checked.
|
|
124
|
+
*/
|
|
126
125
|
forbidden: boolean | undefined;
|
|
127
126
|
}
|
|
128
127
|
/**
|
|
129
|
-
* ITrieNode instances are not unique. It is possible for multiple ITrieNode instances to
|
|
130
|
-
* represent the same node.
|
|
131
|
-
* `id` is used to see if two instances refer to the same node.
|
|
132
|
-
* The type is obscured because it is up the the backing structure to provide the best value.
|
|
133
|
-
* Note, only nodes from the same root are guaranteed to be unique. It is possible for two
|
|
134
|
-
* different ITrieNode instances to have the same `id` value if they come from different roots.
|
|
135
|
-
*/
|
|
128
|
+
* ITrieNode instances are not unique. It is possible for multiple ITrieNode instances to
|
|
129
|
+
* represent the same node.
|
|
130
|
+
* `id` is used to see if two instances refer to the same node.
|
|
131
|
+
* The type is obscured because it is up the the backing structure to provide the best value.
|
|
132
|
+
* Note, only nodes from the same root are guaranteed to be unique. It is possible for two
|
|
133
|
+
* different ITrieNode instances to have the same `id` value if they come from different roots.
|
|
134
|
+
*/
|
|
136
135
|
type ITrieNodeId = object | number | string | bigint;
|
|
137
136
|
type Entry = readonly [string, ITrieNode];
|
|
138
137
|
interface ITrieNode {
|
|
139
138
|
/**
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
139
|
+
* ITrieNode instances are not unique. It is possible for multiple ITrieNode instances to
|
|
140
|
+
* represent the same node.
|
|
141
|
+
* `id` is used to see if two instances refer to the same node.
|
|
142
|
+
* The type is obscured because it is up the the backing structure to provide the best value.
|
|
143
|
+
* Note, only nodes from the same root are guaranteed to be unique. It is possible for two
|
|
144
|
+
* different ITrieNode instances to have the same `id` value if they come from different roots.
|
|
145
|
+
*/
|
|
147
146
|
readonly id: ITrieNodeId;
|
|
148
147
|
/** flag End of Word */
|
|
149
148
|
readonly eow: boolean;
|
|
@@ -167,17 +166,17 @@ interface ITrieNode {
|
|
|
167
166
|
interface ITrieNodeRoot extends ITrieNode {
|
|
168
167
|
readonly info: Readonly<TrieInfo>;
|
|
169
168
|
/**
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
* converts an `id` into a node.
|
|
170
|
+
* @param id an of a ITrieNode in this Trie
|
|
171
|
+
*/
|
|
173
172
|
resolveId(id: ITrieNodeId): ITrieNode;
|
|
174
173
|
findExact: ((word: string) => boolean) | undefined;
|
|
175
174
|
/**
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
175
|
+
* Try to find a word.
|
|
176
|
+
* @param word - the normalized word to look up.
|
|
177
|
+
* @param strict - if `true` the case and accents must match.
|
|
178
|
+
* @returns undefined if it did not try to find the word, otherwise a FindResult.
|
|
179
|
+
*/
|
|
181
180
|
find?: ((word: string, strict: boolean) => FindResult$1 | undefined) | undefined;
|
|
182
181
|
isForbidden?: ((word: string) => boolean) | undefined;
|
|
183
182
|
readonly forbidPrefix: string;
|
|
@@ -215,16 +214,16 @@ interface YieldResult {
|
|
|
215
214
|
}
|
|
216
215
|
declare const CompoundWordsMethodEnum: {
|
|
217
216
|
/**
|
|
218
|
-
|
|
219
|
-
|
|
217
|
+
* Do not compound words.
|
|
218
|
+
*/
|
|
220
219
|
readonly NONE: 0;
|
|
221
220
|
/**
|
|
222
|
-
|
|
223
|
-
|
|
221
|
+
* Create word compounds separated by spaces.
|
|
222
|
+
*/
|
|
224
223
|
readonly SEPARATE_WORDS: 1;
|
|
225
224
|
/**
|
|
226
|
-
|
|
227
|
-
|
|
225
|
+
* Create word compounds without separation.
|
|
226
|
+
*/
|
|
228
227
|
readonly JOIN_WORDS: 2;
|
|
229
228
|
};
|
|
230
229
|
type CompoundWordsMethodEnum = typeof CompoundWordsMethodEnum;
|
|
@@ -245,17 +244,17 @@ interface YieldResult$1 {
|
|
|
245
244
|
}
|
|
246
245
|
type FalseToNotGoDeeper = boolean;
|
|
247
246
|
/**
|
|
248
|
-
* By default a Walker Iterator will go depth first. To prevent the
|
|
249
|
-
* walker from going deeper use `iterator.next(false)`.
|
|
250
|
-
*/
|
|
247
|
+
* By default a Walker Iterator will go depth first. To prevent the
|
|
248
|
+
* walker from going deeper use `iterator.next(false)`.
|
|
249
|
+
*/
|
|
251
250
|
type WalkerIterator$1 = Generator<YieldResult$1, void, FalseToNotGoDeeper | undefined>;
|
|
252
251
|
//#endregion
|
|
253
252
|
//#region src/lib/walker/hintedWalker.d.ts
|
|
254
253
|
/**
|
|
255
|
-
* Ask for the next result.
|
|
256
|
-
* goDeeper of true tells the walker to go deeper in the Trie if possible. Default is true.
|
|
257
|
-
* This can be used to limit the walker's depth.
|
|
258
|
-
*/
|
|
254
|
+
* Ask for the next result.
|
|
255
|
+
* goDeeper of true tells the walker to go deeper in the Trie if possible. Default is true.
|
|
256
|
+
* This can be used to limit the walker's depth.
|
|
257
|
+
*/
|
|
259
258
|
type HintedWalkerIterator = Generator<YieldResult, void, Hinting | undefined>;
|
|
260
259
|
declare function hintedWalker(root: TrieRoot, ignoreCase: boolean, hint: string, compoundingMethod: CompoundWordsMethod | undefined, emitWordSeparator?: string): HintedWalkerIterator;
|
|
261
260
|
interface Hinting {
|
|
@@ -268,23 +267,23 @@ declare function walker(root: TrieNode, compoundingMethod?: CompoundWordsMethod)
|
|
|
268
267
|
//#region src/lib/suggestions/genSuggestionsOptions.d.ts
|
|
269
268
|
interface GenSuggestionOptionsStrict {
|
|
270
269
|
/**
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
270
|
+
* Controls forcing compound words.
|
|
271
|
+
* @default CompoundWordsMethod.NONE
|
|
272
|
+
*/
|
|
274
273
|
compoundMethod?: CompoundWordsMethod;
|
|
275
274
|
/**
|
|
276
|
-
|
|
277
|
-
|
|
275
|
+
* ignore case when searching.
|
|
276
|
+
*/
|
|
278
277
|
ignoreCase: boolean;
|
|
279
278
|
/**
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
279
|
+
* Maximum number of "edits" allowed.
|
|
280
|
+
* 3 is a good number. Above 5 can be very slow.
|
|
281
|
+
*/
|
|
283
282
|
changeLimit: number;
|
|
284
283
|
/**
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
284
|
+
* Inserts a compound character between compounded word segments.
|
|
285
|
+
* @default ""
|
|
286
|
+
*/
|
|
288
287
|
compoundSeparator?: string;
|
|
289
288
|
}
|
|
290
289
|
type GenSuggestionOptionsStrictRO = Readonly<GenSuggestionOptionsStrict>;
|
|
@@ -292,26 +291,26 @@ type GenSuggestionOptions = Partial<GenSuggestionOptionsStrict>;
|
|
|
292
291
|
type GenSuggestionOptionsRO = Readonly<GenSuggestionOptions>;
|
|
293
292
|
interface SuggestionOptionsStrict extends GenSuggestionOptionsStrict {
|
|
294
293
|
/**
|
|
295
|
-
|
|
296
|
-
|
|
294
|
+
* Maximum number of suggestions to make.
|
|
295
|
+
*/
|
|
297
296
|
numSuggestions: number;
|
|
298
297
|
/**
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
298
|
+
* Allow ties when making suggestions.
|
|
299
|
+
* if `true` it is possible to have more than `numSuggestions`.
|
|
300
|
+
*/
|
|
302
301
|
includeTies: boolean;
|
|
303
302
|
/**
|
|
304
|
-
|
|
305
|
-
|
|
303
|
+
* Time alloted in milliseconds to generate suggestions.
|
|
304
|
+
*/
|
|
306
305
|
timeout: number;
|
|
307
306
|
/**
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
307
|
+
* Optional filter function.
|
|
308
|
+
* return true to keep the candidate.
|
|
309
|
+
*/
|
|
311
310
|
filter?: (word: string, cost: number) => boolean;
|
|
312
311
|
/**
|
|
313
|
-
|
|
314
|
-
|
|
312
|
+
* Apply weights to improve the suggestions.
|
|
313
|
+
*/
|
|
315
314
|
weightMap?: WeightMap | undefined;
|
|
316
315
|
}
|
|
317
316
|
type SuggestionOptions = Partial<SuggestionOptionsStrict>;
|
|
@@ -326,9 +325,9 @@ interface SuggestionResultBase {
|
|
|
326
325
|
/** The edit cost 100 = 1 edit */
|
|
327
326
|
cost: Cost;
|
|
328
327
|
/**
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
328
|
+
* This suggestion is the preferred suggestion.
|
|
329
|
+
* Setting this to `true` implies that an auto fix is possible.
|
|
330
|
+
*/
|
|
332
331
|
isPreferred?: boolean | undefined;
|
|
333
332
|
}
|
|
334
333
|
interface SuggestionResult extends SuggestionResultBase {
|
|
@@ -340,36 +339,36 @@ interface Progress {
|
|
|
340
339
|
/** Number of Completed Tasks so far */
|
|
341
340
|
completed: number;
|
|
342
341
|
/**
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
342
|
+
* Number of tasks remaining, this number is allowed to increase over time since
|
|
343
|
+
* completed tasks can generate new tasks.
|
|
344
|
+
*/
|
|
346
345
|
remaining: number;
|
|
347
346
|
}
|
|
348
347
|
type GenerateNextParam = MaxCost | symbol | undefined;
|
|
349
348
|
type GenerateSuggestionResult = SuggestionResultBase | Progress | undefined;
|
|
350
349
|
/**
|
|
351
|
-
* Ask for the next result.
|
|
352
|
-
* maxCost - sets the max cost for following suggestions
|
|
353
|
-
* This is used to limit which suggestions are emitted.
|
|
354
|
-
* If the `iterator.next()` returns `undefined`, it is to request a value for maxCost.
|
|
355
|
-
*
|
|
356
|
-
* The SuggestionIterator is generally the
|
|
357
|
-
*/
|
|
350
|
+
* Ask for the next result.
|
|
351
|
+
* maxCost - sets the max cost for following suggestions
|
|
352
|
+
* This is used to limit which suggestions are emitted.
|
|
353
|
+
* If the `iterator.next()` returns `undefined`, it is to request a value for maxCost.
|
|
354
|
+
*
|
|
355
|
+
* The SuggestionIterator is generally the
|
|
356
|
+
*/
|
|
358
357
|
type SuggestionGenerator = Generator<GenerateSuggestionResult, void, GenerateNextParam>;
|
|
359
358
|
//#endregion
|
|
360
359
|
//#region src/lib/suggestions/suggestCollector.d.ts
|
|
361
360
|
type FilterWordFn = (word: string, cost: number) => boolean;
|
|
362
361
|
interface SuggestionCollector {
|
|
363
362
|
/**
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
363
|
+
* Collection suggestions from a SuggestionIterator
|
|
364
|
+
* @param src - the SuggestionIterator used to generate suggestions.
|
|
365
|
+
* @param timeout - the amount of time in milliseconds to allow for suggestions.
|
|
366
|
+
* before sending `symbolStopProcessing`
|
|
367
|
+
* Iterator implementation:
|
|
368
|
+
* @example
|
|
369
|
+
* r = yield(suggestion);
|
|
370
|
+
* if (r === collector.symbolStopProcessing) // ...stop generating suggestions.
|
|
371
|
+
*/
|
|
373
372
|
collect: (src: SuggestionGenerator, timeout?: number, filter?: FilterWordFn) => void;
|
|
374
373
|
add: (suggestion: SuggestionResultBase) => SuggestionCollector;
|
|
375
374
|
readonly suggestions: SuggestionResult[];
|
|
@@ -381,56 +380,56 @@ interface SuggestionCollector {
|
|
|
381
380
|
readonly ignoreCase: boolean;
|
|
382
381
|
readonly genSuggestionOptions: GenSuggestionOptionsRO;
|
|
383
382
|
/**
|
|
384
|
-
|
|
385
|
-
|
|
383
|
+
* Possible value sent to the SuggestionIterator telling it to stop processing.
|
|
384
|
+
*/
|
|
386
385
|
readonly symbolStopProcessing: symbol;
|
|
387
386
|
}
|
|
388
387
|
interface SuggestionCollectorOptions extends Omit<GenSuggestionOptionsStrictRO, "ignoreCase" | "changeLimit"> {
|
|
389
388
|
/**
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
389
|
+
* number of best matching suggestions.
|
|
390
|
+
* @default 10
|
|
391
|
+
*/
|
|
393
392
|
numSuggestions: number;
|
|
394
393
|
/**
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
394
|
+
* An optional filter function that can be used to limit remove unwanted suggestions.
|
|
395
|
+
* I.E. to remove forbidden terms.
|
|
396
|
+
* @default () => true
|
|
397
|
+
*/
|
|
399
398
|
filter?: FilterWordFn | undefined;
|
|
400
399
|
/**
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
400
|
+
* The number of letters that can be changed when looking for a match
|
|
401
|
+
* @default 5
|
|
402
|
+
*/
|
|
404
403
|
changeLimit: number | undefined;
|
|
405
404
|
/**
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
405
|
+
* Include suggestions with tied cost even if the number is greater than `numSuggestions`.
|
|
406
|
+
* @default true
|
|
407
|
+
*/
|
|
409
408
|
includeTies?: boolean | undefined;
|
|
410
409
|
/**
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
410
|
+
* specify if case / accents should be ignored when looking for suggestions.
|
|
411
|
+
* @default true
|
|
412
|
+
*/
|
|
414
413
|
ignoreCase: boolean | undefined;
|
|
415
414
|
/**
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
415
|
+
* the total amount of time to allow for suggestions.
|
|
416
|
+
* @default 1000
|
|
417
|
+
*/
|
|
419
418
|
timeout?: number | undefined;
|
|
420
419
|
/**
|
|
421
|
-
|
|
422
|
-
|
|
420
|
+
* Used to improve the sorted results.
|
|
421
|
+
*/
|
|
423
422
|
weightMap?: WeightMap | undefined;
|
|
424
423
|
}
|
|
425
424
|
type SuggestionCollectorOptionsRO = Readonly<SuggestionCollectorOptions>;
|
|
426
425
|
declare function suggestionCollector(wordToMatch: string, options: SuggestionCollectorOptionsRO): SuggestionCollector;
|
|
427
426
|
/**
|
|
428
|
-
* Impersonating a Collector, allows searching for multiple variants on the same word.
|
|
429
|
-
* The collection is still in the original collector.
|
|
430
|
-
* @param collector - collector to impersonate
|
|
431
|
-
* @param word - word to present instead of `collector.word`.
|
|
432
|
-
* @returns a SuggestionCollector
|
|
433
|
-
*/
|
|
427
|
+
* Impersonating a Collector, allows searching for multiple variants on the same word.
|
|
428
|
+
* The collection is still in the original collector.
|
|
429
|
+
* @param collector - collector to impersonate
|
|
430
|
+
* @param word - word to present instead of `collector.word`.
|
|
431
|
+
* @returns a SuggestionCollector
|
|
432
|
+
*/
|
|
434
433
|
declare function impersonateCollector(collector: SuggestionCollector, word: string): SuggestionCollector;
|
|
435
434
|
//#endregion
|
|
436
435
|
//#region src/lib/TrieData.d.ts
|
|
@@ -442,9 +441,9 @@ interface TrieData extends TrieDataFundamentals, Readonly<TrieCharacteristics> {
|
|
|
442
441
|
/** Method used to split words into individual characters. */
|
|
443
442
|
wordToCharacters(word: string): readonly string[];
|
|
444
443
|
/**
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
444
|
+
* get an iterable for all the words in the dictionary.
|
|
445
|
+
* @param prefix - optional prefix to filter the words returned. The words will be prefixed with this value.
|
|
446
|
+
*/
|
|
448
447
|
words(prefix?: string): Iterable<string>;
|
|
449
448
|
getRoot(): ITrieNodeRoot;
|
|
450
449
|
getNode(prefix: string): ITrieNode | undefined;
|
|
@@ -461,117 +460,117 @@ interface TrieData extends TrieDataFundamentals, Readonly<TrieCharacteristics> {
|
|
|
461
460
|
interface ITrie {
|
|
462
461
|
readonly data: TrieData;
|
|
463
462
|
/**
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
463
|
+
* Approximate number of words in the Trie, the first call to this method might be expensive.
|
|
464
|
+
* Use `size` to get the number of nodes.
|
|
465
|
+
*
|
|
466
|
+
* It does NOT count natural compound words. Natural compounds are words that are composed of appending
|
|
467
|
+
* multiple words to make a new word. This is common in languages like German and Dutch.
|
|
468
|
+
*/
|
|
470
469
|
numWords(): number;
|
|
471
470
|
/**
|
|
472
|
-
|
|
473
|
-
|
|
471
|
+
* Used to check if the number of words has been calculated.
|
|
472
|
+
*/
|
|
474
473
|
isNumWordsKnown(): boolean;
|
|
475
474
|
/**
|
|
476
|
-
|
|
477
|
-
|
|
475
|
+
* The number of nodes in the Trie. There is a rough corelation between the size and the number of words.
|
|
476
|
+
*/
|
|
478
477
|
readonly size: number;
|
|
479
478
|
readonly info: Readonly<TrieInfo>;
|
|
480
479
|
/**
|
|
481
|
-
|
|
482
|
-
|
|
480
|
+
* @param text - text to find in the Trie
|
|
481
|
+
*/
|
|
483
482
|
find(text: string): ITrieNode | undefined;
|
|
484
483
|
/**
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
484
|
+
* A case sensitive search for the word.
|
|
485
|
+
* @param word - the word to search for.
|
|
486
|
+
* @returns true if the word is found and not forbidden.
|
|
487
|
+
*/
|
|
489
488
|
has(word: string): boolean;
|
|
490
489
|
/**
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
490
|
+
* The legacy case insensitive search for the word.
|
|
491
|
+
* @param word - the word to search for.
|
|
492
|
+
* @param minLegacyCompoundLength - minimum length of legacy compounds to consider.
|
|
493
|
+
* @returns true if the word is found and not forbidden.
|
|
494
|
+
* @deprecated use hasWord or findWord instead. Support for this method signature may be removed in the future.
|
|
495
|
+
*/
|
|
497
496
|
has(word: string, minLegacyCompoundLength: boolean | number): boolean;
|
|
498
497
|
/**
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
498
|
+
* Determine if a word is in the dictionary.
|
|
499
|
+
* @param word - the exact word to search for - must be normalized.
|
|
500
|
+
* @param caseSensitive - false means also searching a dictionary where the words were normalized to lower case and accents removed.
|
|
501
|
+
* @returns true if the word was found and is not forbidden.
|
|
502
|
+
*/
|
|
504
503
|
hasWord(word: string, caseSensitive: boolean): boolean;
|
|
505
504
|
findWord(word: string, options?: FindWordOptionsRO): FindFullResult$1;
|
|
506
505
|
/**
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
506
|
+
* Determine if a word is in the forbidden word list.
|
|
507
|
+
* @param word the word to lookup.
|
|
508
|
+
*/
|
|
510
509
|
isForbiddenWord(word: string): boolean;
|
|
511
510
|
/**
|
|
512
|
-
|
|
513
|
-
|
|
511
|
+
* Provides an ordered sequence of words with the prefix of text.
|
|
512
|
+
*/
|
|
514
513
|
completeWord(text: string): Iterable<string>;
|
|
515
514
|
/**
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
515
|
+
* Checks to see if there are preferred suggestions for the given text.
|
|
516
|
+
*
|
|
517
|
+
* @param word
|
|
518
|
+
*/
|
|
520
519
|
wordHasPreferredSuggestions(word: string): boolean;
|
|
521
520
|
/**
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
521
|
+
* Get preferred suggestions for the given text.
|
|
522
|
+
* @param text - the exact word to search for.
|
|
523
|
+
*/
|
|
525
524
|
getPreferredSuggestions(text: string): Iterable<string>;
|
|
526
525
|
/**
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
526
|
+
* Get a list of all preferred suggestions in the trie.
|
|
527
|
+
* They are returned in order and in the following format:
|
|
528
|
+
* ```
|
|
529
|
+
* <word1>:<suggestion1>
|
|
530
|
+
* <word1>:<suggestion2>
|
|
531
|
+
* <word2>:<suggestion1>
|
|
532
|
+
* ```
|
|
533
|
+
*
|
|
534
|
+
* If `startingWith` is provided, only words that start with the prefix are returned.
|
|
535
|
+
*
|
|
536
|
+
* @param startingWith - optional prefix to filter the words returned.
|
|
537
|
+
*/
|
|
539
538
|
getAllPreferredSuggestions(startingWith?: string): Iterable<string>;
|
|
540
539
|
/**
|
|
541
|
-
|
|
542
|
-
|
|
540
|
+
* Checks to see if the trie contains preferred suggestions for any words.
|
|
541
|
+
*/
|
|
543
542
|
readonly hasPreferredSuggestions: boolean;
|
|
544
543
|
/**
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
544
|
+
* Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
|
|
545
|
+
* @param text - the text to search for
|
|
546
|
+
* @param options - Controls the generated suggestions:
|
|
547
|
+
* - ignoreCase - Ignore Case and Accents
|
|
548
|
+
* - numSuggestions - the maximum number of suggestions to return.
|
|
549
|
+
* - compoundMethod - Use to control splitting words.
|
|
550
|
+
* - changeLimit - the maximum number of changes allowed to text. This is an approximate value, since some changes cost less than others.
|
|
551
|
+
* the lower the value, the faster results are returned. Values less than 4 are best.
|
|
552
|
+
*/
|
|
554
553
|
suggest(text: string, options: SuggestionOptions): string[];
|
|
555
554
|
/**
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
555
|
+
* Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
|
|
556
|
+
* The results include the word and adjusted edit cost. This is useful for merging results from multiple tries.
|
|
557
|
+
*/
|
|
559
558
|
suggestWithCost(text: string, options: SuggestionOptions): SuggestionResult[];
|
|
560
559
|
/**
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
560
|
+
* genSuggestions will generate suggestions and send them to `collector`. `collector` is responsible for returning the max acceptable cost.
|
|
561
|
+
* Costs are measured in weighted changes. A cost of 100 is the same as 1 edit. Some edits are considered cheaper.
|
|
562
|
+
* Returning a MaxCost < 0 will effectively cause the search for suggestions to stop.
|
|
563
|
+
*/
|
|
565
564
|
genSuggestions(collector: SuggestionCollector, compoundMethod?: CompoundWordsMethod): void;
|
|
566
565
|
/**
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
566
|
+
* Returns an iterator that can be used to get all words in the trie. For some dictionaries, this can result in millions of words.
|
|
567
|
+
* @param prefix - optional prefix to filter the words returned. The words will be prefixed with this value.
|
|
568
|
+
*/
|
|
570
569
|
words(prefix?: string): Iterable<string>;
|
|
571
570
|
/**
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
571
|
+
* Allows iteration over the entire tree.
|
|
572
|
+
* On the returned Iterator, calling .next(goDeeper: boolean), allows for controlling the depth.
|
|
573
|
+
*/
|
|
575
574
|
iterate(): WalkerIterator$1;
|
|
576
575
|
readonly weightMap: WeightMap | undefined;
|
|
577
576
|
readonly hasForbiddenWords: boolean;
|
|
@@ -583,8 +582,8 @@ interface FindWordOptions {
|
|
|
583
582
|
useLegacyWordCompounds?: boolean | number;
|
|
584
583
|
checkForbidden?: boolean;
|
|
585
584
|
/**
|
|
586
|
-
|
|
587
|
-
|
|
585
|
+
* Separate compound words with the given string.
|
|
586
|
+
*/
|
|
588
587
|
compoundSeparator?: string;
|
|
589
588
|
}
|
|
590
589
|
type FindWordOptionsRO = Readonly<FindWordOptions>;
|
|
@@ -594,9 +593,9 @@ declare function buildITrieFromWords(words: Iterable<string>, info?: PartialTrie
|
|
|
594
593
|
//#endregion
|
|
595
594
|
//#region src/lib/consolidate.d.ts
|
|
596
595
|
/**
|
|
597
|
-
* Consolidate to DAWG
|
|
598
|
-
* @param root the root of the Trie tree
|
|
599
|
-
*/
|
|
596
|
+
* Consolidate to DAWG
|
|
597
|
+
* @param root the root of the Trie tree
|
|
598
|
+
*/
|
|
600
599
|
declare function consolidate(root: TrieRoot): TrieRoot;
|
|
601
600
|
//#endregion
|
|
602
601
|
//#region src/lib/constants.d.ts
|
|
@@ -617,11 +616,11 @@ interface FindResult {
|
|
|
617
616
|
}
|
|
618
617
|
interface FindFullResult extends FindResult {
|
|
619
618
|
/**
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
619
|
+
* Is the word explicitly forbidden.
|
|
620
|
+
* - `true` - word is in the forbidden list.
|
|
621
|
+
* - `false` - word is not in the forbidden list.
|
|
622
|
+
* - `undefined` - unknown - was not checked.
|
|
623
|
+
* */
|
|
625
624
|
forbidden: boolean | undefined;
|
|
626
625
|
}
|
|
627
626
|
//#endregion
|
|
@@ -637,75 +636,75 @@ declare class Trie {
|
|
|
637
636
|
private count;
|
|
638
637
|
constructor(root: TrieRoot, count?: number);
|
|
639
638
|
/**
|
|
640
|
-
|
|
641
|
-
|
|
639
|
+
* Number of words in the Trie
|
|
640
|
+
*/
|
|
642
641
|
size(): number;
|
|
643
642
|
isSizeKnown(): boolean;
|
|
644
643
|
get options(): Readonly<TrieInfo>;
|
|
645
644
|
/**
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
645
|
+
* @param text - text to find in the Trie
|
|
646
|
+
* @param minCompoundLength - deprecated - allows words to be glued together
|
|
647
|
+
*/
|
|
649
648
|
find(text: string, minCompoundLength?: boolean | number): TrieNode | undefined;
|
|
650
649
|
/**
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
650
|
+
* A case sensitive search for the word.
|
|
651
|
+
* @param word - the word to search for.
|
|
652
|
+
* @returns true if the word is found and not forbidden.
|
|
653
|
+
*/
|
|
655
654
|
has(word: string): boolean;
|
|
656
655
|
/**
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
656
|
+
* A case insensitive search for the word.
|
|
657
|
+
* @param word - the word to search for.
|
|
658
|
+
* @param minLegacyCompoundLength - minimum length of legacy compounds to consider.
|
|
659
|
+
* @returns true if the word is found and not forbidden.
|
|
660
|
+
* @deprecated use hasWord or findWord instead. Support for this method signature may be removed in the future.
|
|
661
|
+
*/
|
|
663
662
|
has(word: string, minLegacyCompoundLength: boolean | number): boolean;
|
|
664
663
|
/**
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
664
|
+
* Determine if a word is in the dictionary.
|
|
665
|
+
* @param word - the exact word to search for - must be normalized.
|
|
666
|
+
* @param caseSensitive - false means also searching a dictionary where the words were normalized to lower case and accents removed.
|
|
667
|
+
* @returns true if the word was found and is not forbidden.
|
|
668
|
+
*/
|
|
670
669
|
hasWord(word: string, caseSensitive: boolean): boolean;
|
|
671
670
|
findWord(word: string, options?: FindWordOptionsRO): FindFullResult;
|
|
672
671
|
/**
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
672
|
+
* Determine if a word is in the forbidden word list.
|
|
673
|
+
* @param word the word to lookup.
|
|
674
|
+
*/
|
|
676
675
|
isForbiddenWord(word: string): boolean;
|
|
677
676
|
/**
|
|
678
|
-
|
|
679
|
-
|
|
677
|
+
* Provides an ordered sequence of words with the prefix of text.
|
|
678
|
+
*/
|
|
680
679
|
completeWord(text: string): Iterable<string>;
|
|
681
680
|
/**
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
681
|
+
* Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
|
|
682
|
+
* @param text - the text to search for
|
|
683
|
+
* @param maxNumSuggestions - the maximum number of suggestions to return.
|
|
684
|
+
* @param compoundMethod - Use to control splitting words.
|
|
685
|
+
* @param numChanges - the maximum number of changes allowed to text. This is an approximate value, since some changes cost less than others.
|
|
686
|
+
* the lower the value, the faster results are returned. Values less than 4 are best.
|
|
687
|
+
*/
|
|
689
688
|
suggest(text: string, options: SuggestionOptionsRO): string[];
|
|
690
689
|
/**
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
690
|
+
* Suggest spellings for `text`. The results are sorted by edit distance with changes near the beginning of a word having a greater impact.
|
|
691
|
+
* The results include the word and adjusted edit cost. This is useful for merging results from multiple tries.
|
|
692
|
+
*/
|
|
694
693
|
suggestWithCost(text: string, options: SuggestionOptionsRO): SuggestionResult[];
|
|
695
694
|
/**
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
695
|
+
* genSuggestions will generate suggestions and send them to `collector`. `collector` is responsible for returning the max acceptable cost.
|
|
696
|
+
* Costs are measured in weighted changes. A cost of 100 is the same as 1 edit. Some edits are considered cheaper.
|
|
697
|
+
* Returning a MaxCost < 0 will effectively cause the search for suggestions to stop.
|
|
698
|
+
*/
|
|
700
699
|
genSuggestions(collector: SuggestionCollector, compoundMethod?: CompoundWordsMethod): void;
|
|
701
700
|
/**
|
|
702
|
-
|
|
703
|
-
|
|
701
|
+
* Returns an iterator that can be used to get all words in the trie. For some dictionaries, this can result in millions of words.
|
|
702
|
+
*/
|
|
704
703
|
words(prefix?: string): Iterable<string>;
|
|
705
704
|
/**
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
705
|
+
* Allows iteration over the entire tree.
|
|
706
|
+
* On the returned Iterator, calling .next(goDeeper: boolean), allows for controlling the depth.
|
|
707
|
+
*/
|
|
709
708
|
iterate(): WalkerIterator;
|
|
710
709
|
insert(word: string): this;
|
|
711
710
|
private calcIsLegacy;
|
|
@@ -722,97 +721,97 @@ interface ParseDictionaryOptions extends BuildOptions {
|
|
|
722
721
|
forbiddenPrefix: string;
|
|
723
722
|
caseInsensitivePrefix: string;
|
|
724
723
|
/**
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
724
|
+
* Start of a single-line comment.
|
|
725
|
+
* @default "#"
|
|
726
|
+
*/
|
|
728
727
|
commentCharacter: string;
|
|
729
728
|
/**
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
729
|
+
* If word starts with prefix, do not strip case or accents.
|
|
730
|
+
* @default false;
|
|
731
|
+
*/
|
|
733
732
|
keepExactPrefix: string;
|
|
734
733
|
/**
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
734
|
+
* Tell the parser to automatically create case / accent insensitive forms.
|
|
735
|
+
* @default true
|
|
736
|
+
*/
|
|
738
737
|
stripCaseAndAccents: boolean;
|
|
739
738
|
/**
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
739
|
+
* Tell the parser to keep non-case/accent version in both forms.
|
|
740
|
+
* @default false
|
|
741
|
+
*/
|
|
743
742
|
stripCaseAndAccentsKeepDuplicate: boolean;
|
|
744
743
|
/**
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
744
|
+
* Tell the parser to keep non-case/accent version in both forms.
|
|
745
|
+
* @default false
|
|
746
|
+
*/
|
|
748
747
|
stripCaseAndAccentsOnForbidden: boolean;
|
|
749
748
|
/**
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
749
|
+
* Tell the parser to split into words along spaces.
|
|
750
|
+
* @default false
|
|
751
|
+
*/
|
|
753
752
|
split: boolean;
|
|
754
753
|
/**
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
754
|
+
* When splitting tells the parser to output both the split and non-split versions of the line.
|
|
755
|
+
* @default false
|
|
756
|
+
*/
|
|
758
757
|
splitKeepBoth: boolean;
|
|
759
758
|
/**
|
|
760
|
-
|
|
761
|
-
|
|
759
|
+
* Specify the separator for splitting words.
|
|
760
|
+
*/
|
|
762
761
|
splitSeparator: RegExp | string;
|
|
763
762
|
/**
|
|
764
|
-
|
|
765
|
-
|
|
763
|
+
* Do not normalize the compound character.
|
|
764
|
+
*/
|
|
766
765
|
keepOptionalCompoundCharacter: boolean;
|
|
767
766
|
/**
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
767
|
+
* The character used to denote suggestion prefixes.
|
|
768
|
+
* An empty string or whitespace disables suggestion handling.
|
|
769
|
+
* @default ":"
|
|
770
|
+
*/
|
|
772
771
|
suggestionPrefix: string;
|
|
773
772
|
/**
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
773
|
+
* Disable suggestion handling. The suggestions prefixes will be treated as normal characters.
|
|
774
|
+
* This will override the `suggestionPrefix` setting.
|
|
775
|
+
* @default false
|
|
776
|
+
*/
|
|
778
777
|
disableSuggestionHandling: boolean;
|
|
779
778
|
/**
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
779
|
+
* If true, all words will be made forbidden words unless they are already marked as forbidden,
|
|
780
|
+
* in that case they will be made normal words.
|
|
781
|
+
* @default false
|
|
782
|
+
*/
|
|
784
783
|
makeWordsForbidden?: boolean;
|
|
785
784
|
/**
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
785
|
+
* Optimize the trie for size by merging duplicate sub-tries and using a String Table.
|
|
786
|
+
* @default false
|
|
787
|
+
*/
|
|
789
788
|
optimize?: boolean;
|
|
790
789
|
/**
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
790
|
+
* Use a string table to reduce memory usage.
|
|
791
|
+
* @default false
|
|
792
|
+
*/
|
|
794
793
|
useStringTable?: boolean;
|
|
795
794
|
/**
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
795
|
+
* The number of lines to batch before sorting.
|
|
796
|
+
* Set to 0 to disable sorting.
|
|
797
|
+
* @default 0
|
|
798
|
+
*/
|
|
800
799
|
sortBatchSize?: number;
|
|
801
800
|
}
|
|
802
801
|
/**
|
|
803
|
-
* Normalizes a dictionary words based upon prefix / suffixes.
|
|
804
|
-
* Case insensitive versions are also generated.
|
|
805
|
-
* @param options - defines prefixes used when parsing lines.
|
|
806
|
-
* @returns words that have been normalized.
|
|
807
|
-
*/
|
|
802
|
+
* Normalizes a dictionary words based upon prefix / suffixes.
|
|
803
|
+
* Case insensitive versions are also generated.
|
|
804
|
+
* @param options - defines prefixes used when parsing lines.
|
|
805
|
+
* @returns words that have been normalized.
|
|
806
|
+
*/
|
|
808
807
|
declare function createDictionaryLineParserMapper(options?: Partial<ParseDictionaryOptions>): OperatorSync<string>;
|
|
809
808
|
/**
|
|
810
|
-
* Normalizes a dictionary words based upon prefix / suffixes.
|
|
811
|
-
* Case insensitive versions are also generated.
|
|
812
|
-
* @param lines - one word per line
|
|
813
|
-
* @param _options - defines prefixes used when parsing lines.
|
|
814
|
-
* @returns words that have been normalized.
|
|
815
|
-
*/
|
|
809
|
+
* Normalizes a dictionary words based upon prefix / suffixes.
|
|
810
|
+
* Case insensitive versions are also generated.
|
|
811
|
+
* @param lines - one word per line
|
|
812
|
+
* @param _options - defines prefixes used when parsing lines.
|
|
813
|
+
* @returns words that have been normalized.
|
|
814
|
+
*/
|
|
816
815
|
declare function parseDictionaryLines(lines: Iterable<string> | string, options?: Partial<ParseDictionaryOptions>): Iterable<string>;
|
|
817
816
|
declare function parseDictionaryLegacy(text: string | string[], options?: Partial<ParseDictionaryOptions>): Trie;
|
|
818
817
|
declare function parseDictionary(text: string | Iterable<string>, options?: Partial<ParseDictionaryOptions>): ITrie;
|
|
@@ -821,12 +820,12 @@ declare function parseDictionary(text: string | Iterable<string>, options?: Part
|
|
|
821
820
|
declare function decodeTrie(raw: string | ArrayBufferView<ArrayBuffer> | Uint8Array<ArrayBuffer>): ITrie;
|
|
822
821
|
interface FileResource {
|
|
823
822
|
/**
|
|
824
|
-
|
|
825
|
-
|
|
823
|
+
* The URL of the File
|
|
824
|
+
*/
|
|
826
825
|
readonly url: URL;
|
|
827
826
|
/**
|
|
828
|
-
|
|
829
|
-
|
|
827
|
+
* The contents of the file
|
|
828
|
+
*/
|
|
830
829
|
readonly content: string | Uint8Array<ArrayBuffer>;
|
|
831
830
|
}
|
|
832
831
|
declare function decodeFile(file: FileResource, options?: Partial<ParseDictionaryOptions>): Promise<ITrie>;
|
|
@@ -839,30 +838,30 @@ declare class GTrieNode<K, V> {
|
|
|
839
838
|
constructor(value?: V, children?: Map<K, GTrieNode<K, V>>);
|
|
840
839
|
}
|
|
841
840
|
/**
|
|
842
|
-
* ### Generic Tries
|
|
843
|
-
*
|
|
844
|
-
* This is a Trie class that can contain any data. It is used in optimizing the dictionary and storing lookup data.
|
|
845
|
-
* The performance is "good enough" for most uses, but may need to be optimized for large data sets.
|
|
846
|
-
*
|
|
847
|
-
* K - Key type
|
|
848
|
-
* V - Value type
|
|
849
|
-
*/
|
|
841
|
+
* ### Generic Tries
|
|
842
|
+
*
|
|
843
|
+
* This is a Trie class that can contain any data. It is used in optimizing the dictionary and storing lookup data.
|
|
844
|
+
* The performance is "good enough" for most uses, but may need to be optimized for large data sets.
|
|
845
|
+
*
|
|
846
|
+
* K - Key type
|
|
847
|
+
* V - Value type
|
|
848
|
+
*/
|
|
850
849
|
declare class GTrie<K, V> {
|
|
851
850
|
root: GTrieNode<K, V>;
|
|
852
851
|
constructor();
|
|
853
852
|
/**
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
853
|
+
*
|
|
854
|
+
* @param keys - the path to the child node
|
|
855
|
+
* @param value - the value to set / insert
|
|
856
|
+
* @return the previous value if one existed
|
|
857
|
+
*/
|
|
859
858
|
insert(keys: Iterable<K>, value: V): V | undefined;
|
|
860
859
|
/**
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
860
|
+
* Insert nodes for the given keys into the trie.
|
|
861
|
+
* Existing nodes are reused.
|
|
862
|
+
* @param keys
|
|
863
|
+
* @returns the final node inserted or found
|
|
864
|
+
*/
|
|
866
865
|
insertNode(keys: Iterable<K>): GTrieNode<K, V>;
|
|
867
866
|
findNode(keys: Iterable<K>): GTrieNode<K, V> | undefined;
|
|
868
867
|
has(keys: Iterable<K>): boolean;
|
|
@@ -879,11 +878,11 @@ interface ExportOptions {
|
|
|
879
878
|
addLineBreaksToImproveDiffs?: boolean;
|
|
880
879
|
}
|
|
881
880
|
/**
|
|
882
|
-
* Serialize a TrieNode.
|
|
883
|
-
* Note: This is destructive. The node will no longer be usable.
|
|
884
|
-
* Even though it is possible to preserve the trie, dealing with very large tries can consume a lot of memory.
|
|
885
|
-
* Considering this is the last step before exporting, it was decided to let this be destructive.
|
|
886
|
-
*/
|
|
881
|
+
* Serialize a TrieNode.
|
|
882
|
+
* Note: This is destructive. The node will no longer be usable.
|
|
883
|
+
* Even though it is possible to preserve the trie, dealing with very large tries can consume a lot of memory.
|
|
884
|
+
* Considering this is the last step before exporting, it was decided to let this be destructive.
|
|
885
|
+
*/
|
|
887
886
|
declare function serializeTrie(root: TrieRoot, options?: ExportOptions | number): Iterable<string>;
|
|
888
887
|
declare function importTrie(input: Iterable<string> | IterableIterator<string> | string[] | string): TrieRoot;
|
|
889
888
|
//#endregion
|
|
@@ -899,17 +898,17 @@ declare function encodeTrieDataToBTrie(data: TrieData, buildOptions?: BuildOptio
|
|
|
899
898
|
//#endregion
|
|
900
899
|
//#region src/lib/TrieBuilder.d.ts
|
|
901
900
|
/**
|
|
902
|
-
* Builds an optimized Trie from a Iterable<string>. It attempts to reduce the size of the trie
|
|
903
|
-
* by finding common endings.
|
|
904
|
-
* @param words Iterable set of words -- no processing is done on the words, they are inserted as is.
|
|
905
|
-
* @param trieOptions options for the Trie
|
|
906
|
-
*/
|
|
901
|
+
* Builds an optimized Trie from a Iterable<string>. It attempts to reduce the size of the trie
|
|
902
|
+
* by finding common endings.
|
|
903
|
+
* @param words Iterable set of words -- no processing is done on the words, they are inserted as is.
|
|
904
|
+
* @param trieOptions options for the Trie
|
|
905
|
+
*/
|
|
907
906
|
declare function buildTrie(words: Iterable<string>, trieOptions?: PartialTrieOptions): Trie;
|
|
908
907
|
/**
|
|
909
|
-
* Builds a Trie from a Iterable<string>. NO attempt a reducing the size of the Trie is done.
|
|
910
|
-
* @param words Iterable set of words -- no processing is done on the words, they are inserted as is.
|
|
911
|
-
* @param trieOptions options for the Trie
|
|
912
|
-
*/
|
|
908
|
+
* Builds a Trie from a Iterable<string>. NO attempt a reducing the size of the Trie is done.
|
|
909
|
+
* @param words Iterable set of words -- no processing is done on the words, they are inserted as is.
|
|
910
|
+
* @param trieOptions options for the Trie
|
|
911
|
+
*/
|
|
913
912
|
declare function buildTrieFast(words: Iterable<string>, trieOptions?: PartialTrieOptions): Trie;
|
|
914
913
|
declare class TrieBuilder {
|
|
915
914
|
#private;
|
|
@@ -930,8 +929,8 @@ declare class TrieBuilder {
|
|
|
930
929
|
insertWord(word: string): void;
|
|
931
930
|
insert(words: Iterable<string>): void;
|
|
932
931
|
/**
|
|
933
|
-
|
|
934
|
-
|
|
932
|
+
* Resets the builder
|
|
933
|
+
*/
|
|
935
934
|
reset(): void;
|
|
936
935
|
build(consolidateSuffixes?: boolean): Trie;
|
|
937
936
|
}
|
|
@@ -940,17 +939,17 @@ declare class TrieBuilder {
|
|
|
940
939
|
declare function insert(word: string, root?: TrieNode): TrieNode;
|
|
941
940
|
declare function isWordTerminationNode(node: TrieNode): boolean;
|
|
942
941
|
/**
|
|
943
|
-
* Sorts the nodes in a trie in place.
|
|
944
|
-
*/
|
|
942
|
+
* Sorts the nodes in a trie in place.
|
|
943
|
+
*/
|
|
945
944
|
declare function orderTrie(node: TrieNode): void;
|
|
946
945
|
/**
|
|
947
|
-
* Generator an iterator that will walk the Trie parent then children in a depth first fashion that preserves sorted order.
|
|
948
|
-
*/
|
|
946
|
+
* Generator an iterator that will walk the Trie parent then children in a depth first fashion that preserves sorted order.
|
|
947
|
+
*/
|
|
949
948
|
declare function walk(node: TrieNode): Iterable<YieldResult>;
|
|
950
949
|
declare const iterateTrie: typeof walk;
|
|
951
950
|
/**
|
|
952
|
-
* Generate a Iterator that can walk a Trie and yield the words.
|
|
953
|
-
*/
|
|
951
|
+
* Generate a Iterator that can walk a Trie and yield the words.
|
|
952
|
+
*/
|
|
954
953
|
declare function iteratorTrieWords(node: TrieNode): Iterable<string>;
|
|
955
954
|
declare function createTrieRoot(options?: PartialTrieInfoRO): TrieRoot;
|
|
956
955
|
declare function createTrieRootFromList(words: Iterable<string>, options?: PartialTrieInfo): TrieRoot;
|
|
@@ -966,12 +965,12 @@ declare function isDefined<T>(t: T | undefined): t is T;
|
|
|
966
965
|
//#endregion
|
|
967
966
|
//#region src/lib/utils/mergeDefaults.d.ts
|
|
968
967
|
/**
|
|
969
|
-
* Creates a new object of type T based upon the field values from `value`.
|
|
970
|
-
* n[k] = value[k] ?? default[k] where k must be a field in default.
|
|
971
|
-
* Note: it will remove fields not in defaultValue!
|
|
972
|
-
* @param value
|
|
973
|
-
* @param defaultValue
|
|
974
|
-
*/
|
|
968
|
+
* Creates a new object of type T based upon the field values from `value`.
|
|
969
|
+
* n[k] = value[k] ?? default[k] where k must be a field in default.
|
|
970
|
+
* Note: it will remove fields not in defaultValue!
|
|
971
|
+
* @param value
|
|
972
|
+
* @param defaultValue
|
|
973
|
+
*/
|
|
975
974
|
declare function mergeDefaults<T extends object>(value: Readonly<PartialWithUndefined<T>> | undefined, defaultValue: T): T;
|
|
976
975
|
//#endregion
|
|
977
976
|
//#region src/lib/utils/mergeOptionalWithDefaults.d.ts
|
|
@@ -981,38 +980,38 @@ declare function mergeOptionalWithDefaults(options: ROPartialTrieOptions, ...mor
|
|
|
981
980
|
//#endregion
|
|
982
981
|
//#region src/lib/utils/normalizeWord.d.ts
|
|
983
982
|
/**
|
|
984
|
-
* Normalize word unicode.
|
|
985
|
-
* @param text - text to normalize
|
|
986
|
-
* @returns returns a word normalized to `NFC`
|
|
987
|
-
*/
|
|
983
|
+
* Normalize word unicode.
|
|
984
|
+
* @param text - text to normalize
|
|
985
|
+
* @returns returns a word normalized to `NFC`
|
|
986
|
+
*/
|
|
988
987
|
declare const normalizeWord: (text: string) => string;
|
|
989
988
|
/**
|
|
990
|
-
* converts text to lower case and removes any accents.
|
|
991
|
-
* @param text - text to convert
|
|
992
|
-
* @returns lowercase word without accents
|
|
993
|
-
* @deprecated true
|
|
994
|
-
*/
|
|
989
|
+
* converts text to lower case and removes any accents.
|
|
990
|
+
* @param text - text to convert
|
|
991
|
+
* @returns lowercase word without accents
|
|
992
|
+
* @deprecated true
|
|
993
|
+
*/
|
|
995
994
|
declare const normalizeWordToLowercase: (text: string) => string;
|
|
996
995
|
/**
|
|
997
|
-
* generate case insensitive forms of a word
|
|
998
|
-
* @param text - text to convert
|
|
999
|
-
* @returns the forms of the word.
|
|
1000
|
-
*/
|
|
996
|
+
* generate case insensitive forms of a word
|
|
997
|
+
* @param text - text to convert
|
|
998
|
+
* @returns the forms of the word.
|
|
999
|
+
*/
|
|
1001
1000
|
declare const normalizeWordForCaseInsensitive: (text: string) => string[];
|
|
1002
1001
|
//#endregion
|
|
1003
1002
|
//#region src/lib/utils/text.d.ts
|
|
1004
1003
|
/**
|
|
1005
|
-
* Expand a line into a set of characters.
|
|
1006
|
-
*
|
|
1007
|
-
* Example:
|
|
1008
|
-
* - `a-c` -> `<a,b,c>`
|
|
1009
|
-
* - `ac-` -> `<a,c,->`
|
|
1010
|
-
* - `-abz` -> `<-,a,b,z>`
|
|
1011
|
-
* - `\u0300-\u0308` -> `<accents>`
|
|
1012
|
-
*
|
|
1013
|
-
* @param line - set of characters
|
|
1014
|
-
* @param rangeChar - the character to indicate ranges, set to empty to not have ranges.
|
|
1015
|
-
*/
|
|
1004
|
+
* Expand a line into a set of characters.
|
|
1005
|
+
*
|
|
1006
|
+
* Example:
|
|
1007
|
+
* - `a-c` -> `<a,b,c>`
|
|
1008
|
+
* - `ac-` -> `<a,c,->`
|
|
1009
|
+
* - `-abz` -> `<-,a,b,z>`
|
|
1010
|
+
* - `\u0300-\u0308` -> `<accents>`
|
|
1011
|
+
*
|
|
1012
|
+
* @param line - set of characters
|
|
1013
|
+
* @param rangeChar - the character to indicate ranges, set to empty to not have ranges.
|
|
1014
|
+
*/
|
|
1016
1015
|
declare function expandCharacterSet(line: string, rangeChar?: string): Set<string>;
|
|
1017
1016
|
//#endregion
|
|
1018
1017
|
export { CASE_INSENSITIVE_PREFIX, COMPOUND_FIX, type ChildMap, CompoundWordsMethod, type ExportOptions, FLAG_WORD, FORBID_PREFIX, type FindFullResult, type FindWordOptions, GTrie, GTrieNode, type HintedWalkerIterator, type Hinting, type ITrie, JOIN_SEPARATOR, type MaxCost, OPTIONAL_COMPOUND_FIX, type PartialTrieOptions, type SuggestionCollector, type SuggestionCostMapDef, type SuggestionResult, Trie, TrieBuilder, type TrieNode, type TrieOptions, type TrieOptionsRO, type TrieRoot, WORD_SEPARATOR, type WalkerIterator, type WeightMap, type YieldResult, buildITrieFromWords, buildTrie, buildTrieFast, consolidate, convertToBTrie, countNodes, countWords, createDictionaryLineParserMapper as createDictionaryLineParser, createTrieRoot, createTrieRootFromList, createWeightedMap, decodeFile, decodeTrie, defaultTrieInfo, defaultTrieInfo as defaultTrieOptions, editDistance, editDistanceWeighted, encodeITrieToBTrie, encodeTrieDataToBTrie, 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 };
|