litte more refactoring

This commit is contained in:
adueck 2023-06-28 00:24:16 +04:00
parent 226da64608
commit 68d83d95d4
5 changed files with 134 additions and 64 deletions

View File

@ -189,6 +189,16 @@ export function getEnglishGenNumInfo(gender: T.Gender, number: T.NounNumber): st
return `${gender === "masc" ? "masc" : "fem"} ${number === "plural" ? "plur." : "sing."}`;
}
export function personToGenNum(p: T.Person): {
gender: T.Gender,
number: T.NounNumber,
} {
return {
gender: personGender(p),
number: personNumber(p),
};
}
export function getEnglishParticipleInflection(person: T.Person, version?: "short" | "long"): string {
const number = personIsPlural(person) ? "plural" : "singular";
const n = version === "short"

View File

@ -2,6 +2,7 @@ import { renderVerb } from "./render-verb";
import { vEntry } from "./rs-helpers";
import * as T from "../../../types";
import { negate } from "rambda";
import { personToGenNum } from "../misc-helpers";
const wahul = vEntry({"ts":1527815399,"i":15049,"p":"وهل","f":"wahul","g":"wahul","e":"to hit","r":4,"c":"v. trans.","tppp":"واهه","tppf":"waahu","ec":"hit,hits,hitting,hit,hit"});
const raawrul = vEntry({"ts":1527815214,"i":6954,"p":"راوړل","f":"raawRúl","g":"raawRul","e":"to bring, deliver (inanimate objects)","r":4,"c":"v. trans.","tppp":"راووړ","tppf":"raawoR","noOo":true,"separationAtP":2,"separationAtF":3,"ec":"bring,brings,bringing,brought,brought"});
@ -52,7 +53,7 @@ test("basic tenses", () => {
verb: wahul,
tense: "presentVerb",
person: T.Person.FirstSingMale,
complementPerson: T.Person.FirstSingMale,
complementGenNum: personToGenNum(T.Person.FirstSingMale),
voice: "active",
negative: false,
})).toEqual({
@ -69,7 +70,7 @@ test("basic tenses", () => {
verb: wahul,
tense: "subjunctiveVerb",
person: T.Person.SecondSingMale,
complementPerson: T.Person.SecondSingMale,
complementGenNum: personToGenNum(T.Person.SecondSingMale),
voice: "active",
negative: false,
})).toEqual({
@ -85,7 +86,7 @@ test("basic tenses", () => {
verb: wahul,
tense: "habitualPerfectivePast",
person: T.Person.ThirdSingFemale,
complementPerson: T.Person.ThirdSingFemale,
complementGenNum: personToGenNum(T.Person.ThirdSingFemale),
voice: "active",
negative: false,
})).toEqual({
@ -111,7 +112,7 @@ test("basic tenses with inflecting roots/stems", () => {
verb: bandawul,
tense: "subjunctiveVerb",
person: T.Person.FirstSingMale,
complementPerson: T.Person.ThirdSingFemale,
complementGenNum: personToGenNum(T.Person.ThirdSingFemale),
voice: "active",
negative: false,
})).toEqual({
@ -524,7 +525,7 @@ test("special endings", () => {
verb: x.verb,
tense: x.tense,
person: T.Person.ThirdSingMale,
complementPerson: T.Person.ThirdSingMale,
complementGenNum: personToGenNum(T.Person.ThirdSingMale),
voice: "active",
negative: false,
})).toEqual({ hasBa: false, vbs: x.result });
@ -534,7 +535,7 @@ test("special endings", () => {
verb: kedulStat,
tense: "perfectivePast",
person: T.Person.FirstPlurMale,
complementPerson: T.Person.FirstPlurMale,
complementGenNum: personToGenNum(T.Person.FirstPlurMale),
voice: "active",
negative: false,
})).toEqual({
@ -557,7 +558,7 @@ test("special endings", () => {
verb: tlul,
tense: "imperfectivePast",
person: T.Person.FirstSingMale,
complementPerson: T.Person.FirstSingMale,
complementGenNum: personToGenNum(T.Person.FirstSingMale),
voice: "active",
negative: false,
})).toEqual({
@ -581,7 +582,7 @@ test("special endings", () => {
verb: tlul,
tense: "imperfectivePast",
person: T.Person.ThirdSingFemale,
complementPerson: T.Person.ThirdSingFemale,
complementGenNum: personToGenNum(T.Person.ThirdSingFemale),
voice: "active",
negative: false,
})).toEqual({
@ -606,7 +607,7 @@ test("special endings", () => {
verb: khorul,
tense: "imperfectivePast",
person: T.Person.ThirdPlurMale,
complementPerson: T.Person.ThirdPlurMale,
complementGenNum: personToGenNum(T.Person.ThirdPlurMale),
voice: "active",
negative: false,
})).toEqual({
@ -629,7 +630,7 @@ test("special endings", () => {
verb: khorul,
tense: "perfectivePast",
person: T.Person.ThirdPlurMale,
complementPerson: T.Person.ThirdPlurMale,
complementGenNum: personToGenNum(T.Person.ThirdPlurMale),
voice: "active",
negative: false,
})).toEqual({
@ -655,7 +656,7 @@ test("imperative tenses", () => {
verb: wahul,
tense: "imperfectiveImperative",
person: T.Person.SecondSingMale,
complementPerson: T.Person.SecondSingMale,
complementGenNum: personToGenNum(T.Person.SecondSingMale),
voice: "active",
negative: false,
})).toEqual({
@ -671,7 +672,7 @@ test("imperative tenses", () => {
verb: wahul,
tense: "perfectiveImperative",
person: T.Person.SecondSingFemale,
complementPerson: T.Person.SecondSingFemale,
complementGenNum: personToGenNum(T.Person.SecondSingFemale),
voice: "active",
negative: false,
})).toEqual({
@ -687,7 +688,7 @@ test("imperative tenses", () => {
verb: wahul,
tense: "imperfectiveImperative",
person: T.Person.SecondPlurMale,
complementPerson: T.Person.SecondPlurMale,
complementGenNum: personToGenNum(T.Person.SecondPlurMale),
voice: "active",
negative: false,
})).toEqual({
@ -703,7 +704,7 @@ test("imperative tenses", () => {
verb: wahul,
tense: "perfectiveImperative",
person: T.Person.SecondPlurFemale,
complementPerson: T.Person.SecondPlurFemale,
complementGenNum: personToGenNum(T.Person.SecondPlurFemale),
voice: "active",
negative: false,
})).toEqual({
@ -722,7 +723,7 @@ test("ability tenses", () => {
verb: wahul,
tense: "presentVerbModal",
person: T.Person.FirstSingMale,
complementPerson: T.Person.FirstSingMale,
complementGenNum: personToGenNum(T.Person.FirstSingMale),
voice: "active",
negative: false,
})).toEqual({
@ -758,7 +759,7 @@ test("basic tenses", () => {
verb: wahul,
tense: "presentVerb",
person: T.Person.FirstSingMale,
complementPerson: T.Person.FirstSingMale,
complementGenNum: personToGenNum(T.Person.FirstSingMale),
voice: "active",
negative: false,
})).toEqual({
@ -775,7 +776,7 @@ test("basic tenses", () => {
verb: wahul,
tense: "subjunctiveVerb",
person: T.Person.SecondSingMale,
complementPerson: T.Person.SecondSingMale,
complementGenNum: personToGenNum(T.Person.SecondSingMale),
voice: "active",
negative: false,
})).toEqual({
@ -791,7 +792,7 @@ test("basic tenses", () => {
verb: wahul,
tense: "habitualPerfectivePast",
person: T.Person.ThirdSingFemale,
complementPerson: T.Person.ThirdSingFemale,
complementGenNum: personToGenNum(T.Person.ThirdSingFemale),
voice: "active",
negative: false,
})).toEqual({
@ -817,7 +818,7 @@ test("perfect tenses", () => {
verb: wahul,
tense: "presentPerfect",
person: T.Person.FirstSingMale,
complementPerson: T.Person.FirstSingMale,
complementGenNum: personToGenNum(T.Person.FirstSingMale),
voice: "active",
negative: false,
})).toEqual({
@ -834,7 +835,7 @@ test("perfect tenses", () => {
verb: wahul,
tense: "subjunctivePerfect",
person: T.Person.FirstSingMale,
complementPerson: T.Person.FirstSingMale,
complementGenNum: personToGenNum(T.Person.FirstSingMale),
voice: "active",
negative: false,
})).toEqual({
@ -851,7 +852,7 @@ test("perfect tenses", () => {
verb: wahul,
tense: "habitualPerfect",
person: T.Person.FirstSingMale,
complementPerson: T.Person.FirstSingMale,
complementGenNum: personToGenNum(T.Person.FirstSingMale),
voice: "active",
negative: false,
})).toEqual({
@ -868,7 +869,7 @@ test("perfect tenses", () => {
verb: wahul,
tense: "habitualPerfect",
person: T.Person.ThirdPlurMale,
complementPerson: T.Person.ThirdPlurMale,
complementGenNum: personToGenNum(T.Person.ThirdPlurMale),
voice: "active",
negative: false,
})).toEqual({
@ -885,7 +886,7 @@ test("perfect tenses", () => {
verb: wahul,
tense: "futurePerfect",
person: T.Person.FirstSingMale,
complementPerson: T.Person.FirstSingMale,
complementGenNum: personToGenNum(T.Person.FirstSingMale),
voice: "active",
negative: false,
})).toEqual({
@ -902,7 +903,7 @@ test("perfect tenses", () => {
verb: wahul,
tense: "pastPerfect",
person: T.Person.SecondSingFemale,
complementPerson: T.Person.SecondSingFemale,
complementGenNum: personToGenNum(T.Person.SecondSingFemale),
voice: "active",
negative: false,
})).toEqual({
@ -926,7 +927,7 @@ test("perfect tenses", () => {
verb: wahul,
tense: "wouldBePerfect",
person: T.Person.SecondSingFemale,
complementPerson: T.Person.SecondSingFemale,
complementGenNum: personToGenNum(T.Person.SecondSingFemale),
voice: "active",
negative: false,
})).toEqual({
@ -950,7 +951,7 @@ test("perfect tenses", () => {
verb: wahul,
tense: "pastSubjunctivePerfect",
person: T.Person.SecondSingFemale,
complementPerson: T.Person.SecondSingFemale,
complementGenNum: personToGenNum(T.Person.SecondSingFemale),
voice: "active",
negative: false,
})).toEqual({
@ -971,7 +972,7 @@ test("perfect tenses", () => {
verb: wahul,
tense: "wouldHaveBeenPerfect",
person: T.Person.SecondSingFemale,
complementPerson: T.Person.SecondSingFemale,
complementGenNum: personToGenNum(T.Person.SecondSingFemale),
voice: "active",
negative: false,
})).toEqual({
@ -996,7 +997,7 @@ test("ending on complex verbs", () => {
tense: "presentVerbModal",
person: T.Person.SecondSingMale,
voice: "active",
complementPerson: T.Person.ThirdSingFemale,
complementGenNum: personToGenNum(T.Person.ThirdSingFemale),
negative: false,
})).toEqual({
hasBa: false,
@ -1041,7 +1042,7 @@ test("ending on complex verbs", () => {
tense: "presentVerb",
person: T.Person.SecondSingMale,
voice: "active",
complementPerson: T.Person.ThirdSingFemale,
complementGenNum: personToGenNum(T.Person.ThirdSingFemale),
negative: false,
})).toEqual({
hasBa: false,

View File

@ -4,6 +4,7 @@ import {
isSecondPerson,
personGender,
personNumber,
personToGenNum,
} from "../misc-helpers";
import {
fmapSingleOrLengthOpts,
@ -19,20 +20,90 @@ import {
imperativeEndings,
} from "../grammar-units";
import { isKawulVerb, isAbilityTense, isPerfectTense, isTlulVerb, isImperativeTense } from "../type-predicates";
import { tenseHasBa } from "../phrase-building/vp-tools";
import { isPastTense } from "../phrase-building/vp-tools";
import { perfectTenseHasBa } from "../phrase-building/vp-tools";
import { makePsString, removeFVarients } from "../accent-and-ps-utils";
import { getPastParticiple, getRootStem } from "./roots-and-stems";
import { getAspect, isKedul, perfectTenseToEquative, verbEndingConcat } from "./rs-helpers";
import { isKedul, perfectTenseToEquative, verbEndingConcat } from "./rs-helpers";
import { accentOnNFromEnd, accentPsSyllable, removeAccents } from "../accent-helpers";
const formulas: Record<T.VerbTense | T.ImperativeTense, {
aspect: T.Aspect,
tenseC: "past" | "present" | "imperative",
hasBa: boolean,
}> = {
"presentVerb": {
aspect: "imperfective",
tenseC: "present",
hasBa: false,
},
"subjunctiveVerb": {
aspect: "imperfective",
tenseC: "present",
hasBa: false,
},
"perfectiveFuture": {
aspect: "perfective",
tenseC: "present",
hasBa: true,
},
"imperfectiveFuture": {
aspect: "imperfective",
tenseC: "present",
hasBa: true,
},
"perfectivePast": {
aspect: "perfective",
tenseC: "past",
hasBa: false,
},
"imperfectivePast": {
aspect: "imperfective",
tenseC: "past",
hasBa: false,
},
"habitualImperfectivePast": {
aspect: "imperfective",
tenseC: "past",
hasBa: true,
},
"habitualPerfectivePast": {
aspect: "perfective",
tenseC: "past",
hasBa: true,
},
"perfectiveImperative": {
aspect: "perfective",
tenseC: "imperative",
hasBa: false,
},
"imperfectiveImperative": {
aspect: "imperfective",
tenseC: "imperative",
hasBa: false,
},
}
// to get the chart of conjugations:
// 1. get the conjugation for all persons
// 2. if transitive present tense, check (or do all the conjugation) the conjugation with all different complement person stuff
// if necessary pull out the object option
//
// to make the verbs displayable for the charts
// - take the output of renderVerb { hasBa, VerbRenderedOutput }
// - filter out a long and short version etc if necessary
// - pass it into combineIntoText
// PROBLEM: how to handle when to specify the object
// present tense
// TODO: problem with laaR - no perfective split
export function renderVerb({ verb, tense, person, voice, negative, complementPerson }: {
export function renderVerb({ verb, tense: tense, person, voice, negative, complementGenNum }: {
verb: T.VerbEntry,
negative: boolean,
tense: T.VerbTense | T.PerfectTense | T.AbilityTense | T.ImperativeTense, // TODO: make T.Tense
person: T.Person,
complementPerson: T.Person,
complementGenNum: { gender: T.Gender, number: T.NounNumber },
voice: T.Voice,
}): {
hasBa: boolean,
@ -41,10 +112,8 @@ export function renderVerb({ verb, tense, person, voice, negative, complementPer
if (isPerfectTense(tense)) {
return renderPerfectVerb({ verb, tense, voice, person });
}
const isPast = isPastTense(tense);
const hasBa = tenseHasBa(tense);
const aspect = getAspect(tense, negative);
const isImperative = isImperativeTense(tense);
const { aspect, tenseC, hasBa } = formulas[removeAbility(tense)];
const isPast = tenseC === "past";
const type = isAbilityTense(tense) ? "ability" : "basic";
// #1 get the appropriate root / stem
@ -54,13 +123,10 @@ export function renderVerb({ verb, tense, person, voice, negative, complementPer
aspect,
voice,
type,
genderNumber: {
gender: personGender(complementPerson),
number: personNumber(complementPerson),
},
genderNumber: complementGenNum,
});
// #2 add the verb ending to it
const ending = getEnding(person, isPast, isImperative, aspect);
const ending = getEnding(person, tenseC, aspect);
return {
hasBa,
vbs: [
@ -85,13 +151,9 @@ function renderPerfectVerb({ tense, verb, voice, person }: {
person: T.Person,
// TODO: Tighter typing on the output for T.VB (enforce genderNumber?)
}): { hasBa: boolean, vbs: [[], [T.VB, T.VBE]] } {
const hasBa = tenseHasBa(tense);
const genderNumber = {
gender: personGender(person),
number: personNumber(person),
};
const hasBa = perfectTenseHasBa(tense);
// #1 get the past participle
const pp = getPastParticiple(verb, voice, genderNumber);
const pp = getPastParticiple(verb, voice, personToGenNum(person));
// #2 get the right equative
const equative = equativeEndings[perfectTenseToEquative(tense)];
const [row, col] = getVerbBlockPosFromPerson(person);
@ -141,7 +203,7 @@ function addEnding({ verb, rs, ending, person, pastThird, aspect, basicForm }: {
}
const endLong = getLength(end, "long");
const endShort = getLength(end, "short");
// TODO: this is hackyۉ
// TODO: this is hacky
return {
...vb,
ps: {
@ -166,8 +228,8 @@ function addEnding({ verb, rs, ending, person, pastThird, aspect, basicForm }: {
}
}
function getEnding(person: T.Person, isPast: boolean, isImperative: boolean, aspect: T.Aspect) {
if (isImperative) {
function getEnding(person: T.Person, tenseC: "present" | "past" | "imperative", aspect: T.Aspect) {
if (tenseC === "imperative") {
if (!isSecondPerson(person)) {
throw new Error("imperative forms must be second person");
}
@ -178,7 +240,7 @@ function getEnding(person: T.Person, isPast: boolean, isImperative: boolean, asp
: ends;
}
const [row, col] = getVerbBlockPosFromPerson(person);
return isPast ? {
return tenseC === "past" ? {
long: pastEndings.long[row][col],
short: pastEndings.short[row][col],
} : presentEndings[row][col];
@ -242,3 +304,7 @@ function ensure3rdPast(rs: T.PsString[], ending: T.PsString[], verb: T.VerbEntry
const ends = endsInDental ? [{ p: "", f: "" }, ...ending] : ending;
return verbEndingConcat(rs, ends);
}
function removeAbility(tense: T.VerbTense | T.AbilityTense | T.ImperativeTense): T.VerbTense | T.ImperativeTense {
return tense.replace("Modal", "") as T.VerbTense | T.ImperativeTense;
}

View File

@ -18,6 +18,7 @@ import { getObjectSelection, getSubjectSelection, makeBlock, makeKid } from "./b
import { renderAPSelection } from "./render-ap";
import { findPossesivesToShrink, orderKids, getMiniPronounPs } from "./render-common";
import { renderComplementSelection } from "./render-complement";
import { personToGenNum } from "../misc-helpers";
export function renderVP(VP: T.VPSelectionComplete): T.VPRendered {
const subject = getSubjectSelection(VP.blocks).selection;
@ -49,7 +50,7 @@ export function renderVP(VP: T.VPSelectionComplete): T.VPRendered {
verb: VP.verb.verb,
tense: VP.verb.tense,
person: kingPerson,
complementPerson: objectPerson || kingPerson,
complementGenNum: personToGenNum(objectPerson || kingPerson),
voice: VP.verb.voice,
negative: VP.verb.negative,
});

View File

@ -198,16 +198,8 @@ export function isPastTense(tense: T.Tense): boolean {
return tense.toLowerCase().includes("past");
}
export function tenseHasBa(tense: T.VerbTense | T.PerfectTense | T.AbilityTense | T.ImperativeTense): boolean {
const withBa: Parameters<typeof tenseHasBa>[0][] = [
"imperfectiveFuture",
"perfectiveFuture",
"habitualPerfectivePast",
"habitualImperfectivePast",
"imperfectiveFutureModal",
"perfectiveFutureModal",
"habitualPerfectivePastModal",
"habitualImperfectivePastModal",
export function perfectTenseHasBa(tense: T.PerfectTense): boolean {
const withBa: Parameters<typeof perfectTenseHasBa>[0][] = [
"futurePerfect",
"wouldBePerfect",
"wouldHaveBeenPerfect",