(grammar) allow different cells depending on plural conjugation

This commit is contained in:
Valentyne Stigloher 2025-05-01 11:07:23 +02:00
parent f6c919bfbf
commit 4d0a24a2a4
6 changed files with 47 additions and 107 deletions

View File

@ -15,22 +15,29 @@ const variantsFromBaseConverter = await loadGrammarTableVariantsConverter();
const expandVariantsForSection = (sectionVariants: SectionDefinition['variants']): Variant[] => {
if (Array.isArray(sectionVariants)) {
return sectionVariants.map((sectionVariant) => {
const cells = sectionVariant.morphemeCells.map((morphemeCell) => {
if (morphemeCell === null) {
const cells = sectionVariant.morphemeCells.map((cellDefinition) => {
if (cellDefinition === null) {
return [];
}
if (typeof morphemeCell === 'string') {
return [{ morpheme: morphemeCell }];
if (typeof cellDefinition === 'string') {
return [{ morpheme: cellDefinition }];
}
const morphemeDisplayDefinitions = Array.isArray(morphemeCell) ? morphemeCell : [morphemeCell];
return morphemeDisplayDefinitions.map((morphemeCell) => ({
...morphemeCell,
prefix: morphemeCell.prefix ? toMorphemeValue(morphemeCell.prefix) : undefined,
suffix: morphemeCell.suffix ? toMorphemeValue(morphemeCell.suffix) : undefined,
highlightsMorphemes: morphemeCell.highlightsMorphemes
? new Set(morphemeCell.highlightsMorphemes)
: undefined,
}));
const cellPartDefinitions = Array.isArray(cellDefinition) ? cellDefinition : [cellDefinition];
return cellPartDefinitions
.map((cellPartDefinition) => {
if ('singular' in cellPartDefinition) {
return cellPartDefinition[!props.exampleValues.plural ? 'singular' : 'plural'];
}
return cellPartDefinition;
})
.map((cellPartDefinition) => ({
...cellPartDefinition,
prefix: cellPartDefinition.prefix ? toMorphemeValue(cellPartDefinition.prefix) : undefined,
suffix: cellPartDefinition.suffix ? toMorphemeValue(cellPartDefinition.suffix) : undefined,
highlightsMorphemes: cellPartDefinition.highlightsMorphemes
? new Set(cellPartDefinition.highlightsMorphemes)
: undefined,
}));
});
return { ...sectionVariant, cells };
});

View File

@ -103,11 +103,29 @@ pronouns:
-
morphemeCells:
-
morpheme: 'verb_middle_inter'
prefix: ''
singular:
morpheme: 'verb_middle_inter'
prefix: ''
suffix: 'm'
plural:
morpheme: 'verb_middle_inter'
prefix: ''
suffix:
spelling: 'śmy'
pronunciation: 'ɕmɨ'
-
morpheme: 'verb_middle_inter'
prefix: ''
singular:
morpheme: 'verb_middle_inter'
prefix: ''
suffix:
spelling: 'ś'
pronunciation: 'ɕ'
plural:
morpheme: 'verb_middle_inter'
prefix: ''
suffix:
spelling: 'ście'
pronunciation: 'ɕʨ̑ɛ'
-
morpheme: 'verb_end_about'
prefix: ''

View File

@ -1,88 +0,0 @@
<template>
<section>
<h2 class="h4">
<Icon v="spell-check" />
Odmiana:
</h2>
<div class="table-responsive">
<table class="table table-sm">
<thead>
<tr>
<th>Mianownik</th>
<th>Dopełniacz</th>
<th>Celownik</th>
<th>Biernik</th>
<th>Narzędnik</th>
<th>Miejscownik</th>
</tr>
</thead>
<tbody>
<tr>
<td><PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="pronoun_n" :counter="counter" /></td>
<td><PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="pronoun_g" :counter="counter" /> / <PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="pronoun_g_acc" :counter="counter" /> / <PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="pronoun_g_prep" :counter="counter" /></td>
<td><PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="pronoun_d" :counter="counter" /> / <PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="pronoun_d_acc" :counter="counter" /> / <PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="pronoun_d_prep" :counter="counter" /></td>
<td><PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="pronoun_a" :counter="counter" /> / <PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="pronoun_a_acc" :counter="counter" /> / <PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="pronoun_a_prep" :counter="counter" /></td>
<td><PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="pronoun_i" :counter="counter" /></td>
<td><PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="pronoun_l" :counter="counter" /></td>
</tr>
</tbody>
</table>
</div>
<p class="small">
Skąd w polszczyźnie tyle różnych form zaimków? Zapraszamy do lektury artykułu:
<nuxt-link to="/jak-działają-zaimki">
Co warto wiedzieć o używaniu (i tworzeniu) zaimków?
</nuxt-link>
</p>
<div class="table-responsive">
<table class="table table-sm">
<thead>
<tr>
<th>1 os.</th>
<th>2 os.</th>
<th>3 os.</th>
<th>Przymiotniki</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<PronounsMorphemeWithPronunciation
:pronoun="selectedPronoun"
morpheme="verb_middle_inter"
:counter="counter"
prepend=""
:append="selectedPronoun.isPlural(counter) ? 'śmy' : 'm'"
:append-pr="selectedPronoun.isPlural(counter) ? 'ɕmɨ' : 'm'"
/>
</td>
<td>
<PronounsMorphemeWithPronunciation
:pronoun="selectedPronoun"
morpheme="verb_middle_inter"
:counter="counter"
prepend=""
:append="selectedPronoun.isPlural(counter) ? 'ście' : 'ś'"
:append-pr="selectedPronoun.isPlural(counter) ? 'ɕʨ̑ɛ' : 'ɕ'"
/>
</td>
<td><PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="verb_end_about" :counter="counter" prepend="" /></td>
<td><PronounsMorphemeWithPronunciation :pronoun="selectedPronoun" morpheme="adjective_n" :counter="counter" prepend="" /></td>
</tr>
</tbody>
</table>
</div>
</section>
</template>
<script>
export default {
props: {
selectedPronoun: { required: true },
counter: { required: true },
},
};
</script>

View File

@ -514,7 +514,7 @@ export class Pronoun {
}
toExampleValues(counter = 0): ExampleValues {
return { morphemeValues: this.toMorphemeValues(counter) };
return { morphemeValues: this.toMorphemeValues(counter), plural: this.isPlural(counter) };
}
isInterchangable(morpheme: string): boolean {

View File

@ -21,6 +21,7 @@ interface ExamplePartNoun {
export interface ExampleValues {
morphemeValues: MorphemeValues;
plural?: boolean;
nounConvention?: NounConvention;
nounDeclensions?: Record<string, NounDeclension>;
}

View File

@ -20,7 +20,7 @@ export interface SectionDefinition {
export interface VariantDefinition {
name?: string;
morphemeCells: (string | MorphemeCellDefinition | MorphemeCellDefinition[] | null)[];
morphemeCells: (string | CellPartDefinition | CellPartDefinition[] | null)[];
}
export interface VariantsFromBaseDefinition {
@ -30,6 +30,8 @@ export interface VariantsFromBaseDefinition {
export type VariantsFromBaseConverter = Record<string, (variantsDefinition: VariantsFromBaseDefinition) => Variant[]>;
type CellPartDefinition = MorphemeCellDefinition | Record<'singular' | 'plural', MorphemeCellDefinition>;
export interface MorphemeCellDefinition {
morpheme: string;
highlightsMorphemes?: string[];