fixed kids blanking thing

This commit is contained in:
lingdocs 2022-06-14 20:44:07 -04:00
parent cd323bd286
commit 36078c2433
2 changed files with 10 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/pashto-inflector", "name": "@lingdocs/pashto-inflector",
"version": "2.9.6", "version": "2.9.7",
"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

@ -263,7 +263,6 @@ function arrangeVerbWNegative(head: T.PsString | undefined, restRaw: T.PsString[
export function compileEP(EP: T.EPRendered): { ps: T.SingleOrLengthOpts<T.PsString[]>, e?: string[] }; export function compileEP(EP: T.EPRendered): { ps: T.SingleOrLengthOpts<T.PsString[]>, e?: string[] };
export function compileEP(EP: T.EPRendered, combineLengths: true, blankOut?: BlankoutOptions): { ps: T.PsString[], e?: string[] }; export function compileEP(EP: T.EPRendered, combineLengths: true, blankOut?: BlankoutOptions): { ps: T.PsString[], e?: string[] };
export function compileEP(EP: T.EPRendered, combineLengths?: boolean, blankOut?: BlankoutOptions): { ps: T.SingleOrLengthOpts<T.PsString[]>, e?: string[] } { export function compileEP(EP: T.EPRendered, combineLengths?: boolean, blankOut?: BlankoutOptions): { ps: T.SingleOrLengthOpts<T.PsString[]>, e?: string[] } {
console.log("blankout options passed", blankOut);
const psResult = compileEPPs(EP.blocks, EP.kids, EP.omitSubject, blankOut); const psResult = compileEPPs(EP.blocks, EP.kids, EP.omitSubject, blankOut);
return { return {
ps: combineLengths ? flattenLengths(psResult) : psResult, ps: combineLengths ? flattenLengths(psResult) : psResult,
@ -283,21 +282,22 @@ function compileEPPs(blocks: T.Block[], kids: T.Kid[], omitSubject: boolean, bla
const blocksWKids = putKidsInKidsSection( const blocksWKids = putKidsInKidsSection(
omitSubject ? blocks.filter(b => b.type !== "subjectSelection") : blocks, omitSubject ? blocks.filter(b => b.type !== "subjectSelection") : blocks,
kids, kids,
!!blankOut?.kidsSection
); );
// BIG TODO: If the kid's section is blank and there are no kids - add a blank for the kids section!
return removeDuplicates(combineIntoText(blocksWKids, subjectPerson, blankOut)); return removeDuplicates(combineIntoText(blocksWKids, subjectPerson, blankOut));
} }
function combineIntoText(pieces: (T.Block | T.Kid)[], subjectPerson: T.Person, blankOut?: BlankoutOptions): T.PsString[] { function combineIntoText(pieces: (T.Block | T.Kid | T.PsString)[], subjectPerson: T.Person, blankOut?: BlankoutOptions): T.PsString[] {
console.log("in text combining blankout", blankOut);
const first = pieces[0]; const first = pieces[0];
const rest = pieces.slice(1); const rest = pieces.slice(1);
const firstPs = (blankOut?.equative && first.type === "equative") const firstPs = ("p" in first)
? [first]
: (blankOut?.equative && first.type === "equative")
? [blank] ? [blank]
: ((blankOut?.ba || blankOut?.kidsSection) && first.type === "ba") : ((blankOut?.ba) && first.type === "ba")
// TODO: properly handle blanking out whole kids section
? [kidsBlank] ? [kidsBlank]
: getPsFromPiece(first, subjectPerson); : getPsFromPiece(first, subjectPerson);
console.log({ first, firstPs });
if (!rest.length) { if (!rest.length) {
return firstPs; return firstPs;
} }
@ -346,12 +346,12 @@ function getEnglishAPs(blocks: (T.Rendered<T.SubjectSelectionComplete> | T.Rende
}, ""); }, "");
} }
function putKidsInKidsSection(blocks: T.Block[], kids: T.Kid[]): (T.Block | T.Kid)[] { function putKidsInKidsSection(blocks: T.Block[], kids: T.Kid[], enforceKidsSectionBlankout: boolean): (T.Block | T.Kid | T.PsString)[] {
const first = blocks[0]; const first = blocks[0];
const rest = blocks.slice(1); const rest = blocks.slice(1);
return [ return [
first, first,
...kids, ...enforceKidsSectionBlankout ? [kidsBlank] : kids,
...rest, ...rest,
]; ];
} }