better blanking in compile

This commit is contained in:
lingdocs 2022-08-29 18:51:33 +04:00
parent 4c199b8f8b
commit 46c897735d
3 changed files with 14 additions and 11 deletions

View File

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

@ -38,7 +38,7 @@ function VPDisplay({ VPS, opts, setForm, justify, onlyOne, length, mode: preferr
</div>; </div>;
} }
const rendered = renderVP(VP); const rendered = renderVP(VP);
const result = compileVP(rendered, rendered.form); const result = compileVP(rendered, rendered.form, true);
return <div className={`text-${justify ? justify : "center"} mt-1`}> return <div className={`text-${justify ? justify : "center"} mt-1`}>
{typeof setForm === "function" && !inlineFormChoice && <AbbreviationFormSelector {typeof setForm === "function" && !inlineFormChoice && <AbbreviationFormSelector
adjustable={rendered.whatsAdjustable} adjustable={rendered.whatsAdjustable}

View File

@ -71,8 +71,8 @@ export function compileEP(EP: T.EPRendered, combineLengths?: boolean, blankOut?:
} }
export function compileVP(VP: T.VPRendered, form: T.FormVersion): { ps: T.SingleOrLengthOpts<T.PsString[]>, e?: string [] }; export function compileVP(VP: T.VPRendered, form: T.FormVersion): { ps: T.SingleOrLengthOpts<T.PsString[]>, e?: string [] };
export function compileVP(VP: T.VPRendered, form: T.FormVersion, combineLengths: true, blankOut?: "verb"): { ps: T.PsString[], e?: string [] }; export function compileVP(VP: T.VPRendered, form: T.FormVersion, combineLengths: true, blankOut?: BlankoutOptions): { ps: T.PsString[], e?: string [] };
export function compileVP(VP: T.VPRendered, form: T.FormVersion, combineLengths?: true, blankOut?: "verb"): { ps: T.SingleOrLengthOpts<T.PsString[]>, e?: string [] } { export function compileVP(VP: T.VPRendered, form: T.FormVersion, combineLengths?: true, blankOut?: BlankoutOptions): { ps: T.SingleOrLengthOpts<T.PsString[]>, e?: string [] } {
const verb = getVerbFromBlocks(VP.blocks).block; const verb = getVerbFromBlocks(VP.blocks).block;
const psResult = compileVPPs(VP.blocks, VP.kids, form, VP.king, blankOut); const psResult = compileVPPs(VP.blocks, VP.kids, form, VP.king, blankOut);
return { return {
@ -82,7 +82,7 @@ export function compileVP(VP: T.VPRendered, form: T.FormVersion, combineLengths?
}; };
} }
function compileVPPs(blocks: T.Block[][], kids: T.Kid[], form: T.FormVersion, king: "subject" | "object", blankOut?: "verb"): T.SingleOrLengthOpts<T.PsString[]> { function compileVPPs(blocks: T.Block[][], kids: T.Kid[], form: T.FormVersion, king: "subject" | "object", blankOut?: BlankoutOptions): T.SingleOrLengthOpts<T.PsString[]> {
const lengthyBlock = getLengthyFromBlocks(blocks); const lengthyBlock = getLengthyFromBlocks(blocks);
const potentialLengthy = lengthyBlock?.type === "verb" const potentialLengthy = lengthyBlock?.type === "verb"
? lengthyBlock.block.ps ? lengthyBlock.block.ps
@ -101,12 +101,9 @@ function compileVPPs(blocks: T.Block[][], kids: T.Kid[], form: T.FormVersion, ki
const blocksWKids = putKidsInKidsSection( const blocksWKids = putKidsInKidsSection(
filterForVisibleBlocksVP(blocks, form, king), filterForVisibleBlocksVP(blocks, form, king),
kids, kids,
false, !!blankOut?.ba
); );
return removeDuplicates(combineIntoText(blocksWKids, subjectPerson, { return removeDuplicates(combineIntoText(blocksWKids, subjectPerson, blankOut));
ba: blankOut === "verb",
verb: blankOut === "verb",
}));
} }
function compileEPPs(blocks: T.Block[][], kids: T.Kid[], omitSubject: boolean, blankOut?: BlankoutOptions): T.SingleOrLengthOpts<T.PsString[]> { function compileEPPs(blocks: T.Block[][], kids: T.Kid[], omitSubject: boolean, blankOut?: BlankoutOptions): T.SingleOrLengthOpts<T.PsString[]> {
@ -161,6 +158,12 @@ export function filterForVisibleBlocksEP(blocks: T.Block[][], omitSubject: boole
} }
function combineIntoText(piecesWVars: (T.Block | T.Kid | T.PsString)[][], subjectPerson: T.Person, blankOut?: BlankoutOptions): T.PsString[] { function combineIntoText(piecesWVars: (T.Block | T.Kid | T.PsString)[][], subjectPerson: T.Person, blankOut?: BlankoutOptions): T.PsString[] {
function removeDoubleBlanks(x: T.PsString): T.PsString {
return {
p: x.p.replace(blank.p+blank.p, blank.p),
f: x.f.replace(blank.f+blank.f, blank.f),
};
}
function combine(pieces: (T.Block | T.Kid | T.PsString)[]): T.PsString[] { function combine(pieces: (T.Block | T.Kid | T.PsString)[]): T.PsString[] {
const first = pieces[0]; const first = pieces[0];
const next = pieces[1]; const next = pieces[1];
@ -188,7 +191,7 @@ function combineIntoText(piecesWVars: (T.Block | T.Kid | T.PsString)[][], subjec
r, r,
)) ))
) )
); ).map(removeDoubleBlanks);
} }
return piecesWVars.flatMap(combine); return piecesWVars.flatMap(combine);
} }