fixed some complement issues

This commit is contained in:
lingdocs 2022-07-21 19:17:41 -05:00
parent 584a3646fe
commit 76349ceaab
5 changed files with 43 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/pashto-inflector", "name": "@lingdocs/pashto-inflector",
"version": "3.4.7", "version": "3.4.8",
"author": "lingdocs.com", "author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com", "homepage": "https://verbs.lingdocs.com",

View File

@ -34,7 +34,7 @@ function Examples(props: ({
const examples = "children" in props ? props.children : props.ex; const examples = "children" in props ? props.children : props.ex;
const Example = ({ children: text }: { children: PsStringWSub }) => ( const Example = ({ children: text }: { children: PsStringWSub }) => (
<div className={props.lineHeight !== undefined ? `mb-${props.lineHeight}` : `mt-1 mb-3`}> <div className={props.lineHeight !== undefined ? `mb-${props.lineHeight}` : `mt-1 mb-3`}>
<div dir="rtl"> <div>
<Pashto opts={props.opts}>{text}</Pashto> <Pashto opts={props.opts}>{text}</Pashto>
</div> </div>
<div> <div>

View File

@ -138,7 +138,7 @@ function ModalVerbBlock({ opts, v, script }: {
</> </>
</Border> </Border>
<div>Verb</div> <div>Verb</div>
<EnglishBelow>Modal</EnglishBelow> <EnglishBelow>Ability</EnglishBelow>
</div> </div>
} }

View File

@ -234,7 +234,11 @@ function getPsFromPiece(piece: T.Block | T.Kid, subjectPerson: T.Person): T.PsSt
} }
if (piece.block.type === "modalVerbBlock") { if (piece.block.type === "modalVerbBlock") {
// getLong is just for type safety - we will have split up the length options earlier in compileVPPs // getLong is just for type safety - we will have split up the length options earlier in compileVPPs
return getLong(piece.block.ps); const verbPs = getLong(piece.block.ps);
if (piece.block.complementWelded) {
return combineComplementWVerbPs(piece.block.complementWelded, verbPs);
}
return verbPs;
} }
if (piece.block.type === "modalVerbKedulPart") { if (piece.block.type === "modalVerbKedulPart") {
// just using the short one for now - it will only be short anyways // just using the short one for now - it will only be short anyways

View File

@ -436,7 +436,9 @@ function renderVerbSelection(vs: T.VerbSelectionComplete, person: T.Person, comp
type: "verb", type: "verb",
block: { block: {
...vs, ...vs,
ps: rest, ps: (!perfective && renderedComplement && vs.verb.entry.p.includes(" "))
? removeComplement(rest, renderedComplement)
: rest,
person, person,
hasBa, hasBa,
complementWelded: ((!perfective && renderedComplement) && ( complementWelded: ((!perfective && renderedComplement) && (
@ -464,13 +466,42 @@ function renderVerbSelection(vs: T.VerbSelectionComplete, person: T.Person, comp
: [], : [],
...splitUpIfModal(vrb), ...splitUpIfModal(vrb),
] as VerbBlocks; ] as VerbBlocks;
const perfectStuff = isPerfectTense(vrb.block.tense) ? getPerfectStuff(rest, vrb) : undefined; const perfectStuff = isPerfectTense(vrb.block.tense) ? getPerfectStuff(vrb) : undefined;
return { return {
verbBlocks: perfectStuff ? perfectStuff : verbBlocks, verbBlocks: perfectStuff ? perfectStuff : verbBlocks,
hasBa, hasBa,
}; };
} }
function removeComplement(ps: T.SingleOrLengthOpts<T.PsString[]>, complement: T.Rendered<T.ComplementSelection | T.UnselectedComplementSelection>): T.SingleOrLengthOpts<T.PsString[]> {
if ("long" in ps) {
return {
long: removeComplement(ps.long, complement) as T.PsString[],
short: removeComplement(ps.short, complement) as T.PsString[],
...ps.mini ? {
mini: removeComplement(ps.mini, complement) as T.PsString[],
} : {},
};
}
const c = complement.selection.type === "adjective"
? complement.selection.ps
: complement.selection.type === "loc. adv."
? complement.selection.ps
: complement.selection.type === "sandwich"
? complement.selection.inside.selection.ps
: complement.selection.type === "noun"
? complement.selection.ps
: complement.selection.ps;
// TODO: this is brutal
const removed = ps.map(p => (
c.reduce((acc, v) => ({
p: acc.p.replace(`${v.p} `, ""),
f: acc.f.replace(`${v.f} `, ""),
}), p)
));
return removed;
}
function createComplementRetroactively(complement: T.DictionaryEntry | undefined, person: T.Person | undefined): T.ComplementSelection { function createComplementRetroactively(complement: T.DictionaryEntry | undefined, person: T.Person | undefined): T.ComplementSelection {
// This is a bit of a hack to work with the current verb conjugation system. // This is a bit of a hack to work with the current verb conjugation system.
if (!complement) { if (!complement) {
@ -534,8 +565,8 @@ function splitUpIfModal(v: T.VerbRenderedBlock): [T.VerbRenderedBlock] | [T.Moda
]; ];
} }
function getPerfectStuff(v: T.SingleOrLengthOpts<T.PsString[]>, vrb: T.VerbRenderedBlock): [T.PerfectParticipleBlock, T.PerfectEquativeBlock] { function getPerfectStuff(vrb: T.VerbRenderedBlock): [T.PerfectParticipleBlock, T.PerfectEquativeBlock] {
const [p, eq] = splitOffLeapfrogWordFull(v); const [p, eq] = splitOffLeapfrogWordFull(vrb.block.ps);
return [ return [
{ {
type: "perfectParticipleBlock", type: "perfectParticipleBlock",