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": { "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.5.1", "@lingdocs/pashto-inflector": "^1.5.4",
"@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",

View File

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

View File

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

View File

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