moer
This commit is contained in:
parent
825b37e9fb
commit
ab19fa995e
|
@ -5,13 +5,13 @@ import {
|
||||||
grammarUnits,
|
grammarUnits,
|
||||||
getVerbBlockPosFromPerson,
|
getVerbBlockPosFromPerson,
|
||||||
} from "@lingdocs/pashto-inflector";
|
} 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<T.PsString[]>, e?: string [] } {
|
export function compileVP(VP: VPRendered, form: FormVersion): { ps: T.SingleOrLengthOpts<T.PsString[]>, e?: string [] } {
|
||||||
const { head, rest } = VP.verb.ps;
|
const { head, rest } = VP.verb.ps;
|
||||||
const { kids, NPs } = shrinkEntitiesAndGatherKids(VP, form);
|
const { kids, NPs } = shrinkSegmentsAndGatherKids(VP, form);
|
||||||
return {
|
return {
|
||||||
ps: compilePs(NPs, head, rest, VP.verb.negative, kids),
|
ps: compilePs(NPs, head, rest, VP.verb.negative, kids),
|
||||||
e: compileEnglish(VP),
|
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
|
// TODO: ISSUE off prefix-nu in the phonetics
|
||||||
|
|
||||||
function compilePs(
|
function compilePs(
|
||||||
nps: ListOfEntities,
|
nps: ListOfSegments,
|
||||||
head: T.PsString | undefined,
|
head: T.PsString | undefined,
|
||||||
rest: T.PsString[],
|
rest: T.PsString[],
|
||||||
negative: boolean,
|
negative: boolean,
|
||||||
kids: ListOfEntities,
|
kids: ListOfSegments,
|
||||||
): T.PsString[];
|
): T.PsString[];
|
||||||
function compilePs(
|
function compilePs(
|
||||||
nps: ListOfEntities,
|
nps: ListOfSegments,
|
||||||
head: T.PsString | undefined,
|
head: T.PsString | undefined,
|
||||||
rest: T.SingleOrLengthOpts<T.PsString[]>,
|
rest: T.SingleOrLengthOpts<T.PsString[]>,
|
||||||
negative: boolean,
|
negative: boolean,
|
||||||
kids: ListOfEntities,
|
kids: ListOfSegments,
|
||||||
): T.SingleOrLengthOpts<T.PsString[]>;
|
): T.SingleOrLengthOpts<T.PsString[]>;
|
||||||
function compilePs(
|
function compilePs(
|
||||||
nps: ListOfEntities,
|
nps: ListOfSegments,
|
||||||
head: T.PsString | undefined,
|
head: T.PsString | undefined,
|
||||||
rest: T.SingleOrLengthOpts<T.PsString[]>,
|
rest: T.SingleOrLengthOpts<T.PsString[]>,
|
||||||
negative: boolean,
|
negative: boolean,
|
||||||
kids: ListOfEntities,
|
kids: ListOfSegments,
|
||||||
): T.SingleOrLengthOpts<T.PsString[]> {
|
): T.SingleOrLengthOpts<T.PsString[]> {
|
||||||
if ("long" in rest) {
|
if ("long" in rest) {
|
||||||
return {
|
return {
|
||||||
|
@ -50,19 +50,19 @@ function compilePs(
|
||||||
} : {},
|
} : {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const verbEntities = compileVerbWNegative(head, rest, negative)
|
const verbSegments = compileVerbWNegative(head, rest, negative)
|
||||||
const entities: ListOfEntities = [
|
const segments: ListOfSegments = [
|
||||||
...nps,
|
...nps,
|
||||||
...verbEntities,
|
...verbSegments,
|
||||||
];
|
];
|
||||||
const entitiesWKids = putKidsInKidsSection(
|
const segmentsWKids = putKidsInKidsSection(
|
||||||
entities,
|
segments,
|
||||||
kids,
|
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 = {
|
const main = {
|
||||||
subject: VP.subject.ps,
|
subject: VP.subject.ps,
|
||||||
object: typeof VP.object === "object" ? VP.object.ps : undefined,
|
object: typeof VP.object === "object" ? VP.object.ps : undefined,
|
||||||
|
@ -99,37 +99,44 @@ function shrink(np: Rendered<NPSelection>): T.PsString[] {
|
||||||
return grammarUnits.pronouns.mini[row][col];
|
return grammarUnits.pronouns.mini[row][col];
|
||||||
}
|
}
|
||||||
|
|
||||||
function putKidsInKidsSection(entities: ListOfEntities, kids: ListOfEntities): ListOfEntities {
|
function putKidsInKidsSection(segments: ListOfSegments, kids: ListOfSegments): ListOfSegments {
|
||||||
const first = entities[0];
|
const first = segments[0];
|
||||||
const rest = entities.slice(1);
|
const rest = segments.slice(1);
|
||||||
|
console.log({ kids }, kids.length);
|
||||||
return [
|
return [
|
||||||
first.map(x => (
|
first.map(x => (
|
||||||
x.isVerbPrefix &&
|
(x.isVerbPrefix && isMiniPronoun(kids[0][0]))
|
||||||
// TODO: This isn't quite working
|
? { ...x, prefixFollowedByMiniPronoun: true }
|
||||||
(kids.length)
|
: x
|
||||||
) ? { ...x, prefixFollowedByParticle: true } : x),
|
)),
|
||||||
...kids,
|
...kids,
|
||||||
...rest,
|
...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 first = loe[0];
|
||||||
const rest = loe.slice(1);
|
const rest = loe.slice(1);
|
||||||
if (!rest.length) return first;
|
if (!rest.length) return first;
|
||||||
return combineEntities(rest).flatMap(r => (
|
console.log({ loe });
|
||||||
|
return combineSegments(rest).flatMap((r, restIndex, arr) => (
|
||||||
first.map(ps => concatPsString(
|
first.map(ps => concatPsString(
|
||||||
ps,
|
ps,
|
||||||
(ps.prefixFollowedByParticle
|
(ps.isVerbPrefix && isLast(restIndex, arr)
|
||||||
|
? ""
|
||||||
|
: ps.prefixFollowedByMiniPronoun
|
||||||
? { p: "", f: "-" }
|
? { p: "", f: "-" }
|
||||||
: ps.isVerbPrefix ? "" : " "),
|
: ps.isVerbPrefix ? " " : " "),
|
||||||
r,
|
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);
|
const rest = restRaw.map(removeBa);
|
||||||
if (!negative) {
|
if (!negative) {
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -2,8 +2,8 @@ import {
|
||||||
Types as T,
|
Types as T,
|
||||||
concatPsString,
|
concatPsString,
|
||||||
grammarUnits,
|
grammarUnits,
|
||||||
|
psRemove,
|
||||||
} from "@lingdocs/pashto-inflector";
|
} 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): T.Person;
|
||||||
export function getPersonFromNP(np: NPSelection | ObjectNP): T.Person | undefined;
|
export function getPersonFromNP(np: NPSelection | ObjectNP): T.Person | undefined;
|
||||||
|
@ -26,3 +26,19 @@ export function getPersonFromNP(np: NPSelection | ObjectNP): T.Person | undefine
|
||||||
export function removeBa(ps: T.PsString): T.PsString {
|
export function removeBa(ps: T.PsString): T.PsString {
|
||||||
return psRemove(ps, concatPsString(grammarUnits.baParticle, " "));
|
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)
|
||||||
|
)));
|
||||||
|
}
|
Loading…
Reference in New Issue