From ab19fa995ee0a042dc59d91e31f164bc2bd0f11e Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Thu, 24 Mar 2022 21:02:51 +0500 Subject: [PATCH] moer --- src/lib/phrase-building/compile-vp.ts | 63 +++++++++++++++------------ src/lib/phrase-building/vp-tools.ts | 18 +++++++- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/lib/phrase-building/compile-vp.ts b/src/lib/phrase-building/compile-vp.ts index 58413db..feeba4d 100644 --- a/src/lib/phrase-building/compile-vp.ts +++ b/src/lib/phrase-building/compile-vp.ts @@ -5,13 +5,13 @@ import { grammarUnits, getVerbBlockPosFromPerson, } from "@lingdocs/pashto-inflector"; -import { removeBa } from "./vp-tools"; +import { isMiniPronoun, removeBa } from "./vp-tools"; -type ListOfEntities = (T.PsString & { isVerbPrefix?: boolean, prefixFollowedByParticle?: boolean })[][]; +type ListOfSegments = (T.PsString & { isVerbPrefix?: boolean, prefixFollowedByMiniPronoun?: boolean })[][]; export function compileVP(VP: VPRendered, form: FormVersion): { ps: T.SingleOrLengthOpts, e?: string [] } { const { head, rest } = VP.verb.ps; - const { kids, NPs } = shrinkEntitiesAndGatherKids(VP, form); + const { kids, NPs } = shrinkSegmentsAndGatherKids(VP, form); return { ps: compilePs(NPs, head, rest, VP.verb.negative, kids), e: compileEnglish(VP), @@ -21,25 +21,25 @@ export function compileVP(VP: VPRendered, form: FormVersion): { ps: T.SingleOrLe // TODO: ISSUE off prefix-nu in the phonetics function compilePs( - nps: ListOfEntities, + nps: ListOfSegments, head: T.PsString | undefined, rest: T.PsString[], negative: boolean, - kids: ListOfEntities, + kids: ListOfSegments, ): T.PsString[]; function compilePs( - nps: ListOfEntities, + nps: ListOfSegments, head: T.PsString | undefined, rest: T.SingleOrLengthOpts, negative: boolean, - kids: ListOfEntities, + kids: ListOfSegments, ): T.SingleOrLengthOpts; function compilePs( - nps: ListOfEntities, + nps: ListOfSegments, head: T.PsString | undefined, rest: T.SingleOrLengthOpts, negative: boolean, - kids: ListOfEntities, + kids: ListOfSegments, ): T.SingleOrLengthOpts { if ("long" in rest) { return { @@ -50,19 +50,19 @@ function compilePs( } : {}, }; } - const verbEntities = compileVerbWNegative(head, rest, negative) - const entities: ListOfEntities = [ + const verbSegments = compileVerbWNegative(head, rest, negative) + const segments: ListOfSegments = [ ...nps, - ...verbEntities, + ...verbSegments, ]; - const entitiesWKids = putKidsInKidsSection( - entities, + const segmentsWKids = putKidsInKidsSection( + segments, kids, ); - return combineEntities(entitiesWKids); + return combineSegments(segmentsWKids); } -function shrinkEntitiesAndGatherKids(VP: VPRendered, form: FormVersion): { kids: ListOfEntities, NPs: ListOfEntities } { +function shrinkSegmentsAndGatherKids(VP: VPRendered, form: FormVersion): { kids: ListOfSegments, NPs: ListOfSegments } { const main = { subject: VP.subject.ps, object: typeof VP.object === "object" ? VP.object.ps : undefined, @@ -99,37 +99,44 @@ function shrink(np: Rendered): T.PsString[] { return grammarUnits.pronouns.mini[row][col]; } -function putKidsInKidsSection(entities: ListOfEntities, kids: ListOfEntities): ListOfEntities { - const first = entities[0]; - const rest = entities.slice(1); +function putKidsInKidsSection(segments: ListOfSegments, kids: ListOfSegments): ListOfSegments { + const first = segments[0]; + const rest = segments.slice(1); + console.log({ kids }, kids.length); return [ first.map(x => ( - x.isVerbPrefix && - // TODO: This isn't quite working - (kids.length) - ) ? { ...x, prefixFollowedByParticle: true } : x), + (x.isVerbPrefix && isMiniPronoun(kids[0][0])) + ? { ...x, prefixFollowedByMiniPronoun: true } + : x + )), ...kids, ...rest, ]; } -function combineEntities(loe: ListOfEntities): T.PsString[] { +function combineSegments(loe: ListOfSegments): T.PsString[] { + function isLast(index: number, arr: any[]): boolean { + return index === (arr.length - 1); + } const first = loe[0]; const rest = loe.slice(1); if (!rest.length) return first; - return combineEntities(rest).flatMap(r => ( + console.log({ loe }); + return combineSegments(rest).flatMap((r, restIndex, arr) => ( first.map(ps => concatPsString( ps, - (ps.prefixFollowedByParticle + (ps.isVerbPrefix && isLast(restIndex, arr) + ? "" + : ps.prefixFollowedByMiniPronoun ? { p: "", f: "-" } - : ps.isVerbPrefix ? "" : " "), + : ps.isVerbPrefix ? " " : " "), r, )) )); } -function compileVerbWNegative(head: T.PsString | undefined, restRaw: T.PsString[], negative: boolean): ListOfEntities { +function compileVerbWNegative(head: T.PsString | undefined, restRaw: T.PsString[], negative: boolean): ListOfSegments { const rest = restRaw.map(removeBa); if (!negative) { return [ diff --git a/src/lib/phrase-building/vp-tools.ts b/src/lib/phrase-building/vp-tools.ts index a9e6cd1..8ccea48 100644 --- a/src/lib/phrase-building/vp-tools.ts +++ b/src/lib/phrase-building/vp-tools.ts @@ -2,8 +2,8 @@ import { Types as T, concatPsString, grammarUnits, + psRemove, } from "@lingdocs/pashto-inflector"; -import { psRemove } from "@lingdocs/pashto-inflector/dist/lib/p-text-helpers"; export function getPersonFromNP(np: NPSelection): T.Person; export function getPersonFromNP(np: NPSelection | ObjectNP): T.Person | undefined; @@ -25,4 +25,20 @@ export function getPersonFromNP(np: NPSelection | ObjectNP): T.Person | undefine export function removeBa(ps: T.PsString): T.PsString { return psRemove(ps, concatPsString(grammarUnits.baParticle, " ")); +} + +export function isMiniPronoun(ps: T.PsString | undefined): boolean { + if (!ps) return false; + return isInVerbBlock(ps.p, grammarUnits.pronouns.mini); +} + +/** + * returns true if the pashto text matches any item in a verb block + * + * @param vb + */ +function isInVerbBlock(p: string, vb: T.VerbBlock): boolean { + return vb.some((r) => ( + r.some(x => x.some(y => y.p === p) + ))); } \ No newline at end of file