more towards perfect verb working - but not done yet

This commit is contained in:
adueck 2023-09-03 16:23:10 +04:00
parent 7ac14371f4
commit ded0030395
5 changed files with 138 additions and 113 deletions

View File

@ -66,7 +66,7 @@ export function parseBlocks(
return []; return [];
} }
// TODO: will have to handle welded // TODO: will have to handle welded
if (r.type === "VB") { if (r.type === "VB" && r.info.type !== "ppart") {
if (!phMatches(prevPh, r)) { if (!phMatches(prevPh, r)) {
return []; return [];
} }

View File

@ -1,4 +1,8 @@
import * as T from "../../../types"; import * as T from "../../../types";
import { getPeople, returnParseResultS } from "./utils";
const allThird = getPeople(3, "both");
const allPeople: T.Person[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
export function parseEquative( export function parseEquative(
tokens: Readonly<T.Token[]> tokens: Readonly<T.Token[]>
@ -7,100 +11,74 @@ export function parseEquative(
return []; return [];
} }
const [{ s }, ...rest] = tokens; const [{ s }, ...rest] = tokens;
const match = table.find((x) => x.ps.includes(s)); function eqMaker(
if (!match) { people: T.Person[],
tenses: T.EquativeTenseWithoutBa[]
): T.ParseResult<T.ParsedVBE>[] {
return tenses.flatMap((tense) =>
people.map((person) => returnParseResultS(rest, makeEqVBE(tense, person)))
);
}
if (s === "دي") {
return eqMaker(allThird, ["present"]);
}
if (s === "وي") {
return eqMaker(allThird, ["habitual", "subjunctive"]);
}
if (s === "دی") {
return eqMaker([T.Person.ThirdSingMale], ["present"]);
}
if (s === "ده") {
return eqMaker([T.Person.ThirdSingFemale], ["present"]);
}
if (["وای", "وی"].includes(s)) {
return eqMaker(allPeople, ["pastSubjunctive"]);
}
if (s === "ول") {
return eqMaker([T.Person.ThirdPlurMale], ["past"]);
}
const persons = getEqEndingPersons(s[s.length - 1]);
if (!persons.length) {
return []; return [];
} }
return match.people.flatMap((person) => if (s.length === 2 && s.startsWith("ی")) {
match.tenses.map((tense) => ({ return eqMaker(persons, ["present", "habitual"]);
tokens: rest, }
body: { if (s.length === 3 && s.startsWith("ول")) {
type: "VB", return eqMaker(persons, ["past"]);
info: { }
type: "equative", if (s.length === 2 && s.startsWith("و")) {
tense, return eqMaker(persons, ["past", "subjunctive"]);
}, }
person, return [];
},
errors: [],
}))
);
} }
// TODO: NOT COMPLETE / CORRECT function getEqEndingPersons(s: string): T.Person[] {
const table: { if (s === "م") {
ps: string[]; return getPeople(1, "sing");
tenses: T.EquativeTenseWithoutBa[]; }
people: T.Person[]; if (s === "ې") {
}[] = [ return getPeople(2, "sing");
{ }
ps: ["یم"], if (s === "و") {
tenses: ["present", "habitual"], return getPeople(1, "pl");
people: [T.Person.FirstSingMale, T.Person.FirstSingFemale], }
}, if (s === "ئ") {
{ return getPeople(2, "pl");
ps: ["یې"], }
tenses: ["present", "habitual"], return [];
people: [T.Person.SecondSingMale, T.Person.SecondSingFemale], }
},
{ function makeEqVBE(
ps: ["یو"], tense: T.EquativeTenseWithoutBa,
tenses: ["present", "habitual"], person: T.Person
people: [T.Person.FirstPlurMale, T.Person.FirstPlurFemale], ): T.ParsedVBE {
}, return {
{ type: "VB",
ps: ["یئ"], info: {
tenses: ["present", "habitual"], type: "equative",
people: [T.Person.SecondPlurMale, T.Person.SecondPlurFemale], tense,
}, },
{ person,
ps: ["وم"], };
tenses: ["subjunctive", "past"], }
people: [T.Person.FirstSingMale, T.Person.FirstSingFemale],
},
{
ps: ["وې"],
tenses: ["subjunctive", "past"],
people: [T.Person.SecondSingMale, T.Person.SecondSingFemale],
},
{
ps: ["وو"],
tenses: ["subjunctive", "past"],
people: [T.Person.FirstPlurMale, T.Person.FirstPlurFemale],
},
{
ps: ["وئ"],
tenses: ["subjunctive", "past"],
people: [T.Person.SecondPlurMale, T.Person.SecondPlurFemale],
},
{
ps: ["دی"],
tenses: ["present"],
people: [T.Person.ThirdSingMale],
},
{
ps: ["ده"],
tenses: ["present"],
people: [T.Person.ThirdSingFemale],
},
{
ps: ["دي"],
tenses: ["present"],
people: [T.Person.ThirdPlurMale, T.Person.ThirdPlurFemale],
},
{
ps: ["وي"],
tenses: ["habitual"],
people: [
T.Person.ThirdSingMale,
T.Person.ThirdSingFemale,
T.Person.ThirdPlurMale,
T.Person.ThirdPlurFemale,
],
},
{
ps: ["وای", "وی"],
tenses: ["pastSubjunctive"],
people: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
},
];

View File

@ -22,7 +22,9 @@ export function parsePhrase(s: T.Token[]): {
...parseVP(s, lookup), ...parseVP(s, lookup),
]; ];
const success = res.map((x) => x.body); console.log({ res });
const success = res.filter((x) => !x.tokens.length).map((x) => x.body);
console.log({ success });
return { return {
success, success,
errors: [ errors: [

View File

@ -13,6 +13,8 @@ import { parseBlocks } from "./parse-blocks";
import { makePronounSelection } from "../phrase-building/make-selections"; import { makePronounSelection } from "../phrase-building/make-selections";
import { isFirstOrSecondPersPronoun } from "../phrase-building/render-vp"; import { isFirstOrSecondPersPronoun } from "../phrase-building/render-vp";
import { LookupFunction } from "./lookup"; import { LookupFunction } from "./lookup";
import { personToGenNum } from "../misc-helpers";
import { equals } from "rambda";
// to hide equatives type-doubling issue // to hide equatives type-doubling issue
// this should also conjugate to // this should also conjugate to
@ -31,6 +33,10 @@ import { LookupFunction } from "./lookup";
// test bo ba ye dzee // test bo ba ye dzee
// test raaba ye wree // test raaba ye wree
// TODO: somehow make sure ALL BLOCKS ARE USED UP
// so we don't get something like ښځو زه خوړلې یم with a hanging
// یم not used
export function parseVP( export function parseVP(
tokens: Readonly<T.Token[]>, tokens: Readonly<T.Token[]>,
lookup: LookupFunction lookup: LookupFunction
@ -65,7 +71,7 @@ function getTenses(
ba: boolean, ba: boolean,
hasKids: boolean hasKids: boolean
): { ): {
tense: T.VerbTense; tense: T.VerbTense | T.PerfectTense;
person: T.Person; person: T.Person;
transitivities: T.Transitivity[]; transitivities: T.Transitivity[];
negative: boolean; negative: boolean;
@ -79,7 +85,7 @@ function getTenses(
const vbeIndex = blocks.findIndex((x) => x.type === "VB"); const vbeIndex = blocks.findIndex((x) => x.type === "VB");
const ph = phIndex !== -1 ? (blocks[phIndex] as T.ParsedPH) : undefined; const ph = phIndex !== -1 ? (blocks[phIndex] as T.ParsedPH) : undefined;
const verb = vbeIndex !== -1 ? (blocks[vbeIndex] as T.ParsedVBE) : undefined; const verb = vbeIndex !== -1 ? (blocks[vbeIndex] as T.ParsedVBE) : undefined;
if (!verb || verb.type !== "VB" || verb.info.type !== "verb") { if (!verb || verb.type !== "VB") {
return []; return [];
} }
if ( if (
@ -93,26 +99,53 @@ function getTenses(
) { ) {
return []; return [];
} }
if (verb.info.aspect === "perfective") { if (verb.info.type === "verb") {
if (!ph) { if (verb.info.aspect === "perfective") {
return []; if (!ph) {
return [];
}
} else {
if (ph) {
return [];
}
} }
const tense = getTenseFromRootsStems(ba, verb.info.base, verb.info.aspect);
const transitivities = getTransitivities(verb.info.verb);
return [
{
tense,
transitivities,
negative,
person: verb.person,
verb: verb.info.verb,
},
];
} else { } else {
if (ph) { // perfect
const pPart = blocks.find(
(x) => x.type === "VB" && x.info.type === "ppart"
) as T.ParsedVBP | undefined;
const equative = blocks.find(
(x) => x.type === "VB" && x.info.type === "equative"
) as T.ParsedVBE | undefined;
if (!pPart || pPart.info.type === "ability" || !equative) {
return []; return [];
} }
const equativeGenNum = personToGenNum(equative.person);
if (!equals(equativeGenNum, pPart.info.genNum)) {
return [];
}
const transitivities = getTransitivities(pPart.info.verb);
return [
{
tense: "presentPerfect",
transitivities,
negative,
person: equative.person,
verb: pPart.info.verb,
},
];
} }
const tense = getTenseFromRootsStems(ba, verb.info.base, verb.info.aspect);
const transitivities = getTransitivities(verb.info.verb);
return [
{
tense,
transitivities,
negative,
person: verb.person,
verb: verb.info.verb,
},
];
} }
function finishPossibleVPSs({ function finishPossibleVPSs({
@ -125,7 +158,7 @@ function finishPossibleVPSs({
tokens, tokens,
person, person,
}: { }: {
tense: T.VerbTense; tense: T.VerbTense | T.PerfectTense;
transitivities: T.Transitivity[]; transitivities: T.Transitivity[];
nps: T.ParsedNP[]; nps: T.ParsedNP[];
miniPronouns: T.ParsedMiniPronoun[]; miniPronouns: T.ParsedMiniPronoun[];

View File

@ -62,6 +62,18 @@ export function bindParseResult<C, D>(
return cleanOutResults(nextPossibilities); return cleanOutResults(nextPossibilities);
} }
export function returnParseResultS<D>(
tokens: Readonly<T.Token[]>,
body: D,
errors?: T.ParseError[]
): T.ParseResult<D> {
return {
tokens,
body,
errors: errors || [],
};
}
export function returnParseResult<D>( export function returnParseResult<D>(
tokens: Readonly<T.Token[]>, tokens: Readonly<T.Token[]>,
body: D, body: D,