From 511e215592fe19a9afb19109c03dc438383d9666 Mon Sep 17 00:00:00 2001
From: lingdocs <71590811+lingdocs@users.noreply.github.com>
Date: Sun, 10 Jul 2022 17:26:55 -0500
Subject: [PATCH] yikes fixed big bug with the length specification in the
blocks when compiling
---
package.json | 2 +-
src/components/blocks/Block.tsx | 2 +-
src/lib/phrase-building/blocks-utils.ts | 23 ++++++++++++++++++++++-
src/lib/phrase-building/compile.ts | 19 +++++++++++--------
4 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/package.json b/package.json
index 97d1ec3..b298204 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@lingdocs/pashto-inflector",
- "version": "3.3.2",
+ "version": "3.3.4",
"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/blocks/Block.tsx b/src/components/blocks/Block.tsx
index 26ee870..e8794b6 100644
--- a/src/components/blocks/Block.tsx
+++ b/src/components/blocks/Block.tsx
@@ -110,7 +110,7 @@ function VerbSBlock({ opts, v, script }: {
>
{v.type === "perfectParticipleBlock" ? "Past Partic." : "Verb"}
- {((v.type === "perfectParticipleBlock" ? "Past Partic." : "Verb")
+ {(v.type === "perfectParticipleBlock"
? getEnglishParticipleInflection
: getEnglishPersonInfo
)(v.person, "short")}
diff --git a/src/lib/phrase-building/blocks-utils.ts b/src/lib/phrase-building/blocks-utils.ts
index 77333e8..972ee3f 100644
--- a/src/lib/phrase-building/blocks-utils.ts
+++ b/src/lib/phrase-building/blocks-utils.ts
@@ -67,6 +67,17 @@ export function getVerbFromBlocks(blocks: T.Block[][]): T.VerbRenderedBlock {
return v;
}
+export function getLengthyFromBlocks(blocks: T.Block[][]): T.VerbRenderedBlock | T.PerfectParticipleBlock | T.ModalVerbBlock | T.PerfectEquativeBlock | undefined {
+ return blocks[0].find(f => f.block.type === "verb"
+ ||
+ f.block.type === "perfectParticipleBlock"
+ ||
+ f.block.type === "modalVerbBlock"
+ ||
+ f.block.type === "perfectEquativeBlock"
+ )?.block as T.VerbRenderedBlock | T.PerfectParticipleBlock | T.ModalVerbBlock | T.PerfectEquativeBlock | undefined;
+}
+
export function getVerbAndHeadFromBlocks(blocks: T.Block[][]): { verb: T.VerbRenderedBlock, perfectiveHead: T.PerfectiveHeadBlock | undefined } {
const verb = getVerbFromBlocks(blocks);
const perfectiveHead = blocks[0].find(f => f.block.type === "perfectiveHead");
@@ -296,7 +307,7 @@ export function specifyEquativeLength(blocksWVars: T.Block[][], length: "long" |
return blocksWVars.map(specify);
}
-export function specifyVerbLength(blocksWVars: T.Block[][], length: "long" | "short" | "mini"): T.Block[][] {
+export function specifyBlockLength(blocksWVars: T.Block[][], length: "long" | "short" | "mini"): T.Block[][] {
function specify(blocks: T.Block[]): T.Block[] {
return blocks.map((block): T.Block => {
if (block.block.type === "verb") {
@@ -312,6 +323,16 @@ export function specifyVerbLength(blocksWVars: T.Block[][], length: "long" | "sh
};
return v;
}
+ if (block.block.type === "perfectEquativeBlock") {
+ const v: T.Block = {
+ ...block,
+ block: {
+ ...block.block,
+ ps: getLength(block.block.ps, length),
+ },
+ };
+ return v;
+ }
if (block.block.type === "perfectParticipleBlock") {
const p: T.Block = {
...block,
diff --git a/src/lib/phrase-building/compile.ts b/src/lib/phrase-building/compile.ts
index 9ba4006..1d39311 100644
--- a/src/lib/phrase-building/compile.ts
+++ b/src/lib/phrase-building/compile.ts
@@ -15,13 +15,14 @@ import { renderVP } from "./render-vp";
import {
getAPsFromBlocks,
getComplementFromBlocks,
+ getLengthyFromBlocks,
getObjectSelectionFromBlocks,
getPredicateSelectionFromBlocks,
getSubjectSelectionFromBlocks,
getVerbFromBlocks,
hasEquativeWithLengths,
+ specifyBlockLength,
specifyEquativeLength,
- specifyVerbLength,
} from "./blocks-utils";
const blank: T.PsString = {
@@ -81,13 +82,16 @@ 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 {
- const verbBlock = getVerbFromBlocks(blocks);
- if ("long" in verbBlock.block.ps) {
+ const lengthyBlock = getLengthyFromBlocks(blocks);
+ const potentialLengthy = lengthyBlock?.type === "verb"
+ ? lengthyBlock.block.ps
+ : lengthyBlock?.ps;
+ if (potentialLengthy && "long" in potentialLengthy) {
return {
- long: compileVPPs(specifyVerbLength(blocks, "long"), kids, form, king) as T.PsString[],
- short: compileVPPs(specifyVerbLength(blocks, "short"), kids, form, king) as T.PsString[],
- ..."mini" in verbBlock.block.ps ? {
- mini: compileVPPs(specifyVerbLength(blocks, "mini"), kids, form, king) as T.PsString[],
+ long: compileVPPs(specifyBlockLength(blocks, "long"), kids, form, king) as T.PsString[],
+ short: compileVPPs(specifyBlockLength(blocks, "short"), kids, form, king) as T.PsString[],
+ ..."mini" in potentialLengthy ? {
+ mini: compileVPPs(specifyBlockLength(blocks, "mini"), kids, form, king) as T.PsString[],
} : {},
};
}
@@ -98,7 +102,6 @@ function compileVPPs(blocks: T.Block[][], kids: T.Kid[], form: T.FormVersion, ki
kids,
false,
);
- console.log({ blocksWKids });
return removeDuplicates(combineIntoText(blocksWKids, subjectPerson, {}));
}