cspell-dictionary 6.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/SpellingDictionary/Dictionaries.d.ts +9 -0
- package/dist/SpellingDictionary/Dictionaries.js +61 -0
- package/dist/SpellingDictionary/SpellingDictionary.d.ts +93 -0
- package/dist/SpellingDictionary/SpellingDictionary.js +6 -0
- package/dist/SpellingDictionary/SpellingDictionaryCollection.d.ts +34 -0
- package/dist/SpellingDictionary/SpellingDictionaryCollection.js +111 -0
- package/dist/SpellingDictionary/SpellingDictionaryError.d.ts +10 -0
- package/dist/SpellingDictionary/SpellingDictionaryError.js +18 -0
- package/dist/SpellingDictionary/SpellingDictionaryFromTrie.d.ts +36 -0
- package/dist/SpellingDictionary/SpellingDictionaryFromTrie.js +148 -0
- package/dist/SpellingDictionary/SpellingDictionaryMethods.d.ts +29 -0
- package/dist/SpellingDictionary/SpellingDictionaryMethods.js +114 -0
- package/dist/SpellingDictionary/charset.d.ts +3 -0
- package/dist/SpellingDictionary/charset.js +16 -0
- package/dist/SpellingDictionary/createSpellingDictionary.d.ts +17 -0
- package/dist/SpellingDictionary/createSpellingDictionary.js +91 -0
- package/dist/SpellingDictionary/index.d.ts +4 -0
- package/dist/SpellingDictionary/index.js +9 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -0
- package/dist/util/Comparable.d.ts +20 -0
- package/dist/util/Comparable.js +55 -0
- package/dist/util/FreqCounter.d.ts +16 -0
- package/dist/util/FreqCounter.js +52 -0
- package/dist/util/IterableLike.d.ts +4 -0
- package/dist/util/IterableLike.js +3 -0
- package/dist/util/Memorizer.d.ts +65 -0
- package/dist/util/Memorizer.js +138 -0
- package/dist/util/MinHeapQueue.d.ts +23 -0
- package/dist/util/MinHeapQueue.js +97 -0
- package/dist/util/PairingHeap.d.ts +32 -0
- package/dist/util/PairingHeap.js +90 -0
- package/dist/util/TextMap.d.ts +15 -0
- package/dist/util/TextMap.js +62 -0
- package/dist/util/TextRange.d.ts +28 -0
- package/dist/util/TextRange.js +144 -0
- package/dist/util/clean.d.ts +7 -0
- package/dist/util/clean.js +18 -0
- package/dist/util/debugPerf.d.ts +9 -0
- package/dist/util/debugPerf.js +22 -0
- package/dist/util/errors.d.ts +17 -0
- package/dist/util/errors.js +52 -0
- package/dist/util/fileReader.d.ts +4 -0
- package/dist/util/fileReader.js +21 -0
- package/dist/util/iterableIteratorLib.d.ts +4 -0
- package/dist/util/iterableIteratorLib.js +14 -0
- package/dist/util/logger.d.ts +33 -0
- package/dist/util/logger.js +46 -0
- package/dist/util/memorizerWeak.d.ts +6 -0
- package/dist/util/memorizerWeak.js +42 -0
- package/dist/util/regexHelper.d.ts +7 -0
- package/dist/util/regexHelper.js +13 -0
- package/dist/util/repMap.d.ts +4 -0
- package/dist/util/repMap.js +38 -0
- package/dist/util/resolveFile.d.ts +13 -0
- package/dist/util/resolveFile.js +127 -0
- package/dist/util/search.d.ts +6 -0
- package/dist/util/search.js +23 -0
- package/dist/util/simpleCache.d.ts +46 -0
- package/dist/util/simpleCache.js +143 -0
- package/dist/util/text.d.ts +9 -0
- package/dist/util/text.js +55 -0
- package/dist/util/textRegex.d.ts +1 -0
- package/dist/util/textRegex.js +2 -0
- package/dist/util/timer.d.ts +26 -0
- package/dist/util/timer.js +58 -0
- package/dist/util/types.d.ts +7 -0
- package/dist/util/types.js +3 -0
- package/dist/util/util.d.ts +2 -0
- package/dist/util/util.js +8 -0
- package/dist/util/util.test copy.d.ts +2 -0
- package/dist/util/util.test copy.js +17 -0
- package/dist/util/wordSplitter.d.ts +46 -0
- package/dist/util/wordSplitter.js +326 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Jason Dent
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CSpellSettingsInternal, DictionaryDefinitionInternal } from '../Models/CSpellSettingsInternalDef';
|
|
2
|
+
import { SpellingDictionary } from './SpellingDictionary';
|
|
3
|
+
import { SpellingDictionaryCollection } from './SpellingDictionaryCollection';
|
|
4
|
+
export declare function loadDictionaryDefs(defsToLoad: DictionaryDefinitionInternal[]): Promise<SpellingDictionary>[];
|
|
5
|
+
export declare function loadDictionaryDefsSync(defsToLoad: DictionaryDefinitionInternal[]): SpellingDictionary[];
|
|
6
|
+
export declare function refreshDictionaryCache(maxAge?: number): Promise<void>;
|
|
7
|
+
export declare function getDictionaryInternal(settings: CSpellSettingsInternal): Promise<SpellingDictionaryCollection>;
|
|
8
|
+
export declare function getDictionaryInternalSync(settings: CSpellSettingsInternal): SpellingDictionaryCollection;
|
|
9
|
+
//# sourceMappingURL=Dictionaries.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDictionaryInternalSync = exports.getDictionaryInternal = exports.refreshDictionaryCache = exports.loadDictionaryDefsSync = exports.loadDictionaryDefs = void 0;
|
|
4
|
+
const DictionarySettings_1 = require("../Settings/DictionarySettings");
|
|
5
|
+
const util_1 = require("../util/util");
|
|
6
|
+
const createSpellingDictionary_1 = require("./createSpellingDictionary");
|
|
7
|
+
const DictionaryLoader_1 = require("./DictionaryLoader");
|
|
8
|
+
const SpellingDictionaryCollection_1 = require("./SpellingDictionaryCollection");
|
|
9
|
+
function loadDictionaryDefs(defsToLoad) {
|
|
10
|
+
return defsToLoad.map(DictionaryLoader_1.loadDictionary);
|
|
11
|
+
}
|
|
12
|
+
exports.loadDictionaryDefs = loadDictionaryDefs;
|
|
13
|
+
function loadDictionaryDefsSync(defsToLoad) {
|
|
14
|
+
return defsToLoad.map(DictionaryLoader_1.loadDictionarySync);
|
|
15
|
+
}
|
|
16
|
+
exports.loadDictionaryDefsSync = loadDictionaryDefsSync;
|
|
17
|
+
function refreshDictionaryCache(maxAge) {
|
|
18
|
+
return (0, DictionaryLoader_1.refreshCacheEntries)(maxAge);
|
|
19
|
+
}
|
|
20
|
+
exports.refreshDictionaryCache = refreshDictionaryCache;
|
|
21
|
+
const emptyWords = Object.freeze([]);
|
|
22
|
+
async function getDictionaryInternal(settings) {
|
|
23
|
+
const spellDictionaries = await Promise.all(loadDictionaryDefs((0, DictionarySettings_1.calcDictionaryDefsToLoad)(settings)));
|
|
24
|
+
return _getDictionaryInternal(settings, spellDictionaries);
|
|
25
|
+
}
|
|
26
|
+
exports.getDictionaryInternal = getDictionaryInternal;
|
|
27
|
+
function getDictionaryInternalSync(settings) {
|
|
28
|
+
const spellDictionaries = loadDictionaryDefsSync((0, DictionarySettings_1.calcDictionaryDefsToLoad)(settings));
|
|
29
|
+
return _getDictionaryInternal(settings, spellDictionaries);
|
|
30
|
+
}
|
|
31
|
+
exports.getDictionaryInternalSync = getDictionaryInternalSync;
|
|
32
|
+
function _getDictionaryInternal(settings, spellDictionaries) {
|
|
33
|
+
const { words = emptyWords, userWords = emptyWords, flagWords = emptyWords, ignoreWords = emptyWords } = settings;
|
|
34
|
+
const settingsWordsDictionary = (0, createSpellingDictionary_1.createSpellingDictionary)(words, '[words]', 'From Settings `words`', {
|
|
35
|
+
caseSensitive: true,
|
|
36
|
+
weightMap: undefined,
|
|
37
|
+
});
|
|
38
|
+
const settingsUserWordsDictionary = userWords.length
|
|
39
|
+
? (0, createSpellingDictionary_1.createSpellingDictionary)(userWords, '[userWords]', 'From Settings `userWords`', {
|
|
40
|
+
caseSensitive: true,
|
|
41
|
+
weightMap: undefined,
|
|
42
|
+
})
|
|
43
|
+
: undefined;
|
|
44
|
+
const ignoreWordsDictionary = (0, createSpellingDictionary_1.createSpellingDictionary)(ignoreWords, '[ignoreWords]', 'From Settings `ignoreWords`', {
|
|
45
|
+
caseSensitive: true,
|
|
46
|
+
noSuggest: true,
|
|
47
|
+
weightMap: undefined,
|
|
48
|
+
});
|
|
49
|
+
const flagWordsDictionary = (0, createSpellingDictionary_1.createForbiddenWordsDictionary)(flagWords, '[flagWords]', 'From Settings `flagWords`', {
|
|
50
|
+
weightMap: undefined,
|
|
51
|
+
});
|
|
52
|
+
const dictionaries = [
|
|
53
|
+
...spellDictionaries,
|
|
54
|
+
settingsWordsDictionary,
|
|
55
|
+
settingsUserWordsDictionary,
|
|
56
|
+
ignoreWordsDictionary,
|
|
57
|
+
flagWordsDictionary,
|
|
58
|
+
].filter(util_1.isDefined);
|
|
59
|
+
return (0, SpellingDictionaryCollection_1.createCollection)(dictionaries, 'dictionary collection');
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=Dictionaries.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ReplaceMap, DictionaryInformation } from '@cspell/cspell-types';
|
|
2
|
+
import type { CompoundWordsMethod, SuggestionCollector, SuggestionResult, WeightMap } from 'cspell-trie-lib';
|
|
3
|
+
export { CompoundWordsMethod, SuggestionCollector, SuggestionResult } from 'cspell-trie-lib';
|
|
4
|
+
export interface SearchOptions {
|
|
5
|
+
useCompounds?: boolean | number | undefined;
|
|
6
|
+
ignoreCase?: boolean | undefined;
|
|
7
|
+
}
|
|
8
|
+
export interface SuggestOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Compounding Mode.
|
|
11
|
+
* `NONE` is the best option.
|
|
12
|
+
*/
|
|
13
|
+
compoundMethod?: CompoundWordsMethod;
|
|
14
|
+
/**
|
|
15
|
+
* The limit on the number of suggestions to generate. If `allowTies` is true, it is possible
|
|
16
|
+
* for more suggestions to be generated.
|
|
17
|
+
*/
|
|
18
|
+
numSuggestions?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Max number of changes / edits to the word to get to a suggestion matching suggestion.
|
|
21
|
+
*/
|
|
22
|
+
numChanges?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Allow for case-ingestive checking.
|
|
25
|
+
*/
|
|
26
|
+
ignoreCase?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* If multiple suggestions have the same edit / change "cost", then included them even if
|
|
29
|
+
* it causes more than `numSuggestions` to be returned.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
includeTies?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Maximum amount of time to allow for generating suggestions.
|
|
35
|
+
*/
|
|
36
|
+
timeout?: number;
|
|
37
|
+
}
|
|
38
|
+
export declare type FindOptions = SearchOptions;
|
|
39
|
+
export interface FindResult {
|
|
40
|
+
/** the text found, otherwise `false` */
|
|
41
|
+
found: string | false;
|
|
42
|
+
/** `true` if it is considered a forbidden word. */
|
|
43
|
+
forbidden: boolean;
|
|
44
|
+
/** `true` if it is a no-suggest word. */
|
|
45
|
+
noSuggest: boolean;
|
|
46
|
+
}
|
|
47
|
+
export declare type HasOptions = SearchOptions;
|
|
48
|
+
export interface SpellingDictionaryOptions {
|
|
49
|
+
repMap?: ReplaceMap;
|
|
50
|
+
useCompounds?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* The dictionary is case aware.
|
|
53
|
+
*/
|
|
54
|
+
caseSensitive?: boolean;
|
|
55
|
+
noSuggest?: boolean;
|
|
56
|
+
weightMap?: WeightMap | undefined;
|
|
57
|
+
dictionaryInformation?: DictionaryInformation;
|
|
58
|
+
/**
|
|
59
|
+
* Strip Case and Accents to allow for case insensitive searches and
|
|
60
|
+
* words without accents.
|
|
61
|
+
*
|
|
62
|
+
* Note: this setting only applies to word lists. It has no-impact on trie
|
|
63
|
+
* dictionaries.
|
|
64
|
+
*
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
supportNonStrictSearches?: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface DictionaryInfo {
|
|
70
|
+
/** The name of the dictionary */
|
|
71
|
+
readonly name: string;
|
|
72
|
+
/** The source, filename or URI */
|
|
73
|
+
readonly source: string;
|
|
74
|
+
/** Options */
|
|
75
|
+
readonly options: SpellingDictionaryOptions;
|
|
76
|
+
}
|
|
77
|
+
export interface SpellingDictionary extends DictionaryInfo {
|
|
78
|
+
readonly type: string;
|
|
79
|
+
readonly containsNoSuggestWords: boolean;
|
|
80
|
+
has(word: string, options?: HasOptions): boolean;
|
|
81
|
+
/** A more detailed search for a word, might take longer than `has` */
|
|
82
|
+
find(word: string, options?: SearchOptions): FindResult | undefined;
|
|
83
|
+
isForbidden(word: string): boolean;
|
|
84
|
+
isNoSuggestWord(word: string, options: HasOptions): boolean;
|
|
85
|
+
suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[];
|
|
86
|
+
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[];
|
|
87
|
+
genSuggestions(collector: SuggestionCollector, suggestOptions: SuggestOptions): void;
|
|
88
|
+
mapWord(word: string): string;
|
|
89
|
+
readonly size: number;
|
|
90
|
+
readonly isDictionaryCaseSensitive: boolean;
|
|
91
|
+
getErrors?(): Error[];
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=SpellingDictionary.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CompoundWordsMethod = void 0;
|
|
4
|
+
var cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
|
+
Object.defineProperty(exports, "CompoundWordsMethod", { enumerable: true, get: function () { return cspell_trie_lib_1.CompoundWordsMethod; } });
|
|
6
|
+
//# sourceMappingURL=SpellingDictionary.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CompoundWordsMethod, FindResult, HasOptions, SearchOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestionCollector, SuggestionResult, SuggestOptions } from './SpellingDictionary';
|
|
2
|
+
declare function identityString(w: string): string;
|
|
3
|
+
export declare class SpellingDictionaryCollection implements SpellingDictionary {
|
|
4
|
+
readonly dictionaries: SpellingDictionary[];
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly options: SpellingDictionaryOptions;
|
|
7
|
+
readonly mapWord: typeof identityString;
|
|
8
|
+
readonly type = "SpellingDictionaryCollection";
|
|
9
|
+
readonly source: string;
|
|
10
|
+
readonly isDictionaryCaseSensitive: boolean;
|
|
11
|
+
readonly containsNoSuggestWords: boolean;
|
|
12
|
+
constructor(dictionaries: SpellingDictionary[], name: string);
|
|
13
|
+
has(word: string, hasOptions?: HasOptions): boolean;
|
|
14
|
+
find(word: string, hasOptions?: HasOptions): FindResult | undefined;
|
|
15
|
+
isNoSuggestWord(word: string, options?: HasOptions): boolean;
|
|
16
|
+
isForbidden(word: string): boolean;
|
|
17
|
+
suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[];
|
|
18
|
+
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[];
|
|
19
|
+
_suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[];
|
|
20
|
+
get size(): number;
|
|
21
|
+
genSuggestions(collector: SuggestionCollector, suggestOptions: SuggestOptions): void;
|
|
22
|
+
getErrors(): Error[];
|
|
23
|
+
private _isForbiddenInDict;
|
|
24
|
+
private _isNoSuggestWord;
|
|
25
|
+
}
|
|
26
|
+
export declare function createCollection(dictionaries: SpellingDictionary[], name: string): SpellingDictionaryCollection;
|
|
27
|
+
declare function isWordInAnyDictionary(dicts: SpellingDictionary[], word: string, options: SearchOptions): SpellingDictionary | undefined;
|
|
28
|
+
declare function isWordForbiddenInAnyDictionary(dicts: SpellingDictionary[], word: string): SpellingDictionary | undefined;
|
|
29
|
+
export declare const __testing__: {
|
|
30
|
+
isWordInAnyDictionary: typeof isWordInAnyDictionary;
|
|
31
|
+
isWordForbiddenInAnyDictionary: typeof isWordForbiddenInAnyDictionary;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=SpellingDictionaryCollection.d.ts.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__testing__ = exports.createCollection = exports.SpellingDictionaryCollection = void 0;
|
|
4
|
+
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
|
+
const gensequence_1 = require("gensequence");
|
|
6
|
+
const util_1 = require("../util/util");
|
|
7
|
+
const clean_1 = require("../util/clean");
|
|
8
|
+
const SpellingDictionary_1 = require("./SpellingDictionary");
|
|
9
|
+
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
10
|
+
function identityString(w) {
|
|
11
|
+
return w;
|
|
12
|
+
}
|
|
13
|
+
class SpellingDictionaryCollection {
|
|
14
|
+
constructor(dictionaries, name) {
|
|
15
|
+
this.dictionaries = dictionaries;
|
|
16
|
+
this.name = name;
|
|
17
|
+
this.options = { weightMap: undefined };
|
|
18
|
+
this.mapWord = identityString;
|
|
19
|
+
this.type = 'SpellingDictionaryCollection';
|
|
20
|
+
this._isForbiddenInDict = (word) => isWordForbiddenInAnyDictionary(this.dictionaries, word);
|
|
21
|
+
this._isNoSuggestWord = (word, options) => {
|
|
22
|
+
if (!this.containsNoSuggestWords)
|
|
23
|
+
return false;
|
|
24
|
+
return !!isNoSuggestWordInAnyDictionary(this.dictionaries, word, options || {});
|
|
25
|
+
};
|
|
26
|
+
this.dictionaries = this.dictionaries.sort((a, b) => b.size - a.size);
|
|
27
|
+
this.source = dictionaries.map((d) => d.name).join(', ');
|
|
28
|
+
this.isDictionaryCaseSensitive = this.dictionaries.reduce((a, b) => a || b.isDictionaryCaseSensitive, false);
|
|
29
|
+
this.containsNoSuggestWords = this.dictionaries.reduce((a, b) => a || b.containsNoSuggestWords, false);
|
|
30
|
+
}
|
|
31
|
+
has(word, hasOptions) {
|
|
32
|
+
const options = (0, SpellingDictionaryMethods_1.hasOptionToSearchOption)(hasOptions);
|
|
33
|
+
return !!isWordInAnyDictionary(this.dictionaries, word, options) && !this.isForbidden(word);
|
|
34
|
+
}
|
|
35
|
+
find(word, hasOptions) {
|
|
36
|
+
const options = (0, SpellingDictionaryMethods_1.hasOptionToSearchOption)(hasOptions);
|
|
37
|
+
const { found = false, forbidden = false, noSuggest = false, } = findInAnyDictionary(this.dictionaries, word, options) || {};
|
|
38
|
+
return { found, forbidden, noSuggest };
|
|
39
|
+
}
|
|
40
|
+
isNoSuggestWord(word, options) {
|
|
41
|
+
return this._isNoSuggestWord(word, options);
|
|
42
|
+
}
|
|
43
|
+
isForbidden(word) {
|
|
44
|
+
return !!this._isForbiddenInDict(word) && !this.isNoSuggestWord(word);
|
|
45
|
+
}
|
|
46
|
+
suggest(...args) {
|
|
47
|
+
const [word] = args;
|
|
48
|
+
const suggestOptions = (0, SpellingDictionaryMethods_1.suggestArgsToSuggestOptions)(args);
|
|
49
|
+
return this._suggest(word, suggestOptions);
|
|
50
|
+
}
|
|
51
|
+
_suggest(word, suggestOptions) {
|
|
52
|
+
const { numSuggestions = SpellingDictionaryMethods_1.defaultNumSuggestions, numChanges, ignoreCase, includeTies, timeout } = suggestOptions;
|
|
53
|
+
const prefixNoCase = cspell_trie_lib_1.CASE_INSENSITIVE_PREFIX;
|
|
54
|
+
const filter = (word, _cost) => {
|
|
55
|
+
return ((ignoreCase || word[0] !== prefixNoCase) &&
|
|
56
|
+
!this.isForbidden(word) &&
|
|
57
|
+
!this.isNoSuggestWord(word, suggestOptions));
|
|
58
|
+
};
|
|
59
|
+
const collector = (0, SpellingDictionaryMethods_1.suggestionCollector)(word, (0, clean_1.clean)({
|
|
60
|
+
numSuggestions,
|
|
61
|
+
filter,
|
|
62
|
+
changeLimit: numChanges,
|
|
63
|
+
includeTies,
|
|
64
|
+
ignoreCase,
|
|
65
|
+
timeout,
|
|
66
|
+
}));
|
|
67
|
+
this.genSuggestions(collector, suggestOptions);
|
|
68
|
+
return collector.suggestions.map((r) => ({ ...r, word: r.word }));
|
|
69
|
+
}
|
|
70
|
+
get size() {
|
|
71
|
+
return this.dictionaries.reduce((a, b) => a + b.size, 0);
|
|
72
|
+
}
|
|
73
|
+
genSuggestions(collector, suggestOptions) {
|
|
74
|
+
const _suggestOptions = { ...suggestOptions };
|
|
75
|
+
const { compoundMethod = SpellingDictionary_1.CompoundWordsMethod.SEPARATE_WORDS } = suggestOptions;
|
|
76
|
+
_suggestOptions.compoundMethod = this.options.useCompounds ? SpellingDictionary_1.CompoundWordsMethod.JOIN_WORDS : compoundMethod;
|
|
77
|
+
this.dictionaries.forEach((dict) => dict.genSuggestions(collector, _suggestOptions));
|
|
78
|
+
}
|
|
79
|
+
getErrors() {
|
|
80
|
+
return this.dictionaries.reduce((errors, dict) => errors.concat(dict.getErrors?.() || []), []);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.SpellingDictionaryCollection = SpellingDictionaryCollection;
|
|
84
|
+
function createCollection(dictionaries, name) {
|
|
85
|
+
return new SpellingDictionaryCollection(dictionaries, name);
|
|
86
|
+
}
|
|
87
|
+
exports.createCollection = createCollection;
|
|
88
|
+
function isWordInAnyDictionary(dicts, word, options) {
|
|
89
|
+
return (0, gensequence_1.genSequence)(dicts).first((dict) => dict.has(word, options));
|
|
90
|
+
}
|
|
91
|
+
function findInAnyDictionary(dicts, word, options) {
|
|
92
|
+
const found = dicts.map((dict) => dict.find(word, options)).filter(util_1.isDefined);
|
|
93
|
+
if (!found.length)
|
|
94
|
+
return undefined;
|
|
95
|
+
return found.reduce((a, b) => ({
|
|
96
|
+
found: a.forbidden ? a.found : b.forbidden ? b.found : a.found || b.found,
|
|
97
|
+
forbidden: a.forbidden || b.forbidden,
|
|
98
|
+
noSuggest: a.noSuggest || b.noSuggest,
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
function isNoSuggestWordInAnyDictionary(dicts, word, options) {
|
|
102
|
+
return (0, gensequence_1.genSequence)(dicts).first((dict) => dict.isNoSuggestWord(word, options));
|
|
103
|
+
}
|
|
104
|
+
function isWordForbiddenInAnyDictionary(dicts, word) {
|
|
105
|
+
return (0, gensequence_1.genSequence)(dicts).first((dict) => dict.isForbidden(word));
|
|
106
|
+
}
|
|
107
|
+
exports.__testing__ = {
|
|
108
|
+
isWordInAnyDictionary,
|
|
109
|
+
isWordForbiddenInAnyDictionary,
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=SpellingDictionaryCollection.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LoadOptions } from './DictionaryLoader';
|
|
2
|
+
export declare class SpellingDictionaryLoadError extends Error {
|
|
3
|
+
readonly uri: string;
|
|
4
|
+
readonly options: LoadOptions;
|
|
5
|
+
readonly cause: Error;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
constructor(uri: string, options: LoadOptions, cause: Error, message: string);
|
|
8
|
+
}
|
|
9
|
+
export declare function isSpellingDictionaryLoadError(e: Error): e is SpellingDictionaryLoadError;
|
|
10
|
+
//# sourceMappingURL=SpellingDictionaryError.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSpellingDictionaryLoadError = exports.SpellingDictionaryLoadError = void 0;
|
|
4
|
+
class SpellingDictionaryLoadError extends Error {
|
|
5
|
+
constructor(uri, options, cause, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.uri = uri;
|
|
8
|
+
this.options = options;
|
|
9
|
+
this.cause = cause;
|
|
10
|
+
this.name = options.name;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.SpellingDictionaryLoadError = SpellingDictionaryLoadError;
|
|
14
|
+
function isSpellingDictionaryLoadError(e) {
|
|
15
|
+
return e instanceof SpellingDictionaryLoadError;
|
|
16
|
+
}
|
|
17
|
+
exports.isSpellingDictionaryLoadError = isSpellingDictionaryLoadError;
|
|
18
|
+
//# sourceMappingURL=SpellingDictionaryError.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SuggestionCollector, SuggestionResult } from 'cspell-trie-lib';
|
|
2
|
+
import { CompoundWordsMethod, Trie } from 'cspell-trie-lib';
|
|
3
|
+
import { FindResult, HasOptions, SpellingDictionary, SpellingDictionaryOptions, SuggestOptions } from './SpellingDictionary';
|
|
4
|
+
export declare class SpellingDictionaryFromTrie implements SpellingDictionary {
|
|
5
|
+
readonly trie: Trie;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly options: SpellingDictionaryOptions;
|
|
8
|
+
readonly source: string;
|
|
9
|
+
static readonly cachedWordsLimit = 50000;
|
|
10
|
+
private _size;
|
|
11
|
+
readonly knownWords: Set<string>;
|
|
12
|
+
readonly unknownWords: Set<string>;
|
|
13
|
+
readonly mapWord: (word: string) => string;
|
|
14
|
+
readonly type = "SpellingDictionaryFromTrie";
|
|
15
|
+
readonly isDictionaryCaseSensitive: boolean;
|
|
16
|
+
readonly containsNoSuggestWords: boolean;
|
|
17
|
+
readonly ignoreCharactersRegExp: RegExp | undefined;
|
|
18
|
+
private weightMap;
|
|
19
|
+
constructor(trie: Trie, name: string, options: SpellingDictionaryOptions, source?: string, size?: number);
|
|
20
|
+
get size(): number;
|
|
21
|
+
has(word: string, hasOptions?: HasOptions): boolean;
|
|
22
|
+
find(word: string, hasOptions?: HasOptions): FindResult | undefined;
|
|
23
|
+
private resolveOptions;
|
|
24
|
+
private _find;
|
|
25
|
+
private findAnyForm;
|
|
26
|
+
private _findAnyForm;
|
|
27
|
+
isNoSuggestWord(word: string, options?: HasOptions): boolean;
|
|
28
|
+
isForbidden(word: string): boolean;
|
|
29
|
+
suggest(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean): SuggestionResult[];
|
|
30
|
+
suggest(word: string, suggestOptions: SuggestOptions): SuggestionResult[];
|
|
31
|
+
private _suggest;
|
|
32
|
+
genSuggestions(collector: SuggestionCollector, suggestOptions: SuggestOptions): void;
|
|
33
|
+
getErrors(): Error[];
|
|
34
|
+
}
|
|
35
|
+
export declare function createSpellingDictionaryTrie(data: Iterable<string>, name: string, source: string, options: SpellingDictionaryOptions): SpellingDictionary;
|
|
36
|
+
//# sourceMappingURL=SpellingDictionaryFromTrie.d.ts.map
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSpellingDictionaryTrie = exports.SpellingDictionaryFromTrie = void 0;
|
|
4
|
+
const cspell_trie_lib_1 = require("cspell-trie-lib");
|
|
5
|
+
const repMap_1 = require("../util/repMap");
|
|
6
|
+
const clean_1 = require("../util/clean");
|
|
7
|
+
const charset_1 = require("./charset");
|
|
8
|
+
const SpellingDictionaryMethods_1 = require("./SpellingDictionaryMethods");
|
|
9
|
+
class SpellingDictionaryFromTrie {
|
|
10
|
+
constructor(trie, name, options, source = 'from trie', size) {
|
|
11
|
+
this.trie = trie;
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.options = options;
|
|
14
|
+
this.source = source;
|
|
15
|
+
this._size = 0;
|
|
16
|
+
this.knownWords = new Set();
|
|
17
|
+
this.unknownWords = new Set();
|
|
18
|
+
this.type = 'SpellingDictionaryFromTrie';
|
|
19
|
+
this._find = (word, useCompounds, ignoreCase) => this.findAnyForm(word, useCompounds, ignoreCase);
|
|
20
|
+
this.mapWord = (0, repMap_1.createMapper)(options.repMap || []);
|
|
21
|
+
this.isDictionaryCaseSensitive = options.caseSensitive ?? !trie.isLegacy;
|
|
22
|
+
this.containsNoSuggestWords = options.noSuggest || false;
|
|
23
|
+
this._size = size || 0;
|
|
24
|
+
this.weightMap = options.weightMap || (0, SpellingDictionaryMethods_1.createWeightMapFromDictionaryInformation)(options.dictionaryInformation);
|
|
25
|
+
this.ignoreCharactersRegExp = (0, charset_1.charsetToRegExp)(this.options.dictionaryInformation?.ignore);
|
|
26
|
+
}
|
|
27
|
+
get size() {
|
|
28
|
+
if (!this._size) {
|
|
29
|
+
// walk the trie and get the approximate size.
|
|
30
|
+
const i = this.trie.iterate();
|
|
31
|
+
let deeper = true;
|
|
32
|
+
let size = 0;
|
|
33
|
+
for (let r = i.next(); !r.done; r = i.next(deeper)) {
|
|
34
|
+
// count all nodes even though they are not words.
|
|
35
|
+
// because we are not going to all the leaves, this should give a good enough approximation.
|
|
36
|
+
size += 1;
|
|
37
|
+
deeper = r.value.text.length < 5;
|
|
38
|
+
}
|
|
39
|
+
this._size = size;
|
|
40
|
+
}
|
|
41
|
+
return this._size;
|
|
42
|
+
}
|
|
43
|
+
has(word, hasOptions) {
|
|
44
|
+
const { useCompounds, ignoreCase } = this.resolveOptions(hasOptions);
|
|
45
|
+
const r = this._find(word, useCompounds, ignoreCase);
|
|
46
|
+
return !!r && !r.forbidden && !!r.found;
|
|
47
|
+
}
|
|
48
|
+
find(word, hasOptions) {
|
|
49
|
+
const { useCompounds, ignoreCase } = this.resolveOptions(hasOptions);
|
|
50
|
+
const r = this._find(word, useCompounds, ignoreCase);
|
|
51
|
+
const { forbidden = this.isForbidden(word) } = r || {};
|
|
52
|
+
if (!r && !forbidden)
|
|
53
|
+
return undefined;
|
|
54
|
+
const { found = forbidden ? word : false } = r || {};
|
|
55
|
+
const noSuggest = found !== false && this.containsNoSuggestWords;
|
|
56
|
+
return { found, forbidden, noSuggest };
|
|
57
|
+
}
|
|
58
|
+
resolveOptions(hasOptions) {
|
|
59
|
+
const { useCompounds = this.options.useCompounds, ignoreCase = true } = (0, SpellingDictionaryMethods_1.hasOptionToSearchOption)(hasOptions);
|
|
60
|
+
return { useCompounds, ignoreCase };
|
|
61
|
+
}
|
|
62
|
+
findAnyForm(word, useCompounds, ignoreCase) {
|
|
63
|
+
const outerForms = new Set([word]);
|
|
64
|
+
if (this.ignoreCharactersRegExp) {
|
|
65
|
+
outerForms.add(word.replace(this.ignoreCharactersRegExp, ''));
|
|
66
|
+
outerForms.add(word.normalize('NFD').replace(this.ignoreCharactersRegExp, ''));
|
|
67
|
+
outerForms.add(word.normalize('NFC').replace(this.ignoreCharactersRegExp, ''));
|
|
68
|
+
}
|
|
69
|
+
for (const form of outerForms) {
|
|
70
|
+
const r = this._findAnyForm(form, useCompounds, ignoreCase);
|
|
71
|
+
if (r)
|
|
72
|
+
return r;
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
_findAnyForm(word, useCompounds, ignoreCase) {
|
|
77
|
+
const mWord = this.mapWord(word.normalize('NFC'));
|
|
78
|
+
const opts = { caseSensitive: !ignoreCase };
|
|
79
|
+
const findResult = this.trie.findWord(mWord, opts);
|
|
80
|
+
if (findResult.found !== false) {
|
|
81
|
+
return findResult;
|
|
82
|
+
}
|
|
83
|
+
const forms = (0, SpellingDictionaryMethods_1.wordSearchForms)(mWord, this.isDictionaryCaseSensitive, ignoreCase);
|
|
84
|
+
for (const w of forms) {
|
|
85
|
+
const findResult = this.trie.findWord(w, opts);
|
|
86
|
+
if (findResult.found !== false) {
|
|
87
|
+
return findResult;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (useCompounds) {
|
|
91
|
+
opts.useLegacyWordCompounds = useCompounds;
|
|
92
|
+
for (const w of forms) {
|
|
93
|
+
const findResult = this.trie.findWord(w, opts);
|
|
94
|
+
if (findResult.found !== false) {
|
|
95
|
+
return findResult;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
isNoSuggestWord(word, options) {
|
|
102
|
+
return this.containsNoSuggestWords ? this.has(word, options) : false;
|
|
103
|
+
}
|
|
104
|
+
isForbidden(word) {
|
|
105
|
+
return this.trie.isForbiddenWord(word);
|
|
106
|
+
}
|
|
107
|
+
suggest(...args) {
|
|
108
|
+
const [word] = args;
|
|
109
|
+
const suggestOptions = (0, SpellingDictionaryMethods_1.suggestArgsToSuggestOptions)(args);
|
|
110
|
+
return this._suggest(word, suggestOptions);
|
|
111
|
+
}
|
|
112
|
+
_suggest(word, suggestOptions) {
|
|
113
|
+
const { numSuggestions = SpellingDictionaryMethods_1.defaultNumSuggestions, numChanges, includeTies, ignoreCase, timeout } = suggestOptions;
|
|
114
|
+
function filter(_word) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
const collector = (0, cspell_trie_lib_1.suggestionCollector)(word, (0, clean_1.clean)({
|
|
118
|
+
numSuggestions,
|
|
119
|
+
filter,
|
|
120
|
+
changeLimit: numChanges,
|
|
121
|
+
includeTies,
|
|
122
|
+
ignoreCase,
|
|
123
|
+
timeout,
|
|
124
|
+
weightMap: this.weightMap,
|
|
125
|
+
}));
|
|
126
|
+
this.genSuggestions(collector, suggestOptions);
|
|
127
|
+
return collector.suggestions.map((r) => ({ ...r, word: r.word }));
|
|
128
|
+
}
|
|
129
|
+
genSuggestions(collector, suggestOptions) {
|
|
130
|
+
if (this.options.noSuggest)
|
|
131
|
+
return;
|
|
132
|
+
const _compoundMethod = suggestOptions.compoundMethod ??
|
|
133
|
+
(this.options.useCompounds ? cspell_trie_lib_1.CompoundWordsMethod.JOIN_WORDS : cspell_trie_lib_1.CompoundWordsMethod.NONE);
|
|
134
|
+
(0, SpellingDictionaryMethods_1.wordSuggestFormsArray)(collector.word).forEach((w) => this.trie.genSuggestions((0, SpellingDictionaryMethods_1.impersonateCollector)(collector, w), _compoundMethod));
|
|
135
|
+
}
|
|
136
|
+
getErrors() {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.SpellingDictionaryFromTrie = SpellingDictionaryFromTrie;
|
|
141
|
+
SpellingDictionaryFromTrie.cachedWordsLimit = 50000;
|
|
142
|
+
function createSpellingDictionaryTrie(data, name, source, options) {
|
|
143
|
+
const trieNode = (0, cspell_trie_lib_1.importTrie)(data);
|
|
144
|
+
const trie = new cspell_trie_lib_1.Trie(trieNode);
|
|
145
|
+
return new SpellingDictionaryFromTrie(trie, name, options, source);
|
|
146
|
+
}
|
|
147
|
+
exports.createSpellingDictionaryTrie = createSpellingDictionaryTrie;
|
|
148
|
+
//# sourceMappingURL=SpellingDictionaryFromTrie.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DictionaryInformation } from '@cspell/cspell-types';
|
|
2
|
+
import { CompoundWordsMethod, SuggestionResult, WeightMap } from 'cspell-trie-lib';
|
|
3
|
+
import { HasOptions, SearchOptions, SpellingDictionary, SuggestOptions } from './SpellingDictionary';
|
|
4
|
+
export { impersonateCollector, suggestionCollector } from 'cspell-trie-lib';
|
|
5
|
+
export declare type FilterSuggestionsPredicate = (word: SuggestionResult) => boolean;
|
|
6
|
+
export declare type SuggestArgs = Parameters<SpellingDictionary['suggest']> | Parameters<(word: string, numSuggestions?: number, compoundMethod?: CompoundWordsMethod, numChanges?: number, ignoreCase?: boolean) => SuggestionResult[]>;
|
|
7
|
+
export declare const defaultNumSuggestions = 10;
|
|
8
|
+
declare function wordSearchFormsArray(word: string, isDictionaryCaseSensitive: boolean, ignoreCase: boolean): string[];
|
|
9
|
+
export declare function wordSearchForms(word: string, isDictionaryCaseSensitive: boolean, ignoreCase: boolean): Set<string>;
|
|
10
|
+
export declare function wordSuggestFormsArray(word: string): string[];
|
|
11
|
+
export declare function wordSuggestForms(word: string): Set<string>;
|
|
12
|
+
interface DictionaryWordForm {
|
|
13
|
+
w: string;
|
|
14
|
+
p: string;
|
|
15
|
+
}
|
|
16
|
+
declare function wordDictionaryForms(word: string, prefixNoCase: string): IterableIterator<DictionaryWordForm>;
|
|
17
|
+
export declare function wordDictionaryFormsCollector(prefixNoCase: string): (word: string) => Iterable<string>;
|
|
18
|
+
export declare function hasOptionToSearchOption(opt: HasOptions | undefined): SearchOptions;
|
|
19
|
+
export declare function suggestArgsToSuggestOptions(args: SuggestArgs): SuggestOptions;
|
|
20
|
+
export declare function createWeightMapFromDictionaryInformation(di: undefined): undefined;
|
|
21
|
+
export declare function createWeightMapFromDictionaryInformation(di: DictionaryInformation): WeightMap;
|
|
22
|
+
export declare function createWeightMapFromDictionaryInformation(di: DictionaryInformation | undefined): WeightMap | undefined;
|
|
23
|
+
export declare const __testMethods__: {
|
|
24
|
+
wordSearchForms: typeof wordSearchForms;
|
|
25
|
+
wordSearchFormsArray: typeof wordSearchFormsArray;
|
|
26
|
+
wordDictionaryForms: typeof wordDictionaryForms;
|
|
27
|
+
wordDictionaryFormsCollector: typeof wordDictionaryFormsCollector;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=SpellingDictionaryMethods.d.ts.map
|