diff options
| -rw-r--r-- | ext/data/language/japanese-transforms.json | 38 | ||||
| -rw-r--r-- | ext/js/language/language-transformer.js | 65 | ||||
| -rw-r--r-- | types/ext/language-transformer.d.ts | 2 | 
3 files changed, 53 insertions, 52 deletions
| diff --git a/ext/data/language/japanese-transforms.json b/ext/data/language/japanese-transforms.json index b1f39cbc..0812f01e 100644 --- a/ext/data/language/japanese-transforms.json +++ b/ext/data/language/japanese-transforms.json @@ -3,107 +3,107 @@      "conditions": {          "v": {              "name": "Verb", -            "partsOfSpeech": ["v1", "v5", "vk", "vs", "vz"],              "i18n": [                  {                      "language": "ja",                      "name": "動詞"                  }              ], +            "isDictionaryForm": false,              "subConditions": ["v1", "v5", "vk", "vs", "vz"]          },          "v1": {              "name": "Ichidan verb", -            "partsOfSpeech": ["v1"],              "i18n": [                  {                      "language": "ja",                      "name": "一段動詞"                  }              ], +            "isDictionaryForm": true,              "subConditions": ["v1d", "v1p"]          },          "v1d": {              "name": "Ichidan verb, dictionary form", -            "partsOfSpeech": ["v1"],              "i18n": [                  {                      "language": "ja",                      "name": "一段動詞、辞書形"                  } -            ] +            ], +            "isDictionaryForm": false          },          "v1p": {              "name": "Ichidan verb, progressive or perfect form", -            "partsOfSpeech": ["v1"],              "i18n": [                  {                      "language": "ja",                      "name": "一段動詞、進行形または完了形"                  } -            ] +            ], +            "isDictionaryForm": false          },          "v5": {              "name": "Godan verb", -            "partsOfSpeech": ["v5"],              "i18n": [                  {                      "language": "ja",                      "name": "五段動詞"                  } -            ] +            ], +            "isDictionaryForm": true          },          "vk": {              "name": "Kuru verb", -            "partsOfSpeech": ["vk"],              "i18n": [                  {                      "language": "ja",                      "name": "来る動詞"                  } -            ] +            ], +            "isDictionaryForm": true          },          "vs": {              "name": "Suru verb", -            "partsOfSpeech": ["vs"],              "i18n": [                  {                      "language": "ja",                      "name": "する動詞"                  } -            ] +            ], +            "isDictionaryForm": true          },          "vz": {              "name": "Zuru verb", -            "partsOfSpeech": ["vz"],              "i18n": [                  {                      "language": "ja",                      "name": "ずる動詞"                  } -            ] +            ], +            "isDictionaryForm": true          },          "adj-i": {              "name": "Adjective with i ending", -            "partsOfSpeech": ["adj-i"],              "i18n": [                  {                      "language": "ja",                      "name": "形容詞"                  } -            ] +            ], +            "isDictionaryForm": true          },          "-te": {              "name": "Intermediate -te endings for progressive or perfect tense", -            "partsOfSpeech": [] +            "isDictionaryForm": false          },          "adv": {              "name": "Intermediate -ku endings for adverbs", -            "partsOfSpeech": [] +            "isDictionaryForm": false          },          "past": {              "name": "-ta past form ending", -            "partsOfSpeech": [] +            "isDictionaryForm": false          }      },      "transforms": [ 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; diff --git a/types/ext/language-transformer.d.ts b/types/ext/language-transformer.d.ts index 08c7a3dc..88dce0b5 100644 --- a/types/ext/language-transformer.d.ts +++ b/types/ext/language-transformer.d.ts @@ -31,7 +31,7 @@ export type ConditionMapEntries = ConditionMapEntry[];  export type Condition = {      name: string; -    partsOfSpeech: string[]; +    isDictionaryForm: boolean;      i18n?: RuleI18n[];      subConditions?: string[];  }; |