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 [];
}
// TODO: will have to handle welded
if (r.type === "VB") {
if (r.type === "VB" && r.info.type !== "ppart") {
if (!phMatches(prevPh, r)) {
return [];
}

View File

@ -1,4 +1,8 @@
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(
tokens: Readonly<T.Token[]>
@ -7,100 +11,74 @@ export function parseEquative(
return [];
}
const [{ s }, ...rest] = tokens;
const match = table.find((x) => x.ps.includes(s));
if (!match) {
function eqMaker(
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 match.people.flatMap((person) =>
match.tenses.map((tense) => ({
tokens: rest,
body: {
type: "VB",
info: {
type: "equative",
tense,
},
person,
},
errors: [],
}))
);
if (s.length === 2 && s.startsWith("ی")) {
return eqMaker(persons, ["present", "habitual"]);
}
if (s.length === 3 && s.startsWith("ول")) {
return eqMaker(persons, ["past"]);
}
if (s.length === 2 && s.startsWith("و")) {
return eqMaker(persons, ["past", "subjunctive"]);
}
return [];
}
// TODO: NOT COMPLETE / CORRECT
const table: {
ps: string[];
tenses: T.EquativeTenseWithoutBa[];
people: T.Person[];
}[] = [
{
ps: ["یم"],
tenses: ["present", "habitual"],
people: [T.Person.FirstSingMale, T.Person.FirstSingFemale],
},
{
ps: ["یې"],
tenses: ["present", "habitual"],
people: [T.Person.SecondSingMale, T.Person.SecondSingFemale],
},
{
ps: ["یو"],
tenses: ["present", "habitual"],
people: [T.Person.FirstPlurMale, T.Person.FirstPlurFemale],
},
{
ps: ["یئ"],
tenses: ["present", "habitual"],
people: [T.Person.SecondPlurMale, T.Person.SecondPlurFemale],
},
{
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],
},
];
function getEqEndingPersons(s: string): T.Person[] {
if (s === "م") {
return getPeople(1, "sing");
}
if (s === "ې") {
return getPeople(2, "sing");
}
if (s === "و") {
return getPeople(1, "pl");
}
if (s === "ئ") {
return getPeople(2, "pl");
}
return [];
}
function makeEqVBE(
tense: T.EquativeTenseWithoutBa,
person: T.Person
): T.ParsedVBE {
return {
type: "VB",
info: {
type: "equative",
tense,
},
person,
};
}

View File

@ -22,7 +22,9 @@ export function parsePhrase(s: T.Token[]): {
...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 {
success,
errors: [

View File

@ -13,6 +13,8 @@ import { parseBlocks } from "./parse-blocks";
import { makePronounSelection } from "../phrase-building/make-selections";
import { isFirstOrSecondPersPronoun } from "../phrase-building/render-vp";
import { LookupFunction } from "./lookup";
import { personToGenNum } from "../misc-helpers";
import { equals } from "rambda";
// to hide equatives type-doubling issue
// this should also conjugate to
@ -31,6 +33,10 @@ import { LookupFunction } from "./lookup";
// test bo ba ye dzee
// 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(
tokens: Readonly<T.Token[]>,
lookup: LookupFunction
@ -65,7 +71,7 @@ function getTenses(
ba: boolean,
hasKids: boolean
): {
tense: T.VerbTense;
tense: T.VerbTense | T.PerfectTense;
person: T.Person;
transitivities: T.Transitivity[];
negative: boolean;
@ -79,7 +85,7 @@ function getTenses(
const vbeIndex = blocks.findIndex((x) => x.type === "VB");
const ph = phIndex !== -1 ? (blocks[phIndex] as T.ParsedPH) : 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 [];
}
if (
@ -93,26 +99,53 @@ function getTenses(
) {
return [];
}
if (verb.info.aspect === "perfective") {
if (!ph) {
return [];
if (verb.info.type === "verb") {
if (verb.info.aspect === "perfective") {
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 {
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 [];
}
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({
@ -125,7 +158,7 @@ function finishPossibleVPSs({
tokens,
person,
}: {
tense: T.VerbTense;
tense: T.VerbTense | T.PerfectTense;
transitivities: T.Transitivity[];
nps: T.ParsedNP[];
miniPronouns: T.ParsedMiniPronoun[];

View File

@ -62,6 +62,18 @@ export function bindParseResult<C, D>(
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>(
tokens: Readonly<T.Token[]>,
body: D,