This commit is contained in:
lingdocs 2022-08-23 17:25:31 +04:00
parent 91fe08f33d
commit 21a0efdd8a
4 changed files with 45 additions and 7 deletions

View File

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

@ -1,6 +1,34 @@
import * as T from "../../types"; import * as T from "../../types";
import { getLength } from "../p-text-helpers"; import { getLength } from "../p-text-helpers";
export function isRenderedVerbB(block: T.Block["block"]): block is T.RenderedVerbB {
if (block.type === "modalVerbBlock") {
return true;
}
if (block.type === "modalVerbKedulPart") {
return true;
}
if (block.type === "perfectEquativeBlock") {
return true;
}
if (block.type === "perfectParticipleBlock") {
return true;
}
if (block.type === "perfectiveHead") {
return true;
}
if (block.type === "verb") {
return true;
}
return false;
}
export function getVerbBlocks(blocks: T.Block[][]): T.RenderedVerbB[] {
return blocks[0]
.filter(b => isRenderedVerbB(b.block))
.map(b => b.block) as T.RenderedVerbB[];
}
export function makeBlock(block: T.Block["block"], key?: number): T.Block { export function makeBlock(block: T.Block["block"], key?: number): T.Block {
return { return {
key: key === undefined ? Math.random() : key, key: key === undefined ? Math.random() : key,

View File

@ -29,7 +29,7 @@ const blank: T.PsString = {
p: "_____", p: "_____",
f: "_____", f: "_____",
}; };
type BlankoutOptions = { equative?: boolean, ba?: boolean, kidsSection?: boolean }; type BlankoutOptions = { equative?: boolean, ba?: boolean, kidsSection?: boolean, verb?: boolean };
const kidsBlank: T.PsString = { p: "___", f: "___" }; const kidsBlank: T.PsString = { p: "___", f: "___" };
@ -70,10 +70,10 @@ 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): { ps: 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): { ps: T.SingleOrLengthOpts<T.PsString[]>, e?: string [] } { export function compileVP(VP: T.VPRendered, form: T.FormVersion, combineLengths?: true, blankOut?: "verb"): { 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); const psResult = compileVPPs(VP.blocks, VP.kids, form, VP.king, blankOut);
return { return {
ps: combineLengths ? flattenLengths(psResult) : psResult, ps: combineLengths ? flattenLengths(psResult) : psResult,
// TODO: English doesn't quite work for dynamic compounds in passive voice // TODO: English doesn't quite work for dynamic compounds in passive voice
@ -81,7 +81,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"): T.SingleOrLengthOpts<T.PsString[]> { function compileVPPs(blocks: T.Block[][], kids: T.Kid[], form: T.FormVersion, king: "subject" | "object", blankOut?: "verb"): 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
@ -102,7 +102,10 @@ function compileVPPs(blocks: T.Block[][], kids: T.Kid[], form: T.FormVersion, ki
kids, kids,
false, false,
); );
return removeDuplicates(combineIntoText(blocksWKids, subjectPerson, {})); return removeDuplicates(combineIntoText(blocksWKids, subjectPerson, {
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[]> {

View File

@ -970,6 +970,13 @@ export type Block = {
| EquativeBlock; | EquativeBlock;
} }
export type RenderedVerbB = VerbRenderedBlock
| PerfectiveHeadBlock
| ModalVerbBlock
| ModalVerbKedulPart
| PerfectEquativeBlock
| PerfectParticipleBlock;
export type Kid = { export type Kid = {
key: number, key: number,
kid: | { type: "ba" } kid: | { type: "ba" }