aboutsummaryrefslogtreecommitdiff
path: root/ext/js
diff options
context:
space:
mode:
authorStefanVukovic99 <stefanvukovic44@gmail.com>2024-02-23 13:32:03 +0100
committerGitHub <noreply@github.com>2024-02-23 12:32:03 +0000
commit9b5de0d2d4cb224751c57bdae6558a046351c2f4 (patch)
treeb8d2c0330524a4829e4557d3e584edf60833083d /ext/js
parent8078e0ec7279916e56bdc8bab88ee7f1e1594425 (diff)
fix translator bug, simplify language-transformer (#687)24.2.23.0
* simplify transformer * use isPartOfSpeech * simplify * rename to isDictionaryForm * NOP --------- Co-authored-by: Darius Jahandarie <djahandarie@gmail.com>
Diffstat (limited to 'ext/js')
-rw-r--r--ext/js/language/language-transformer.js65
1 files changed, 33 insertions, 32 deletions
diff --git a/ext/js/language/language-transformer.js b/ext/js/language/language-transformer.js
index 7ad1895f..08a2166f 100644
--- a/ext/js/language/language-transformer.js
+++ b/ext/js/language/language-transformer.js
@@ -56,9 +56,9 @@ export class LanguageTransformer {
const rules2 = [];
for (let j = 0, jj = rules.length; j < jj; ++j) {
const {suffixIn, suffixOut, conditionsIn, conditionsOut} = rules[j];
- const conditionFlagsIn = this._getConditionFlags(conditionFlagsMap, conditionsIn);
+ const conditionFlagsIn = this._getConditionFlagsStrict(conditionFlagsMap, conditionsIn);
if (conditionFlagsIn === null) { throw new Error(`Invalid conditionsIn for transform[${i}].rules[${j}]`); }
- const conditionFlagsOut = this._getConditionFlags(conditionFlagsMap, conditionsOut);
+ const conditionFlagsOut = this._getConditionFlagsStrict(conditionFlagsMap, conditionsOut);
if (conditionFlagsOut === null) { throw new Error(`Invalid conditionsOut for transform[${i}].rules[${j}]`); }
rules2.push({
suffixIn,
@@ -81,52 +81,34 @@ export class LanguageTransformer {
const flags = conditionFlagsMap.get(type);
if (typeof flags === 'undefined') { continue; } // This case should never happen
this._conditionTypeToConditionFlagsMap.set(type, flags);
- for (const partOfSpeech of condition.partsOfSpeech) {
- this._partOfSpeechToConditionFlagsMap.set(partOfSpeech, this.getConditionFlagsFromPartOfSpeech(partOfSpeech) | flags);
+ if (condition.isDictionaryForm) {
+ this._partOfSpeechToConditionFlagsMap.set(type, flags);
}
}
}
/**
- * @param {string} partOfSpeech
- * @returns {number}
- */
- getConditionFlagsFromPartOfSpeech(partOfSpeech) {
- const conditionFlags = this._partOfSpeechToConditionFlagsMap.get(partOfSpeech);
- return typeof conditionFlags !== 'undefined' ? conditionFlags : 0;
- }
-
- /**
* @param {string[]} partsOfSpeech
* @returns {number}
*/
getConditionFlagsFromPartsOfSpeech(partsOfSpeech) {
- let result = 0;
- for (const partOfSpeech of partsOfSpeech) {
- result |= this.getConditionFlagsFromPartOfSpeech(partOfSpeech);
- }
- return result;
+ return this._getConditionFlags(this._partOfSpeechToConditionFlagsMap, partsOfSpeech);
}
/**
- * @param {string} conditionType
+ * @param {string[]} conditionTypes
* @returns {number}
*/
- getConditionFlagsFromConditionType(conditionType) {
- const conditionFlags = this._conditionTypeToConditionFlagsMap.get(conditionType);
- return typeof conditionFlags !== 'undefined' ? conditionFlags : 0;
+ getConditionFlagsFromConditionTypes(conditionTypes) {
+ return this._getConditionFlags(this._conditionTypeToConditionFlagsMap, conditionTypes);
}
/**
- * @param {string[]} conditionTypes
+ * @param {string} conditionType
* @returns {number}
*/
- getConditionFlagsFromConditionTypes(conditionTypes) {
- let result = 0;
- for (const conditionType of conditionTypes) {
- result |= this.getConditionFlagsFromConditionType(conditionType);
- }
- return result;
+ getConditionFlagsFromConditionType(conditionType) {
+ return this._getConditionFlags(this._conditionTypeToConditionFlagsMap, [conditionType]);
}
/**
@@ -182,7 +164,7 @@ export class LanguageTransformer {
flags = 1 << nextFlagIndex;
++nextFlagIndex;
} else {
- const multiFlags = this._getConditionFlags(conditionFlagsMap, subConditions);
+ const multiFlags = this._getConditionFlagsStrict(conditionFlagsMap, subConditions);
if (multiFlags === null) {
nextTargets.push(target);
continue;
@@ -206,11 +188,30 @@ export class LanguageTransformer {
* @param {string[]} conditionTypes
* @returns {?number}
*/
- _getConditionFlags(conditionFlagsMap, conditionTypes) {
+ _getConditionFlagsStrict(conditionFlagsMap, conditionTypes) {
let flags = 0;
for (const conditionType of conditionTypes) {
const flags2 = conditionFlagsMap.get(conditionType);
- if (typeof flags2 === 'undefined') { return null; }
+ if (typeof flags2 === 'undefined') {
+ return null;
+ }
+ flags |= flags2;
+ }
+ return flags;
+ }
+
+ /**
+ * @param {Map<string, number>} conditionFlagsMap
+ * @param {string[]} conditionTypes
+ * @returns {number}
+ */
+ _getConditionFlags(conditionFlagsMap, conditionTypes) {
+ let flags = 0;
+ for (const conditionType of conditionTypes) {
+ let flags2 = conditionFlagsMap.get(conditionType);
+ if (typeof flags2 === 'undefined') {
+ flags2 = 0;
+ }
flags |= flags2;
}
return flags;