fix ba handling in verbs

This commit is contained in:
lingdocs 2022-03-22 15:57:18 +05:00
parent bac409bc0a
commit f0ff07aedb
5 changed files with 42 additions and 44 deletions

View File

@ -5,7 +5,7 @@
"dependencies": {
"@fortawesome/fontawesome-free": "^5.15.4",
"@lingdocs/lingdocs-main": "^0.2.0",
"@lingdocs/pashto-inflector": "^1.5.1",
"@lingdocs/pashto-inflector": "^1.5.4",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",

View File

@ -5,7 +5,6 @@ import {
grammarUnits,
getVerbBlockPosFromPerson,
} from "@lingdocs/pashto-inflector";
import { hasBaParticle } from "@lingdocs/pashto-inflector/dist/lib/p-text-helpers";
import { removeBa } from "./vp-tools";
type ListOfEntities = (T.PsString & { isVerbPrefix?: boolean, prefixFollowedByParticle?: boolean })[][];
@ -51,14 +50,14 @@ function compilePs(
} : {},
};
}
const { hasBa, verbEntities } = compileVerbWNegative(head, rest, negative)
const verbEntities = compileVerbWNegative(head, rest, negative)
const entities: ListOfEntities = [
...nps,
...verbEntities,
];
const entitiesWKids = putKidsInKidsSection(
entities,
hasBa ? [[grammarUnits.baParticle], ...kids] : kids,
kids,
);
return combineEntities(entitiesWKids);
}
@ -84,6 +83,8 @@ function shrinkEntitiesAndGatherKids(VP: VPRendered, form: FormVersion): { kids:
);
return {
kids: [
...VP.verb.hasBa
? [[grammarUnits.baParticle]] : [],
...toShrink
? [shrink(toShrink)] : [],
],
@ -129,43 +130,29 @@ function combineEntities(loe: ListOfEntities): T.PsString[] {
}
function compileVerbWNegative(head: T.PsString | undefined, restRaw: T.PsString[], negative: boolean): {
hasBa: boolean,
verbEntities: ListOfEntities,
} {
const hasBa = hasBaParticle(restRaw[0]);
const rest = hasBa
? restRaw.map(removeBa)
: restRaw;
function compileVerbWNegative(head: T.PsString | undefined, restRaw: T.PsString[], negative: boolean): ListOfEntities {
console.log({ head, restRaw });
const rest = restRaw.map(removeBa);
if (!negative) {
return {
hasBa,
verbEntities: [
...head ? [[{...head, isVerbPrefix: true}]] : [],
rest,
],
};
return [
...head ? [[{...head, isVerbPrefix: true}]] : [],
rest,
];
}
const nu: T.PsString = { p: "نه", f: "nú" };
if (!head) {
return {
hasBa,
verbEntities: [
[nu],
rest.map(r => removeAccents(r)),
],
};
return [
[nu],
rest.map(r => removeAccents(r)),
];
}
// const regularPrefix = head.p === "و" || head.p === "وا";
// if (regularPrefix) {
// dashes for oo-nu etc
return {
hasBa,
verbEntities: [
[{ ...removeAccents(head), isVerbPrefix: true }],
rest.map(r => concatPsString(nu, " ", removeAccents(r))),
],
};
return [
[{ ...removeAccents(head), isVerbPrefix: true }],
rest.map(r => concatPsString(nu, " ", removeAccents(r))),
];
}
function compileEnglish(VP: VPRendered): string[] | undefined {

View File

@ -18,6 +18,7 @@ import {
getPersonFromNP, removeBa,
} from "./vp-tools";
import { isPattern4Entry } from "../type-predicates";
import { hasBaParticle } from "@lingdocs/pashto-inflector/dist/lib/p-text-helpers";
// TODO: ISSUE GETTING SPLIT HEAD NOT MATCHING WITH FUTURE VERBS
@ -133,7 +134,7 @@ function renderVerbSelection(vs: VerbSelection, person: T.Person, objectPerson:
return {
...vs,
person,
ps: getPsVerbConjugation(conj, vs.tense, person, objectPerson),
...getPsVerbConjugation(conj, vs.tense, person, objectPerson),
}
}
@ -200,26 +201,35 @@ function renderEnglishVPBase({ subjectPerson, object, vs }: {
}
function getPsVerbConjugation(conj: T.VerbConjugation, tense: VerbTense, person: T.Person, objectPerson: T.Person | undefined): {
head: T.PsString | undefined,
rest: T.SingleOrLengthOpts<T.PsString[]>,
ps: {
head: T.PsString | undefined,
rest: T.SingleOrLengthOpts<T.PsString[]>,
},
hasBa: boolean,
} {
const f = getTenseVerbForm(conj, tense);
const block = getMatrixBlock(f, objectPerson, person);
const perfective = isPerfective(tense);
const verbForm = getVerbFromBlock(block, person);
const hasBa = hasBaParticle(getLong(verbForm)[0]);
if (perfective) {
const past = isPastTense(tense);
const splitInfo = conj.info[past ? "root" : "stem"].perfectiveSplit;
if (!splitInfo) return { head: undefined, rest: verbForm };
if (!splitInfo) return { ps: { head: undefined, rest: verbForm }, hasBa };
// TODO: Either solve this in the inflector or here, it seems silly (or redundant)
// to have a length option in the perfective split stem??
const [splitHead] = getLong(getMatrixBlock(splitInfo, objectPerson, person));
console.log("removing from verb form", { splitHead, verbForm });
console.log(removeHead(splitHead, verbForm));
return {
head: splitHead,
rest: removeHead(splitHead, verbForm),
hasBa,
ps: {
head: splitHead,
rest: removeHead(splitHead, verbForm),
},
};
}
return { head: undefined, rest: verbForm };
return { hasBa, ps: { head: undefined, rest: verbForm }};
}
function getVerbFromBlock(block: T.SingleOrLengthOpts<T.VerbBlock>, person: T.Person): T.SingleOrLengthOpts<T.PsString[]> {

View File

@ -43,6 +43,7 @@ type VerbRendered = Omit<VerbSelection, "object"> & {
import("@lingdocs/pashto-inflector").Types.PsString[]
>,
},
hasBa: boolean,
person: import("@lingdocs/pashto-inflector").Types.Person,
};

View File

@ -1684,10 +1684,10 @@
pbf "^3.2.1"
rambda "^6.7.0"
"@lingdocs/pashto-inflector@^1.5.1":
version "1.5.1"
resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.5.1.tgz#515c7a42748190900f0b6d7b09878223d770857d"
integrity sha512-PiLr1c4plIpANLNx7zmJ3Ay50knPbsrArykz5ljiHd/sfJyLw/r3AcDnJAVMYs2vfv4yKFTxg3ig9qGf+CivcA==
"@lingdocs/pashto-inflector@^1.5.4":
version "1.5.4"
resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.5.4.tgz#2ef3ebce061e62493f79b0b0862d1d9fb7954b40"
integrity sha512-rvQuhld+Ioz5P1SsMKDoeT27RLSZN/r2qy4qm8JCpfPs3y/pFXmoTWhgnfXtbcZ8n2dy7UNiO3jTd4eCQXPsFA==
dependencies:
classnames "^2.2.6"
pbf "^3.2.1"