From 76349ceaab4b2083020780111480fe0511d72e01 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Thu, 21 Jul 2022 19:17:41 -0500 Subject: [PATCH] fixed some complement issues --- package.json | 2 +- src/components/Examples.tsx | 2 +- src/components/blocks/Block.tsx | 2 +- src/lib/phrase-building/compile.ts | 6 ++++- src/lib/phrase-building/render-vp.ts | 39 +++++++++++++++++++++++++--- 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 1df32f1..17c11e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "3.4.7", + "version": "3.4.8", "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/Examples.tsx b/src/components/Examples.tsx index 08eeecd..8faa5f0 100644 --- a/src/components/Examples.tsx +++ b/src/components/Examples.tsx @@ -34,7 +34,7 @@ function Examples(props: ({ const examples = "children" in props ? props.children : props.ex; const Example = ({ children: text }: { children: PsStringWSub }) => (
-
+
{text}
diff --git a/src/components/blocks/Block.tsx b/src/components/blocks/Block.tsx index 0e2c906..2d68326 100644 --- a/src/components/blocks/Block.tsx +++ b/src/components/blocks/Block.tsx @@ -138,7 +138,7 @@ function ModalVerbBlock({ opts, v, script }: {
Verb
- Modal + Ability
} diff --git a/src/lib/phrase-building/compile.ts b/src/lib/phrase-building/compile.ts index 2550972..5327058 100644 --- a/src/lib/phrase-building/compile.ts +++ b/src/lib/phrase-building/compile.ts @@ -234,7 +234,11 @@ function getPsFromPiece(piece: T.Block | T.Kid, subjectPerson: T.Person): T.PsSt } if (piece.block.type === "modalVerbBlock") { // 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") { // just using the short one for now - it will only be short anyways diff --git a/src/lib/phrase-building/render-vp.ts b/src/lib/phrase-building/render-vp.ts index cef831d..c1c1f46 100644 --- a/src/lib/phrase-building/render-vp.ts +++ b/src/lib/phrase-building/render-vp.ts @@ -436,7 +436,9 @@ function renderVerbSelection(vs: T.VerbSelectionComplete, person: T.Person, comp type: "verb", block: { ...vs, - ps: rest, + ps: (!perfective && renderedComplement && vs.verb.entry.p.includes(" ")) + ? removeComplement(rest, renderedComplement) + : rest, person, hasBa, complementWelded: ((!perfective && renderedComplement) && ( @@ -464,13 +466,42 @@ function renderVerbSelection(vs: T.VerbSelectionComplete, person: T.Person, comp : [], ...splitUpIfModal(vrb), ] as VerbBlocks; - const perfectStuff = isPerfectTense(vrb.block.tense) ? getPerfectStuff(rest, vrb) : undefined; + const perfectStuff = isPerfectTense(vrb.block.tense) ? getPerfectStuff(vrb) : undefined; return { verbBlocks: perfectStuff ? perfectStuff : verbBlocks, hasBa, }; } +function removeComplement(ps: T.SingleOrLengthOpts, complement: T.Rendered): T.SingleOrLengthOpts { + 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 { // This is a bit of a hack to work with the current verb conjugation system. if (!complement) { @@ -534,8 +565,8 @@ function splitUpIfModal(v: T.VerbRenderedBlock): [T.VerbRenderedBlock] | [T.Moda ]; } -function getPerfectStuff(v: T.SingleOrLengthOpts, vrb: T.VerbRenderedBlock): [T.PerfectParticipleBlock, T.PerfectEquativeBlock] { - const [p, eq] = splitOffLeapfrogWordFull(v); +function getPerfectStuff(vrb: T.VerbRenderedBlock): [T.PerfectParticipleBlock, T.PerfectEquativeBlock] { + const [p, eq] = splitOffLeapfrogWordFull(vrb.block.ps); return [ { type: "perfectParticipleBlock",