From b6112c3892b5131f9c78989ead3bc77d836e79ad Mon Sep 17 00:00:00 2001 From: Cashew Date: Mon, 15 Jul 2024 11:32:26 +0700 Subject: [PATCH] stricten condition types --- ext/js/language/en/english-transforms.js | 86 ++++--- ext/js/language/es/spanish-transforms.js | 76 +++--- ext/js/language/ja/japanese-transforms.js | 254 ++++++++++---------- ext/js/language/ko/korean-transforms.js | 164 ++++++------- ext/js/language/la/latin-transforms.js | 210 ++++++++-------- ext/js/language/language-transforms.js | 21 +- ext/js/language/sga/old-irish-transforms.js | 14 +- ext/js/language/sq/albanian-transforms.js | 66 ++--- types/ext/language-descriptors.d.ts | 2 +- types/ext/language-transformer.d.ts | 46 ++-- types/ext/language.d.ts | 3 +- 11 files changed, 492 insertions(+), 450 deletions(-) diff --git a/ext/js/language/en/english-transforms.js b/ext/js/language/en/english-transforms.js index 96b30e4f5c..24777bf8c6 100644 --- a/ext/js/language/en/english-transforms.js +++ b/ext/js/language/en/english-transforms.js @@ -17,12 +17,14 @@ import {prefixInflection, suffixInflection} from '../language-transforms.js'; +/** @typedef {keyof typeof conditions} Condition */ + /** * @param {string} consonants * @param {string} suffix - * @param {string[]} conditionsIn - * @param {string[]} conditionsOut - * @returns {import('language-transformer').SuffixRule[]} + * @param {Condition[]} conditionsIn + * @param {Condition[]} conditionsOut + * @returns {import('language-transformer').SuffixRule[]} */ function doubledConsonantInflection(consonants, suffix, conditionsIn, conditionsOut) { const inflections = []; @@ -64,7 +66,9 @@ const phrasalVerbPrepositions = ['aback', 'about', 'above', 'across', 'after', ' const particlesDisjunction = phrasalVerbParticles.join('|'); const phrasalVerbWordSet = new Set([...phrasalVerbParticles, ...phrasalVerbPrepositions]); const phrasalVerbWordDisjunction = [...phrasalVerbWordSet].join('|'); -/** @type {import('language-transformer').Rule} */ +/** + * @type {import('language-transformer').Rule} + */ const phrasalVerbInterposedObjectRule = { type: 'other', isInflected: new RegExp(`^\\w* (?:(?!\\b(${phrasalVerbWordDisjunction})\\b).)+ (?:${particlesDisjunction})`), @@ -78,7 +82,7 @@ const phrasalVerbInterposedObjectRule = { /** * @param {string} inflected * @param {string} deinflected - * @returns {import('language-transformer').Rule} + * @returns {import('language-transformer').Rule} */ function createPhrasalVerbInflection(inflected, deinflected) { return { @@ -93,8 +97,8 @@ function createPhrasalVerbInflection(inflected, deinflected) { } /** - * @param {import('language-transformer').SuffixRule[]} sourceRules - * @returns {import('language-transformer').Rule[]} + * @param {import('language-transformer').SuffixRule[]} sourceRules + * @returns {import('language-transformer').Rule[]} */ function createPhrasalVerbInflectionsFromSuffixInflections(sourceRules) { return sourceRules.flatMap(({isInflected, deinflected}) => { @@ -105,41 +109,43 @@ function createPhrasalVerbInflectionsFromSuffixInflections(sourceRules) { }); } -/** @type {import('language-transformer').LanguageTransformDescriptor} */ +const conditions = { + v: { + name: 'Verb', + isDictionaryForm: true, + subConditions: ['v_phr'], + }, + v_phr: { + name: 'Phrasal verb', + isDictionaryForm: true, + }, + n: { + name: 'Noun', + isDictionaryForm: true, + subConditions: ['np', 'ns'], + }, + np: { + name: 'Noun plural', + isDictionaryForm: true, + }, + ns: { + name: 'Noun singular', + isDictionaryForm: true, + }, + adj: { + name: 'Adjective', + isDictionaryForm: true, + }, + adv: { + name: 'Adverb', + isDictionaryForm: true, + }, +}; + +/** @type {import('language-transformer').LanguageTransformDescriptor} */ export const englishTransforms = { language: 'en', - conditions: { - v: { - name: 'Verb', - isDictionaryForm: true, - subConditions: ['v_phr'], - }, - v_phr: { - name: 'Phrasal verb', - isDictionaryForm: true, - }, - n: { - name: 'Noun', - isDictionaryForm: true, - subConditions: ['np', 'ns'], - }, - np: { - name: 'Noun plural', - isDictionaryForm: true, - }, - ns: { - name: 'Noun singular', - isDictionaryForm: true, - }, - adj: { - name: 'Adjective', - isDictionaryForm: true, - }, - adv: { - name: 'Adverb', - isDictionaryForm: true, - }, - }, + conditions, transforms: { 'plural': { name: 'plural', diff --git a/ext/js/language/es/spanish-transforms.js b/ext/js/language/es/spanish-transforms.js index dc4fc5a522..202f1387a9 100644 --- a/ext/js/language/es/spanish-transforms.js +++ b/ext/js/language/es/spanish-transforms.js @@ -34,45 +34,47 @@ function addAccent(char) { return ACCENTS.get(char) || char; } -/** @type {import('language-transformer').LanguageTransformDescriptor} */ +const conditions = { + n: { + name: 'Noun', + isDictionaryForm: true, + subConditions: ['ns', 'np'], + }, + np: { + name: 'Noun plural', + isDictionaryForm: false, + }, + ns: { + name: 'Noun singular', + isDictionaryForm: false, + }, + v: { + name: 'Verb', + isDictionaryForm: true, + subConditions: ['v_ar', 'v_er', 'v_ir'], + }, + v_ar: { + name: '-ar verb', + isDictionaryForm: false, + }, + v_er: { + name: '-er verb', + isDictionaryForm: false, + }, + v_ir: { + name: '-ir verb', + isDictionaryForm: false, + }, + adj: { + name: 'Adjective', + isDictionaryForm: true, + }, +}; + +/** @type {import('language-transformer').LanguageTransformDescriptor} */ export const spanishTransforms = { language: 'es', - conditions: { - n: { - name: 'Noun', - isDictionaryForm: true, - subConditions: ['ns', 'np'], - }, - np: { - name: 'Noun plural', - isDictionaryForm: false, - }, - ns: { - name: 'Noun singular', - isDictionaryForm: false, - }, - v: { - name: 'Verb', - isDictionaryForm: true, - subConditions: ['v_ar', 'v_er', 'v_ir'], - }, - v_ar: { - name: '-ar verb', - isDictionaryForm: false, - }, - v_er: { - name: '-er verb', - isDictionaryForm: false, - }, - v_ir: { - name: '-ir verb', - isDictionaryForm: false, - }, - adj: { - name: 'Adjective', - isDictionaryForm: true, - }, - }, + conditions, transforms: { 'plural': { name: 'plural', diff --git a/ext/js/language/ja/japanese-transforms.js b/ext/js/language/ja/japanese-transforms.js index 835c53602d..9931087fc0 100644 --- a/ext/js/language/ja/japanese-transforms.js +++ b/ext/js/language/ja/japanese-transforms.js @@ -24,134 +24,136 @@ const shimauEnglishDescription = '1. Shows a sense of regret/surprise when you d const passiveEnglishDescription = '1. Indicates an action received from an action performer.\n' + '2. Expresses respect for the subject of action performer.\n'; -/** @type {import('language-transformer').LanguageTransformDescriptor} */ +const conditions = { + 'v': { + name: 'Verb', + i18n: [ + { + language: 'ja', + name: '動詞', + }, + ], + isDictionaryForm: false, + subConditions: ['v1', 'v5', 'vk', 'vs', 'vz'], + }, + 'v1': { + name: 'Ichidan verb', + i18n: [ + { + language: 'ja', + name: '一段動詞', + }, + ], + isDictionaryForm: true, + subConditions: ['v1d', 'v1p'], + }, + 'v1d': { + name: 'Ichidan verb, dictionary form', + i18n: [ + { + language: 'ja', + name: '一段動詞、辞書形', + }, + ], + isDictionaryForm: false, + }, + 'v1p': { + name: 'Ichidan verb, progressive or perfect form', + i18n: [ + { + language: 'ja', + name: '一段動詞、進行形または完了形', + }, + ], + isDictionaryForm: false, + }, + 'v5': { + name: 'Godan verb', + i18n: [ + { + language: 'ja', + name: '五段動詞', + }, + ], + isDictionaryForm: true, + subConditions: ['v5d', 'v5m'], + }, + 'v5d': { + name: 'Godan verb, dictionary form', + i18n: [ + { + language: 'ja', + name: '五段動詞、辞書形', + }, + ], + isDictionaryForm: false, + }, + 'v5m': { + name: 'Godan verb, polite (masu) form', + isDictionaryForm: false, + }, + 'vk': { + name: 'Kuru verb', + i18n: [ + { + language: 'ja', + name: '来る動詞', + }, + ], + isDictionaryForm: true, + }, + 'vs': { + name: 'Suru verb', + i18n: [ + { + language: 'ja', + name: 'する動詞', + }, + ], + isDictionaryForm: true, + }, + 'vz': { + name: 'Zuru verb', + i18n: [ + { + language: 'ja', + name: 'ずる動詞', + }, + ], + isDictionaryForm: true, + }, + 'adj-i': { + name: 'Adjective with i ending', + i18n: [ + { + language: 'ja', + name: '形容詞', + }, + ], + isDictionaryForm: true, + }, + '-te': { + name: 'Intermediate -te endings for progressive or perfect tense', + isDictionaryForm: false, + }, + '-ba': { + name: 'Intermediate -ba endings for conditional contraction', + isDictionaryForm: false, + }, + 'adv': { + name: 'Intermediate -ku endings for adverbs', + isDictionaryForm: false, + }, + 'past': { + name: '-ta past form ending', + isDictionaryForm: false, + }, +}; + +/** @type {import('language-transformer').LanguageTransformDescriptor} */ export const japaneseTransforms = { language: 'ja', - conditions: { - 'v': { - name: 'Verb', - i18n: [ - { - language: 'ja', - name: '動詞', - }, - ], - isDictionaryForm: false, - subConditions: ['v1', 'v5', 'vk', 'vs', 'vz'], - }, - 'v1': { - name: 'Ichidan verb', - i18n: [ - { - language: 'ja', - name: '一段動詞', - }, - ], - isDictionaryForm: true, - subConditions: ['v1d', 'v1p'], - }, - 'v1d': { - name: 'Ichidan verb, dictionary form', - i18n: [ - { - language: 'ja', - name: '一段動詞、辞書形', - }, - ], - isDictionaryForm: false, - }, - 'v1p': { - name: 'Ichidan verb, progressive or perfect form', - i18n: [ - { - language: 'ja', - name: '一段動詞、進行形または完了形', - }, - ], - isDictionaryForm: false, - }, - 'v5': { - name: 'Godan verb', - i18n: [ - { - language: 'ja', - name: '五段動詞', - }, - ], - isDictionaryForm: true, - subConditions: ['v5d', 'v5m'], - }, - 'v5d': { - name: 'Godan verb, dictionary form', - i18n: [ - { - language: 'ja', - name: '五段動詞、辞書形', - }, - ], - isDictionaryForm: false, - }, - 'v5m': { - name: 'Godan verb, polite (masu) form', - isDictionaryForm: false, - }, - 'vk': { - name: 'Kuru verb', - i18n: [ - { - language: 'ja', - name: '来る動詞', - }, - ], - isDictionaryForm: true, - }, - 'vs': { - name: 'Suru verb', - i18n: [ - { - language: 'ja', - name: 'する動詞', - }, - ], - isDictionaryForm: true, - }, - 'vz': { - name: 'Zuru verb', - i18n: [ - { - language: 'ja', - name: 'ずる動詞', - }, - ], - isDictionaryForm: true, - }, - 'adj-i': { - name: 'Adjective with i ending', - i18n: [ - { - language: 'ja', - name: '形容詞', - }, - ], - isDictionaryForm: true, - }, - '-te': { - name: 'Intermediate -te endings for progressive or perfect tense', - isDictionaryForm: false, - }, - '-ba': { - name: 'Intermediate -ba endings for conditional contraction', - isDictionaryForm: false, - }, - 'adv': { - name: 'Intermediate -ku endings for adverbs', - isDictionaryForm: false, - }, - 'past': { - name: '-ta past form ending', - isDictionaryForm: false, - }, - }, + conditions, transforms: { '-ba': { name: '-ba', diff --git a/ext/js/language/ko/korean-transforms.js b/ext/js/language/ko/korean-transforms.js index 49f4b91fb2..ac74859136 100644 --- a/ext/js/language/ko/korean-transforms.js +++ b/ext/js/language/ko/korean-transforms.js @@ -17,89 +17,91 @@ import {suffixInflection} from '../language-transforms.js'; -/** @type {import('language-transformer').LanguageTransformDescriptor} */ +const conditions = { + v: { + name: 'Verb or Auxiliary Verb', + isDictionaryForm: true, + i18n: [ + { + language: 'ko', + name: '동사 / 보조 동사', + }, + ], + }, + adj: { + name: 'Adjective or Auxiliary Adjective', + isDictionaryForm: true, + i18n: [ + { + language: 'ko', + name: '형용사 / 보조 형용사', + }, + ], + }, + ida: { + name: 'Postpositional particle ida', + isDictionaryForm: true, + i18n: [ + { + language: 'ko', + name: '조사 이다', + }, + ], + }, + p: { + name: 'Intermediate past tense ending', + isDictionaryForm: false, + }, + f: { + name: 'Intermediate future tense ending', + isDictionaryForm: false, + }, + eusi: { + name: 'Intermediate formal ending', + isDictionaryForm: false, + }, + euob: { + name: 'Intermediate formal ending', + isDictionaryForm: false, + }, + euo: { + name: 'Intermediate formal ending', + isDictionaryForm: false, + }, + sao: { + name: 'Intermediate formal ending', + isDictionaryForm: false, + }, + saob: { + name: 'Intermediate formal ending', + isDictionaryForm: false, + }, + sab: { + name: 'Intermediate formal ending', + isDictionaryForm: false, + }, + jaob: { + name: 'Intermediate formal ending', + isDictionaryForm: false, + }, + jao: { + name: 'Intermediate formal ending', + isDictionaryForm: false, + }, + jab: { + name: 'Intermediate formal ending', + isDictionaryForm: false, + }, + do: { + name: 'Intermediate ending', + isDictionaryForm: false, + }, +}; + +/** @type {import('language-transformer').LanguageTransformDescriptor} */ export const koreanTransforms = { language: 'ko', - conditions: { - v: { - name: 'Verb or Auxiliary Verb', - isDictionaryForm: true, - i18n: [ - { - language: 'ko', - name: '동사 / 보조 동사', - }, - ], - }, - adj: { - name: 'Adjective or Auxiliary Adjective', - isDictionaryForm: true, - i18n: [ - { - language: 'ko', - name: '형용사 / 보조 형용사', - }, - ], - }, - ida: { - name: 'Postpositional particle ida', - isDictionaryForm: true, - i18n: [ - { - language: 'ko', - name: '조사 이다', - }, - ], - }, - p: { - name: 'Intermediate past tense ending', - isDictionaryForm: false, - }, - f: { - name: 'Intermediate future tense ending', - isDictionaryForm: false, - }, - eusi: { - name: 'Intermediate formal ending', - isDictionaryForm: false, - }, - euob: { - name: 'Intermediate formal ending', - isDictionaryForm: false, - }, - euo: { - name: 'Intermediate formal ending', - isDictionaryForm: false, - }, - sao: { - name: 'Intermediate formal ending', - isDictionaryForm: false, - }, - saob: { - name: 'Intermediate formal ending', - isDictionaryForm: false, - }, - sab: { - name: 'Intermediate formal ending', - isDictionaryForm: false, - }, - jaob: { - name: 'Intermediate formal ending', - isDictionaryForm: false, - }, - jao: { - name: 'Intermediate formal ending', - isDictionaryForm: false, - }, - jab: { - name: 'Intermediate formal ending', - isDictionaryForm: false, - }, - do: { - name: 'Intermediate ending', - isDictionaryForm: false, - }, - }, + conditions, transforms: { '어간': { name: '어간', diff --git a/ext/js/language/la/latin-transforms.js b/ext/js/language/la/latin-transforms.js index 60a99f4439..20af008a40 100644 --- a/ext/js/language/la/latin-transforms.js +++ b/ext/js/language/la/latin-transforms.js @@ -19,112 +19,114 @@ import {suffixInflection} from '../language-transforms.js'; // TODO: -ne suffix (estne, nonne)? -/** @type {import('language-transformer').LanguageTransformDescriptor} */ +const conditions = { + v: { + name: 'Verb', + isDictionaryForm: true, + }, + n: { + name: 'Noun', + isDictionaryForm: true, + subConditions: ['ns', 'np'], + }, + ns: { + name: 'Noun, singular', + isDictionaryForm: true, + subConditions: ['n1s', 'n2s', 'n3s', 'n4s', 'n5s'], + }, + np: { + name: 'Noun, plural', + isDictionaryForm: true, + subConditions: ['n1p', 'n2p', 'n3p', 'n4p', 'n5p'], + }, + n1: { + name: 'Noun, 1st declension', + isDictionaryForm: true, + subConditions: ['n1s', 'n1p'], + }, + n1p: { + name: 'Noun, 1st declension, plural', + isDictionaryForm: true, + }, + n1s: { + name: 'Noun, 1st declension, singular', + isDictionaryForm: true, + }, + n2: { + name: 'Noun, 2nd declension', + isDictionaryForm: true, + subConditions: ['n2s', 'n2p'], + }, + n2p: { + name: 'Noun, 2nd declension, plural', + isDictionaryForm: true, + }, + n2s: { + name: 'Noun, 2nd declension, singular', + isDictionaryForm: true, + }, + n3: { + name: 'Noun, 3rd declension', + isDictionaryForm: true, + subConditions: ['n3s', 'n3p'], + }, + n3p: { + name: 'Noun, 3rd declension, plural', + isDictionaryForm: true, + }, + n3s: { + name: 'Noun, 3rd declension, singular', + isDictionaryForm: true, + }, + n4: { + name: 'Noun, 4th declension', + isDictionaryForm: true, + subConditions: ['n4s', 'n4p'], + }, + n4p: { + name: 'Noun, 4th declension, plural', + isDictionaryForm: true, + }, + n4s: { + name: 'Noun, 4th declension, singular', + isDictionaryForm: true, + }, + n5: { + name: 'Noun, 5th declension', + isDictionaryForm: true, + subConditions: ['n5s', 'n5p'], + }, + n5p: { + name: 'Noun, 5th declension, plural', + isDictionaryForm: true, + }, + n5s: { + name: 'Noun, 5th declension, singular', + isDictionaryForm: true, + }, + adj: { + name: 'Adjective', + isDictionaryForm: true, + subConditions: ['adj3', 'adj12'], + }, + adj12: { + name: 'Adjective, 1st-2nd declension', + isDictionaryForm: true, + }, + adj3: { + name: 'Adjective, 3rd declension', + isDictionaryForm: true, + }, + adv: { + name: 'Adverb', + isDictionaryForm: true, + }, +}; + +/** @type {import('language-transformer').LanguageTransformDescriptor} */ export const latinTransforms = { language: 'la', - conditions: { - v: { - name: 'Verb', - isDictionaryForm: true, - }, - n: { - name: 'Noun', - isDictionaryForm: true, - subConditions: ['ns', 'np'], - }, - ns: { - name: 'Noun, singular', - isDictionaryForm: true, - subConditions: ['n1s', 'n2s', 'n3s', 'n4s', 'n5s'], - }, - np: { - name: 'Noun, plural', - isDictionaryForm: true, - subConditions: ['n1p', 'n2p', 'n3p', 'n4p', 'n5p'], - }, - n1: { - name: 'Noun, 1st declension', - isDictionaryForm: true, - subConditions: ['n1s', 'n1p'], - }, - n1p: { - name: 'Noun, 1st declension, plural', - isDictionaryForm: true, - }, - n1s: { - name: 'Noun, 1st declension, singular', - isDictionaryForm: true, - }, - n2: { - name: 'Noun, 2nd declension', - isDictionaryForm: true, - subConditions: ['n2s', 'n2p'], - }, - n2p: { - name: 'Noun, 2nd declension, plural', - isDictionaryForm: true, - }, - n2s: { - name: 'Noun, 2nd declension, singular', - isDictionaryForm: true, - }, - n3: { - name: 'Noun, 3rd declension', - isDictionaryForm: true, - subConditions: ['n3s', 'n3p'], - }, - n3p: { - name: 'Noun, 3rd declension, plural', - isDictionaryForm: true, - }, - n3s: { - name: 'Noun, 3rd declension, singular', - isDictionaryForm: true, - }, - n4: { - name: 'Noun, 4th declension', - isDictionaryForm: true, - subConditions: ['n4s', 'n4p'], - }, - n4p: { - name: 'Noun, 4th declension, plural', - isDictionaryForm: true, - }, - n4s: { - name: 'Noun, 4th declension, singular', - isDictionaryForm: true, - }, - n5: { - name: 'Noun, 5th declension', - isDictionaryForm: true, - subConditions: ['n5s', 'n5p'], - }, - n5p: { - name: 'Noun, 5th declension, plural', - isDictionaryForm: true, - }, - n5s: { - name: 'Noun, 5th declension, singular', - isDictionaryForm: true, - }, - adj: { - name: 'Adjective', - isDictionaryForm: true, - subConditions: ['adj3', 'adj12'], - }, - adj12: { - name: 'Adjective, 1st-2nd declension', - isDictionaryForm: true, - }, - adj3: { - name: 'Adjective, 3rd declension', - isDictionaryForm: true, - }, - adv: { - name: 'Adverb', - isDictionaryForm: true, - }, - }, + conditions, transforms: { plural: { name: 'plural', diff --git a/ext/js/language/language-transforms.js b/ext/js/language/language-transforms.js index c7bfd8c0d1..cbf5063850 100644 --- a/ext/js/language/language-transforms.js +++ b/ext/js/language/language-transforms.js @@ -17,11 +17,12 @@ /** + * @template {string} TCondition * @param {string} inflectedSuffix * @param {string} deinflectedSuffix - * @param {string[]} conditionsIn - * @param {string[]} conditionsOut - * @returns {import('language-transformer').SuffixRule} + * @param {TCondition[]} conditionsIn + * @param {TCondition[]} conditionsOut + * @returns {import('language-transformer').SuffixRule} */ export function suffixInflection(inflectedSuffix, deinflectedSuffix, conditionsIn, conditionsOut) { const suffixRegExp = new RegExp(inflectedSuffix + '$'); @@ -36,11 +37,12 @@ export function suffixInflection(inflectedSuffix, deinflectedSuffix, conditionsI } /** + * @template {string} TCondition * @param {string} inflectedPrefix * @param {string} deinflectedPrefix - * @param {string[]} conditionsIn - * @param {string[]} conditionsOut - * @returns {import('language-transformer').Rule} + * @param {TCondition[]} conditionsIn + * @param {TCondition[]} conditionsOut + * @returns {import('language-transformer').Rule} */ export function prefixInflection(inflectedPrefix, deinflectedPrefix, conditionsIn, conditionsOut) { const prefixRegExp = new RegExp('^' + inflectedPrefix); @@ -54,11 +56,12 @@ export function prefixInflection(inflectedPrefix, deinflectedPrefix, conditionsI } /** + * @template {string} TCondition * @param {string} inflectedWord * @param {string} deinflectedWord - * @param {string[]} conditionsIn - * @param {string[]} conditionsOut - * @returns {import('language-transformer').Rule} + * @param {TCondition[]} conditionsIn + * @param {TCondition[]} conditionsOut + * @returns {import('language-transformer').Rule} */ export function wholeWordInflection(inflectedWord, deinflectedWord, conditionsIn, conditionsOut) { const regex = new RegExp('^' + inflectedWord + '$'); diff --git a/ext/js/language/sga/old-irish-transforms.js b/ext/js/language/sga/old-irish-transforms.js index 793c39a809..a700b2edc5 100644 --- a/ext/js/language/sga/old-irish-transforms.js +++ b/ext/js/language/sga/old-irish-transforms.js @@ -17,13 +17,15 @@ import {prefixInflection, suffixInflection} from '../language-transforms.js'; +/** @typedef {keyof typeof conditions} Condition */ + /** * @param {boolean} notBeginning * @param {string} originalOrthography * @param {string} alternateOrthography - * @param {string[]} conditionsIn - * @param {string[]} conditionsOut - * @returns {import('language-transformer').Rule} + * @param {Condition[]} conditionsIn + * @param {Condition[]} conditionsOut + * @returns {import('language-transformer').Rule} */ function tryAlternateOrthography(notBeginning, originalOrthography, alternateOrthography, conditionsIn, conditionsOut) { const orthographyRegExp = notBeginning ? new RegExp('(?} */ export const oldIrishTransforms = { language: 'sga', - conditions: {}, + conditions, transforms: { 'nd for nn': { name: 'nd for nn', diff --git a/ext/js/language/sq/albanian-transforms.js b/ext/js/language/sq/albanian-transforms.js index 0c6625c694..c533717808 100644 --- a/ext/js/language/sq/albanian-transforms.js +++ b/ext/js/language/sq/albanian-transforms.js @@ -17,12 +17,14 @@ import {suffixInflection} from '../language-transforms.js'; +/** @typedef {keyof typeof conditions} Condition */ + /** * @param {string} inflectedSuffix * @param {string} deinflectedSuffix - * @param {string[]} conditionsIn - * @param {string[]} conditionsOut - * @returns {import('language-transformer').Rule} + * @param {Condition[]} conditionsIn + * @param {Condition[]} conditionsOut + * @returns {import('language-transformer').Rule} */ function conjugationIISuffixInflection(inflectedSuffix, deinflectedSuffix, conditionsIn, conditionsOut) { return { @@ -32,36 +34,38 @@ function conjugationIISuffixInflection(inflectedSuffix, deinflectedSuffix, condi }; } -/** @type {import('language-transformer').LanguageTransformDescriptor} */ +const conditions = { + v: { + name: 'Verb', + isDictionaryForm: true, + }, + n: { + name: 'Noun', + isDictionaryForm: true, + subConditions: ['np', 'ns'], + }, + np: { + name: 'Noun plural', + isDictionaryForm: true, + }, + ns: { + name: 'Noun singular', + isDictionaryForm: true, + }, + adj: { + name: 'Adjective', + isDictionaryForm: true, + }, + adv: { + name: 'Adverb', + isDictionaryForm: true, + }, +}; + +/** @type {import('language-transformer').LanguageTransformDescriptor} */ export const albanianTransforms = { language: 'sq', - conditions: { - v: { - name: 'Verb', - isDictionaryForm: true, - }, - n: { - name: 'Noun', - isDictionaryForm: true, - subConditions: ['np', 'ns'], - }, - np: { - name: 'Noun plural', - isDictionaryForm: true, - }, - ns: { - name: 'Noun singular', - isDictionaryForm: true, - }, - adj: { - name: 'Adjective', - isDictionaryForm: true, - }, - adv: { - name: 'Adverb', - isDictionaryForm: true, - }, - }, + conditions, transforms: { // Nouns 'definite': { diff --git a/types/ext/language-descriptors.d.ts b/types/ext/language-descriptors.d.ts index a88f0f6611..97ae2a2d59 100644 --- a/types/ext/language-descriptors.d.ts +++ b/types/ext/language-descriptors.d.ts @@ -40,7 +40,7 @@ type LanguageDescriptor< readingNormalizer?: ReadingNormalizer; textPreprocessors?: TTextPreprocessorDescriptor; textPostprocessors?: TTextPostprocessorDescriptor; - languageTransforms?: LanguageTransformDescriptor; + languageTransforms?: LanguageTransformDescriptor; }; type TextProcessorDescriptor = { diff --git a/types/ext/language-transformer.d.ts b/types/ext/language-transformer.d.ts index cf5a004106..2e448f3751 100644 --- a/types/ext/language-transformer.d.ts +++ b/types/ext/language-transformer.d.ts @@ -15,16 +15,18 @@ * along with this program. If not, see . */ -export type LanguageTransformDescriptor = { +export type LanguageTransformDescriptor = { language: string; - conditions: ConditionMapObject; - transforms: { - [name: string]: Transform; - }; + conditions: ConditionMapObject; + transforms: TransformMapObject; }; -export type ConditionMapObject = { - [type: string]: Condition; +export type ConditionMapObject = { + [type in TCondition]: Condition; +}; + +export type TransformMapObject = { + [name: string]: Transform; }; export type ConditionMapEntry = [type: string, condition: Condition]; @@ -43,11 +45,11 @@ export type RuleI18n = { name: string; }; -export type Transform = { +export type Transform = { name: string; description?: string; i18n?: TransformI18n[]; - rules: Rule[]; + rules: Rule[]; }; export type TransformI18n = { @@ -56,19 +58,33 @@ export type TransformI18n = { description?: string; }; -export type Rule = { +export type Rule = { type: 'suffix' | 'prefix' | 'wholeWord' | 'other'; isInflected: RegExp; deinflect: (inflectedWord: string) => string; - conditionsIn: string[]; - conditionsOut: string[]; + conditionsIn: TCondition[]; + conditionsOut: TCondition[]; }; -export type SuffixRule = { +export type SuffixRule = { type: 'suffix'; isInflected: RegExp; deinflected: string; deinflect: (inflectedWord: string) => string; - conditionsIn: string[]; - conditionsOut: string[]; + conditionsIn: TCondition[]; + conditionsOut: TCondition[]; }; + +export type InflectionBase = ( + inflected: string, + deinflected: string, + conditionsIn: TCondition[], + conditionsOut: TCondition[] +) => Rule; + +export type SuffixInflectionBase = ( + inflected: string, + deinflected: string, + conditionsIn: TCondition[], + conditionsOut: TCondition[] +) => SuffixRule; diff --git a/types/ext/language.d.ts b/types/ext/language.d.ts index ccc668af99..f613469d10 100644 --- a/types/ext/language.d.ts +++ b/types/ext/language.d.ts @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +import {SafeAny} from 'core.js'; import type {LanguageTransformDescriptor} from './language-transformer.js'; export type TextProcessorOptions = T[]; @@ -52,7 +53,7 @@ export type LanguageAndReadingNormalizer = { export type LanguageAndTransforms = { iso: string; - languageTransforms: LanguageTransformDescriptor; + languageTransforms: LanguageTransformDescriptor; }; export type TextProcessorWithId = {