From f6414985a450d29b5af7a09a73d948efa00a79f3 Mon Sep 17 00:00:00 2001 From: adueck Date: Tue, 26 Sep 2023 14:48:21 -0400 Subject: [PATCH] fixed perfect verb parsing issue --- src/lib/src/parsing/parse-adverb.ts | 23 ++++++++++ src/lib/src/parsing/parse-ap.ts | 18 ++------ src/lib/src/parsing/parse-equative.ts | 5 ++- src/lib/src/parsing/parse-vp.test.ts | 4 ++ src/lib/src/parsing/parse-vp.ts | 64 ++++++++++++++++++++------- 5 files changed, 83 insertions(+), 31 deletions(-) create mode 100644 src/lib/src/parsing/parse-adverb.ts diff --git a/src/lib/src/parsing/parse-adverb.ts b/src/lib/src/parsing/parse-adverb.ts new file mode 100644 index 0000000..5ee1b6a --- /dev/null +++ b/src/lib/src/parsing/parse-adverb.ts @@ -0,0 +1,23 @@ +import * as T from "../../../types"; +import { LookupFunction } from "./lookup"; +import { returnParseResultS } from "./utils"; + +export function parseAdverb( + tokens: Readonly, + lookup: LookupFunction +): T.ParseResult[] { + 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, + }, + }) + ); +} diff --git a/src/lib/src/parsing/parse-ap.ts b/src/lib/src/parsing/parse-ap.ts index 9ed2dae..ed1e664 100644 --- a/src/lib/src/parsing/parse-ap.ts +++ b/src/lib/src/parsing/parse-ap.ts @@ -1,23 +1,13 @@ import * as T from "../../../types"; import { LookupFunction } from "./lookup"; -import { returnParseResultS } from "./utils"; +import { parseAdverb } from "./parse-adverb"; export function parseAP( - tokens: Readonly, + s: Readonly, lookup: LookupFunction ): T.ParseResult[] { - if (tokens.length === 0) { + if (s.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, - }, - }) - ); + return parseAdverb(s, lookup); } diff --git a/src/lib/src/parsing/parse-equative.ts b/src/lib/src/parsing/parse-equative.ts index f79286a..0806856 100644 --- a/src/lib/src/parsing/parse-equative.ts +++ b/src/lib/src/parsing/parse-equative.ts @@ -20,7 +20,10 @@ export function parseEquative( ); } if (s === "دي") { - return eqMaker(allThird, ["present"]); + return eqMaker( + [T.Person.ThirdPlurMale, T.Person.ThirdPlurFemale], + ["present"] + ); } if (s === "وي") { return eqMaker(allThird, ["habitual", "subjunctive"]); diff --git a/src/lib/src/parsing/parse-vp.test.ts b/src/lib/src/parsing/parse-vp.test.ts index db2c10d..1dfb42a 100644 --- a/src/lib/src/parsing/parse-vp.test.ts +++ b/src/lib/src/parsing/parse-vp.test.ts @@ -90,6 +90,10 @@ const tests: { input: "ما وانه اخیست", output: [], }, + { + input: "ما سړی نه دي لیدلی", + output: [], + }, ], }, { diff --git a/src/lib/src/parsing/parse-vp.ts b/src/lib/src/parsing/parse-vp.ts index 9358891..ec64121 100644 --- a/src/lib/src/parsing/parse-vp.ts +++ b/src/lib/src/parsing/parse-vp.ts @@ -28,16 +28,9 @@ import { equals, zip } from "rambda"; // 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 // 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 // not matching up @@ -55,7 +48,13 @@ export function parseVP( const ba = !!kids.find((k) => k === "ba"); const miniPronouns = getMiniPronouns(kids); 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) return tenses.flatMap(({ tense, person, transitivities, negative, verb }) => finishPossibleVPSs({ @@ -74,8 +73,7 @@ export function parseVP( function getTenses( blocks: T.ParsedBlock[], - ba: boolean, - hasKids: boolean + ba: boolean ): { tense: T.VerbTense | T.PerfectTense; person: T.Person; @@ -89,15 +87,11 @@ function getTenses( const negative = negIndex !== -1; const phIndex = blocks.findIndex((x) => x.type === "PH"); const vbeIndex = blocks.findIndex((x) => x.type === "VB"); - const verbSection = blocks.findIndex(startsVerbSection); 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") { return []; } - if (!verbSectionOK(blocks.slice(verbSection))) { - return []; - } if (verb.info.type === "verb") { if (verb.info.aspect === "perfective") { if (!ph) { @@ -127,7 +121,12 @@ function getTenses( const equative = blocks.find( (x) => x.type === "VB" && x.info.type === "equative" ) as T.ParsedVBE | undefined; - if (!pPart || pPart.info.type === "ability" || !equative) { + if ( + !pPart || + pPart.info.type === "ability" || + !equative || + equative.info.type !== "equative" + ) { return []; } const equativeGenNum = personToGenNum(equative.person); @@ -135,9 +134,13 @@ function getTenses( return []; } const transitivities = getTransitivities(pPart.info.verb); + const tense = getPerfectTense(ba, equative.info.tense); + if (!tense) { + return []; + } return [ { - tense: "presentPerfect", + tense, transitivities, negative, person: equative.person, @@ -945,3 +948,32 @@ function getTransitivities(v: T.VerbEntry): T.Transitivity[] { }); 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; +}