From 370ba3e52182a4da173f656c430077c21c7f5892 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Sat, 4 Jun 2022 20:42:35 -0500 Subject: [PATCH] getting EP blocks working --- package.json | 2 +- src/components/blocks/Block.tsx | 58 ++++++++----------- src/components/blocks/KidDisplay.tsx | 16 +++++ .../ep-explorer/EPBlocksDisplay.tsx | 37 +++++++++--- src/components/ep-explorer/EPDisplay.tsx | 27 +++++---- src/components/ep-explorer/EPExplorer.tsx | 2 +- src/components/ep-explorer/EPTextDisplay.tsx | 3 - src/lib/phrase-building/compile.ts | 13 +++-- src/lib/phrase-building/render-ep.ts | 28 ++++----- 9 files changed, 110 insertions(+), 76 deletions(-) create mode 100644 src/components/blocks/KidDisplay.tsx diff --git a/package.json b/package.json index 13a7213..7050468 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "2.8.2", + "version": "2.8.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", diff --git a/src/components/blocks/Block.tsx b/src/components/blocks/Block.tsx index 4c9f061..fbf421f 100644 --- a/src/components/blocks/Block.tsx +++ b/src/components/blocks/Block.tsx @@ -21,7 +21,7 @@ function Block({ opts, block }: { if (block.type === "predicateSelection") { const english = getEnglishFromRendered(block.selection); return
-
Pred
+
Predicate
{block.selection.type === "EQComp" ? : {block.selection}} @@ -49,12 +49,8 @@ function NUBlock({ opts }: { > nu
-
not
+
Neg.
+ not ; } @@ -73,6 +69,8 @@ function EquativeBlock({ opts, eq }: { > {"short" in eq.ps ? eq.ps.short[0].f : eq.ps[0].f} +
Equative
+ {"="} ; } @@ -82,7 +80,7 @@ function SubjectBlock({ opts, np }: { }) { const english = getEnglishFromRendered(np); return
-
Subject
+
Subject
{np}
; } @@ -107,12 +105,7 @@ function EqCompBlock({ opts, comp }: { {adj.ps[0].f}
Adj.
- {adj.e &&
{adj.e}
} + {adj.e} ; } @@ -132,16 +125,11 @@ function EqCompBlock({ opts, comp }: { {adv.ps[0].f}
Loc. Adv.
- {adv.e &&
{adv.e}
} + {adv.e} ; } - return
+ return
Comp.
{comp.type === "adjective" ? @@ -150,6 +138,7 @@ function EqCompBlock({ opts, comp }: { :
Sandwich
+ {comp.e}
}
; } @@ -184,12 +173,7 @@ export function APBlock({ opts, children, english }: { return
AP
- {english &&
{english}
} + {english}
; } @@ -226,7 +210,7 @@ export function NPBlock({ opts, children, inside, english }: { english?: string, }) { const np = children; - const hasPossesor = !!(np.selection.type !== "pronoun" && np.selection.possesor); + const hasPossesor = !!(np.selection.type !== "pronoun" && np.selection.possesor && !np.selection.possesor.shrunken); return
{np.selection.ps[0].f}
NP
- {english &&
{english}
} + {english}
} @@ -257,6 +236,9 @@ function Possesors({ opts, children }: { if (!children) { return null; } + if (children.shrunken) { + return null; + } const contraction = checkForContraction(children.np); return
a.ps[0].f).join(" ")}{` `} } + +function EnglishBelow({ children: e }: { children: string | undefined }) { + return
{e ? e : ""}
; +} diff --git a/src/components/blocks/KidDisplay.tsx b/src/components/blocks/KidDisplay.tsx new file mode 100644 index 0000000..7d31dce --- /dev/null +++ b/src/components/blocks/KidDisplay.tsx @@ -0,0 +1,16 @@ +import { baParticle } from "../../lib/grammar-units"; +import * as T from "../../types"; +import Phonetics from "../Phonetics"; + +function KidDisplay({ opts, kid }: { + opts: T.TextOptions, + kid: T.Kid, +}) { + return
+ {kid.type === "ba" + ? {baParticle} + : {kid.ps}} +
+} + +export default KidDisplay; \ No newline at end of file diff --git a/src/components/ep-explorer/EPBlocksDisplay.tsx b/src/components/ep-explorer/EPBlocksDisplay.tsx index 42fab10..5233fe7 100644 --- a/src/components/ep-explorer/EPBlocksDisplay.tsx +++ b/src/components/ep-explorer/EPBlocksDisplay.tsx @@ -1,18 +1,41 @@ import * as T from "../../types"; import Block from "../blocks/Block"; +import KidDisplay from "../blocks/KidDisplay"; -function EPBlocksDisplay({ opts, rendered }: { opts: T.TextOptions, rendered: T.EPRendered }) { +function EPBlocksDisplay({ opts, rendered }: { + opts: T.TextOptions, + rendered: T.EPRendered, +}) { const blocks = rendered.omitSubject ? rendered.blocks.filter(b => b.type !== "subjectSelection") : rendered.blocks; - - return
- {blocks.map((block, i) => ( + return
+
- +
- ))} -
; + + {blocks.slice(1).map((block, i) => ( +
+ +
+ ))} +
+
+} + +function KidsSection({ opts, kids }: { + opts: T.TextOptions, + kids: T.Kid[], +}) { + return kids.length > 0 ?
+
+ {kids.map(kid => ( + + ))} +
+
kids
+
: null; } export default EPBlocksDisplay; \ No newline at end of file diff --git a/src/components/ep-explorer/EPDisplay.tsx b/src/components/ep-explorer/EPDisplay.tsx index c7126bf..b5fe94b 100644 --- a/src/components/ep-explorer/EPDisplay.tsx +++ b/src/components/ep-explorer/EPDisplay.tsx @@ -8,12 +8,14 @@ import EPTextDisplay from "./EPTextDisplay"; import EPBlocksDisplay from "./EPBlocksDisplay"; type Mode = "text" | "blocks"; +// BIG TODO: FIGRUE OUT A WAY TO HANDLE OMITING SUBJECT + function EPDisplay({ eps, opts, setOmitSubject }: { eps: T.EPSelectionState, opts: T.TextOptions, setOmitSubject: (value: "true" | "false") => void, }) { - const [mode] = useState("text"); + const [mode, setMode] = useState("text"); const EP = completeEPSelection(eps); const subject = getSubjectSelection(eps.blocks); @@ -34,7 +36,7 @@ function EPDisplay({ eps, opts, setOmitSubject }: { const renderedPredicate = getPredicateSelectionFromBlocks(rendered.blocks).selection; return
- {/* */} + : } + {result.e &&
+ {result.e.map((e, i) =>
{e}
)} +
} {EP.predicate.selection.selection.type === "participle" &&

⚠️ NOTE: This means that the subject {renderedSubject.selection.e ? `(${renderedSubject.selection.e})` : ""} is the action/idea of {` `} @@ -58,14 +63,14 @@ function EPDisplay({ eps, opts, setOmitSubject }: {

} -// function ModeSelect({ value, onChange }: { value: Mode, onChange: (m: Mode) => void }) { -// return
-// {value === "text" ?
onChange("blocks")}> -// -//
:
onChange("text")}> -// -//
} -//
; -// } +function ModeSelect({ value, onChange }: { value: Mode, onChange: (m: Mode) => void }) { + return
+ {value === "text" ?
onChange("blocks")}> + +
:
onChange("text")}> + +
} +
; +} export default EPDisplay; \ No newline at end of file diff --git a/src/components/ep-explorer/EPExplorer.tsx b/src/components/ep-explorer/EPExplorer.tsx index dfb8379..6f9a3c0 100644 --- a/src/components/ep-explorer/EPExplorer.tsx +++ b/src/components/ep-explorer/EPExplorer.tsx @@ -38,7 +38,7 @@ function EPExplorer(props: { entryFeeder: T.EntryFeeder, }) { const [mode, setMode] = useStickyState<"charts" | "phrases">("charts", "EPExplorerMode"); - const [eps, adjustEps] = useStickyReducer(epsReducer, blankEps, "EPState6", flashMessage); + const [eps, adjustEps] = useStickyReducer(epsReducer, blankEps, "EPState7", flashMessage); const [alert, setAlert] = useState(undefined); const [showClipped, setShowClipped] = useState(""); const parent = useRef(null); diff --git a/src/components/ep-explorer/EPTextDisplay.tsx b/src/components/ep-explorer/EPTextDisplay.tsx index ee1f2bf..14ecff8 100644 --- a/src/components/ep-explorer/EPTextDisplay.tsx +++ b/src/components/ep-explorer/EPTextDisplay.tsx @@ -19,9 +19,6 @@ function EPTextDisplay({ compiled, opts }: { compiled: {
: } - {compiled.e &&
- {compiled.e.map((e, i) =>
{e}
)} -
}
; } diff --git a/src/lib/phrase-building/compile.ts b/src/lib/phrase-building/compile.ts index 433e793..b4e0cdc 100644 --- a/src/lib/phrase-building/compile.ts +++ b/src/lib/phrase-building/compile.ts @@ -263,23 +263,26 @@ function arrangeVerbWNegative(head: T.PsString | undefined, restRaw: T.PsString[ export function compileEP(EP: T.EPRendered): { ps: T.SingleOrLengthOpts, e?: string[] }; export function compileEP(EP: T.EPRendered, combineLengths: true, blankOut?: BlankoutOptions): { ps: T.PsString[], e?: string[] }; export function compileEP(EP: T.EPRendered, combineLengths?: boolean, blankOut?: BlankoutOptions): { ps: T.SingleOrLengthOpts, e?: string[] } { - const psResult = compileEPPs(EP.blocks, EP.kids, blankOut); + const psResult = compileEPPs(EP.blocks, EP.kids, EP.omitSubject, blankOut); return { ps: combineLengths ? flattenLengths(psResult) : psResult, e: compileEnglishEP(EP), }; } -function compileEPPs(blocks: T.Block[], kids: T.Kid[], blankOut?: BlankoutOptions): T.SingleOrLengthOpts { +function compileEPPs(blocks: T.Block[], kids: T.Kid[], omitSubject: boolean, blankOut?: BlankoutOptions): T.SingleOrLengthOpts { if (hasEquativeWithLengths(blocks)) { return { - long: compileEPPs(specifyEquativeLength(blocks, "long"), kids, blankOut) as T.PsString[], - short: compileEPPs(specifyEquativeLength(blocks, "short"), kids, blankOut) as T.PsString[], + long: compileEPPs(specifyEquativeLength(blocks, "long"), kids, omitSubject, blankOut) as T.PsString[], + short: compileEPPs(specifyEquativeLength(blocks, "short"), kids, omitSubject, blankOut) as T.PsString[], }; } const subjectPerson = getSubjectSelectionFromBlocks(blocks) .selection.selection.person; - const blocksWKids = putKidsInKidsSection(blocks, kids); + const blocksWKids = putKidsInKidsSection( + omitSubject ? blocks.filter(b => b.type !== "subjectSelection") : blocks, + kids, + ); return removeDuplicates(combineIntoText(blocksWKids, subjectPerson)); } diff --git a/src/lib/phrase-building/render-ep.ts b/src/lib/phrase-building/render-ep.ts index 4faa18e..0e9c1b1 100644 --- a/src/lib/phrase-building/render-ep.ts +++ b/src/lib/phrase-building/render-ep.ts @@ -39,7 +39,7 @@ function getEPSBlocksAndKids(EP: T.EPSelectionComplete): { kids: T.Kid[], blocks const commandingPerson = getPersonFromNP(commandingNP); const equative: T.EquativeBlock = { type: "equative", equative: renderEquative(EP.equative, commandingPerson) }; const blocks: T.Block[] = [ - ...renderEPSBlocks(EP.omitSubject ? EP.blocks.filter(b => b.block.type !== "subjectSelection") : EP.blocks), + ...renderEPSBlocks(EP.blocks), { type: "predicateSelection", selection: EP.predicate.selection.type === "NP" @@ -122,19 +122,19 @@ function findPossesivesToShrink(blocks: (T.EPSBlockComplete | T.SubjectSelection function findShrunkenPossInNP(NP: T.NPSelection): T.MiniPronoun[] { if (NP.selection.type === "pronoun") return []; if (!NP.selection.possesor) return []; - if (NP.selection.type === "noun") { - if (NP.selection.adjectives) { - const { adjectives, ...rest } = NP.selection; - return [ - // TODO: ability to find possesives shrinkage in sandwiches in adjectives - // ...findShrunkenPossInAdjectives(adjectives), - ...findShrunkenPossInNP({ type: "NP", selection: { - ...rest, - adjectives: [], - }}), - ]; - } - } + // if (NP.selection.type === "noun") { + // if (NP.selection.adjectives) { + // const { adjectives, ...rest } = NP.selection; + // return [ + // // TODO: ability to find possesives shrinkage in sandwiches in adjectives + // // ...findShrunkenPossInAdjectives(adjectives), + // ...findShrunkenPossInNP({ type: "NP", selection: { + // ...rest, + // adjectives: [], + // }}), + // ]; + // } + // } if (NP.selection.possesor.shrunken) { const person = getPersonFromNP(NP.selection.possesor.np); const miniP: T.MiniPronoun = {