error handling for verbs erroring on render

This commit is contained in:
adueck 2024-08-06 14:03:56 -04:00
parent b2f3dfe93c
commit 62fcbbe4ce
12 changed files with 587 additions and 485 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "pashto-inflector",
"version": "7.3.2",
"version": "7.3.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "pashto-inflector",
"version": "7.3.2",
"version": "7.3.3",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "pashto-inflector",
"version": "7.3.2",
"version": "7.3.3",
"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",

View File

@ -1,12 +1,12 @@
{
"name": "@lingdocs/ps-react",
"version": "7.3.2",
"version": "7.3.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@lingdocs/ps-react",
"version": "7.3.2",
"version": "7.3.3",
"license": "MIT",
"dependencies": {
"@formkit/auto-animate": "^1.0.0-beta.3",

View File

@ -1,6 +1,6 @@
{
"name": "@lingdocs/ps-react",
"version": "7.3.2",
"version": "7.3.3",
"description": "Pashto inflector library module with React components",
"main": "dist/components/library.js",
"module": "dist/components/library.js",

View File

@ -24,6 +24,7 @@ function ChartDisplay({
transitivity: T.Transitivity;
objectNP: T.NPSelection | undefined;
}) {
try {
const verbChart = buildVerbChart({
verb,
tense,
@ -45,6 +46,10 @@ function ChartDisplay({
/>
</div>
);
} catch (e) {
console.error(e);
return <h4>Error conjugating verb!</h4>;
}
}
export default ChartDisplay;

View File

@ -1,72 +1,138 @@
import { compileVP } from "../../../lib/src/phrase-building/compile";
import * as T from "../../../types";
import AbbreviationFormSelector from "./AbbreviationFormSelector";
import { getObjectSelection, getSubjectSelection } from "../../../lib/src/phrase-building/blocks-utils";
import {
getObjectSelection,
getSubjectSelection,
} from "../../../lib/src/phrase-building/blocks-utils";
import { completeVPSelection } from "../../../lib/src/phrase-building/vp-tools";
import { renderVP } from "../../../lib/src/phrase-building/render-vp";
import ModeSelect, { LengthSelect, Mode, ScriptSelect } from "../DisplayModeSelect";
import ModeSelect, {
LengthSelect,
Mode,
ScriptSelect,
} from "../DisplayModeSelect";
import { useState } from "react";
import CompiledPTextDisplay from "../CompiledPTextDisplay";
import RenderedBlocksDisplay from "../RenderedBlocksDisplay";
import useStickyState from "../useStickyState";
function VPDisplay({ VPS, opts, setForm, justify, onlyOne, length, mode: preferredMode, script: preferredScript, onLengthChange, inlineFormChoice }: {
VPS: T.VPSelectionState,
opts: T.TextOptions,
setForm: "disable" | ((form: T.FormVersion) => void),
justify?: "left" | "right" | "center",
onlyOne?: boolean | "concat",
length?: "long" | "short",
mode?: Mode,
script?: "p" | "f",
onLengthChange?: (length: "long" | "short") => void,
inlineFormChoice?: boolean,
function VPDisplay({
VPS,
opts,
setForm,
justify,
onlyOne,
length,
mode: preferredMode,
script: preferredScript,
onLengthChange,
inlineFormChoice,
}: {
VPS: T.VPSelectionState;
opts: T.TextOptions;
setForm: "disable" | ((form: T.FormVersion) => void);
justify?: "left" | "right" | "center";
onlyOne?: boolean | "concat";
length?: "long" | "short";
mode?: Mode;
script?: "p" | "f";
onLengthChange?: (length: "long" | "short") => void;
inlineFormChoice?: boolean;
}) {
const [mode, setMode] = useState<Mode>(preferredMode || "text");
const [script, setScript] = useStickyState<"p" | "f">(preferredScript || "f", "blockScriptChoice");
const [script, setScript] = useStickyState<"p" | "f">(
preferredScript || "f",
"blockScriptChoice"
);
const VP = completeVPSelection(VPS);
if (!VP) {
return <div className="lead text-muted text-center mt-4">
return (
<div className="lead text-muted text-center mt-4">
{(() => {
const subject = getSubjectSelection(VPS.blocks).selection;
const object = getObjectSelection(VPS.blocks).selection;
if (subject === undefined || object === undefined) {
return `Choose NP${((subject === undefined) && (object === undefined)) ? "s " : ""} to make a phrase`;
return `Choose NP${
subject === undefined && object === undefined ? "s " : ""
} to make a phrase`;
}
return `Choose/remove AP to complete the phrase`;
})()}
</div>;
</div>
);
}
try {
const rendered = renderVP(VP);
const result = compileVP(rendered, rendered.form, true);
return <div className={`text-${justify ? justify : "center"} mt-1`}>
{typeof setForm === "function" && !inlineFormChoice && <AbbreviationFormSelector
return (
<div className={`text-${justify ? justify : "center"} mt-1`}>
{typeof setForm === "function" && !inlineFormChoice && (
<AbbreviationFormSelector
adjustable={rendered.whatsAdjustable}
form={rendered.form}
onChange={setForm}
/>}
/>
)}
<div className="d-flex flex-row mb-2">
<ModeSelect value={mode} onChange={setMode} />
{mode === "blocks" && <ScriptSelect value={script} onChange={setScript} />}
{mode === "text" && length && "long" in result.ps && onLengthChange && <LengthSelect value={length} onChange={onLengthChange} />}
{typeof setForm === "function" && inlineFormChoice && <AbbreviationFormSelector
{mode === "blocks" && (
<ScriptSelect value={script} onChange={setScript} />
)}
{mode === "text" &&
length &&
"long" in result.ps &&
onLengthChange && (
<LengthSelect value={length} onChange={onLengthChange} />
)}
{typeof setForm === "function" && inlineFormChoice && (
<AbbreviationFormSelector
adjustable={rendered.whatsAdjustable}
form={rendered.form}
onChange={setForm}
inline
/>}
/>
)}
</div>
{mode === "text"
? <CompiledPTextDisplay opts={opts} compiled={result} justify={justify} onlyOne={!!onlyOne} length={length} />
: <RenderedBlocksDisplay opts={opts} rendered={rendered} justify={justify} script={script} />}
{result.e && <div className={`text-muted mt-2 text-${justify === "left" ? "left" : justify === "right" ? "right" : "center"}`}>
{mode === "text" ? (
<CompiledPTextDisplay
opts={opts}
compiled={result}
justify={justify}
onlyOne={!!onlyOne}
length={length}
/>
) : (
<RenderedBlocksDisplay
opts={opts}
rendered={rendered}
justify={justify}
script={script}
/>
)}
{result.e && (
<div
className={`text-muted mt-2 text-${
justify === "left"
? "left"
: justify === "right"
? "right"
: "center"
}`}
>
{onlyOne === "concat"
? result.e.join(" • ")
: onlyOne
? [result.e[0]]
: result.e.map((e, i) => <div key={i}>{e}</div>)}
</div>}
</div>
)}
</div>
);
} catch (e) {
console.error(e);
return <h4>Error conjugating verb!</h4>;
}
}
export default VPDisplay;

View File

@ -144,6 +144,7 @@ function VPExplorerQuiz(props: {
});
}
}
try {
const rendered = renderVP(quizState.vps);
const subject: T.Rendered<T.NPSelection> = getSubjectSelectionFromBlocks(
rendered.blocks
@ -256,7 +257,10 @@ function VPExplorerQuiz(props: {
onChange={(e) => setAnswerBlank(e.target.value)}
/>
</div>
<div className="form-check mb-4" style={{ fontSize: "large" }}>
<div
className="form-check mb-4"
style={{ fontSize: "large" }}
>
<input
className="form-check-input"
type="checkbox"
@ -294,7 +298,9 @@ function VPExplorerQuiz(props: {
</div>
) : (
<div>
<div className="my-4 lead">Possible correct answers were:</div>
<div className="my-4 lead">
Possible correct answers were:
</div>
{quizState.answer.ps.map((p, i) => (
<div key={i}>
<InlinePs opts={props.opts}>{p}</InlinePs>
@ -306,8 +312,8 @@ function VPExplorerQuiz(props: {
? "With"
: "without"}
</strong>
{` `}a <InlinePs opts={props.opts}>{baParticle}</InlinePs> in
the phrase
{` `}a <InlinePs opts={props.opts}>{baParticle}</InlinePs>{" "}
in the phrase
</div>
</div>
)}
@ -324,6 +330,10 @@ function VPExplorerQuiz(props: {
</div>
</div>
);
} catch (e) {
console.error(e);
return <h4>Error conjugating verb!</h4>;
}
}
function blanksAnswerCorrect(

View File

@ -72,7 +72,16 @@ function VPPicker({
const subject = getSubjectSelection(vps.blocks).selection;
const VPS = completeVPSelection(vps);
const phraseIsComplete = !!VPS;
const rendered = VPS ? renderVP(VPS) : undefined;
const rendered = VPS
? (() => {
try {
return renderVP(VPS);
} catch (e) {
console.error(e);
return undefined;
}
})()
: undefined;
const servantIsShrunk = includesShrunkenServant(rendered?.kids);
const isPast = isPastTense(
vps.verb.tenseCategory === "perfect"

View File

@ -1,6 +1,6 @@
{
"name": "@lingdocs/inflect",
"version": "7.3.2",
"version": "7.3.3",
"description": "Pashto inflector library",
"main": "dist/index.js",
"types": "dist/lib/library.d.ts",

View File

@ -6,7 +6,10 @@ module.exports = [
{ ts: 1527816724, e: `room, chamber` }, // اتاق - Utaaq
{ ts: 1527811859, e: `union, alliance` }, // اتحاد - itihaad
{ ts: 1527822033, e: `joining, connection, contiguity, junction` }, // اتصال - ittisáal
{ ts: 1527811858, e: `unity, alliance, agreement, understanding, consent; coincidence` }, // اتفاق - itifaaq
{
ts: 1527811858,
e: `unity, alliance, agreement, understanding, consent; coincidence`,
}, // اتفاق - itifaaq
{ ts: 1527813560, e: `accusation, charge, indictment` }, // اتهام - itihaam
{ ts: 1527812105, e: `respect, honor, esteem, deference` }, // احترام - ihtiraam
{ ts: 1527819653, e: `possibility, probability, likelihood` }, // احتمال - ihtimaal
@ -42,7 +45,7 @@ module.exports = [
{ ts: 1527821586, e: `pity, sympathy` }, // ترحم - tarahhÚm
{ ts: 1527811389, e: `picture` }, // تصویر - tasweer
{ ts: 1527814679, e: `guarantee, insurance, security` }, // تضمین - tazmeen
{ ts: 1527814258, e: `speech, lecture` }, // تقریر - taqreer
{ ts: 1702629785933, e: `speech, lecture` }, // تقریر - taqreer
{ ts: 1527821670, e: `cheating, deception, fraud, forgery` }, // تقلب - taqalÚb
{ ts: 1527811602, e: `attempt, aspiration, intention, effort` }, // تکل - takál
{ ts: 1527813398, e: `movement, motion, going` }, // تګ - tug, tag
@ -61,7 +64,10 @@ module.exports = [
{ ts: 1527811705, e: `structure` }, // جوړښت - joRuxt
{ ts: 1527814058, e: `answer, reply` }, // ځواب - dzawaab
{ ts: 1527816887, e: `life, existence, energy, force` }, // ځواک - dzwaak
{ ts: 1527814649, e: `market square, crossroads, paved area in front of entrance` }, // چوک - chok
{
ts: 1527814649,
e: `market square, crossroads, paved area in front of entrance`,
}, // چوک - chok
{ ts: 1527815065, e: `hammer` }, // څټک - tsaTak, tsTuk
{ ts: 1527814589, e: `side` }, // څنګ - tsang
{ ts: 1527816228, e: `boundary, limit, extent` }, // حد - had
@ -96,8 +102,14 @@ module.exports = [
{ ts: 1527811441, e: `door, gate, entrance` }, // ور - war
{ ts: 1527815406, e: `homeland, home country` }, // وطن - watán
{ ts: 1573149648251, e: `fellow country-man` }, // وطن وال - watanwaal
{ ts: 1586428847646, e: `national (person), a citizen or person of that land` }, // وطنوال - watanwáal
{
ts: 1586428847646,
e: `national (person), a citizen or person of that land`,
}, // وطنوال - watanwáal
{ ts: 1527822208, e: `bat, coward, pipsqueak, hesitant person` }, // وطواط - watwáat
{ ts: 1527819571, e: `apprehension, anxiety, suspicion; imagination, whims, some problem made up in someones head` }, // وهم - wáhum, wahm
{
ts: 1527819571,
e: `apprehension, anxiety, suspicion; imagination, whims, some problem made up in someones head`,
}, // وهم - wáhum, wahm
{ ts: 1527816332, e: `pride, glory` }, // ویاړ - wyaaR
];

View File

@ -26,7 +26,7 @@ module.exports = [
1527817582, // بېزارېدل - to be fed up with, tired of, repulsed by, dissatisfied with, done with, disgusted by
1527815844, // بېلېدل - to be separated
1588073731662, // پاکېدل - to be cleaned, become clean, to be cleansed, purified
1527813895, // پټېدل - to hide, to be hidden
1715816590539, // پټېدل - to hide, to be hidden
1527812011, // پخلا کېدل - to be reconciled, brought to an agreement
1581906176268, // پخېدل - to be cooked, prepared, ripened, matured
1584689265872, // پستېدل - to become soft, tender, gentle, loosened
@ -137,4 +137,4 @@ module.exports = [
1527812941, // یادېدل - to be remembered, to be missed
1527814768, // یخېدل - to chill, cool down, freeze
1579824223049, // یو ځای کېدل - to be gathered, brought together, come together
]
];

View File

@ -43,8 +43,8 @@ module.exports = [
1527816945, // جوتول - to make clear, evident, apparent, explained, established
1527816947, // جوتول - to harness, hitch up
1527812712, // جوړول - to make, form, build, mend, fix
1527817455, // ځایول - to place, put, accommodate, make room for, to make fit
1527815074, // چاپول - to print, publish
1718311465186, // ځایول - to place, put, accommodate, make room for, to make fit
1718377727926, // چاپول - to print, publish
1527811693, // چاغول - to fatten up, to fatten, to make stout, plump
1527816239, // خبرول - to inform, communicate, make known, notify
1527811395, // خپرول - to spread, disperse, open, unfold, publicize, distribute