From 76f9158e2a5b93079a2d2a217737820b1287f016 Mon Sep 17 00:00:00 2001 From: adueck Date: Tue, 11 Apr 2023 13:53:10 +0400 Subject: [PATCH] working with basic verbs with participles - testing totally broken and needs to be redone --- .../src/np-picker/NPPronounPicker.tsx | 16 ++--- src/lib/src/new-verb-engine/render-verb.ts | 3 +- .../src/new-verb-engine/roots-and-stems.ts | 64 +++++++++++++------ src/lib/src/new-verb-engine/rs-helpers.ts | 27 +++----- src/types.ts | 12 +++- 5 files changed, 73 insertions(+), 49 deletions(-) diff --git a/src/components/src/np-picker/NPPronounPicker.tsx b/src/components/src/np-picker/NPPronounPicker.tsx index 173d490..07c57ae 100644 --- a/src/components/src/np-picker/NPPronounPicker.tsx +++ b/src/components/src/np-picker/NPPronounPicker.tsx @@ -35,45 +35,45 @@ const labels = (role: "subject" | "object" | "ergative" | "possesor") => ({ far: [ ["زه", "مونږ"], ["ته", "تاسو"], - ["هغه", "هغوي"], + ["هغه", "هغوی"], ], near: [ ["زه", "مونږ"], ["ته", "تاسو"], - [{ masc: "دی", fem: "دا" }, "دوي"], + [{ masc: "دی", fem: "دا" }, "دوی"], ], } : role === "object" ? { far: [ ["زه", "مونږ"], ["ته", "تاسو"], - [{ masc: "هغهٔ", fem: "هغې" }, "هغوي"], + [{ masc: "هغهٔ", fem: "هغې" }, "هغوی"], ], near: [ ["زه", "مونږ"], ["ته", "تاسو"], - [{ masc: "دهٔ", fem: "دې" }, "دوي"], + [{ masc: "دهٔ", fem: "دې" }, "دوی"], ], } : role === "possesor" ? { far: [ ["زما", "زمونږ"], ["ستا", "ستاسو"], - [{ masc: "د هغهٔ", fem: "د هغې" }, "د هغوي"], + [{ masc: "د هغهٔ", fem: "د هغې" }, "د هغوی"], ], near: [ ["زما", "زمونږ"], ["ستا", "ستاسو"], - [{ masc: "د دهٔ", fem: "د دې" }, "د دوي"], + [{ masc: "د دهٔ", fem: "د دې" }, "د دوی"], ], } : { far: [ ["ما", "مونږ"], ["تا", "تاسو"], - [{ masc: "هغهٔ", fem: "هغې" }, "هغوي"], + [{ masc: "هغهٔ", fem: "هغې" }, "هغوی"], ], near: [ ["ما", "مونږ"], ["تا", "تاسو"], - [{ masc: "دهٔ", fem: "دې" }, "دوي"], + [{ masc: "دهٔ", fem: "دې" }, "دوی"], ], }, }); diff --git a/src/lib/src/new-verb-engine/render-verb.ts b/src/lib/src/new-verb-engine/render-verb.ts index 4f474d1..32dce8d 100644 --- a/src/lib/src/new-verb-engine/render-verb.ts +++ b/src/lib/src/new-verb-engine/render-verb.ts @@ -95,7 +95,8 @@ function renderPerfectVerb({ tense, verb, voice, person }: { verb: T.VerbEntry, voice: T.Voice, person: T.Person, -}): { hasBa: boolean, vbs: [[], [T.VBGenNum, T.VBE]] } { + // TODO: Tighter typing on the output for T.VB (enforce genderNumber?) +}): { hasBa: boolean, vbs: [[], [T.VB, T.VBE]] } { const hasBa = tenseHasBa(tense); const genderNumber = { gender: personGender(person), diff --git a/src/lib/src/new-verb-engine/roots-and-stems.ts b/src/lib/src/new-verb-engine/roots-and-stems.ts index 0995b68..a260961 100644 --- a/src/lib/src/new-verb-engine/roots-and-stems.ts +++ b/src/lib/src/new-verb-engine/roots-and-stems.ts @@ -30,8 +30,8 @@ const shVB: T.VBBasic = { ps: [{ p: "ش", f: "sh" }], } -// TODO: kuRee shuwey etc -export function getPastParticiple(verb: T.VerbEntry, voice: T.Voice, { gender, number }: { gender: T.Gender, number: T.NounNumber }): T.VBGenNum { +// TODO: kuRee shuwey etc +export function getPastParticiple(verb: T.VerbEntry, voice: T.Voice, { gender, number }: { gender: T.Gender, number: T.NounNumber }): T.VBGenNum | T.WeldedGN { const v = removeFVarientsFromVerb(verb); if (voice === "passive") { return getPassivePp(v, { gender, number }); @@ -47,21 +47,22 @@ export function getPastParticiple(verb: T.VerbEntry, voice: T.Voice, { gender, n } const [_, [basicRoot]] = getImperfectiveRoot(removeFVarientsFromVerb(verb)); const longRoot = getLongVB(basicRoot); + const rootWLengths = possiblePPartLengths(longRoot); - if ("right" in longRoot) { + if ("right" in rootWLengths) { return { - ...longRoot, + ...rootWLengths, right: { - ...longRoot.right, - ps: addTail(longRoot.right.ps), + ...rootWLengths.right, + ps: addTail(rootWLengths.right.ps), + gender, + number, }, - gender, - number, }; } else { return { - ...longRoot, - ps: addTail(longRoot.ps), + ...rootWLengths, + ps: addTail(rootWLengths.ps), gender, number, }; @@ -79,6 +80,36 @@ export function getPastParticiple(verb: T.VerbEntry, voice: T.Voice, { gender, n } } +function possiblePPartLengths(vba: T.VBNoLenghts): T.VBBasic; +function possiblePPartLengths(vba: T.VBNoLenghts): T.VBA; +function possiblePPartLengths(vba: T.VBNoLenghts): T.VBA { + const shortenableEndings = ["ښتل", "ستل", "وتل"]; + const wrul = ["وړل", "راوړل", "وروړل", "دروړل"]; + if ("right" in vba) { + return { + ...vba, + right: possiblePPartLengths(vba.right), + }; + } + const infinitive = vba.ps[0]; + const [trimP, trimF] = (infinitive.p.slice(-4) === "ښودل" && infinitive.p.length > 4 && infinitive.p !== "کېښودل" && infinitive.p !== "کښېښودل") + // special thing for اېښودل - پرېښودل + ? [3, 4] + : (wrul.includes(infinitive.p) || (shortenableEndings.includes(infinitive.p.slice(-3)) && infinitive.p.slice(-4) !== "استل")) + ? [1, 2] + : [0, 0]; + if (trimP) { + return { + type: "VB", + ps: { + long: [infinitive], + short: [accentOnNFromEnd(trimOffPs(infinitive, trimP, trimF), 0)], + }, + }; + } + return vba; +} + export function getRootStem({ verb, rs, aspect, type, genderNumber, voice }: { verb: T.VerbEntry, rs: "root" | "stem", @@ -128,17 +159,14 @@ function getAbilityRs( ]; } -function getPassivePp(verb: T.VerbEntryNoFVars, genderNumber: T.GenderNumber): T.VBGenNum { +function getPassivePp(verb: T.VerbEntryNoFVars, genderNumber: T.GenderNumber): T.WeldedGN { const [_, [basicRoot]] = getImperfectiveRoot(verb); const longRoot = getLongVB(basicRoot); - const kedulVbGenNum = getPastParticiple(kedulStat, "active", genderNumber) as T.VBBasic & T.GenderNumber; - const kedulVb: T.VBBasic = { - type: "VB", - ps: kedulVbGenNum.ps, - }; - return weld(longRoot, kedulVb, genderNumber); -} + const kedulVb: T.VBGenNum = getPastParticiple(kedulStat, "active", genderNumber) as T.VBGenNum; + return weld(longRoot, kedulVb); +} +// TODO: could combine these two functions... function getPassiveRs(verb: T.VerbEntryNoFVars, aspect: T.Aspect, rs: "root" | "stem"): [[] | [T.VHead], [T.VBA]] { const [vHead, [basicRoot]] = (aspect === "imperfective" ? getImperfectiveRoot diff --git a/src/lib/src/new-verb-engine/rs-helpers.ts b/src/lib/src/new-verb-engine/rs-helpers.ts index c8e54e9..5cf4986 100644 --- a/src/lib/src/new-verb-engine/rs-helpers.ts +++ b/src/lib/src/new-verb-engine/rs-helpers.ts @@ -67,26 +67,19 @@ export function verbEndingConcat(ps: T.PsString[], end: T.PsString[]): T.PsStrin )); } -// TODO: better to have the genderNumber included and inferred in the right? -export function weld(left: T.Welded["left"], right: T.Welded["right"]): T.Welded; -export function weld(left: T.Welded["left"], right: T.Welded["right"], genderNum: T.GenderNumber): T.Welded & T.GenderNumber; -export function weld(left: T.Welded["left"], right: T.Welded["right"], genderNum?: T.GenderNumber): T.Welded { +export function weld(left: T.Welded["left"], right: T.VBGenNum): T.WeldedGN; +export function weld(left: T.Welded["left"], right: T.VBBasic): T.Welded; +export function weld(left: T.Welded["left"], right: T.VBBasic | T.VBGenNum): T.Welded | T.WeldedGN { return { type: "welded", left: removeAccentsFromLeft(left), right, - ...genderNum ? { - ...genderNum, - } : {}, - } + }; function removeAccentsFromLeft(left: T.Welded["left"]): T.Welded["left"] { if (left.type === "VB") { return { ...left, ps: removeAccentsWLength(left.ps), - ...genderNum ? { - ...genderNum, - } : {}, } } if (left.type === "NComp") { @@ -96,9 +89,6 @@ export function weld(left: T.Welded["left"], right: T.Welded["right"], genderNum ...left.comp, ps: removeAccents(left.comp.ps), }, - ...genderNum ? { - ...genderNum, - } : {}, }; } return { @@ -107,9 +97,6 @@ export function weld(left: T.Welded["left"], right: T.Welded["right"], genderNum ...left.right, ps: removeAccentsWLength(left.right.ps), }, - ...genderNum ? { - ...genderNum, - } : {}, }; } } @@ -174,11 +161,13 @@ export function addToVBBasicEnd(vb: T.VBBasic, end: T.PsString[]): T.VBBasic { }; } -export function getLongVB(vb: T.VBA): T.VBA { +export function getLongVB(vb: T.VBBasic): T.VBNoLenghts; +export function getLongVB(vb: T.VBA): T.VBNoLenghts; +export function getLongVB(vb: T.VBA): T.VBNoLenghts { if (vb.type === "welded") { return { ...vb, - right: getLongVB(vb) as T.VBBasic, + right: getLongVB(vb.right), }; } return { diff --git a/src/types.ts b/src/types.ts index aa138fb..09729a3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1077,14 +1077,18 @@ export type MiniPronoun = { export type VerbRenderedOutput = [[VHead] | [], [VB, VBE] | [VBE]]; export type RootsStemsOutput = [[VHead] | [], [VB, VBA] | [VBA]]; // or perfect / equative -export type VB = VBBasic | VBGenNum | Welded; +export type VB = VBBasic | VBGenNum | Welded | WeldedGN; /** A VB block that can have endings attached to it */ -export type VBA = Exclude; +export type VBA = Exclude; /** A VB block that has had a person verb ending attached */ export type VBE = (VBBasic | Welded) & { person: Person, }; // or equative +export type VBNoLenghts = V extends VBBasic + ? Omit & { ps: PsString[] } + : Omit & { right: VBNoLenghts> }; + export type VBBasic = { type: "VB", ps: SingleOrLengthOpts, @@ -1092,7 +1096,7 @@ export type VBBasic = { // TODO: might be a better design decision to keep the GenderNuber stuff // in the RIGHT side of the weld -export type VBGenNum = (VBBasic | Welded) & GenderNumber; +export type VBGenNum = VBBasic & GenderNumber; export type GenderNumber = { gender: Gender, @@ -1105,6 +1109,8 @@ export type Welded = { right: VBBasic, }; +export type WeldedGN = Omit & { right: VBGenNum }; + export type VHead = PH | NComp; /** perfective head block */