close
Skip to content

[paradigm dictionary] remove code from dictionary mode paradigm definition files #520

@jonorthwash

Description

@jonorthwash

Could the parseTags() and lngPlugin() functions in the dictionary mode paradigm definition files (e.g., below) be made general and moved to language-agnostic code. It would be great, if needed, to add some variables in their place that the language-agnostic code could make use of.

export function parseTags(origTags: string[], cellTags: string): string[] {
const parts = cellTags.split('.');
const first = origTags[0] || '';
if (first === 'np' || first.startsWith('np.')) return [...origTags, ...parts];
if (first.startsWith('v')) return [...origTags, ...parts];
if (parts.length === 3 && parts[0] === 'pl') return ['n', 'pl', parts[1], parts[2]];
if (parts.length === 2 && parts[0].startsWith('px')) return ['n', parts[0], parts[1]];
if (parts.length === 2 && parts[0] === 'pl') return ['n', 'pl', parts[1]];
return ['n', parts[0]];
}
const defaultLangKey = Object.keys(uumLabels)[0];
const defaultModes = uumLabels[defaultLangKey];
export const uumPlugin: LanguagePlugin = {
backendLangCode: 'uum',
getAvailableModes(locale: string): string[] {
const code = locale.split('-')[0].toLowerCase();
const modesForLang = uumLabels[code] ?? defaultModes;
return Object.keys(modesForLang);
},
addParadigms({ head, mode, locale, t, apyFetch }: AddParadigmsArgs): ParadigmBlock[] {
const code = locale.split('-')[0].toLowerCase();
const modesForLang = uumLabels[code] ?? defaultModes;
const modeKeys = Object.keys(modesForLang);
const fallbackMode = modeKeys[0];
const labelsForMode = modesForLang[mode] ?? modesForLang[fallbackMode];
const blocksMap = add_uum({ labels: labelsForMode, t });
const origTags = Array.from(head.matchAll(/<([^>]+)>/g), (m) => m[1]);
let key: string | undefined;
if (origTags.includes('iv')) key = 'verb_iv';
else if (origTags.includes('tv')) key = 'verb_tv';
else if (origTags.some((tag) => tag.startsWith('v'))) key = 'vaux';
else if (origTags.some((tag) => tag.startsWith('np.'))) key = 'pnoun';
else if (origTags[0] === 'n') key = 'noun';
if (!key) return [];
return blocksMap[key] || [];
},
parseTags,
};

In the end, we want the language-specific paradigm definition files to a bunch of definitions that someone can edit easily, so anything that needs to be done algorithmically should be done elsewhere, only drawing data from these files. For example, if tags need to be excluded in a language-specific way, define the tags here and write the function for excluding them elsewhere.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions