From 5aa83aa1f0deda8a7202b95c439d05207a9d68d0 Mon Sep 17 00:00:00 2001 From: Valentyne Stigloher Date: Sun, 13 Apr 2025 22:17:47 +0200 Subject: [PATCH] (nouns) filter example sentences missing required morphemes or declensions --- components/ExampleCategoryListItem.vue | 11 +++-------- components/MorphemeWithPronunciation.vue | 2 +- .../pronouns/PronounsMorphemeWithPronunciation.vue | 2 +- locale/de/pronouns/GrammarTables.vue | 2 +- locale/it/pronouns/GrammarTables.vue | 2 +- pages/nouns/[convention].vue | 6 +++++- server/pronouns.ts | 3 +-- src/classes.ts | 6 +++++- src/language/examples.ts | 5 ++--- test/classes.test.ts | 6 +++--- 10 files changed, 23 insertions(+), 22 deletions(-) diff --git a/components/ExampleCategoryListItem.vue b/components/ExampleCategoryListItem.vue index bb2d6f09a..1b4bc6f6d 100644 --- a/components/ExampleCategoryListItem.vue +++ b/components/ExampleCategoryListItem.vue @@ -24,18 +24,13 @@ const example = computed(() => { const pronoun = ref(); -const exampleValues = computed(() => { - if (pronoun.value === undefined) { - return undefined; - } - return { morphemeValues: pronoun.value.toMorphemeValues(props.counter) }; -}); +const exampleValues = computed(() => pronoun.value?.toExampleValues(props.counter)); const suitablePronounExamples = computed((): PronounExample[] => { return props.exampleCategory.examples.filter((pronounExample) => { return props.pronounsChoice.some((pronoun) => { const example = pronounExample.example(pronoun, props.counter); - return example.requiredMorphemesPresent(pronoun.toMorphemeValues(props.counter)); + return example.areRequiredExampleValuesPresent(pronoun.toExampleValues(props.counter)); }); }); }); @@ -64,7 +59,7 @@ const selectDifferentExample = (): void => { const selectPronounForExample = (forceDifferent: boolean): void => { const suitablePronouns = props.pronounsChoice.filter((otherPronoun) => { - return example.value.requiredMorphemesPresent(otherPronoun.toMorphemeValues()) && + return example.value.areRequiredExampleValuesPresent(otherPronoun.toExampleValues()) && (!forceDifferent || otherPronoun !== toRaw(pronoun.value)); }); pronoun.value = randomItem(suitablePronouns); diff --git a/components/MorphemeWithPronunciation.vue b/components/MorphemeWithPronunciation.vue index 253a8d31f..b18c52513 100644 --- a/components/MorphemeWithPronunciation.vue +++ b/components/MorphemeWithPronunciation.vue @@ -30,7 +30,7 @@ const pronunciation = computed(() => { const visibleExamples = computed(() => { return props.examples?.filter((example) => { - return example.requiredMorphemesPresent(props.exampleValues.morphemeValues) && + return example.areRequiredExampleValuesPresent(props.exampleValues) && [...props.highlightsMorphemes.values()].some((morpheme) => example.hasMorpheme(morpheme)); }); }); diff --git a/components/pronouns/PronounsMorphemeWithPronunciation.vue b/components/pronouns/PronounsMorphemeWithPronunciation.vue index 6c9214df0..9eb65f36f 100644 --- a/components/pronouns/PronounsMorphemeWithPronunciation.vue +++ b/components/pronouns/PronounsMorphemeWithPronunciation.vue @@ -33,7 +33,7 @@ const examples = computed((): Example[] => {