mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-08-03 11:07:00 -04:00
(refactor)(nouns) move cases.ts into nounsData.suml
This commit is contained in:
parent
dc1ee7424e
commit
71499f3f9a
@ -33,20 +33,24 @@ const declension = computed(() => {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const declension = nounsData.declensions[template.value.declension];
|
const declension = nounsData.declensions?.[template.value.declension];
|
||||||
if (!declension[numerus.value]) {
|
if (declension?.[numerus.value] === undefined || nounsData.classExample?.[numerus.value] === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const entries = Object.entries(declension[numerus.value] ?? {}).map(([caseAbbreviation, declensionSuffix]) => {
|
const entries = Object.entries(declension[numerus.value] ?? {}).map(([caseAbbreviation, declensionSuffix]) => {
|
||||||
return [caseAbbreviation.toUpperCase() + (props.plural ? '_pl' : ''),
|
const article = nounsData.classExample?.[numerus.value][caseAbbreviation]
|
||||||
nounsData.classExample[numerus.value][caseAbbreviation].replace(/\{([^}]+)}/, (_match, morpheme) => {
|
.replace(/\{([^}]+)}/, (_match, morpheme) => {
|
||||||
const value = props.nounConvention.morphemes[morpheme];
|
const value = props.nounConvention.morphemes[morpheme];
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return typeof value === 'string' ? value : value.spelling;
|
return typeof value === 'string' ? value : value.spelling;
|
||||||
}) + stem.value + template.value.suffix + declensionSuffix];
|
}) ?? '';
|
||||||
|
return [
|
||||||
|
caseAbbreviation.toUpperCase() + (props.plural ? '_pl' : ''),
|
||||||
|
article + stem.value + template.value.suffix + declensionSuffix,
|
||||||
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
return new NounDeclension(Object.fromEntries(entries));
|
return new NounDeclension(Object.fromEntries(entries));
|
||||||
|
@ -36,12 +36,12 @@ const examples = computed(() => {
|
|||||||
if (exampleValues.value === undefined) {
|
if (exampleValues.value === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return nounsData?.examples.map((example) => Example.parse(example))
|
return nounsData.examples?.map((example) => Example.parse(example))
|
||||||
.filter((example) => example.areRequiredExampleValuesPresent(exampleValues.value!));
|
.filter((example) => example.areRequiredExampleValuesPresent(exampleValues.value!));
|
||||||
});
|
});
|
||||||
|
|
||||||
const nounConventionGroup = computed(() => {
|
const nounConventionGroup = computed(() => {
|
||||||
return Object.values(nounsData.groups).find((nounConventionGroup) => {
|
return Object.values(nounsData.groups ?? []).find((nounConventionGroup) => {
|
||||||
return nounConventionGroup.conventions.includes(props.nounConvention.key);
|
return nounConventionGroup.conventions.includes(props.nounConvention.key);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -5,7 +5,7 @@ const nounsData = await loadNounsData();
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ul v-if="nounsData" class="list-group mt-4">
|
<ul v-if="nounsData.groups" class="list-group mt-4">
|
||||||
<li
|
<li
|
||||||
v-for="nounConventionGroup of withKey(nounsData.groups)"
|
v-for="nounConventionGroup of withKey(nounsData.groups)"
|
||||||
:key="nounConventionGroup.key"
|
:key="nounConventionGroup.key"
|
||||||
|
@ -11,7 +11,7 @@ if (nounsData === undefined) {
|
|||||||
throw new Error('nounsData is undefined');
|
throw new Error('nounsData is undefined');
|
||||||
}
|
}
|
||||||
const visibleNounConventions = computed(() => {
|
const visibleNounConventions = computed(() => {
|
||||||
return withKey(nounsData.conventions).filter((nounConvention) => {
|
return withKey(nounsData.conventions ?? {}).filter((nounConvention) => {
|
||||||
return props.nounConventionGroup.conventions.includes(nounConvention.key);
|
return props.nounConventionGroup.conventions.includes(nounConvention.key);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -24,10 +24,10 @@ const stem = computed(() => {
|
|||||||
return stems[template.stem ?? 'default'];
|
return stems[template.stem ?? 'default'];
|
||||||
});
|
});
|
||||||
|
|
||||||
const declension = nounsData.declensions[template.declension];
|
const declension = nounsData.declensions?.[template.declension];
|
||||||
|
|
||||||
const singularExample = computed(() => {
|
const singularExample = computed(() => {
|
||||||
if (declension.singular?.n === undefined) {
|
if (declension?.singular?.n === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ const singularExample = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const pluralExample = computed(() => {
|
const pluralExample = computed(() => {
|
||||||
if (declension.plural?.n === undefined) {
|
if (declension?.plural?.n === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { NounDeclension } from '~/src/classes.ts';
|
import type { NounDeclension } from '~/src/classes.ts';
|
||||||
import { loadNounDeclensionTemplates, loadNounCases } from '~/src/data.ts';
|
import { loadNounDeclensionTemplates, loadNounsData } from '~/src/data.ts';
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
word: string;
|
word: string;
|
||||||
@ -14,7 +14,7 @@ const props = withDefaults(defineProps<{
|
|||||||
plural: false,
|
plural: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [nounDeclensionTemplates, cases] = await Promise.all([loadNounDeclensionTemplates(), loadNounCases()]);
|
const [nounsData, nounDeclensionTemplates] = await Promise.all([loadNounsData(), loadNounDeclensionTemplates()]);
|
||||||
|
|
||||||
const visible = ref(props.open);
|
const visible = ref(props.open);
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ const findTemplate = (): NounDeclension | null => {
|
|||||||
>
|
>
|
||||||
<strong>
|
<strong>
|
||||||
{{ caseName }}
|
{{ caseName }}
|
||||||
<small v-if="!condense">({{ cases[caseName] }})</small>
|
<small v-if="!condense">({{ nounsData.cases?.[caseName.toLowerCase()] }})</small>
|
||||||
</strong>
|
</strong>
|
||||||
{{ declined.join(' / ') }}
|
{{ declined.join(' / ') }}
|
||||||
</li>
|
</li>
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
export default {
|
|
||||||
N: 'wer? was?',
|
|
||||||
G: 'wessen?',
|
|
||||||
D: 'wem?',
|
|
||||||
A: 'wen? was?',
|
|
||||||
};
|
|
@ -1,3 +1,9 @@
|
|||||||
|
cases:
|
||||||
|
n: 'wer? was?'
|
||||||
|
g: 'wessen?'
|
||||||
|
d: 'wem?'
|
||||||
|
a: 'wen? was?'
|
||||||
|
|
||||||
morphemes:
|
morphemes:
|
||||||
- 'article_n'
|
- 'article_n'
|
||||||
- 'article_g'
|
- 'article_g'
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
export default {
|
|
||||||
M: 'kto? co?',
|
|
||||||
D: 'kogo? czego?',
|
|
||||||
C: 'komu? czemu?',
|
|
||||||
B: 'kogo? co?',
|
|
||||||
N: 'z kim? z czym?',
|
|
||||||
Msc: 'o kim? o czym?',
|
|
||||||
W: 'o!',
|
|
||||||
};
|
|
8
locale/pl/nouns/nounsData.suml
Normal file
8
locale/pl/nouns/nounsData.suml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
cases:
|
||||||
|
m: 'kto? co?'
|
||||||
|
d: 'kogo? czego?'
|
||||||
|
c: 'komu? czemu?'
|
||||||
|
b: 'kogo? co?'
|
||||||
|
n: 'z kim? z czym?'
|
||||||
|
msc: 'o kim? o czym?'
|
||||||
|
w: 'o!'
|
@ -1,9 +0,0 @@
|
|||||||
export default {
|
|
||||||
M: 'kto? co?',
|
|
||||||
D: 'kogo? czego?',
|
|
||||||
C: 'komu? czemu?',
|
|
||||||
B: 'kogo? co?',
|
|
||||||
N: 'z kim? z czym?',
|
|
||||||
Msc: 'o kim? o czym?',
|
|
||||||
W: 'o!',
|
|
||||||
};
|
|
@ -1,9 +0,0 @@
|
|||||||
export default {
|
|
||||||
M: 'kto? co?',
|
|
||||||
D: 'kogo? czego?',
|
|
||||||
C: 'komu? czemu?',
|
|
||||||
B: 'kogo? co?',
|
|
||||||
N: 'z kim? z czym?',
|
|
||||||
Msc: 'o kim? o czym?',
|
|
||||||
W: 'o!',
|
|
||||||
};
|
|
@ -25,7 +25,7 @@ const findNounConvention = async (path: string, config: Config) => {
|
|||||||
|
|
||||||
const nounsData = await loadNounsData();
|
const nounsData = await loadNounsData();
|
||||||
|
|
||||||
return withKey(nounsData?.conventions ?? {})
|
return withKey(nounsData.conventions ?? {})
|
||||||
.find((nounConvention) => nounConvention.key === path);
|
.find((nounConvention) => nounConvention.key === path);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
12
src/data.ts
12
src/data.ts
@ -64,11 +64,11 @@ export const loadPronounLibrary = async (config: Config) => {
|
|||||||
return new PronounLibrary(config, pronounGroups, pronouns);
|
return new PronounLibrary(config, pronounGroups, pronouns);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loadNounsData = async (): Promise<NounsData | undefined> => {
|
export const loadNounsData = async (): Promise<NounsData> => {
|
||||||
try {
|
try {
|
||||||
return (await import(`~/locale/${getLocale()}/nouns/nounsData.suml`)).default;
|
return (await import(`~/locale/${getLocale()}/nouns/nounsData.suml`)).default;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return undefined;
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -109,14 +109,6 @@ export const loadNounAbbreviations = async (): Promise<Record<string, string>> =
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loadNounCases = async () => {
|
|
||||||
try {
|
|
||||||
return (await import(`~/locale/${getLocale()}/nouns/cases.ts`)).default;
|
|
||||||
} catch (error) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const loadPeople = async () => {
|
export const loadPeople = async () => {
|
||||||
const peopleRaw = (await import(`~/locale/${getLocale()}/people/people.tsv`)).default;
|
const peopleRaw = (await import(`~/locale/${getLocale()}/people/people.tsv`)).default;
|
||||||
return buildList(function* () {
|
return buildList(function* () {
|
||||||
|
17
src/nouns.ts
17
src/nouns.ts
@ -68,12 +68,13 @@ export interface NounDeclension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface NounsData {
|
export interface NounsData {
|
||||||
morphemes: string[];
|
cases?: Record<string, string>;
|
||||||
examples: string[];
|
morphemes?: string[];
|
||||||
grammarTables: GrammarTableDefinition[];
|
examples?: string[];
|
||||||
classes: Record<string, NounClass>;
|
grammarTables?: GrammarTableDefinition[];
|
||||||
classExample: NounClassExample;
|
classes?: Record<string, NounClass>;
|
||||||
declensions: Record<string, NounDeclension>;
|
classExample?: NounClassExample;
|
||||||
groups: Record<string, NounConventionGroup>;
|
declensions?: Record<string, NounDeclension>;
|
||||||
conventions: Record<string, NounConvention>;
|
groups?: Record<string, NounConventionGroup>;
|
||||||
|
conventions?: Record<string, NounConvention>;
|
||||||
}
|
}
|
||||||
|
@ -163,32 +163,64 @@ describe.each(allLocales)('data files of $code', async ({ code }) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.nouns.conventions?.enabled) {
|
let nounsData: NounsData | undefined;
|
||||||
const nounsData = await loadSuml<NounsData>(`locale/${code}/nouns/nounsData.suml`);
|
try {
|
||||||
|
nounsData = await loadSuml<NounsData>(`locale/${code}/nouns/nounsData.suml`);
|
||||||
|
} catch (error) {
|
||||||
|
nounsData = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.nouns.enabled && config.nouns.conventions?.enabled) {
|
||||||
|
test('config.nouns.conventions.enabled requires properties in nouns/nounsData.suml', () => {
|
||||||
|
expect(nounsData?.morphemes).toBeDefined();
|
||||||
|
expect(nounsData?.conventions).toBeDefined();
|
||||||
|
expect(nounsData?.groups).toBeDefined();
|
||||||
|
expect(nounsData?.classes).toBeDefined();
|
||||||
|
expect(nounsData?.classExample).toBeDefined();
|
||||||
|
expect(nounsData?.examples).toBeDefined();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nounsData) {
|
||||||
describe('nouns/nounsData.suml', () => {
|
describe('nouns/nounsData.suml', () => {
|
||||||
test('has valid variant types', async () => {
|
if (nounsData.grammarTables) {
|
||||||
const grammarTableVariantsConverter = (await import(`~/locale/${code}/language/grammarTableVariantsConverter.ts`)).default as VariantsFromBaseConverter;
|
test('grammar tables have valid variant types', async () => {
|
||||||
|
const grammarTableVariantsConverter = (await import(`~/locale/${code}/language/grammarTableVariantsConverter.ts`)).default as VariantsFromBaseConverter;
|
||||||
|
|
||||||
for (const grammarTable of nounsData.grammarTables) {
|
for (const grammarTable of nounsData.grammarTables!) {
|
||||||
for (const section of grammarTable.sections) {
|
for (const section of grammarTable.sections) {
|
||||||
if (!Array.isArray(section.variants)) {
|
if (!Array.isArray(section.variants)) {
|
||||||
expect(Object.keys(grammarTableVariantsConverter)).toContain(section.variants.type);
|
expect(Object.keys(grammarTableVariantsConverter)).toContain(section.variants.type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
test('has valid morphemes', () => {
|
if (nounsData.conventions) {
|
||||||
for (const convention of Object.values(nounsData.conventions)) {
|
test('conventions have valid morphemes', () => {
|
||||||
expect(nounsData.morphemes)
|
for (const convention of Object.values(nounsData.conventions!)) {
|
||||||
.toEqual(expect.arrayContaining(Object.keys(convention.morphemes)));
|
expect(nounsData.morphemes)
|
||||||
}
|
.toEqual(expect.arrayContaining(Object.keys(convention.morphemes)));
|
||||||
});
|
}
|
||||||
test('groups reference conventions by key', () => {
|
});
|
||||||
for (const group of Object.values(nounsData.groups)) {
|
}
|
||||||
expect(Object.keys(nounsData.conventions)).toEqual(expect.arrayContaining(group.conventions));
|
if (nounsData.conventions && nounsData.groups) {
|
||||||
}
|
test('convention groups reference conventions by key', () => {
|
||||||
});
|
for (const group of Object.values(nounsData.groups!)) {
|
||||||
|
expect(Object.keys(nounsData.conventions!)).toEqual(expect.arrayContaining(group.conventions));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (nounsData.cases && nounsData.declensions) {
|
||||||
|
test('declensions have valid cases', () => {
|
||||||
|
for (const declension of Object.values(nounsData.declensions!)) {
|
||||||
|
for (const numerus of ['singular', 'plural'] as const) {
|
||||||
|
expect(Object.keys(nounsData.cases!))
|
||||||
|
.toEqual(expect.arrayContaining(Object.keys(declension[numerus] ?? {})));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user