diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-12-17 17:02:13 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-17 17:02:13 -0500 |
commit | 8a377cabe6b3d177aac50cdb7ffb5a4328d27fd0 (patch) | |
tree | 59a84764df29679c01be2b0f2b191538947f6da8 /ext/js/language/translator.js | |
parent | 8e548a17eba180b5773a9900de3f3cb3a92ec6ff (diff) |
matchType/deinflect distinction (#2040)
* Pass a "deinflect" option to findTerms
* Update Translator to use deinflect option
* Fix test input options
Diffstat (limited to 'ext/js/language/translator.js')
-rw-r--r-- | ext/js/language/translator.js | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js index dd7d54a0..31a3b7ed 100644 --- a/ext/js/language/translator.js +++ b/ext/js/language/translator.js @@ -234,12 +234,7 @@ class Translator { return {dictionaryEntries: [], originalTextLength: 0}; } - const {matchType} = options; - const deinflections = await ( - matchType && matchType !== 'exact' ? - this._findTermsWildcard(text, enabledDictionaryMap, matchType) : - this._findTermDeinflections(text, enabledDictionaryMap, options) - ); + const deinflections = await this._findTermsInternal2(text, enabledDictionaryMap, options); let originalTextLength = 0; const dictionaryEntries = []; @@ -259,17 +254,13 @@ class Translator { return {dictionaryEntries, originalTextLength}; } - async _findTermsWildcard(text, enabledDictionaryMap, matchType) { - const databaseEntries = await this._database.findTermsBulk([text], enabledDictionaryMap, matchType); - return databaseEntries.length > 0 ? [this._createDeinflection(text, text, text, 0, [], databaseEntries)] : []; - } - - async _findTermDeinflections(text, enabledDictionaryMap, options) { - const deinflections = this._getAllDeinflections(text, options); - - if (deinflections.length === 0) { - return []; - } + async _findTermsInternal2(text, enabledDictionaryMap, options) { + const deinflections = ( + options.deinflect ? + this._getAllDeinflections(text, options) : + [this._createDeinflection(text, text, text, 0, [], [])] + ); + if (deinflections.length === 0) { return []; } const uniqueDeinflectionTerms = []; const uniqueDeinflectionArrays = []; @@ -286,7 +277,8 @@ class Translator { deinflectionArray.push(deinflection); } - const databaseEntries = await this._database.findTermsBulk(uniqueDeinflectionTerms, enabledDictionaryMap, null); + const {matchType} = options; + const databaseEntries = await this._database.findTermsBulk(uniqueDeinflectionTerms, enabledDictionaryMap, matchType); for (const databaseEntry of databaseEntries) { const definitionRules = Deinflector.rulesToRuleFlags(databaseEntry.rules); |