From aee3257ea3020ca23fff35f1c7d129db4157a622 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Sun, 4 Jul 2021 12:55:26 +0300 Subject: [PATCH] very beta functionality for showing the English transations of sentences in the conjugation viewer. To do this you need to have a verb with the 'ec' field showing the English conjugation info from the dictionary. --- package.json | 2 +- src/App.tsx | 3 +- src/components/ConjugationViewer.tsx | 6 +- src/components/verb-info/VerbInfo.tsx | 22 +- src/lib/add-pronouns.ts | 34 +- src/lib/conjugation-forms.tsx | 997 +++++++++++++++----------- src/lib/grammar-units.ts | 25 + src/lib/misc-helpers.test.ts | 18 + src/lib/misc-helpers.ts | 24 + src/types.ts | 8 + 10 files changed, 710 insertions(+), 429 deletions(-) create mode 100644 src/lib/misc-helpers.test.ts diff --git a/package.json b/package.json index d7f5c00..d4aaac0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "0.4.6", + "version": "0.4.7", "author": "lingdocs.com", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "homepage": "https://verbs.lingdocs.com", diff --git a/src/App.tsx b/src/App.tsx index f74a536..a8d9fbc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -40,7 +40,7 @@ const transitivities: T.Transitivity[] = [ "grammatically transitive", ]; -const allVerbs = verbs.map((v: any) => ({ +const allVerbs = verbs.map((v: { entry: T.DictionaryEntry, complement?: T.DictionaryEntry }) => ({ verb: v, info: getVerbInfo(v.entry, v.complement), })); @@ -311,6 +311,7 @@ function App() { {conjugation && } diff --git a/src/components/ConjugationViewer.tsx b/src/components/ConjugationViewer.tsx index c79ca9c..b1fbaf6 100644 --- a/src/components/ConjugationViewer.tsx +++ b/src/components/ConjugationViewer.tsx @@ -17,6 +17,7 @@ import { personIsAllowed, randomPerson, incrementPerson, + parseEc, } from "../lib/misc-helpers"; import * as T from "../types"; @@ -170,9 +171,10 @@ const initialState: State = { formsOpened: [], }; -function ConjugationViewer({ conjugation, textOptions }: { +function ConjugationViewer({ conjugation, textOptions, ec }: { conjugation: T.VerbOutput, textOptions: T.TextOptions, + ec?: string | undefined, }) { const [state, dispatch] = useReducer(reducer, initialState); useEffect(() => { @@ -194,6 +196,7 @@ function ConjugationViewer({ conjugation, textOptions }: { const verbConj = (verbConj1.singularForm && state.compoundComplementVersionSelected === "sing") ? verbConj1.singularForm : verbConj1; + const englishConjugation = parseEc(ec); useEffect(() => { localStorage.setItem(stateLocalStorageName, JSON.stringify(state)); @@ -209,6 +212,7 @@ function ConjugationViewer({ conjugation, textOptions }: { subject: state.subject, object: state.object, negative: state.negative, + englishConjugation, }); return
{"transitive" in conjugation &&
diff --git a/src/components/verb-info/VerbInfo.tsx b/src/components/verb-info/VerbInfo.tsx index d92303c..54824c1 100644 --- a/src/components/verb-info/VerbInfo.tsx +++ b/src/components/verb-info/VerbInfo.tsx @@ -29,15 +29,21 @@ const indentR = { paddingLeft: "1rem", }; +const highlight = { + background: "yellow", +}; + const title: CSSProperties = { fontWeight: "bolder", marginBottom: "0.5rem", marginTop: "0.5rem", }; -export function RootsAndStems({ textOptions, info }: { +export function RootsAndStems({ textOptions, info, hidePastParticiple, highlighted }: { textOptions: T.TextOptions, info: T.NonComboVerbInfo, + hidePastParticiple?: boolean, + highlighted?: ("imperfective root" | "perfective root" | "imperfective stem" | "perfective stem" | "past participle")[], }) { const hasPerfectiveSplit = !!(info.root.perfectiveSplit || info.stem.perfectiveSplit); const showPersInf = hasPersInfs(info); @@ -64,7 +70,7 @@ export function RootsAndStems({ textOptions, info }: { margin: "0 auto", backgroundImage: `url(${fadedTree})`, backgroundRepeat: "no-repeat", - backgroundPosition: "50% 35%", + backgroundPosition: hidePastParticiple ? "50% 45%" : "50% 35%", backgroundSize: "50%", }}> {/*
-
+
Imperfective Stem
@@ -115,7 +121,7 @@ export function RootsAndStems({ textOptions, info }: { />
-
+
Perfective Stem
@@ -129,7 +135,7 @@ export function RootsAndStems({ textOptions, info }: {
-
+
Imperfective Root
@@ -140,7 +146,7 @@ export function RootsAndStems({ textOptions, info }: { />
-
+
Perfective Root
@@ -154,13 +160,13 @@ export function RootsAndStems({ textOptions, info }: {
-
+ {!hidePastParticiple &&
Past Participle
-
+
}
diff --git a/src/lib/add-pronouns.ts b/src/lib/add-pronouns.ts index 39564cf..8f5dea8 100644 --- a/src/lib/add-pronouns.ts +++ b/src/lib/add-pronouns.ts @@ -63,7 +63,7 @@ type Pronouns = undefined | { const nuParticle = { p: "نه", f: "nú" }; -export default function addPronouns({ s, subject, object, info, displayForm, intransitive, ergative, matrixKey, negative }: { +export default function addPronouns({ s, subject, object, info, displayForm, intransitive, ergative, matrixKey, englishConjugation, negative }: { s: T.SentenceForm, subject: T.Person, object: T.Person, @@ -73,13 +73,14 @@ export default function addPronouns({ s, subject, object, info, displayForm, int ergative: boolean, matrixKey: T.PersonInflectionsField, negative: boolean, + englishConjugation?: T.EnglishVerbConjugation, }): T.SentenceForm { if ("long" in s) { return { - long: addPronouns({ s: s.long, subject, object, info, displayForm, intransitive, ergative, matrixKey, negative }) as T.ArrayOneOrMore, - short: addPronouns({ s: s.short, subject, object, info, displayForm, intransitive, ergative, matrixKey, negative }) as T.ArrayOneOrMore, + long: addPronouns({ s: s.long, subject, object, info, displayForm, intransitive, ergative, matrixKey, englishConjugation, negative }) as T.ArrayOneOrMore, + short: addPronouns({ s: s.short, subject, object, info, displayForm, intransitive, ergative, matrixKey, englishConjugation, negative }) as T.ArrayOneOrMore, ...s.mini ? { - mini: addPronouns({ s: s.mini, subject, object, info, displayForm, intransitive, ergative, matrixKey, negative }) as T.ArrayOneOrMore, + mini: addPronouns({ s: s.mini, subject, object, info, displayForm, intransitive, ergative, matrixKey, englishConjugation, negative }) as T.ArrayOneOrMore, } : {}, } } @@ -124,6 +125,11 @@ export default function addPronouns({ s, subject, object, info, displayForm, int object: nearPronounPossible(object) ? [objectPronoun, nearObjectPronoun] : objectPronoun, mini: miniPronoun, }; + const english = (displayForm.englishBuilder && englishConjugation) + ? displayForm.englishBuilder(subject, englishConjugation, negative).map(sen => ( + intransitive ? sen : `${sen} ${engObj(object)}` + )).join(" / ") + : undefined; function attachPronounsToVariation(ps: T.PsString, prns: Pronouns): T.ArrayOneOrMore { if (!prns) { @@ -170,7 +176,7 @@ export default function addPronouns({ s, subject, object, info, displayForm, int ...canWorkWithOnlyMini ? makeOnlyMiniForm(ps, splitHead, displayForm, info, negative, prns.mini) : [], - ] as T.ArrayOneOrMore; + ].map((ps) => english ? { ...ps, e: english } : ps) as T.ArrayOneOrMore; } // @ts-ignore @@ -485,3 +491,21 @@ function getObjComplement(info: T.NonComboVerbInfo): T.PsString | undefined { (info.objComplement.plural ? info.objComplement.plural : info.objComplement.entry) : undefined; } + +function engObj(s: T.Person): string { + return (s === T.Person.FirstSingMale || s === T.Person.FirstSingFemale) + ? "me" + : (s === T.Person.FirstPlurMale || s === T.Person.FirstPlurFemale) + ? "us" + : (s === T.Person.SecondSingMale || s === T.Person.SecondSingFemale) + ? "you" + : (s === T.Person.SecondPlurMale || s === T.Person.SecondPlurFemale) + ? "you (pl.)" + : (s === T.Person.ThirdSingMale) + ? "him/it" + : (s === T.Person.ThirdSingFemale) + ? "her/it" + : (s === T.Person.ThirdPlurMale) + ? "them" + : "them (f.)"; +} diff --git a/src/lib/conjugation-forms.tsx b/src/lib/conjugation-forms.tsx index 468b885..cddd4f6 100644 --- a/src/lib/conjugation-forms.tsx +++ b/src/lib/conjugation-forms.tsx @@ -6,13 +6,31 @@ * */ +// FOR ENGLISH FORMS +// GIVEN VERB INFO LIKE THIS +// ["hit", "hits", "hitting", "hit", "hit"] +// ["eat", "eats", "eating", "ate", "eaten"] +// ["see", "sees", "seeing", "saw", "seen"] + +// Present Perfect + +// Past Perfect +// - subj "had" (N && "not") v.4 obj + +// Future Perfect +// - subj "will have" (N && "not") v.4 obj + + + import { getPersonInflectionsKey, pickPersInf, getPersonFromVerbForm, + getBlockRowCol, } from "./misc-helpers"; import addPronouns from "./add-pronouns"; import * as T from "../types"; +import { englishEquative } from "./grammar-units"; type FilterFunc = (form: any) => boolean; type MapFunc = (opts: { @@ -21,6 +39,7 @@ type MapFunc = (opts: { displayForm: T.DisplayFormForSentence, info: T.NonComboVerbInfo, negative: boolean, + englishConjugation?: T.EnglishVerbConjugation, }) => T.DisplayFormItem; /** @@ -67,22 +86,22 @@ const formMap = ( subject: T.Person, object: T.Person, negative: boolean, + englishConjugation?: T.EnglishVerbConjugation, ): T.DisplayFormItem[] => { - return ( - input.map((f) => ( - "content" in f - ? { ...f, content: formMap(f.content, func, info, subject, object, negative) } - : func({ displayForm: f as T.DisplayFormForSentence, info, subject, object, negative }) - )) - ); + return input.map((f) => ( + "content" in f + ? { ...f, content: formMap(f.content, func, info, subject, object, negative, englishConjugation) } + : func({ displayForm: f as T.DisplayFormForSentence, info, subject, object, negative, englishConjugation }) + )); }; -const makeSentence = ({ subject, object, info, displayForm, negative }: { +const makeSentence = ({ subject, object, info, displayForm, englishConjugation, negative }: { subject: T.Person, object: T.Person, info: T.NonComboVerbInfo, displayForm: T.DisplayFormForSentence, negative: boolean, + englishConjugation?: T.EnglishVerbConjugation, }): T.DisplayForm => { const intransitive = info.transitivity === "intransitive" || !!displayForm.passive; const ergative = !intransitive && !!displayForm.past; @@ -107,6 +126,7 @@ const makeSentence = ({ subject, object, info, displayForm, negative }: { ergative, matrixKey, negative, + englishConjugation, }); return { ...displayForm, @@ -114,426 +134,577 @@ const makeSentence = ({ subject, object, info, displayForm, negative }: { }; } -export const getForms = ({ conj, filterFunc, mode, subject, object, negative } : { +const formsOfConjugation = (conj: T.VerbConjugation): T.DisplayFormItem[] => [ + { + label: "Present", + aspect: "imperfective", + form: conj.imperfective.nonImperative, + formula: "Imperfective Stem + Present Ending", + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} ${n ? `${engPresC(s, ["don't", "doesn't"])} ` : ""}${n ? v[0] : engPresC(s, v)}`, + `${engSubj(s)} ${engEquative("present", s)}${n ? " not" : ""} ${v[2]}`, + ]), + explanation: "Something that is happening, happens generally, or is definitely about to happen. ('I am ____ing', 'I _____')", + }, + { + label: "Subjunctive", + aspect: "perfective", + form: conj.perfective.nonImperative, + formula: "Perfective Stem + Present Ending", + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `that ${engSubj(s, true)}${n ? " won't" : "'ll"} ${v[0]}`, + `should ${engSubj(s, true)}${n ? " not" : ""} ${v[0]}`, + ]), + explanation: "Used for hypothetical statements about the desire, necessity, purpose, or possibility of something happening. Or for saying something should or shouldn't happen. ('Should I ____?', 'so that'll I'll _____')" + }, + { + label: "Imperfective Future", + aspect: "imperfective", + form: conj.imperfective.future, + advanced: true, + formula: "به - ba + Present", + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} will${n ? " not" : ""} ${v[0]}`, + ]), + explanation: "Saying something will happen, repeatedly or as an ongoing action", + }, + { + label: "Perfective Future", + aspect: "perfective", + form: conj.perfective.future, + advanced: true, + formula: "به - ba + Subjunctive", + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} will${n ? " not" : ""} ${v[0]}`, + ]), + explanation: "Saying something will happen as a one-time event - May also used when there is some doubt", + }, + { + label: "Continuous Past", + aspect: "imperfective", + form: conj.imperfective.past, + formula: "Imperfective Root + Past Ending", + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + // - subj "was" (N && "not") v.2 obj + `${engSubj(s)} ${engEquative("past", s)}${n ? " not" : ""} ${v[2]}`, + // - subj "would" (N && "not") v.0 obj + `${engSubj(s)} would${n ? " not" : ""} ${v[0]}`, + ]), + explanation: "Saying something was happening, or would happen ('I was ____ing', 'I would ____')", + past: true, + }, + { + label: "Simple Past", + aspect: "perfective", + form: conj.perfective.past, + formula: "Perfective Root + Past Ending", + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)}${n ? " did not" : ""} ${v[3]}`, + ]), + explanation: "Saying something happened ('I ____ed')", + past: true, + }, + { + label: "Modal (ability/possibility)", + subgroup: "modal", + sentence: true, + content: [ + { + label: "Present Modal", + aspect: "imperfective", + form: conj.imperfective.modal.nonImperative, + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} can${n ? "'t" : ""} ${v[0]}`, + ]), + formula: "Imperfective Root + Non-Inflectinig Ey-Tail + Subjunctive کېدل - to become", + explanation: "saying that something is possible currently or in general ('I can ____')", + reorderWithNegative: true, + }, + { + label: "Subjunctive Modal", + aspect: "perfective", + form: conj.perfective.modal.nonImperative, + advanced: true, + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `that ${engSubj(s, true)} can${n ? "'t" : ""} ${v[0]}`, + ]), + formula: "Perfective Root + Non-Inflectinig Ey-Tail + Subjunctive کېدل - to become", + explanation: "talking about the possibility of something in a subjunctive way ('so that I can ____')", + reorderWithNegative: true, + }, + { + label: "Imperfective Future Modal", + aspect: "imperfective", + form: conj.imperfective.modal.future, + advanced: true, + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} will${n ? " not" : ""} be able to ${v[0]}`, + ]), + formula: "به - ba + Present Modal", + explanation: "saying that something will be possible in general or in an ongoing sense in the future ('I'll be able to ____')", + reorderWithNegative: true, + }, + { + label: "Perfective Future Modal", + aspect: "perfective", + form: conj.perfective.modal.future, + advanced: true, + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} will${n ? " not" : ""} be able to ${v[0]}`, + ]), + formula: "به - ba + Subjunctive Modal", + explanation: "saying that something will be possible at a certain point in the future ('I'll be able to ____')", + reorderWithNegative: true, + }, + { + label: "Continous Past Modal", + aspect: "imperfective", + form: conj.imperfective.modal.past, + advanced: true, + past: true, + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} ${engEquative("past", s)} ${n ? " not" : ""} able to ${v[0]}`, + `${engSubj(s)} could${n ? " not" : ""} ${v[0]}`, + ]), + formula: "Imperfective Root + Non-Inflectinig Ey-Tail + Simple Past کېدل - to become", + explanation: "saying that something was possible in general, in an ongoing sense ('I was able to ____', ie. 'I could do ____ any time')", + reorderWithNegative: true, + }, + { + label: "Simple Past Modal", + aspect: "perfective", + form: conj.perfective.modal.past, + formula: "Perfective Root + Non-Inflectinig Ey-Tail + Simple Past کېدل - to become", + explanation: "saying that something was possible at a certain point in time ('I was able to ____, at one particular point in time')", + past: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} ${engEquative("past", s)} ${n ? " not" : ""} able to ${v[0]}`, + `${engSubj(s)} could${n ? " not" : ""} ${v[0]}`, + ]), + sentence: true, + advanced: true, + reorderWithNegative: true, + }, + { + label: "Imperfective hypothetical/wildcard Past Modal", + aspect: "imperfective", + form: conj.imperfective.modal.hypotheticalPast, + formula: "Imperfective Root + Non-Inflectinig Ey-Tail + ش - sh + Non-Inflectinig Ey-Tail", + explanation: "saying that something was possible in general, in an ongoing sense ('I was able to ____', ie. 'I could do ____ any time'). This 'wildcard' form can be used either to talk about hypothetical things, or to avoid worrying about verb agreement", + past: true, + sentence: true, + advanced: true, + reorderWithNegative: true, + }, + { + label: "Perfective hypothetical/wildcard Past Modal", + aspect: "perfective", + form: conj.perfective.modal.hypotheticalPast, + formula: "Perfective Root + Non-Inflectinig Ey-Tail + ش - sh + Non-Inflectinig Ey-Tail", + explanation: "saying that something was possible at a certain point in time ('I was able to ____, at one particular point in time'). This 'wildcard' form can be used either to talk about hypothetical things, or to avoid worrying about verb agreement", + past: true, + sentence: true, + advanced: true, + reorderWithNegative: true, + }, + ], + }, + ...conj.imperfective.imperative ? + [{ + label: "Imperfective Imperative", + aspect: "imperfective", + form: conj.imperfective.imperative, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${v[0]}`, + ]), + formula: "Imperfective Stem + Imperative Ending", + explanation: "Commanding someone/people to do something repeatedly, or in general", + } as T.DisplayForm] : [], + ...conj.perfective.imperative ? + [{ + label: "Perfective Imperative", + aspect: "perfective", + form: conj.perfective.imperative, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${v[0]}`, + ]), + formula: "Perfective Stem + Imperative Ending", + explanation: "Commanding someone/people to do something one time", + } as T.DisplayForm] : [], + { + label: "Perfect", + subgroup: "perfect", + sentence: true, + content: [ + { + label: "Half Perfect", + form: conj.perfect.halfPerfect, + past: true, + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} ${engHave(s)}${n ? " not" : ""} ${v[4]}`, + ]), + formula: "Past participle inflected", + secondPronounNeeded: true, + explanation: "The base of all perfect forms. Used on it's own as a sort of weaker form of the present perfect.", + }, + { + label: "Past Perfect", + form: conj.perfect.past, + past: true, + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} had${n ? " not" : ""} ${v[4]}`, + ]), + formula: "Past participle inflected + Past Equative", + explanation: "Talking about events that had happened in the past, or had affected a past situation ('I had ____ed')", + reorderWithNegative: true, + }, + { + label: "Present Perfect", + form: conj.perfect.present, + past: true, + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} ${engHave(s)}${n ? " not" : ""} ${v[4]}`, + ]), + formula: "Past participle inflected + Present Equative", + explanation: "Talking about that something happened in the past and it affects the present ('I have _____ed')", + reorderWithNegative: true, + }, + { + label: "Subjunctive/Habitual Perfect", + form: conj.perfect.subjunctive, + past: true, + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `that ${engSubj(s, true)} will have${n ? " not" : ""} ${v[4]}`, + ]), + formula: "Past participle inflected + Subjunctive/Habitual Equative", + explanation: "Talking about something that will have happened habitually, or expressing hope, desire, or judgement about an action having happened", + reorderWithNegative: true, + }, + { + label: "Future/Presumptive Perfect", + form: conj.perfect.future, + advanced: true, + past: true, + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} will${n ? " not" : ""} have ${v[4]}`, + ]), + formula: "به - ba + Past participle Inflected + Future Equative", + explanation: "Talking about something that will have happened in the future, or guessing that the event will have occured presently ('I will have ____ed')", + reorderWithNegative: true, + }, + { + label: "Affirmational Perfect", + form: conj.perfect.affirmational, + advanced: true, + past: true, + sentence: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} will${n ? " not" : ""} have ${v[4]}`, + ]), + explanation: "Affirming that an event will have taken place ('I will have ____ed')", + formula: "به - ba + Past Participle Inflected + Past Equative", + reorderWithNegative: true, + }, + { + label: "Conterfactual/Past Subjunctive Perfect", + form: conj.perfect.pastSubjunctiveHypothetical, + advanced: true, + past: true, + sentence: true, + secondPronounNeeded: true, + explanation: "Talking about an event that would have hypothetically taken place (but didn't), or that should have taken place but didn't", + formula: "به - ba + Past Participle Inflected + Past Subjunctive / Hypothetical Equative", + reorderWithNegative: true, + }, + ], + }, + { + label: "Hypothetical/Wish", + advanced: true, + form: conj.hypothetical, + formula: "Imperfective Root + Non-Inflecting Ey-Tail", + explanation: "Talking about a hypothetical, unreal situation, or something that is wished for ('If I ____')", + past: true, + }, + { + label: "Participle", + subgroup: "participle", + advanced: true, + content: [ + { + label: "Present Participle", + form: conj.participle.present, + formula: "Short form of Ininitive Root + ونکی - oonkey", + explanation: "Making a verb into a noun or adjective, talking about a person or thing that does or experiences something. Also used to say something is about to happen. ('____ing', '____er')", + }, + { + label: "Past Participle", + form: conj.participle.past, + past: true, + formula: "Infinitive Root or Special Form + Inflecting Ey-Tail", + explanation: "Making a verb into a noun or adjective, talking about how a person or thing did or experienced something. ('____ed')", + }, + ], + }, + ...conj.passive ? + [{ + label: "Passive", + subgroup: "passive", + advanced: true, + sentence: true, + content: [ + { + label: "Passive Present", + aspect: "imperfective", + form: conj.passive.imperfective.nonImperative, + sentence: true, + passive: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} ${engEquative("present", s)}${n ? " not" : ""} being ${v[4]}`, + ]), + formula: "Long Imperfective Root + Present کېدل - to become", + explanation: "Saying that something is being done or is done in general, without mentioning the subject/agent. ('I am being ____en')", + }, + { + label: "Passive Subjunctive", + aspect: "perfective", + form: conj.passive.perfective.nonImperative, + sentence: true, + passive: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `that ${engSubj(s, true)} will${n ? " not" : ""} be ${v[4]}`, + ]), + formula: "Long Perfective Root + Subjunctive کېدل - to become", + explanation: "Saying that something should be done, or giving a purpose for something being done etc., without mentioning the subject/agent. ('Should I be ____en?', 'So that I'll be ____en')" + }, + { + label: "Passive Imperfective Future", + aspect: "imperfective", + form: conj.passive.imperfective.future, + sentence: true, + passive: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} will${n ? " not" : ""} be ${v[4]}`, + ]), + formula: "به - ba + Passive Present", + explanation: "Saying something will be done as a one-time event, without mentioning the subject/agent.", + }, + { + label: "Passive Perfective Future", + aspect: "perfective", + form: conj.passive.perfective.future, + sentence: true, + passive: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} will${n ? " not" : ""} be ${v[4]}`, + ]), + formula: "به - ba + Passive Subjunctive", + explanation: "Saying something will be done in an ongoing or repeated sense, without mentioning the subject/agent." + }, + { + label: "Passive Continuous Past", + aspect: "imperfective", + form: conj.passive.imperfective.past, + past: true, + sentence: true, + passive: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} ${engEquative("past", s)}${n ? " not" : ""} being ${v[4]}`, + ]), + formula: "Long Imperfective Root + Continuous Past کېدل - to become", + explanation: "Saying that something was being done, or would be done, without mentioning the subject/agent. ('I was being ____en', 'I would be ____en')", + }, + { + label: "Passive Simple Past", + aspect: "perfective", + form: conj.passive.perfective.past, + past: true, + sentence: true, + passive: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} ${engEquative("past", s)}${n ? " not" : ""} ${v[4]}`, + ]), + formula: "Long Perfective Root + Simple Past کېدل - to become", + explanation: "Saying that was done as a one-time event, without mentioning the subject/agent. ('I was ____en')" + }, + { + label: "Passive Perfect", + subgroup: "passive perfect", + passive: true, + sentence: true, + content: [ + { + label: "Passive Half Perfect", + form: conj.passive.perfect.halfPerfect, + past: true, + sentence: true, + passive: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} ${engHave(s)}${n ? " not" : ""} been ${v[4]}`, + ]), + formula: "Infinitive + کېدل (to be) past participle inflected", + explanation: "The base of all perfect forms. Used on it's own as a sort of weaker form of the present perfect. (Passive voice)", + }, + { + label: "Passive Past Perfect", + form: conj.passive.perfect.past, + past: true, + sentence: true, + passive: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} had${n ? " not" : ""} been ${v[4]}`, + ]), + formula: "Infinitive + کېدل (to be) past participle inflected + Past Equative", + explanation: "Talking about events that had happened in the past, or had affected a past situation (Passive voice) ('I had been ____ed')", + }, + { + label: "Passive Present Perfect", + form: conj.passive.perfect.present, + past: true, + sentence: true, + passive: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} ${engHave(s)}${n ? " not" : ""} been ${v[4]}`, + ]), + formula: "Infinitive + کېدل (to be) past participle inflected + Present Equative", + explanation: "Talking about that something happened in the past and it affects the present (Passive voice) ('I have been _____ed')", + }, + { + label: "Passive Subjunctive/Habitual Perfect", + form: conj.passive.perfect.subjunctive, + past: true, + sentence: true, + passive: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `that ${engSubj(s, true)} will have been ${v[4]}`, + ]), + formula: "Infinitive + کېدل (to be) past participle inflected + Subjunctive/Habitual Equative", + }, + { + label: "Passive Future/Presumptive Perfect", + form: conj.passive.perfect.future, + advanced: true, + past: true, + sentence: true, + passive: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} will have been ${v[4]}`, + ]), + formula: "به - ba + Infinitive + کېدل (to be) past participle inflected + Future Equative", + explanation: "Talking about something that will have happened in the future, or guessing that the event will have occured presently (Passive voice) ('I will have been ____ed')", + }, + { + label: "Passive Affirmational Perfect", + form: conj.passive.perfect.affirmational, + advanced: true, + past: true, + sentence: true, + passive: true, + englishBuilder: (s: T.Person, v: T.EnglishVerbConjugation, n: boolean) => ([ + `${engSubj(s)} will have been ${v[4]}`, + ]), + explanation: "Affirming that an event will have taken place (Passive voice) ('I will have been ____ed')", + formula: "به - ba + Infinitive + کېدل (to be) past participle inflected + Past Equative" + }, + { + label: "Passive Past Subjunctive / Hypothetical Perfect", + form: conj.passive.perfect.pastSubjunctiveHypothetical, + advanced: true, + past: true, + sentence: true, + passive: true, + explanation: "Talking about an event that would have hypothetically taken place, or that should have taken place (Passive voice) ('I would have been ____ed')", + formula: "به - ba + Infinitive + کېدل (to be) past participle inflected + Past Subjunctive / Hypothetical Equative" + }, + ], + }, + ] + } as T.DisplayFormSubgroup] + : [], +]; + +export const getForms = ({ conj, filterFunc, mode, subject, object, englishConjugation, negative } : { conj: T.VerbConjugation, + englishConjugation?: T.EnglishVerbConjugation filterFunc?: FilterFunc | FilterFunc[], mode: "chart" | "sentence", subject: T.Person, object: T.Person, negative: boolean, }): T.DisplayFormItem[] => { - const forms: T.DisplayFormItem[] = [ - { - label: "Present", - aspect: "imperfective", - form: conj.imperfective.nonImperative, - formula: "Imperfective Stem + Present Ending", - sentence: true, - explanation: "Something that is happening, happens generally, or is definitely about to happen. ('I am ____ing', 'I _____')", - }, - { - label: "Subjunctive", - aspect: "perfective", - form: conj.perfective.nonImperative, - formula: "Perfective Stem + Present Ending", - sentence: true, - explanation: "Used for hypothetical statements about the desire, necessity, purpose, or possibility of something happening. Or for saying something should or shouldn't happen. ('Should I ____?', 'so that'll I'll _____')" - }, - { - label: "Imperfective Future", - aspect: "imperfective", - form: conj.imperfective.future, - advanced: true, - formula: "به - ba + Present", - sentence: true, - explanation: "Saying something will happen, repeatedly or as an ongoing action", - }, - { - label: "Perfective Future", - aspect: "perfective", - form: conj.perfective.future, - advanced: true, - formula: "به - ba + Subjunctive", - sentence: true, - explanation: "Saying something will happen as a one-time event - May also used when there is some doubt", - }, - { - label: "Continuous Past", - aspect: "imperfective", - form: conj.imperfective.past, - formula: "Imperfective Root + Past Ending", - sentence: true, - explanation: "Saying something was happening, or would happen ('I was ____ing', 'I would ____')", - past: true, - }, - { - label: "Simple Past", - aspect: "perfective", - form: conj.perfective.past, - formula: "Perfective Root + Past Ending", - sentence: true, - explanation: "Saying something happened ('I ____ed')", - past: true, - }, - { - label: "Modal (ability/possibility)", - subgroup: "modal", - sentence: true, - content: [ - { - label: "Present Modal", - aspect: "imperfective", - form: conj.imperfective.modal.nonImperative, - sentence: true, - formula: "Imperfective Root + Non-Inflectinig Ey-Tail + Subjunctive کېدل - to become", - explanation: "saying that something is possible currently or in general ('I can ____')", - reorderWithNegative: true, - }, - { - label: "Subjunctive Modal", - aspect: "perfective", - form: conj.perfective.modal.nonImperative, - advanced: true, - sentence: true, - formula: "Perfective Root + Non-Inflectinig Ey-Tail + Subjunctive کېدل - to become", - explanation: "talking about the possibility of something in a subjunctive way ('so that I can ____')", - reorderWithNegative: true, - }, - { - label: "Imperfective Future Modal", - aspect: "imperfective", - form: conj.imperfective.modal.future, - advanced: true, - sentence: true, - formula: "به - ba + Present Modal", - explanation: "saying that something will be possible in general or in an ongoing sense in the future ('I'll be able to ____')", - reorderWithNegative: true, - }, - { - label: "Perfective Future Modal", - aspect: "perfective", - form: conj.perfective.modal.future, - advanced: true, - sentence: true, - formula: "به - ba + Subjunctive Modal", - explanation: "saying that something will be possible at a certain point in the future ('I'll be able to ____')", - reorderWithNegative: true, - }, - { - label: "Continous Past Modal", - aspect: "imperfective", - form: conj.imperfective.modal.past, - advanced: true, - past: true, - sentence: true, - formula: "Imperfective Root + Non-Inflectinig Ey-Tail + Simple Past کېدل - to become", - explanation: "saying that something was possible in general, in an ongoing sense ('I was able to ____', ie. 'I could do ____ any time')", - reorderWithNegative: true, - }, - { - label: "Simple Past Modal", - aspect: "perfective", - form: conj.perfective.modal.past, - formula: "Perfective Root + Non-Inflectinig Ey-Tail + Simple Past کېدل - to become", - explanation: "saying that something was possible at a certain point in time ('I was able to ____, at one particular point in time')", - past: true, - sentence: true, - advanced: true, - reorderWithNegative: true, - }, - { - label: "Imperfective hypothetical/wildcard Past Modal", - aspect: "imperfective", - form: conj.imperfective.modal.hypotheticalPast, - formula: "Imperfective Root + Non-Inflectinig Ey-Tail + ش - sh + Non-Inflectinig Ey-Tail", - explanation: "saying that something was possible in general, in an ongoing sense ('I was able to ____', ie. 'I could do ____ any time'). This 'wildcard' form can be used either to talk about hypothetical things, or to avoid worrying about verb agreement", - past: true, - sentence: true, - advanced: true, - reorderWithNegative: true, - }, - { - label: "Perfective hypothetical/wildcard Past Modal", - aspect: "perfective", - form: conj.perfective.modal.hypotheticalPast, - formula: "Perfective Root + Non-Inflectinig Ey-Tail + ش - sh + Non-Inflectinig Ey-Tail", - explanation: "saying that something was possible at a certain point in time ('I was able to ____, at one particular point in time'). This 'wildcard' form can be used either to talk about hypothetical things, or to avoid worrying about verb agreement", - past: true, - sentence: true, - advanced: true, - reorderWithNegative: true, - }, - ], - }, - ...conj.imperfective.imperative ? - [{ - label: "Imperfective Imperative", - aspect: "imperfective", - form: conj.imperfective.imperative, - formula: "Imperfective Stem + Imperative Ending", - explanation: "Commanding someone/people to do something repeatedly, or in general", - } as T.DisplayForm] : [], - ...conj.perfective.imperative ? - [{ - label: "Perfective Imperative", - aspect: "perfective", - form: conj.perfective.imperative, - formula: "Perfective Stem + Imperative Ending", - explanation: "Commanding someone/people to do something one time", - } as T.DisplayForm] : [], - { - label: "Perfect", - subgroup: "perfect", - sentence: true, - content: [ - { - label: "Half Perfect", - form: conj.perfect.halfPerfect, - past: true, - sentence: true, - formula: "Past participle inflected", - secondPronounNeeded: true, - explanation: "The base of all perfect forms. Used on it's own as a sort of weaker form of the present perfect.", - }, - { - label: "Past Perfect", - form: conj.perfect.past, - past: true, - sentence: true, - formula: "Past participle inflected + Past Equative", - explanation: "Talking about events that had happened in the past, or had affected a past situation ('I had ____ed')", - reorderWithNegative: true, - }, - { - label: "Present Perfect", - form: conj.perfect.present, - past: true, - sentence: true, - formula: "Past participle inflected + Present Equative", - explanation: "Talking about that something happened in the past and it affects the present ('I have _____ed')", - reorderWithNegative: true, - }, - { - label: "Subjunctive/Habitual Perfect", - form: conj.perfect.subjunctive, - past: true, - sentence: true, - formula: "Past participle inflected + Subjunctive/Habitual Equative", - explanation: "Talking about something that will have happened habitually, or expressing hope, desire, or judgement about an action having happened", - reorderWithNegative: true, - }, - { - label: "Future/Presumptive Perfect", - form: conj.perfect.future, - advanced: true, - past: true, - sentence: true, - formula: "به - ba + Past participle Inflected + Future Equative", - explanation: "Talking about something that will have happened in the future, or guessing that the event will have occured presently ('I will have ____ed')", - reorderWithNegative: true, - }, - { - label: "Affirmational Perfect", - form: conj.perfect.affirmational, - advanced: true, - past: true, - sentence: true, - explanation: "Affirming that an event will have taken place ('I will have ____ed')", - formula: "به - ba + Past Participle Inflected + Past Equative", - reorderWithNegative: true, - }, - { - label: "Conterfactual/Past Subjunctive Perfect", - form: conj.perfect.pastSubjunctiveHypothetical, - advanced: true, - past: true, - sentence: true, - secondPronounNeeded: true, - explanation: "Talking about an event that would have hypothetically taken place (but didn't), or that should have taken place but didn't", - formula: "به - ba + Past Participle Inflected + Past Subjunctive / Hypothetical Equative", - reorderWithNegative: true, - }, - ], - }, - { - label: "Hypothetical/Wish", - advanced: true, - form: conj.hypothetical, - formula: "Imperfective Root + Non-Inflecting Ey-Tail", - explanation: "Talking about a hypothetical, unreal situation, or something that is wished for ('If I ____')", - past: true, - }, - { - label: "Participle", - subgroup: "participle", - advanced: true, - content: [ - { - label: "Present Participle", - form: conj.participle.present, - formula: "Short form of Ininitive Root + ونکی - oonkey", - explanation: "Making a verb into a noun or adjective, talking about a person or thing that does or experiences something. Also used to say something is about to happen. ('____ing', '____er')", - }, - { - label: "Past Participle", - form: conj.participle.past, - past: true, - formula: "Infinitive Root or Special Form + Inflecting Ey-Tail", - explanation: "Making a verb into a noun or adjective, talking about how a person or thing did or experienced something. ('____ed')", - }, - ], - }, - ...conj.passive ? - [{ - label: "Passive", - subgroup: "passive", - advanced: true, - sentence: true, - content: [ - { - label: "Passive Present", - aspect: "imperfective", - form: conj.passive.imperfective.nonImperative, - sentence: true, - passive: true, - formula: "Long Imperfective Root + Present کېدل - to become", - explanation: "Saying that something is being done or is done in general, without mentioning the subject/agent. ('I am being ____en')", - }, - { - label: "Passive Subjunctive", - aspect: "perfective", - form: conj.passive.perfective.nonImperative, - sentence: true, - passive: true, - formula: "Long Perfective Root + Subjunctive کېدل - to become", - explanation: "Saying that something should be done, or giving a purpose for something being done etc., without mentioning the subject/agent. ('Should I be ____en?', 'So that I'll be ____en')" - }, - { - label: "Passive Imperfective Future", - aspect: "imperfective", - form: conj.passive.imperfective.future, - sentence: true, - passive: true, - formula: "به - ba + Passive Present", - explanation: "Saying something will be done as a one-time event, without mentioning the subject/agent.", - }, - { - label: "Passive Perfective Future", - aspect: "perfective", - form: conj.passive.perfective.future, - sentence: true, - passive: true, - formula: "به - ba + Passive Subjunctive", - explanation: "Saying something will be done in an ongoing or repeated sense, without mentioning the subject/agent." - }, - { - label: "Passive Continuous Past", - aspect: "imperfective", - form: conj.passive.imperfective.past, - past: true, - sentence: true, - passive: true, - formula: "Long Imperfective Root + Continuous Past کېدل - to become", - explanation: "Saying that something was being done, or would be done, without mentioning the subject/agent. ('I was being ____en', 'I would be ____en')", - }, - { - label: "Passive Simple Past", - aspect: "perfective", - form: conj.passive.perfective.past, - past: true, - sentence: true, - passive: true, - formula: "Long Perfective Root + Simple Past کېدل - to become", - explanation: "Saying that was done as a one-time event, without mentioning the subject/agent. ('I was ____en')" - }, - { - label: "Passive Perfect", - subgroup: "passive perfect", - passive: true, - sentence: true, - content: [ - { - label: "Passive Half Perfect", - form: conj.passive.perfect.halfPerfect, - past: true, - sentence: true, - passive: true, - formula: "Infinitive + کېدل (to be) past participle inflected", - explanation: "The base of all perfect forms. Used on it's own as a sort of weaker form of the present perfect. (Passive voice)", - }, - { - label: "Passive Past Perfect", - form: conj.passive.perfect.past, - past: true, - sentence: true, - passive: true, - formula: "Infinitive + کېدل (to be) past participle inflected + Past Equative", - explanation: "Talking about events that had happened in the past, or had affected a past situation (Passive voice) ('I had been ____ed')", - }, - { - label: "Passive Present Perfect", - form: conj.passive.perfect.present, - past: true, - sentence: true, - passive: true, - formula: "Infinitive + کېدل (to be) past participle inflected + Present Equative", - explanation: "Talking about that something happened in the past and it affects the present (Passive voice) ('I have been _____ed')", - }, - { - label: "Passive Subjunctive/Habitual Perfect", - form: conj.passive.perfect.subjunctive, - past: true, - sentence: true, - passive: true, - formula: "Infinitive + کېدل (to be) past participle inflected + Subjunctive/Habitual Equative", - }, - { - label: "Passive Future/Presumptive Perfect", - form: conj.passive.perfect.future, - advanced: true, - past: true, - sentence: true, - passive: true, - formula: "به - ba + Infinitive + کېدل (to be) past participle inflected + Future Equative", - explanation: "Talking about something that will have happened in the future, or guessing that the event will have occured presently (Passive voice) ('I will have been ____ed')", - }, - { - label: "Passive Affirmational Perfect", - form: conj.passive.perfect.affirmational, - advanced: true, - past: true, - sentence: true, - passive: true, - explanation: "Affirming that an event will have taken place (Passive voice) ('I will have been ____ed')", - formula: "به - ba + Infinitive + کېدل (to be) past participle inflected + Past Equative" - }, - { - label: "Passive Past Subjunctive / Hypothetical Perfect", - form: conj.passive.perfect.pastSubjunctiveHypothetical, - advanced: true, - past: true, - sentence: true, - passive: true, - explanation: "Talking about an event that would have hypothetically taken place, or that should have taken place (Passive voice) ('I would have been ____ed')", - formula: "به - ba + Infinitive + کېدل (to be) past participle inflected + Past Subjunctive / Hypothetical Equative" - }, - ], - }, - ] - } as T.DisplayFormSubgroup] - : [], - ]; - const initialFilter = filterFunc + const forms = formsOfConjugation(conj); + const formsToUse = filterFunc ? formFilter(forms, filterFunc) : forms; return mode === "chart" - ? initialFilter + ? formsToUse : formMap( - formFilter(initialFilter, (f) => f.sentence), + // TODO: somewhere in one of these the english conjugations are being stripped out for the past tense items + formFilter(formsToUse, (f) => f.sentence), makeSentence, conj.info, subject, object, negative, + englishConjugation, ); } + +function isThirdPerson(p: T.Person): boolean { + return ( + p === T.Person.ThirdSingMale || + p === T.Person.ThirdSingFemale || + p === T.Person.ThirdPlurMale || + p === T.Person.ThirdPlurFemale + ); +} + +function engPresC(s: T.Person, ec: T.EnglishVerbConjugation | [string, string]): string { + return isThirdPerson(s) ? ec[1] : ec[0]; +} + +function engEquative(tense: "past" | "present", s: T.Person): string { + const [row, col] = getBlockRowCol(s); + return englishEquative[tense][row][col]; +} + +function engHave(s: T.Person): string { + return isThirdPerson(s) ? "has" : "have"; +} + +function engSubj(s: T.Person, lowerCase?: boolean): string { + const pronoun = (s === T.Person.FirstSingMale || s === T.Person.FirstSingFemale) + ? "I" + : (s === T.Person.FirstPlurMale || s === T.Person.FirstPlurFemale) + ? "We" + : (s === T.Person.SecondSingMale || s === T.Person.SecondSingFemale) + ? "You" + : (s === T.Person.SecondPlurMale || s === T.Person.SecondPlurFemale) + ? "You (pl.)" + : (s === T.Person.ThirdSingMale) + ? "He/it" + : (s === T.Person.ThirdSingFemale) + ? "She/it" + : (s === T.Person.ThirdPlurMale) + ? "They" + : "They (f.)"; + return (lowerCase && pronoun !== "I") + ? pronoun.toLowerCase() + : pronoun; +} diff --git a/src/lib/grammar-units.ts b/src/lib/grammar-units.ts index 3e23377..d5109e0 100644 --- a/src/lib/grammar-units.ts +++ b/src/lib/grammar-units.ts @@ -149,6 +149,31 @@ export const subjPastEquative: T.PsString = { f: "w" + aayTail.f, }; +export const englishEquative: { + past: T.EnglishBlock, + present: T.EnglishBlock, + // present: T.VerbBlock, + // subjunctive: T.VerbBlock, + // hypothetical: T.VerbBlock, +} = { + past: [ + ["was", "were"], + ["was", "were"], + ["were", "were"], + ["were", "were"], + ["was", "were"], + ["was", "were"], + ], + present: [ + ["am", "are"], + ["am", "are"], + ["are", "are"], + ["are", "are"], + ["is", "are"], + ["is", "are"], + ], +} + export const equativeEndings: { past: T.LengthOptions, present: T.VerbBlock, diff --git a/src/lib/misc-helpers.test.ts b/src/lib/misc-helpers.test.ts new file mode 100644 index 0000000..8b57be4 --- /dev/null +++ b/src/lib/misc-helpers.test.ts @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2021 lingdocs.com + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + + import { + parseEc, +} from "./misc-helpers"; + +test("parseEc should work", () => { + expect(parseEc("walk")).toEqual(["walk", "walks", "walking", "walked", "walked"]); + expect(parseEc("scare")).toEqual(["scare", "scares", "scaring", "scared", "scared"]); + expect(parseEc("sew,sews,sewing,sewed,sown")).toEqual(["sew", "sews", "sewing", "sewed", "sown"]); + expect(parseEc(" sew, sews,sewing ,sewed, sown")).toEqual(["sew", "sews", "sewing", "sewed", "sown"]); +}); \ No newline at end of file diff --git a/src/lib/misc-helpers.ts b/src/lib/misc-helpers.ts index 6a455fb..279f64b 100644 --- a/src/lib/misc-helpers.ts +++ b/src/lib/misc-helpers.ts @@ -206,6 +206,30 @@ export function isNounAdjOrVerb(entry: T.DictionaryEntry): "nounAdj" | "verb" | return false; } +/** + * takes the ec field from a dictionary entry and produces an array of an EnglishVerbConjugation + * for use with the conjugations display for showing English translation sentences of various verb + * forms and conjugations + * + * @param ec + * @returns + */ +export function parseEc(ec: string | undefined): T.EnglishVerbConjugation | undefined { + function makeRegularConjugations(s: string): T.EnglishVerbConjugation { + const b = (s.slice(-1) === "e") + ? s.slice(0, -1) + : s; + return [`${s}`, `${s}s`, `${b}ing`, `${b}ed`, `${b}ed`]; + } + if (!ec) { + return undefined; + } + const items = ec.split(",").map(x => x.trim()); + return (items.length !== 5) + ? makeRegularConjugations(items[0]) + : [items[0], items[1], items[2], items[3], items[4]]; +} + // not being used // export function isImperativeBlock(f: any): boolean { // function isPersonLine(g: any): boolean { diff --git a/src/types.ts b/src/types.ts index d4e7232..3176798 100644 --- a/src/types.ts +++ b/src/types.ts @@ -106,6 +106,9 @@ export type DictionaryEntry = { // PHONETICS - PASHTO - DIACRITICS INFO /** Is an exception to the rules of diacritics for Pashto/Phonetics */ diacExcept?: boolean; + + /** the English conjugations of a verb comma seperated set of 5 ie. "see,sees,seeing,saw,seen" or single word ie. "walk" if regular */ + ec?: string; } export type DictionaryEntryTextField = "p" | "f" | "e" | "c" | "infap" | "infaf" | "infbp" | "infbf" | "app" | "apf" | "ppp" | "ppf" | "psp" | "psf" | "ssp" | "ssf" | "prp" | "prf" | "pprtp" | "pprtf" | "tppp" | "tppf"; @@ -383,6 +386,9 @@ export type ArrayOneOrMore = { 0: T } & Array +/* i.e. ["eat", "eats", "eating", "ate", "eaten"] */ +export type EnglishVerbConjugation = [string, string, string, string, string]; + export type DisplayFormItem = DisplayForm | DisplayFormSubgroup | DisplayFormForSentence; export type DisplayForm = { @@ -390,6 +396,7 @@ export type DisplayForm = { aspect?: Aspect, form: VerbForm | ImperativeForm | ParticipleForm | SentenceForm, advanced?: boolean, + englishBuilder?: (subject: Person, ec: EnglishVerbConjugation, neg: boolean) => string[], formula: React.ReactNode, explanation: React.ReactNode, sentence?: boolean, @@ -402,6 +409,7 @@ export type DisplayFormForSentence = { aspect?: Aspect, form: VerbForm, advanced?: boolean, + englishBuilder?: (subject: Person, ec: EnglishVerbConjugation, neg: boolean) => string[], formula: React.ReactNode, secondPronounNeeded?: boolean, explanation: React.ReactNode,