From 590ed3e0d8a63c7612237437e7840854e133cc39 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Sun, 10 Jul 2022 18:55:23 -0500 Subject: [PATCH] english working properly with kawul/kedul w compounds --- package.json | 2 +- src/lib/phrase-building/blocks-utils.ts | 14 ++++++++------ src/lib/phrase-building/compile.ts | 11 +++++++---- src/lib/phrase-building/english-vp-rendering.ts | 5 +++-- src/lib/phrase-building/render-vp.ts | 4 ++-- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index b298204..2f31bb5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "3.3.4", + "version": "3.3.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/lib/phrase-building/blocks-utils.ts b/src/lib/phrase-building/blocks-utils.ts index 972ee3f..4557147 100644 --- a/src/lib/phrase-building/blocks-utils.ts +++ b/src/lib/phrase-building/blocks-utils.ts @@ -113,14 +113,16 @@ export function getAPsFromBlocks(blocks: T.Block[][]): T.Rendered } export function getComplementFromBlocks(blocks: T.Block[][]): T.Rendered | T.Rendered | undefined { - const complement = blocks[0].find(b => b.block.type === "complement"); - if (!complement) { - return undefined; + const complement = blocks[0].find(b => b.block.type === "complement")?.block as T.Rendered | T.Rendered | undefined; + if (complement) { + return complement; } - if (complement.block.type !== "complement") { - throw new Error("error finding complement - other kind of block retrieved"); + // maybe there's a complement in the verb block + const verb = blocks[0].find(b => b.block.type === "verb" && b.block)?.block as T.VerbRenderedBlock | undefined; + if (verb?.block.complement) { + return verb.block.complement; } - return complement.block; + return undefined; } export function getObjectSelection(blocks: T.VPSBlockComplete[]): T.ObjectSelectionComplete; diff --git a/src/lib/phrase-building/compile.ts b/src/lib/phrase-building/compile.ts index 1d39311..4830b8d 100644 --- a/src/lib/phrase-building/compile.ts +++ b/src/lib/phrase-building/compile.ts @@ -26,8 +26,8 @@ import { } from "./blocks-utils"; const blank: T.PsString = { - p: "______", - f: "______", + p: "_____", + f: "_____", }; type BlankoutOptions = { equative?: boolean, ba?: boolean, kidsSection?: boolean }; @@ -174,8 +174,9 @@ function combineIntoText(piecesWVars: (T.Block | T.Kid | T.PsString)[][], subjec return combine(rest).flatMap(r => ( firstPs.map(fPs => concatPsString( fPs, + // TODO: this spacing is a mess and not accurate (!("p" in first) && "block" in first && first.block.type === "perfectiveHead" && !("p" in next) && (("block" in next && (next.block.type === "verb" || next.block.type === "negative" || next.block.type === "modalVerbBlock")) || ("kid" in next && next.kid.type === "mini-pronoun"))) - ? ((("block" in next && next.block.type === "negative") || ("kid" in next && next.kid.type === "mini-pronoun")) ? { p: "", f: "-" } : "") + ? ((("block" in next && next.block.type === "negative") || ("kid" in next && next.kid.type === "mini-pronoun")) ? { p: "", f: " " } : "") : " ", r, )) @@ -206,6 +207,7 @@ function getPsFromPiece(piece: T.Block | T.Kid, subjectPerson: T.Person): T.PsSt return [piece.block.ps]; } if (piece.block.type === "verbComplement") { + // TODO: WHAAAAT return [{ p: "____", f: "____"}]; //getPashtoFromRendered(piece.block.complement); } if (piece.block.type === "objectSelection") { @@ -277,12 +279,13 @@ function getEngAPs(blocks: T.Block[][]): string { function getEngComplement(blocks: T.Block[][]): string | undefined { const comp = getComplementFromBlocks(blocks); if (!comp) return undefined; - if (comp.selection === undefined) { + if (comp.selection.type === "unselected") { return "____"; } if (comp.selection.type === "sandwich") { return getEnglishFromRendered({ type: "AP", selection: comp.selection }); } + return comp.selection.e; } function putKidsInKidsSection(blocksWVars: T.Block[][], kids: T.Kid[], enforceKidsSectionBlankout: boolean): (T.Block | T.Kid | T.PsString)[][] { diff --git a/src/lib/phrase-building/english-vp-rendering.ts b/src/lib/phrase-building/english-vp-rendering.ts index ba294d0..489bf3e 100644 --- a/src/lib/phrase-building/english-vp-rendering.ts +++ b/src/lib/phrase-building/english-vp-rendering.ts @@ -24,7 +24,8 @@ export function renderEnglishVPBase({ subjectPerson, object, vs }: { vs: T.VerbSelectionComplete, }): string[] { const ec = parseEc(vs.verb.entry.ec || ""); - const ep = vs.verb.entry.ep; + // in case there's something left with the deprecated ep as _____ + const ep = vs.verb.entry.ep?.includes("__") ? undefined : vs.verb.entry.ep; function engEquative(tense: "past" | "present", s: T.Person): string { const [row, col] = getVerbBlockPosFromPerson(s); return grammarUnits.englishEquative[tense][row][col]; @@ -53,8 +54,8 @@ export function renderEnglishVPBase({ subjectPerson, object, vs }: { `$SUBJ ${engEquative("present", s)}${n ? " not" : ""} ${ec[2]}`, ]), subjunctiveVerb: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([ - `that $SUBJ ${n ? " won't" : " will"} ${isToBe(ec) ? "be" : ec[0]}`, `$SUBJ ${n ? " not" : ""} should ${isToBe(ec) ? "be" : ec[0]}`, + `that $SUBJ ${n ? " won't" : " will"} ${isToBe(ec) ? "be" : ec[0]}`, ]), imperfectiveFuture: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([ `$SUBJ will${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`, diff --git a/src/lib/phrase-building/render-vp.ts b/src/lib/phrase-building/render-vp.ts index e36f370..63eb0c1 100644 --- a/src/lib/phrase-building/render-vp.ts +++ b/src/lib/phrase-building/render-vp.ts @@ -60,7 +60,7 @@ export function renderVP(VP: T.VPSelectionComplete): T.VPRendered { king, complementPerson, }); - const { verbBlocks, hasBa } = renderVerbSelection(VP.verb, kingPerson, objectPerson, VP.externalComplement); + const { verbBlocks, hasBa } = renderVerbSelection(VP.verb, kingPerson, objectPerson === undefined ? subjectPerson : objectPerson, VP.externalComplement); const b: T.VPRendered = { type: "VPRendered", king, @@ -436,7 +436,7 @@ function renderVerbSelection(vs: T.VerbSelectionComplete, person: T.Person, comp }; const verbBlocks = [ ...(head ? ( - (vs.isCompound === "stative" && !vrb.block.complement) ? [{ + (!!(vs.isCompound === "stative" && vrb.block.complement)) ? [{ type: "verbComplement", complement: head, } as T.VerbComplementBlock] : [{