more correct? modal and perfect ordering
This commit is contained in:
parent
d94b1d3d71
commit
7449e8d4ad
|
@ -5,7 +5,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-free": "^5.15.4",
|
"@fortawesome/fontawesome-free": "^5.15.4",
|
||||||
"@lingdocs/lingdocs-main": "^0.2.0",
|
"@lingdocs/lingdocs-main": "^0.2.0",
|
||||||
"@lingdocs/pashto-inflector": "^1.6.2",
|
"@lingdocs/pashto-inflector": "^1.6.3",
|
||||||
"@testing-library/jest-dom": "^5.11.4",
|
"@testing-library/jest-dom": "^5.11.4",
|
||||||
"@testing-library/react": "^11.1.0",
|
"@testing-library/react": "^11.1.0",
|
||||||
"@testing-library/user-event": "^12.1.10",
|
"@testing-library/user-event": "^12.1.10",
|
||||||
|
|
|
@ -6,16 +6,16 @@ import {
|
||||||
getVerbBlockPosFromPerson,
|
getVerbBlockPosFromPerson,
|
||||||
makePsString,
|
makePsString,
|
||||||
} from "@lingdocs/pashto-inflector";
|
} from "@lingdocs/pashto-inflector";
|
||||||
import { removeBa } from "./vp-tools";
|
import {
|
||||||
|
removeBa,
|
||||||
|
removeDuplicates,
|
||||||
|
} from "./vp-tools";
|
||||||
|
|
||||||
// also
|
// TODO: get the past tense order right
|
||||||
// nú dey me leeduley
|
// ویې نه کړای شو
|
||||||
|
// ویې نه شو کړای
|
||||||
|
// add modal to the passive
|
||||||
|
|
||||||
// نه مې دی لیدلی - nú me dey leeduley
|
|
||||||
// لیدلی مې نه دی - leeduley me nú dey
|
|
||||||
//
|
|
||||||
// TODO: make it an option to include O S V order ?
|
|
||||||
// TODO: tu ba laaR nu she hyphens all messed up
|
|
||||||
type Form = FormVersion & { OSV?: boolean };
|
type Form = FormVersion & { OSV?: boolean };
|
||||||
export function compileVP(VP: VPRendered, form: Form): { ps: T.SingleOrLengthOpts<T.PsString[]>, e?: string [] };
|
export function compileVP(VP: VPRendered, form: Form): { ps: T.SingleOrLengthOpts<T.PsString[]>, e?: string [] };
|
||||||
export function compileVP(VP: VPRendered, form: Form, combineLengths: true): { ps: T.PsString[], e?: string [] };
|
export function compileVP(VP: VPRendered, form: Form, combineLengths: true): { ps: T.PsString[], e?: string [] };
|
||||||
|
@ -26,9 +26,7 @@ export function compileVP(VP: VPRendered, form: Form, combineLengths?: true): {
|
||||||
NPs,
|
NPs,
|
||||||
kids,
|
kids,
|
||||||
verb,
|
verb,
|
||||||
hasLeapfrog: VP.verb.tenseCategory !== "basic",
|
VP,
|
||||||
negative: VP.verb.negative,
|
|
||||||
isCompound: VP.isCompound,
|
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
ps: combineLengths ? flattenLengths(psResult) : psResult,
|
ps: combineLengths ? flattenLengths(psResult) : psResult,
|
||||||
|
@ -43,25 +41,23 @@ type CompilePsInput = {
|
||||||
head: T.PsString | undefined,
|
head: T.PsString | undefined,
|
||||||
rest: T.SingleOrLengthOpts<T.PsString[]>,
|
rest: T.SingleOrLengthOpts<T.PsString[]>,
|
||||||
},
|
},
|
||||||
isCompound: "stative" | "dynamic" | false,
|
VP: VPRendered,
|
||||||
hasLeapfrog: boolean,
|
|
||||||
negative: boolean,
|
|
||||||
}
|
}
|
||||||
function compilePs({ NPs, kids, verb: { head, rest }, isCompound, hasLeapfrog, negative }: CompilePsInput): T.SingleOrLengthOpts<T.PsString[]> {
|
function compilePs({ NPs, kids, verb: { head, rest }, VP }: CompilePsInput): T.SingleOrLengthOpts<T.PsString[]> {
|
||||||
if ("long" in rest) {
|
if ("long" in rest) {
|
||||||
return {
|
return {
|
||||||
long: compilePs({ NPs, verb: { head, rest: rest.long }, negative, hasLeapfrog, isCompound, kids }) as T.PsString[],
|
long: compilePs({ NPs, verb: { head, rest: rest.long }, VP, kids }) as T.PsString[],
|
||||||
short: compilePs({ NPs, verb: { head, rest: rest.short }, negative, hasLeapfrog, isCompound, kids }) as T.PsString[],
|
short: compilePs({ NPs, verb: { head, rest: rest.short }, VP, kids }) as T.PsString[],
|
||||||
...rest.mini ? {
|
...rest.mini ? {
|
||||||
mini: compilePs({ NPs, verb: { head, rest: rest.mini }, negative, hasLeapfrog, isCompound, kids }) as T.PsString[],
|
mini: compilePs({ NPs, verb: { head, rest: rest.mini }, VP, kids }) as T.PsString[],
|
||||||
} : {},
|
} : {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const verbWNegativeVersions = arrangeVerbWNegative(head, rest, negative, isCompound, hasLeapfrog);
|
const verbWNegativeVersions = arrangeVerbWNegative(head, rest, VP.verb);
|
||||||
|
|
||||||
// put together all the different possible permutations based on:
|
// put together all the different possible permutations based on:
|
||||||
// a. potential different versions of where the nu goes
|
// a. potential different versions of where the nu goes
|
||||||
return verbWNegativeVersions.flatMap((verbSegments) => (
|
return removeDuplicates(verbWNegativeVersions.flatMap((verbSegments) => (
|
||||||
// b. potential reordering of NPs
|
// b. potential reordering of NPs
|
||||||
NPs.flatMap(NP => {
|
NPs.flatMap(NP => {
|
||||||
// for each permutation of the possible ordering of NPs and Verb + nu
|
// for each permutation of the possible ordering of NPs and Verb + nu
|
||||||
|
@ -72,7 +68,7 @@ function compilePs({ NPs, kids, verb: { head, rest }, isCompound, hasLeapfrog, n
|
||||||
// 3. throw it all together into a PsString for each permutation
|
// 3. throw it all together into a PsString for each permutation
|
||||||
return combineSegments(withProperSpaces);
|
return combineSegments(withProperSpaces);
|
||||||
})
|
})
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSegmentsAndKids(VP: VPRendered, form: Form): { kids: Segment[], NPs: Segment[][] } {
|
function getSegmentsAndKids(VP: VPRendered, form: Form): { kids: Segment[], NPs: Segment[][] } {
|
||||||
|
@ -134,7 +130,8 @@ function putKidsInKidsSection(segments: Segment[], kids: Segment[]): Segment[] {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
function arrangeVerbWNegative(head: T.PsString | undefined, restRaw: T.PsString[], negative: boolean, isCompound: "stative" | "dynamic" | false, hasLeapfrog: boolean): Segment[][] {
|
function arrangeVerbWNegative(head: T.PsString | undefined, restRaw: T.PsString[], V: VerbRendered): Segment[][] {
|
||||||
|
const hasLeapfrog = V.tenseCategory === "modal" || V.tenseCategory === "perfect";
|
||||||
const rest = (() => {
|
const rest = (() => {
|
||||||
if (hasLeapfrog) {
|
if (hasLeapfrog) {
|
||||||
const [restF, restLast] = splitOffLeapfrogWord(restRaw);
|
const [restF, restLast] = splitOffLeapfrogWord(restRaw);
|
||||||
|
@ -153,7 +150,7 @@ function arrangeVerbWNegative(head: T.PsString | undefined, restRaw: T.PsString[
|
||||||
? ["isVerbHead", "isOoOrWaaHead"]
|
? ["isVerbHead", "isOoOrWaaHead"]
|
||||||
: ["isVerbHead"]
|
: ["isVerbHead"]
|
||||||
);
|
);
|
||||||
if (!negative) {
|
if (!V.negative) {
|
||||||
if ("front" in rest) {
|
if ("front" in rest) {
|
||||||
return [
|
return [
|
||||||
headSegment ? [headSegment, rest.front, rest.last] : [rest.front, rest.last],
|
headSegment ? [headSegment, rest.front, rest.last] : [rest.front, rest.last],
|
||||||
|
@ -195,7 +192,7 @@ function arrangeVerbWNegative(head: T.PsString | undefined, restRaw: T.PsString[
|
||||||
if ("front" in rest) {
|
if ("front" in rest) {
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
...headSegment ? [headSegment.adjust({ ps: removeAccents })] : [],
|
headSegment.adjust({ ps: removeAccents }),
|
||||||
rest.last.adjust({
|
rest.last.adjust({
|
||||||
ps: r => concatPsString(nu, " ", removeAccents(r)),
|
ps: r => concatPsString(nu, " ", removeAccents(r)),
|
||||||
desc: ["isNu"],
|
desc: ["isNu"],
|
||||||
|
@ -205,23 +202,24 @@ function arrangeVerbWNegative(head: T.PsString | undefined, restRaw: T.PsString[
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
...headSegment ? [headSegment.adjust({ ps: removeAccents })] : [],
|
headSegment.adjust({ ps: removeAccents }),
|
||||||
rest.front.adjust({
|
rest.front.adjust({
|
||||||
ps: r => removeAccents(r),
|
|
||||||
}),
|
|
||||||
rest.last.adjust({
|
|
||||||
ps: r => concatPsString(nu, " ", removeAccents(r)),
|
ps: r => concatPsString(nu, " ", removeAccents(r)),
|
||||||
desc: ["isNu"],
|
desc: ["isNu"],
|
||||||
}),
|
}),
|
||||||
|
rest.last.adjust({
|
||||||
|
ps: r => removeAccents(r),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
// TODO: do something like this with the leapfrog?
|
...(!headSegment.isOoOrWaaHead && !V.isCompound) ? [[
|
||||||
// // verbs that have a perfective prefix that is not و or وا can put the
|
mergeSegments(headSegment, rest.front, "no space").adjust({
|
||||||
// // nu *before* the prefix as well // TODO: also وي prefixes?
|
ps: r => concatPsString(nu, " ", removeAccents(r)),
|
||||||
// ...(!headSegment.isOoOrWaaHead && !isCompound) ? [[
|
desc: ["isNu"],
|
||||||
// makeSegment(nu, ["isNu"]),
|
}),
|
||||||
// headSegment.adjust({ ps: removeAccents }),
|
rest.last.adjust({
|
||||||
// rest.adjust({ ps: removeAccents }),
|
ps: r => removeAccents(r),
|
||||||
// ]] : [],
|
}),
|
||||||
|
]] : [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
|
@ -234,7 +232,7 @@ function arrangeVerbWNegative(head: T.PsString | undefined, restRaw: T.PsString[
|
||||||
],
|
],
|
||||||
// verbs that have a perfective prefix that is not و or وا can put the
|
// verbs that have a perfective prefix that is not و or وا can put the
|
||||||
// nu *before* the prefix as well // TODO: also وي prefixes?
|
// nu *before* the prefix as well // TODO: also وي prefixes?
|
||||||
...(!headSegment.isOoOrWaaHead && !isCompound) ? [[
|
...(!headSegment.isOoOrWaaHead && !V.isCompound) ? [[
|
||||||
makeSegment(nu, ["isNu"]),
|
makeSegment(nu, ["isNu"]),
|
||||||
headSegment.adjust({ ps: removeAccents }),
|
headSegment.adjust({ ps: removeAccents }),
|
||||||
rest.adjust({ ps: removeAccents }),
|
rest.adjust({ ps: removeAccents }),
|
||||||
|
@ -247,7 +245,10 @@ function shrinkNP(np: Rendered<NPSelection>): Segment {
|
||||||
return makeSegment(grammarUnits.pronouns.mini[row][col], ["isKid", "isMiniPronoun"]);
|
return makeSegment(grammarUnits.pronouns.mini[row][col], ["isKid", "isMiniPronoun"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeSegments(s1: Segment, s2: Segment): Segment {
|
function mergeSegments(s1: Segment, s2: Segment, noSpace?: "no space"): Segment {
|
||||||
|
if (noSpace) {
|
||||||
|
return s2.adjust({ ps: (p) => concatPsString(s1.ps[0], p) });
|
||||||
|
}
|
||||||
return s2.adjust({ ps: (p) => concatPsString(s1.ps[0], " ", p) });
|
return s2.adjust({ ps: (p) => concatPsString(s1.ps[0], " ", p) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
grammarUnits,
|
grammarUnits,
|
||||||
psRemove,
|
psRemove,
|
||||||
} from "@lingdocs/pashto-inflector";
|
} from "@lingdocs/pashto-inflector";
|
||||||
|
import { psStringEquals } 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;
|
||||||
|
@ -47,3 +48,11 @@ export function isPastTense(tense: VerbTense | PerfectTense): boolean {
|
||||||
if (isPerfectTense(tense)) return true;
|
if (isPerfectTense(tense)) return true;
|
||||||
return tense.toLowerCase().includes("past");
|
return tense.toLowerCase().includes("past");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function removeDuplicates(psv: T.PsString[]): T.PsString[] {
|
||||||
|
return psv.filter((ps, i, arr) => (
|
||||||
|
i === arr.findIndex(t => (
|
||||||
|
psStringEquals(t, ps)
|
||||||
|
))
|
||||||
|
));
|
||||||
|
}
|
Loading…
Reference in New Issue