more, getting closer

This commit is contained in:
adueck 2023-04-07 20:44:26 +04:00
parent 305fb545b9
commit ce2fa640c0
4 changed files with 185 additions and 79 deletions

View File

@ -4,9 +4,6 @@ import {
personGender, personGender,
personNumber, personNumber,
} from "../misc-helpers"; } from "../misc-helpers";
import {
trimOffPs,
} from "../p-text-helpers";
import { import {
concatPsString, concatPsString,
getLength, getLength,
@ -21,8 +18,8 @@ import { tenseHasBa } from "../phrase-building/vp-tools";
import { isPastTense } from "../phrase-building/vp-tools"; import { isPastTense } from "../phrase-building/vp-tools";
import { makePsString, removeFVarients } from "../accent-and-ps-utils"; import { makePsString, removeFVarients } from "../accent-and-ps-utils";
import { pashtoConsonants } from "../pashto-consonants"; import { pashtoConsonants } from "../pashto-consonants";
import { accentPsSyllable } from "../accent-helpers";
import { getRootStem } from "./roots-and-stems"; import { getRootStem } from "./roots-and-stems";
import { verbEndingConcat } from "./rs-helpers";
// For the chart display of the results: base the length thing on the VBE at the end, if there are other // For the chart display of the results: base the length thing on the VBE at the end, if there are other
// length variations earlier in the blocks, flatten those into the variations // length variations earlier in the blocks, flatten those into the variations
@ -65,14 +62,17 @@ export function renderVerb({ verb, tense, person, voice }: {
number: personNumber(person), number: personNumber(person),
}; };
// #1 get the appropriate root / stem // #1 get the appropriate root / stem
console.log({ isAbility });
const [vHead, rest] = getRootStem({ const [vHead, rest] = getRootStem({
verb, verb,
part: { part: {
rs: isPast ? "root" : "stem", rs: isPast ? "root" : "stem",
aspect, aspect,
}, },
type: isAbility ? "ability" : "basic", type: voice === "passive"
? "passive"
: isAbility
? "ability"
: "basic",
genderNumber, genderNumber,
}); });
// #2 add the verb ending to it // #2 add the verb ending to it
@ -156,20 +156,6 @@ function addEnding({ verb, rs, ending, person, pastThird, aspect }: {
} }
} }
function verbEndingConcat(ps: T.PsString[], end: T.PsString[]): T.PsString[] {
return ps.flatMap(v => (
end.map(e => {
if (v.f.charAt(v.f.length-1) === "X") {
return concatPsString(trimOffPs(v, 0, 1), accentPsSyllable(e))
}
if (e.p === "ل" && ["ul", "úl"].includes(v.f.slice(-2))) {
return v;
}
return concatPsString(v, e);
})
));
}
function getEnding(person: T.Person, isPast: boolean) { function getEnding(person: T.Person, isPast: boolean) {
const [row, col] = getVerbBlockPosFromPerson(person); const [row, col] = getVerbBlockPosFromPerson(person);
return isPast ? { return isPast ? {

View File

@ -7,13 +7,15 @@
*/ */
import { import {
concatPsString, trimOffPs, concatPsString, getLength, trimOffPs,
} from "../p-text-helpers"; } from "../p-text-helpers";
import * as T from "../../../types"; import * as T from "../../../types";
import { makePsString, removeFVarientsFromVerb } from "../accent-and-ps-utils"; import { makePsString, removeFVarientsFromVerb } from "../accent-and-ps-utils";
import { accentOnNFromEnd, accentSyllable, removeAccents } from "../accent-helpers"; import { accentOnNFromEnd, accentSyllable, removeAccents } from "../accent-helpers";
import { isKawulVerb } from "../type-predicates"; import { isKawulVerb } from "../type-predicates";
import { inflectPattern1 } from "./new-inflectors"; import { vEntry, addAbilityEnding, weld, removeL, addTrailingAccent, tlulPerfectiveStem } from "./rs-helpers";
const kedulStat = vEntry({"ts":1581086654898,"i":11100,"p":"کېدل","f":"kedul","g":"kedul","e":"to become _____","r":2,"c":"v. intrans.","ssp":"ش","ssf":"sh","prp":"شول","prf":"shwul","pprtp":"شوی","pprtf":"shúwey","noOo":true,"ec":"become"});
const shwulVB: T.VBBasic = { const shwulVB: T.VBBasic = {
type: "VB", type: "VB",
@ -22,6 +24,10 @@ const shwulVB: T.VBBasic = {
short: [{ p: "شو", f: "shw" }], short: [{ p: "شو", f: "shw" }],
}, },
} }
const shVB: T.VBBasic = {
type: "VB",
ps: [{ p: "ش", f: "sh" }],
}
// start basic inflection functions for pattern 1 and pattern ey things // start basic inflection functions for pattern 1 and pattern ey things
// to be used by inflecting لاړ and participles // to be used by inflecting لاړ and participles
@ -38,36 +44,65 @@ export function getRootStem({ verb, part, type, genderNumber }: {
number: T.NounNumber, number: T.NounNumber,
}, },
}): T.RootsStemsOutput { }): T.RootsStemsOutput {
console.log({ type });
const v = removeFVarientsFromVerb(verb); const v = removeFVarientsFromVerb(verb);
if (part === "pastPart") { if (part === "pastPart") {
throw new Error("not implemented yet"); throw new Error("not implemented yet");
} }
console.log({ part }); if (type === "ability") {
return getAbilityRs(v, part);
}
if (type === "passive") {
return getPassiveRs(v, part);
}
return part.rs === "stem" return part.rs === "stem"
? part.aspect === "imperfective" ? part.aspect === "imperfective"
? getImperfectiveStem(v) ? getImperfectiveStem(v)
: getPerfectiveStem(v, genderNumber) : getPerfectiveStem(v, genderNumber)
: part.aspect === "imperfective" : part.aspect === "imperfective"
? getImperfectiveRoot(v, type) ? getImperfectiveRoot(v)
: getPerfectiveRoot(v); : getPerfectiveRoot(v);
} }
function getImperfectiveRoot(verb: T.VerbEntryNoFVars, type: "basic" | "ability" | "passive"): T.RootsStemsOutput { function getAbilityRs(verb: T.VerbEntryNoFVars, { aspect, rs }: { aspect: T.Aspect, rs: "root" | "stem" }): [[] | [T.VHead], [T.VB, T.VBA]] {
// if (type === "ability") { const [vHead, [basicRoot]] = (aspect === "imperfective"
// console.log("in ability"); ? getImperfectiveRoot
// const basic = getImperfectiveRoot(verb, "basic") as [[T.VHead] | [], [T.VBA]]; : getPerfectiveRoot
// return [ )(verb);
// basic[0], return [
// [ vHead,
// { [
// type: "VB", addAbilityEnding(basicRoot),
rs === "root" ? shwulVB : shVB,
],
];
}
// [1], function getPassiveRs(verb: T.VerbEntryNoFVars, part: { aspect: T.Aspect, rs: "root" | "stem" }): [[] | [T.VHead], [T.VBA]] {
// shwulVB, const [vHead, [basicRoot]] = (part.aspect === "imperfective"
// ], ? getImperfectiveRoot
// ]; : getPerfectiveRoot
// } )(verb);
const longRoot = getLongVB(basicRoot);
const kedulVba = getRootStem({ verb: kedulStat, part, type: "basic", genderNumber: { gender: "masc", number: "singular" }})[1][0] as T.VBBasic;
return [
vHead,
[weld(longRoot, kedulVba)],
];
function getLongVB(vb: T.VBA): T.VBA {
if (vb.type === "welded") {
return {
...vb,
right: getLongVB(vb) as T.VBBasic,
};
}
return {
...vb,
ps: getLength(vb.ps, "long"),
};
}
}
function getImperfectiveRoot(verb: T.VerbEntryNoFVars): [[], [T.VBA]] {
const infinitive = accentOnNFromEnd(makePsString(verb.entry.p, verb.entry.f), 0); const infinitive = accentOnNFromEnd(makePsString(verb.entry.p, verb.entry.f), 0);
return [ return [
[], [],
@ -83,7 +118,7 @@ function getImperfectiveRoot(verb: T.VerbEntryNoFVars, type: "basic" | "ability"
]; ];
} }
function getPerfectiveRoot(verb: T.VerbEntryNoFVars): T.RootsStemsOutput { function getPerfectiveRoot(verb: T.VerbEntryNoFVars): [[T.VHead] | [], [T.VBA]] {
const base = removeAccents( const base = removeAccents(
(verb.entry.prp && verb.entry.prf) (verb.entry.prp && verb.entry.prf)
? makePsString(verb.entry.prp, verb.entry.prf) ? makePsString(verb.entry.prp, verb.entry.prf)
@ -258,37 +293,3 @@ function getPerfectiveHead(base: T.PsString, { entry }: T.VerbEntryNoFVars): [T.
}; };
} }
} }
function addTrailingAccent(ps: T.PsString): T.PsString {
return {
p: ps.p,
f: ps.f + "X",
};
}
function addUl(b: T.PsString): T.PsString {
return concatPsString(b, { p: "ل", f: "ul" });
}
// TODO: could do removeEndingL (slower but safer)
function removeL(ps: T.PsString): T.PsString {
return trimOffPs(ps, 1, 2);
}
function tlulPerfectiveStem(person: { gender: T.Gender, number: T.NounNumber }): T.RootsStemsOutput {
return [
[
{
type: "PH",
ps: inflectPattern1({ p: "لاړ", f: "laaR" }, person).map(x => concatPsString(x, " "))[0],
},
],
[
{
type: "VB",
ps: [{ p: "ش", f: "sh" }],
},
],
];
}

View File

@ -1,13 +1,17 @@
import * as T from "../../../types"; import * as T from "../../../types";
import { removeFVarients } from "../accent-and-ps-utils";
import { accentPsSyllable, removeAccents, removeAccentsWLength } from "../accent-helpers";
import { concatPsString, trimOffPs } from "../p-text-helpers";
import { getRootStem } from "./roots-and-stems"; import { getRootStem } from "./roots-and-stems";
import { inflectPattern1 } from "./new-inflectors";
export function vEntry(e: any, c?: any): T.VerbEntry { export function vEntry(e: any, c?: any): T.VerbEntryNoFVars {
return { return {
entry: e, entry: removeFVarients(e),
...c ? { ...c ? {
c, c,
} : {}, } : {},
} as T.VerbEntry; } as T.VerbEntryNoFVars;
} }
export function getAllRs(verb: T.VerbEntry): { export function getAllRs(verb: T.VerbEntry): {
@ -31,3 +35,117 @@ export function getAllRs(verb: T.VerbEntry): {
}, },
}; };
} }
/**
* adds a verb ending, creating all the variations with a set of root psStrings
* it is aware of the trailing accent marker X and also avoids adding the double ل ending 3rd pers masc plur
*
* @param ps - a verb root/stem
* @param end - the verb ending
* @returns
*/
export function verbEndingConcat(ps: T.PsString[], end: T.PsString[]): T.PsString[] {
return ps.flatMap(v => (
end.map(e => {
if (v.f.charAt(v.f.length-1) === "X") {
return concatPsString(trimOffPs(v, 0, 1), accentPsSyllable(e))
}
if (e.p === "ل" && ["ul", "úl"].includes(v.f.slice(-2))) {
return v;
}
return concatPsString(v, e);
})
));
}
export function weld(left: T.Welded["left"], right: T.Welded["right"]): T.Welded {
return {
type: "welded",
left: removeAccentsFromLeft(left),
right,
}
function removeAccentsFromLeft(left: T.Welded["left"]): T.Welded["left"] {
if (left.type === "VB") {
return {
...left,
ps: removeAccentsWLength(left.ps),
}
}
if (left.type === "NComp") {
return {
...left,
comp: {
...left.comp,
ps: removeAccents(left.comp.ps),
}
};
}
return {
...left,
right: {
...left.right,
ps: removeAccentsWLength(left.right.ps),
},
};
}
}
export function addTrailingAccent(ps: T.PsString): T.PsString {
return {
p: ps.p,
f: ps.f + "X",
};
}
// TODO: could do removeEndingL (slower but safer)
export function removeL(ps: T.PsString): T.PsString {
return trimOffPs(ps, 1, 2);
}
export function tlulPerfectiveStem(person: { gender: T.Gender, number: T.NounNumber }): T.RootsStemsOutput {
return [
[
{
type: "PH",
ps: inflectPattern1({ p: "لاړ", f: "laaR" }, person).map(x => concatPsString(x, " "))[0],
},
],
[
{
type: "VB",
ps: [{ p: "ش", f: "sh" }],
},
],
];
}
export function addAbilityEnding(vb: T.VBA): T.VBA {
const abilityEnding: T.PsString[] = [
{ p: "ی", f: "ey" },
{ p: "ای", f: "aay" },
];
if (vb.type === "welded") {
return {
...vb,
right: addToVBBasicEnd(vb.right, abilityEnding),
};
}
return addToVBBasicEnd(vb, abilityEnding);
}
export function addToVBBasicEnd(vb: T.VBBasic, end: T.PsString[]): T.VBBasic {
if ("long" in vb.ps) {
return {
...vb,
ps: {
long: verbEndingConcat(vb.ps.long, end),
short: verbEndingConcat(vb.ps.short, end),
},
};
}
return {
...vb,
ps: verbEndingConcat(vb.ps, end),
};
}

View File

@ -1078,8 +1078,9 @@ export type VerbRenderedOutput = [[VHead] | [], [VB, VBE] | [VBE]];
export type RootsStemsOutput = [[VHead] | [], [VB, VBA] | [VBA]]; // or perfect / equative export type RootsStemsOutput = [[VHead] | [], [VB, VBA] | [VBA]]; // or perfect / equative
export type VB = VBBasic | VBGenNum | Welded; export type VB = VBBasic | VBGenNum | Welded;
/** A VB block that can have endings attached to it */
export type VBA = Exclude<VB, VBGenNum>; export type VBA = Exclude<VB, VBGenNum>;
/** A VB block that has had a person verb ending attached */
export type VBE = (VBBasic | Welded) & { export type VBE = (VBBasic | Welded) & {
person: Person, person: Person,
}; // or equative }; // or equative