diff --git a/src/components/phrase-builder/PhraseBuilder.tsx b/src/components/phrase-builder/PhraseBuilder.tsx index d701b85..72015a2 100644 --- a/src/components/phrase-builder/PhraseBuilder.tsx +++ b/src/components/phrase-builder/PhraseBuilder.tsx @@ -3,28 +3,30 @@ import NPPicker from "../np-picker/NPPicker"; import VerbPicker from "../VerbPicker"; import VPDisplay from "./VPDisplay"; import ObjectDisplay from "./ObjectDisplay"; -import { verbs } from "../../words/words"; +import { verbs as verbsRaw } from "../../words/words"; import { isInvalidSubjObjCombo, } from "../../lib/np-tools"; -function verbPhraseComplete({ subject, verb, shrinkServant }: { subject: NPSelection | undefined, verb: VerbSelection | undefined, shrinkServant: boolean }): VPSelection | undefined { +const verbs = verbsRaw.filter(v => !v.entry.c?.includes("gramm.")) + +function verbPhraseComplete({ subject, verb }: { subject: NPSelection | undefined, verb: VerbSelection | undefined }): VPSelection | undefined { if (!subject) return undefined; if (!verb) return undefined; if (verb.object === undefined) return undefined; return { type: "VPSelection", - shrinkServant, subject, object: verb.object, verb, }; } +// TODO: BIG ISSUE, IF YOU OPEN THE OBJECT PRONOUN BOX AND IT CONFLICTS WITH THE SUBJECT +// IT CAN SAY THE COMBO IS NOT ALLOWED AND SHOW SOMETHING BLANK export function PhraseBuilder() { const [subject, setSubject] = useState(undefined); const [verb, setVerb] = useState(undefined); - const [shrinkServant, setShrinkServant] = useState(false); function handleSubjectChange(subject: NPSelection | undefined) { const objPronoun = (typeof verb?.object === "object" && verb.object.type === "pronoun") ? verb.object.person @@ -57,40 +59,26 @@ export function PhraseBuilder() { object, }); } - function handleShrinkServantChange(e: React.ChangeEvent) { - setShrinkServant(e.target.checked); - } - const verbPhrase: VPSelection | undefined = verbPhraseComplete({ subject, verb, shrinkServant }); - return
-
-
-
Subject
+ const verbPhrase: VPSelection | undefined = verbPhraseComplete({ subject, verb }); + return
+
+
+
Subject
- {verb && (verb.object !== "none") &&
-
Object
+ {verb && (verb.object !== "none") &&
+
Object
} -
-
Verb
+
+
Verb
- {/* TODO: make this appear conditionally */} - {(verbPhrase?.object && typeof verbPhrase.object === "object") &&
- - -
} {verbPhrase &&
} diff --git a/src/components/phrase-builder/VPDisplay.tsx b/src/components/phrase-builder/VPDisplay.tsx index 36963bc..597923e 100644 --- a/src/components/phrase-builder/VPDisplay.tsx +++ b/src/components/phrase-builder/VPDisplay.tsx @@ -1,21 +1,68 @@ +import { useState } from "react"; import { renderVP, compileVP } from "../../lib/phrase-building"; import { InlinePs, defaultTextOptions as opts, + ButtonSelect, + Types as T, } from "@lingdocs/pashto-inflector"; +function adjustForm(form: FormVersion, servantShrinkable: boolean): FormVersion { + if (!servantShrinkable) { + return form === "shortest" + ? "no king" + : form === "mini servant" + ? "full" + : form; + } + return form; +} + function VPDisplay({ VP }: { VP: VPSelection }) { + const [form, setForm] = useState("full"); // TODO: Possibly put the servant shrinking in here after the render - const result = compileVP(renderVP(VP)); - const rPs = "long" in result.ps ? result.ps.long : result.ps; + const result = compileVP(renderVP(VP), form); + const servantShrinkable = VP.object && typeof VP.object === "object"; return
- {rPs.map((r, i) =>
- {r} -
)} +
+ +
+ {"long" in result.ps ? +
+
Long Verb:
+ +
Short Verb:
+ + {result.ps.mini && <> +
Mini Verb:
+ + } +
+ : + } {result.e &&
{result.e.map((e, i) =>
{e}
)}
}
} +function VariationLayer({ vs }: { vs: T.PsString[] }) { + return
+ {vs.map((r, i) =>
+ {r} +
)} +
; +} + export default VPDisplay; \ No newline at end of file diff --git a/src/lib/phrase-building/compile-vp.ts b/src/lib/phrase-building/compile-vp.ts index 182ac3e..4a491b3 100644 --- a/src/lib/phrase-building/compile-vp.ts +++ b/src/lib/phrase-building/compile-vp.ts @@ -6,17 +6,19 @@ import { getVerbBlockPosFromPerson, } from "@lingdocs/pashto-inflector"; -type ListOfEntities = T.PsString[][]; +type ListOfEntities = (T.PsString & { isVerbPrefix?: boolean, prefixFollowedByParticle?: boolean })[][]; -export function compileVP(VP: VPRendered): { ps: T.SingleOrLengthOpts, e?: string [] } { +export function compileVP(VP: VPRendered, form: FormVersion): { ps: T.SingleOrLengthOpts, e?: string [] } { const { head, rest } = VP.verb.ps; - const { kids, NPs } = shrinkEntitiesAndGatherKids(VP); + const { kids, NPs } = shrinkEntitiesAndGatherKids(VP, form); return { ps: compilePs(NPs, head, rest, VP.verb.negative, kids), e: compileEnglish(VP), }; } +// TODO: ISSUE off prefix-nu in the phonetics + function compilePs( nps: ListOfEntities, head: T.PsString | undefined, @@ -49,33 +51,37 @@ function compilePs( } const entities: ListOfEntities = [ ...nps, - ...compileVerbWNegative(head, rest, negative) + ...compileVerbWNegative(head, rest, negative), ]; const entitiesWKids = putKidsInKidsSection(entities, kids); return combineEntities(entitiesWKids); } -function shrinkEntitiesAndGatherKids(VP: VPRendered): { kids: ListOfEntities, NPs: ListOfEntities } { +function shrinkEntitiesAndGatherKids(VP: VPRendered, form: FormVersion): { kids: ListOfEntities, NPs: ListOfEntities } { const main = { subject: VP.subject.ps, object: typeof VP.object === "object" ? VP.object.ps : undefined, } - const toShrink = (VP.shrinkServant && VP.servant) + const removeKing = form === "no king" || form === "shortest"; + const shrinkServant = form === "mini servant" || form === "shortest"; + const shrinkCanditate = ((form === "mini servant" || form === "shortest") && VP.servant) ? VP[VP.servant] : undefined; - if (!toShrink || typeof toShrink !== "object") { - return { - kids: [], - NPs: [main.subject, ...main.object ? [main.object] : []] - }; - } + const toShrink = (!shrinkCanditate || typeof shrinkCanditate !== "object") + ? undefined + : shrinkCanditate; + // TODO: big problem, the king removal doesn't work with grammatically transitive things const king = main[VP.king]; - if (!king) { - throw new Error("lost the king in the shrinking process"); - } + const showSubject = (VP.king === "subject" && !removeKing && king) || (VP.servant === "subject" && !shrinkServant); + const showObject = ( + (VP.king === "object" && !removeKing && king) || (VP.servant === "object" && !shrinkServant) + ); return { - kids: [shrink(toShrink)], - NPs: [king], + kids: [...toShrink ? [shrink(toShrink)] : []], + NPs: [ + ...showSubject ? [main.subject] : [], + ...(showObject && main.object) ? [main.object] : [], + ], } } @@ -92,7 +98,11 @@ function putKidsInKidsSection(entities: ListOfEntities, kids: ListOfEntities): L const first = entities[0]; const rest = entities.slice(1); return [ - first, + first.map(x => ( + x.isVerbPrefix && + // TODO: This isn't quite working + (kids.length) + ) ? { ...x, prefixFollowedByParticle: true } : x), ...kids, ...rest, ]; @@ -105,7 +115,9 @@ function combineEntities(loe: ListOfEntities): T.PsString[] { return combineEntities(rest).flatMap(r => ( first.map(ps => concatPsString( ps, - ps.p === "و" ? { p: "", f: "-" } : " ", + (ps.prefixFollowedByParticle + ? { p: "", f: "-" } + : ps.isVerbPrefix ? "" : " "), r, )) )); @@ -115,7 +127,7 @@ function combineEntities(loe: ListOfEntities): T.PsString[] { function compileVerbWNegative(head: T.PsString | undefined, rest: T.PsString[], negative: boolean): ListOfEntities { if (!negative) { return [ - ...head ? [[head]] : [], + ...head ? [[{...head, isVerbPrefix: true}]] : [], rest, ]; } @@ -130,7 +142,7 @@ function compileVerbWNegative(head: T.PsString | undefined, rest: T.PsString[], // if (regularPrefix) { // dashes for oo-nu etc return [ - [removeAccents(head)], + [{ ...removeAccents(head), isVerbPrefix: true }], rest.map(r => concatPsString(nu, " ", removeAccents(r))) ]; } diff --git a/src/lib/phrase-building/render-vp.ts b/src/lib/phrase-building/render-vp.ts index cd6a640..951324b 100644 --- a/src/lib/phrase-building/render-vp.ts +++ b/src/lib/phrase-building/render-vp.ts @@ -39,7 +39,6 @@ export function renderVP(VP: VPSelection): VPRendered { servant, isPast, isTransitive, - shrinkServant: VP.shrinkServant, subject: renderNPSelection(VP.subject, inflectSubject, false, "subject"), object: renderNPSelection(VP.object, inflectObject, true, "object"), verb: renderVerbSelection(VP.verb, kingPerson, objectPerson), diff --git a/src/types/gen-g.d.ts b/src/types/gen-g.d.ts index e0feb83..60c1ae9 100644 --- a/src/types/gen-g.d.ts +++ b/src/types/gen-g.d.ts @@ -10,7 +10,6 @@ type VPSelection = { subject: NPSelection, object: Exclude, verb: Exclude, - shrinkServant: boolean, }; // TODO: make this Rendered with recursive Rendered<> @@ -18,7 +17,6 @@ type VPRendered = { type: "VPRendered", king: "subject" | "object", servant: "subject" | "object" | undefined, - shrinkServant: boolean, isPast: boolean, isTransitive: boolean, subject: Rendered, @@ -96,6 +94,7 @@ type ParticipleSelection = { // If T has key K ("user"), replace it type ReplaceKey = T extends Record ? (Omit & Record) : T; +type FormVersion = "full" | "no king" | "mini servant" | "shortest"; // TODO: "all"; type Rendered = ReplaceKey< Omit,