fixed perfect verb parsing issue

This commit is contained in:
adueck 2023-09-26 14:48:21 -04:00
parent 9168265043
commit f6414985a4
5 changed files with 83 additions and 31 deletions

View File

@ -0,0 +1,23 @@
import * as T from "../../../types";
import { LookupFunction } from "./lookup";
import { returnParseResultS } from "./utils";
export function parseAdverb(
tokens: Readonly<T.Token[]>,
lookup: LookupFunction
): T.ParseResult<T.APSelection>[] {
if (tokens.length === 0) {
return [];
}
const [first, ...rest] = tokens;
const adverbs = lookup(first.s, "adverb");
return adverbs.map((entry) =>
returnParseResultS(rest, {
type: "AP",
selection: {
type: "adverb",
entry,
},
})
);
}

View File

@ -1,23 +1,13 @@
import * as T from "../../../types"; import * as T from "../../../types";
import { LookupFunction } from "./lookup"; import { LookupFunction } from "./lookup";
import { returnParseResultS } from "./utils"; import { parseAdverb } from "./parse-adverb";
export function parseAP( export function parseAP(
tokens: Readonly<T.Token[]>, s: Readonly<T.Token[]>,
lookup: LookupFunction lookup: LookupFunction
): T.ParseResult<T.APSelection>[] { ): T.ParseResult<T.APSelection>[] {
if (tokens.length === 0) { if (s.length === 0) {
return []; return [];
} }
const [first, ...rest] = tokens; return parseAdverb(s, lookup);
const adverbs = lookup(first.s, "adverb");
return adverbs.map((entry) =>
returnParseResultS(rest, {
type: "AP",
selection: {
type: "adverb",
entry,
},
})
);
} }

View File

@ -20,7 +20,10 @@ export function parseEquative(
); );
} }
if (s === "دي") { if (s === "دي") {
return eqMaker(allThird, ["present"]); return eqMaker(
[T.Person.ThirdPlurMale, T.Person.ThirdPlurFemale],
["present"]
);
} }
if (s === "وي") { if (s === "وي") {
return eqMaker(allThird, ["habitual", "subjunctive"]); return eqMaker(allThird, ["habitual", "subjunctive"]);

View File

@ -90,6 +90,10 @@ const tests: {
input: "ما وانه اخیست", input: "ما وانه اخیست",
output: [], output: [],
}, },
{
input: "ما سړی نه دي لیدلی",
output: [],
},
], ],
}, },
{ {

View File

@ -28,16 +28,9 @@ import { equals, zip } from "rambda";
// TODO: word query for kawul/kedul/stat/dyn // TODO: word query for kawul/kedul/stat/dyn
// TODO: learn how to yank / use plugin for JSON neovim
// learn to use jq to edit selected json in vim ?? COOOL
// TODO: test grammatically transitive stuff // TODO: test grammatically transitive stuff
// 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
// TODO: way to get an error message for past participle and equative // TODO: way to get an error message for past participle and equative
// not matching up // not matching up
@ -55,7 +48,13 @@ export function parseVP(
const ba = !!kids.find((k) => k === "ba"); const ba = !!kids.find((k) => k === "ba");
const miniPronouns = getMiniPronouns(kids); const miniPronouns = getMiniPronouns(kids);
const nps = blocks.filter((x): x is T.ParsedNP => x.type === "NP"); const nps = blocks.filter((x): x is T.ParsedNP => x.type === "NP");
const tenses = getTenses(blocks, ba, !!kids.length); const verbSection = blocks.findIndex(startsVerbSection);
// TODO: would be nice if this could pass error messages about the
// negative being out of place etc
if (!verbSectionOK(blocks.slice(verbSection))) {
return [];
}
const tenses = getTenses(blocks, ba);
// TODO get errors from the get tenses (perfect verbs not agreeing) // TODO get errors from the get tenses (perfect verbs not agreeing)
return tenses.flatMap(({ tense, person, transitivities, negative, verb }) => return tenses.flatMap(({ tense, person, transitivities, negative, verb }) =>
finishPossibleVPSs({ finishPossibleVPSs({
@ -74,8 +73,7 @@ export function parseVP(
function getTenses( function getTenses(
blocks: T.ParsedBlock[], blocks: T.ParsedBlock[],
ba: boolean, ba: boolean
hasKids: boolean
): { ): {
tense: T.VerbTense | T.PerfectTense; tense: T.VerbTense | T.PerfectTense;
person: T.Person; person: T.Person;
@ -89,15 +87,11 @@ function getTenses(
const negative = negIndex !== -1; const negative = negIndex !== -1;
const phIndex = blocks.findIndex((x) => x.type === "PH"); const phIndex = blocks.findIndex((x) => x.type === "PH");
const vbeIndex = blocks.findIndex((x) => x.type === "VB"); const vbeIndex = blocks.findIndex((x) => x.type === "VB");
const verbSection = blocks.findIndex(startsVerbSection);
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") { if (!verb || verb.type !== "VB") {
return []; return [];
} }
if (!verbSectionOK(blocks.slice(verbSection))) {
return [];
}
if (verb.info.type === "verb") { if (verb.info.type === "verb") {
if (verb.info.aspect === "perfective") { if (verb.info.aspect === "perfective") {
if (!ph) { if (!ph) {
@ -127,7 +121,12 @@ function getTenses(
const equative = blocks.find( const equative = blocks.find(
(x) => x.type === "VB" && x.info.type === "equative" (x) => x.type === "VB" && x.info.type === "equative"
) as T.ParsedVBE | undefined; ) as T.ParsedVBE | undefined;
if (!pPart || pPart.info.type === "ability" || !equative) { if (
!pPart ||
pPart.info.type === "ability" ||
!equative ||
equative.info.type !== "equative"
) {
return []; return [];
} }
const equativeGenNum = personToGenNum(equative.person); const equativeGenNum = personToGenNum(equative.person);
@ -135,9 +134,13 @@ function getTenses(
return []; return [];
} }
const transitivities = getTransitivities(pPart.info.verb); const transitivities = getTransitivities(pPart.info.verb);
const tense = getPerfectTense(ba, equative.info.tense);
if (!tense) {
return [];
}
return [ return [
{ {
tense: "presentPerfect", tense,
transitivities, transitivities,
negative, negative,
person: equative.person, person: equative.person,
@ -945,3 +948,32 @@ function getTransitivities(v: T.VerbEntry): T.Transitivity[] {
}); });
return transitivities; return transitivities;
} }
function getPerfectTense(
ba: boolean,
tense: T.EquativeTenseWithoutBa
): T.PerfectTense | undefined {
const et = getEquativeTense(ba, tense);
if (!et) return undefined;
return `${et}Perfect`;
}
function getEquativeTense(
ba: boolean,
tense: T.EquativeTenseWithoutBa
): T.EquativeTense | undefined {
if (ba) {
if (tense === "habitual") {
return "future";
}
if (tense === "past") {
return "wouldBe";
}
if (tense === "pastSubjunctive") {
return "wouldHaveBeen";
}
// illegal use of ba
return undefined;
}
return tense;
}