diff options
author | StefanVukovic99 <stefanvukovic44@gmail.com> | 2024-02-27 13:16:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-27 12:16:21 +0000 |
commit | 0792954e345925b3e3b2ebb733367e138375978e (patch) | |
tree | a9f169cf7dc2de396d6e46c9d8c418f9870d9301 /ext/js/language/language-transformer.js | |
parent | c4fea2251606fb0b3d0d761a544dac578f3d9048 (diff) |
make deinflections language-specific (#720)
* abstract deinflections
* undo redundant changes
* remove cast
* MultiLanguageTransformer
* comments
* comments
Diffstat (limited to 'ext/js/language/language-transformer.js')
-rw-r--r-- | ext/js/language/language-transformer.js | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/ext/js/language/language-transformer.js b/ext/js/language/language-transformer.js index 08a2166f..8a82e4d2 100644 --- a/ext/js/language/language-transformer.js +++ b/ext/js/language/language-transformer.js @@ -77,11 +77,11 @@ export class LanguageTransformer { this._transforms.push(transform); } - for (const [type, condition] of conditionEntries) { + for (const [type, {isDictionaryForm}] of conditionEntries) { const flags = conditionFlagsMap.get(type); if (typeof flags === 'undefined') { continue; } // This case should never happen this._conditionTypeToConditionFlagsMap.set(type, flags); - if (condition.isDictionaryForm) { + if (isDictionaryForm) { this._partOfSpeechToConditionFlagsMap.set(type, flags); } } @@ -116,7 +116,7 @@ export class LanguageTransformer { * @returns {import('language-transformer-internal').TransformedText[]} */ transform(sourceText) { - const results = [this._createTransformedText(sourceText, 0, [])]; + const results = [LanguageTransformer.createTransformedText(sourceText, 0, [])]; for (let i = 0; i < results.length; ++i) { const {text, conditions, trace} = results[i]; for (const transform of this._transforms) { @@ -128,7 +128,7 @@ export class LanguageTransformer { if (!LanguageTransformer.conditionsMatch(conditions, rule.conditionsIn)) { continue; } const {suffixIn, suffixOut} = rule; if (!text.endsWith(suffixIn) || (text.length - suffixIn.length + suffixOut.length) <= 0) { continue; } - results.push(this._createTransformedText( + results.push(LanguageTransformer.createTransformedText( text.substring(0, text.length - suffixIn.length) + suffixOut, rule.conditionsOut, this._extendTrace(trace, {transform: name, ruleIndex: j}) @@ -140,6 +140,27 @@ export class LanguageTransformer { } /** + * @param {string} text + * @param {number} conditions + * @param {import('language-transformer-internal').Trace} trace + * @returns {import('language-transformer-internal').TransformedText} + */ + static createTransformedText(text, conditions, trace) { + return {text, conditions, trace}; + } + + /** + * If `currentConditions` is `0`, then `nextConditions` is ignored and `true` is returned. + * Otherwise, there must be at least one shared condition between `currentConditions` and `nextConditions`. + * @param {number} currentConditions + * @param {number} nextConditions + * @returns {boolean} + */ + static conditionsMatch(currentConditions, nextConditions) { + return currentConditions === 0 || (currentConditions & nextConditions) !== 0; + } + + /** * @param {import('language-transformer').ConditionMapEntries} conditions * @param {number} nextFlagIndex * @returns {{conditionFlagsMap: Map<string, number>, nextFlagIndex: number}} @@ -218,16 +239,6 @@ export class LanguageTransformer { } /** - * @param {string} text - * @param {number} conditions - * @param {import('language-transformer-internal').Trace} trace - * @returns {import('language-transformer-internal').TransformedText} - */ - _createTransformedText(text, conditions, trace) { - return {text, conditions, trace}; - } - - /** * @param {import('language-transformer-internal').Trace} trace * @param {import('language-transformer-internal').TraceFrame} newFrame * @returns {import('language-transformer-internal').Trace} @@ -239,15 +250,4 @@ export class LanguageTransformer { } return newTrace; } - - /** - * If `currentConditions` is `0`, then `nextConditions` is ignored and `true` is returned. - * Otherwise, there must be at least one shared condition between `currentConditions` and `nextConditions`. - * @param {number} currentConditions - * @param {number} nextConditions - * @returns {boolean} - */ - static conditionsMatch(currentConditions, nextConditions) { - return currentConditions === 0 || (currentConditions & nextConditions) !== 0; - } } |