From 1a0af4ab9412d290ef39691f6f0bf2ced974a91c Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Wed, 14 Jul 2021 14:31:13 +0300 Subject: [PATCH] fixed big bugs with trans/gramm trans and stative/dynamic combo verbs not rendering! --- package.json | 2 +- src/components/ConjugationViewer.tsx | 8 ++-- src/lib/grammar-units.ts | 43 ++++++++--------- src/lib/p-text-helpers.ts | 8 +++- src/lib/verb-conjugation.ts | 69 ++++++++++++++-------------- 5 files changed, 68 insertions(+), 62 deletions(-) diff --git a/package.json b/package.json index 1e84a4d..1f5ea11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "0.7.4", + "version": "0.7.5", "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/components/ConjugationViewer.tsx b/src/components/ConjugationViewer.tsx index c7dc1eb..577a909 100644 --- a/src/components/ConjugationViewer.tsx +++ b/src/components/ConjugationViewer.tsx @@ -172,11 +172,10 @@ const initialState: State = { formsOpened: [], }; -function ConjugationViewer({ entry, complement, textOptions, aayTailType, showOnly, highlightInRootsAndStems, hidePastParticiple, sentenceLevel }: { +function ConjugationViewer({ entry, complement, textOptions, showOnly, highlightInRootsAndStems, hidePastParticiple, sentenceLevel }: { entry: T.DictionaryEntry, complement?: T.DictionaryEntry, textOptions: T.TextOptions, - aayTailType?: T.AayTail, showOnly?: string | string[], highlightInRootsAndStems?: T.RootsOrStemsToHighlight, hidePastParticiple?: boolean, @@ -197,12 +196,13 @@ function ConjugationViewer({ entry, complement, textOptions, aayTailType, showOn useEffect(() => { localStorage.setItem(stateLocalStorageName, JSON.stringify(state)); }); - const conjugation = (() => { if (!(entry.c && entry.c.slice(0, 2) === "v.")) return undefined; try { - return conjugateVerb(entry, aayTailType ? aayTailType : "aay", complement); + console.log("my entry is", entry); + return conjugateVerb(entry, complement); } catch(e) { + console.log("conjugation error", e); return undefined; } })(); diff --git a/src/lib/grammar-units.ts b/src/lib/grammar-units.ts index d5109e0..b0eeb0b 100644 --- a/src/lib/grammar-units.ts +++ b/src/lib/grammar-units.ts @@ -142,12 +142,12 @@ export const pastEndings: T.VerbBlock = [ // TODO: MAKE THIS VARIABLE FOR DIALECTS! -export const aayTail: T.PsString = { p: "ی", f: "ey" }; +export const aayTail: T.PsString[] = [{p: "ای", f: "aay" }, { p: "ی", f: "ey" }]; -export const subjPastEquative: T.PsString = { - p: "و" + aayTail.p, - f: "w" + aayTail.f, -}; +export const subjPastEquative: T.ArrayOneOrMore = aayTail.map((a) => ({ + p: "و" + a.p, + f: "w" + a.f, +})) as T.ArrayOneOrMore; export const englishEquative: { past: T.EnglishBlock, @@ -438,12 +438,12 @@ export const equativeEndings: { ], ], hypothetical: [ - [[subjPastEquative], [subjPastEquative]], - [[subjPastEquative], [subjPastEquative]], - [[subjPastEquative], [subjPastEquative]], - [[subjPastEquative], [subjPastEquative]], - [[subjPastEquative], [subjPastEquative]], - [[subjPastEquative], [subjPastEquative]], + [subjPastEquative, subjPastEquative], + [subjPastEquative, subjPastEquative], + [subjPastEquative, subjPastEquative], + [subjPastEquative, subjPastEquative], + [subjPastEquative, subjPastEquative], + [subjPastEquative, subjPastEquative], ], }; @@ -509,16 +509,17 @@ export const passiveStativeBridge = [ short: ksPerf.long, long: ksPerf.long, }, - { - short: { - p: ksPerf.short.p + aayTail.p, - f: ksPerf.short.f + aayTail.f, - }, - long: { - p: ksPerf.long.p + aayTail.p, - f: ksPerf.long.f + aayTail.f, - }, - }, + // PK VARIATION - NOT BEING USED - ADD TO FORMS NOT ADDING THE SECOND FORM FOR SOME REASON + // { + // short: { + // p: ksPerf.short.p + aayTail[1].p, + // f: ksPerf.short.f + aayTail[1].f, + // }, + // long: { + // p: ksPerf.long.p + aayTail[1].p, + // f: ksPerf.long.f + aayTail[1].f, + // }, + // }, ]; const basePlainPronouns = [ diff --git a/src/lib/p-text-helpers.ts b/src/lib/p-text-helpers.ts index d0b325b..3c4c6e3 100644 --- a/src/lib/p-text-helpers.ts +++ b/src/lib/p-text-helpers.ts @@ -16,6 +16,10 @@ import { } from "./misc-helpers"; import * as T from "../types"; +// export function concatPsStringWithVars(...items: Array): T.PsString[] { + +// } + /** * Concats sections of Pashto text with Pashto and Phonetics * in PsString type, also accepts spaces as " " @@ -267,7 +271,7 @@ export function isInflectionSet(x: any): boolean { } -type toAddToForm = Array<" " | T.SingleOrLengthOpts | T.SingleOrLengthOpts | T.SingleOrLengthOpts[] | T.OptionalPersonInflections | T.VerbBlock>; +type toAddToForm = Array<" " | T.SingleOrLengthOpts | T.SingleOrLengthOpts | T.SingleOrLengthOpts[] | T.SingleOrLengthOpts | T.OptionalPersonInflections | T.VerbBlock>; type toAddToFormLengthChosen = Array<" " | T.PsString | T.UnisexInflections | T.PsString[] | T.OptionalPersonInflections | T.VerbBlock>; export function addToForm( toAdd: toAddToForm, @@ -324,7 +328,7 @@ export function addToForm( const multiplyEachVariationBy = toAdd.reduce((acc, cur) => ( // make sure we don't make 6 variations when concating a verb block to a verb block! (Array.isArray(cur) && !isVerbBlock(cur)) ? Math.max(acc, cur.length) : acc - ), 1) + ), 1); const b = "long" in base ? base[length] || base.short // in case mini does not exist : base; diff --git a/src/lib/verb-conjugation.ts b/src/lib/verb-conjugation.ts index 27d791c..a3b4cd3 100644 --- a/src/lib/verb-conjugation.ts +++ b/src/lib/verb-conjugation.ts @@ -15,7 +15,6 @@ import { equativeEndings, emptyVerbBlock, passiveStativeBridge, - aayTail, } from "./grammar-units"; import { addToForm, @@ -47,13 +46,9 @@ import * as T from "../types"; const dummyEntry: T.DictionaryEntry = { i: 0, p: "", f: "", g: "", e: "", c: "", ts: 0 }; -const getAayTail = (type: T.AayTail): T.PsString => ( - type === "ey" - ? { p: "ی", f: "ey" } - : { p: "ای", f: "aay" } -); +const aayTail = [{p: "ای", f: "aay" }, { p: "ی", f: "ey" }]; -export function conjugateVerb(entry: T.DictionaryEntry, aayTailType: T.AayTail, complement?: T.DictionaryEntry, verbInfo?: T.NonComboVerbInfo): T.VerbOutput { +export function conjugateVerb(entry: T.DictionaryEntry, complement?: T.DictionaryEntry, verbInfo?: T.NonComboVerbInfo): T.VerbOutput { if (!(entry.c && entry.c.slice(0, 2) === "v.")) { throw new Error("not a verb"); }; @@ -65,21 +60,21 @@ export function conjugateVerb(entry: T.DictionaryEntry, aayTailType: T.AayTail, if (info.type === "transitive or grammatically transitive simple") { return { info, - transitive: conjugateVerb(dummyEntry, aayTailType, dummyEntry, info.transitive) as T.VerbConjugation, - grammaticallyTransitive: conjugateVerb(dummyEntry, aayTailType, dummyEntry, info.grammaticallyTransitive) as T.VerbConjugation, + transitive: conjugateVerb({ ...entry, c: entry.c ? entry.c.replace("/gramm. trans.", "") : "" }, dummyEntry, info.transitive) as T.VerbConjugation, + grammaticallyTransitive: conjugateVerb({ ...entry, c: entry.c ? entry.c?.replace("trans./", "") : "" }, dummyEntry, info.grammaticallyTransitive) as T.VerbConjugation, }; } if (info.type === "dynamic or stative compound" || info.type === "dynamic or generative stative compound") { return { info, - stative: conjugateVerb(dummyEntry, aayTailType, dummyEntry, info.stative) as T.VerbConjugation, - dynamic: conjugateVerb(dummyEntry, aayTailType, dummyEntry, info.dynamic) as T.VerbConjugation, + stative: conjugateVerb({ ...entry, c: entry.c ? entry.c.replace("dyn./", "") : "" }, dummyEntry, info.stative) as T.VerbConjugation, + dynamic: conjugateVerb({ ...entry, c: entry.c ? entry.c.replace("/stat.", "") : "" }, dummyEntry, info.dynamic) as T.VerbConjugation, }; } if (info.type === "dynamic compound") { - return conjugateDynamicCompound(info, aayTailType); + return conjugateDynamicCompound(info); } const nonComboInfo = info as T.NonComboVerbInfo; @@ -87,13 +82,13 @@ export function conjugateVerb(entry: T.DictionaryEntry, aayTailType: T.AayTail, // TODO: Handle verbs like چيغه کول const conjugation: T.VerbConjugation = { info: nonComboInfo, - imperfective: makeAspectContent(nonComboInfo, "imperfective", aayTailType), - perfective: makeAspectContent(nonComboInfo, "perfective", aayTailType), + imperfective: makeAspectContent(nonComboInfo, "imperfective"), + perfective: makeAspectContent(nonComboInfo, "perfective"), hypothetical: makeHypotheticalContent(nonComboInfo), participle: makeParticipleContent(nonComboInfo), perfect: makePerfectContent(nonComboInfo), ..."singularForm" in info ? { - singularForm: conjugateVerb(entry, aayTailType, complement, info.singularForm) as T.VerbConjugation, + singularForm: conjugateVerb(entry, complement, info.singularForm) as T.VerbConjugation, } : {}, // if transitive include passive voice ...info.transitivity !== "intransitive" ? { @@ -109,14 +104,14 @@ export function conjugateVerb(entry: T.DictionaryEntry, aayTailType: T.AayTail, : conjugation; } -function conjugateDynamicCompound(info: T.DynamicCompoundVerbInfo, aayTailType: "ey" | "aay"): T.VerbConjugation { +function conjugateDynamicCompound(info: T.DynamicCompoundVerbInfo): T.VerbConjugation { const willUseImperative = !( info.type === "dynamic compound" && info.transitivity === "intransitive" && info.auxVerb.p === "کېدل" ); const auxConj = enforceObject( - conjugateVerb(info.auxVerb, aayTailType, info.auxVerbComplement) as T.VerbConjugation, + conjugateVerb(info.auxVerb, info.auxVerbComplement) as T.VerbConjugation, info.objComplement.person, ); const complement = info.objComplement.plural @@ -200,17 +195,17 @@ function conjugateDynamicCompound(info: T.DynamicCompoundVerbInfo, aayTailType: }, } : {}, ...info.singularForm ? { - singularForm: conjugateDynamicCompound(info.singularForm, aayTailType) + singularForm: conjugateDynamicCompound(info.singularForm) } : {}, ...info.intransitiveForm ? { - intransitiveForm: conjugateDynamicCompound(info.intransitiveForm, aayTailType) + intransitiveForm: conjugateDynamicCompound(info.intransitiveForm) } : {}, }; } -function makeAspectContent(info: T.NonComboVerbInfo, aspect: T.Aspect, aayTailType: T.AayTail): T.AspectContent { +function makeAspectContent(info: T.NonComboVerbInfo, aspect: T.Aspect): T.AspectContent { if ((info.type === "stative compound") && spaceInForm(info.root[aspect])) { - return makeStativeCompoundSeperatedAspectContent(info, aspect, aayTailType); + return makeStativeCompoundSeperatedAspectContent(info, aspect); } const stem = noPersInfs(info.stem[aspect]); const root = noPersInfs(info.root[aspect]); @@ -225,17 +220,16 @@ function makeAspectContent(info: T.NonComboVerbInfo, aspect: T.Aspect, aayTailTy future, // به - ba + nonImperative imperative, // stem + imperative endings past, // root + past endings - modal: makeJoinedModalContent(info, aspect, aayTailType), + modal: makeJoinedModalContent(info, aspect), }; } -function makeJoinedModalContent(info: T.NonComboVerbInfo, aspectIn: T.Aspect, aayTailType: T.AayTail): T.ModalContent { +function makeJoinedModalContent(info: T.NonComboVerbInfo, aspectIn: T.Aspect): T.ModalContent { const aspect: T.Aspect = noPerfectiveModal(info) ? "imperfective" : aspectIn; - const aayTail = getAayTail(aayTailType); const aux = stativeAux.intransitive.perfective; const rAndT = info.yulEnding - ? concatPsString(noPersInfs(info.root[aspect]).long, aayTail) - : concatPsString(noPersInfs(info.root[aspect]), aayTail); + ? concatPsString(noPersInfs(info.root[aspect]).long, aayTail[1]) + : concatPsString(noPersInfs(info.root[aspect]), aayTail[1]); const rootAndTail = aspect === "imperfective" ? accentImperfectiveModalRootAndTail(info, rAndT) : rAndT; @@ -256,7 +250,7 @@ function makeJoinedModalContent(info: T.NonComboVerbInfo, aspectIn: T.Aspect, aa }; } -function makeStativeCompoundSeperatedAspectContent(info: T.StativeCompoundVerbInfo, aspect: T.Aspect, aayTailType: T.AayTail): T.AspectContent { +function makeStativeCompoundSeperatedAspectContent(info: T.StativeCompoundVerbInfo, aspect: T.Aspect): T.AspectContent { const transitivity = getTransitivity(info); const presentComplement = (transitivity === "transitive" && complementInflects(info.complement)) ? unisexInfToObjectMatrix(info.complement) // transitive verb requires an object matrix for the complex @@ -296,7 +290,7 @@ function makeStativeCompoundSeperatedAspectContent(info: T.StativeCompoundVerbIn } : {}, modal: info.transitivity === "transitive" ? makeTransitiveStativeModalContent() - : makeJoinedModalContent(info, "imperfective", aayTailType), + : makeJoinedModalContent(info, "imperfective"), }; } @@ -314,20 +308,27 @@ function makeHypotheticalContent(info: T.NonComboVerbInfo): T.VerbForm { if (("complement" in info) && spaceInForm(info.root.imperfective)) { return makeStativeCompoundSepHypotheticalContent(info as T.StativeCompoundVerbInfo); } - const makeHypothetical = (root: T.OptionalPersonInflections>, length: "short" | "long"): T.PsString => { + const makeHypothetical = (root: T.OptionalPersonInflections>, length: "short" | "long"): T.PsString[] => { if ("mascSing" in root) { // BIG TODO: SHOULD THERE BE PERS INFS HERE?? IGNORING THEM NOW IF THEY EXIST - return makeHypothetical(root.mascSing, length) as T.PsString; + return makeHypothetical(root.mascSing, length) as T.PsString[]; } - return accentOnNFromEnd( - concatPsString(root[length], aayTail), - (length === "long" ? 1 : 0) + (info.yulEnding ? 1 : 0), - ) + return [ + accentOnNFromEnd( + concatPsString(root[length], aayTail[0]), + (length === "long" ? 1 : 0) + (info.yulEnding ? 1 : 0), + ), + accentOnNFromEnd( + concatPsString(root[length], aayTail[1]), + (length === "long" ? 1 : 0) + (info.yulEnding ? 1 : 0), + ), + ]; }; const hyp = { short: makeHypothetical(info.root.imperfective, "short"), long: makeHypothetical(info.root.imperfective, "long"), }; + // TODO: ADD TO FORM IS NOT ADDING THE SECOND VARIATION PASSED IN! return addToForm([hyp], emptyVerbBlock); }