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", "name": "pashto-inflector",
"version": "7.3.2", "version": "7.3.3",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "7.3.2", "version": "7.3.3",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

@ -72,7 +72,16 @@ function VPPicker({
const subject = getSubjectSelection(vps.blocks).selection; const subject = getSubjectSelection(vps.blocks).selection;
const VPS = completeVPSelection(vps); const VPS = completeVPSelection(vps);
const phraseIsComplete = !!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 servantIsShrunk = includesShrunkenServant(rendered?.kids);
const isPast = isPastTense( const isPast = isPastTense(
vps.verb.tenseCategory === "perfect" vps.verb.tenseCategory === "perfect"

View File

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

View File

@ -6,7 +6,10 @@ module.exports = [
{ ts: 1527816724, e: `room, chamber` }, // اتاق - Utaaq { ts: 1527816724, e: `room, chamber` }, // اتاق - Utaaq
{ ts: 1527811859, e: `union, alliance` }, // اتحاد - itihaad { ts: 1527811859, e: `union, alliance` }, // اتحاد - itihaad
{ ts: 1527822033, e: `joining, connection, contiguity, junction` }, // اتصال - ittisáal { 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: 1527813560, e: `accusation, charge, indictment` }, // اتهام - itihaam
{ ts: 1527812105, e: `respect, honor, esteem, deference` }, // احترام - ihtiraam { ts: 1527812105, e: `respect, honor, esteem, deference` }, // احترام - ihtiraam
{ ts: 1527819653, e: `possibility, probability, likelihood` }, // احتمال - ihtimaal { ts: 1527819653, e: `possibility, probability, likelihood` }, // احتمال - ihtimaal
@ -42,7 +45,7 @@ module.exports = [
{ ts: 1527821586, e: `pity, sympathy` }, // ترحم - tarahhÚm { ts: 1527821586, e: `pity, sympathy` }, // ترحم - tarahhÚm
{ ts: 1527811389, e: `picture` }, // تصویر - tasweer { ts: 1527811389, e: `picture` }, // تصویر - tasweer
{ ts: 1527814679, e: `guarantee, insurance, security` }, // تضمین - tazmeen { 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: 1527821670, e: `cheating, deception, fraud, forgery` }, // تقلب - taqalÚb
{ ts: 1527811602, e: `attempt, aspiration, intention, effort` }, // تکل - takál { ts: 1527811602, e: `attempt, aspiration, intention, effort` }, // تکل - takál
{ ts: 1527813398, e: `movement, motion, going` }, // تګ - tug, tag { ts: 1527813398, e: `movement, motion, going` }, // تګ - tug, tag
@ -61,7 +64,10 @@ module.exports = [
{ ts: 1527811705, e: `structure` }, // جوړښت - joRuxt { ts: 1527811705, e: `structure` }, // جوړښت - joRuxt
{ ts: 1527814058, e: `answer, reply` }, // ځواب - dzawaab { ts: 1527814058, e: `answer, reply` }, // ځواب - dzawaab
{ ts: 1527816887, e: `life, existence, energy, force` }, // ځواک - dzwaak { 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: 1527815065, e: `hammer` }, // څټک - tsaTak, tsTuk
{ ts: 1527814589, e: `side` }, // څنګ - tsang { ts: 1527814589, e: `side` }, // څنګ - tsang
{ ts: 1527816228, e: `boundary, limit, extent` }, // حد - had { ts: 1527816228, e: `boundary, limit, extent` }, // حد - had
@ -96,8 +102,14 @@ module.exports = [
{ ts: 1527811441, e: `door, gate, entrance` }, // ور - war { ts: 1527811441, e: `door, gate, entrance` }, // ور - war
{ ts: 1527815406, e: `homeland, home country` }, // وطن - watán { ts: 1527815406, e: `homeland, home country` }, // وطن - watán
{ ts: 1573149648251, e: `fellow country-man` }, // وطن وال - watanwaal { 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: 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 { 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 1527817582, // بېزارېدل - to be fed up with, tired of, repulsed by, dissatisfied with, done with, disgusted by
1527815844, // بېلېدل - to be separated 1527815844, // بېلېدل - to be separated
1588073731662, // پاکېدل - to be cleaned, become clean, to be cleansed, purified 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 1527812011, // پخلا کېدل - to be reconciled, brought to an agreement
1581906176268, // پخېدل - to be cooked, prepared, ripened, matured 1581906176268, // پخېدل - to be cooked, prepared, ripened, matured
1584689265872, // پستېدل - to become soft, tender, gentle, loosened 1584689265872, // پستېدل - to become soft, tender, gentle, loosened
@ -137,4 +137,4 @@ module.exports = [
1527812941, // یادېدل - to be remembered, to be missed 1527812941, // یادېدل - to be remembered, to be missed
1527814768, // یخېدل - to chill, cool down, freeze 1527814768, // یخېدل - to chill, cool down, freeze
1579824223049, // یو ځای کېدل - to be gathered, brought together, come together 1579824223049, // یو ځای کېدل - to be gathered, brought together, come together
] ];

View File

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