cleanup perfect

This commit is contained in:
lingdocs 2022-03-30 18:30:29 +05:00
parent f8964c6799
commit eef285aead
5 changed files with 112 additions and 107 deletions

View File

@ -9,7 +9,7 @@ import {
ButtonSelect,
getVerbInfo,
} from "@lingdocs/pashto-inflector";
import { isEquativeTense } from "../lib/phrase-building/vp-tools";
import { isPerfectTense } from "../lib/phrase-building/vp-tools";
// import { useState } from "react";
const tenseOptions: { label: string | JSX.Element, value: VerbTense }[] = [{
@ -38,27 +38,27 @@ const tenseOptions: { label: string | JSX.Element, value: VerbTense }[] = [{
value: "habitualPerfectivePast",
}];
const equativeTenseOptions: { label: string | JSX.Element, value: EquativeTense }[] = [{
const perfectTenseOptions: { label: string | JSX.Element, value: PerfectTense }[] = [{
label: "Present Perfect",
value: "present",
value: "present perfect",
}, {
label: "Habitual Perfect",
value: "habitual",
value: "habitual perfect",
}, {
label: "Subjunctive Perfect",
value: "subjunctive",
value: "subjunctive perfect",
}, {
label: "Future Perfect",
value: "future",
value: "future perfect",
}, {
label: "Past Perfect",
value: "past",
value: "past perfect",
}, {
label: "Would Be Perfect",
value: "wouldBe",
value: "wouldBe perfect",
}, {
label: "Past Subjunctive Perfect",
value: "pastSubjunctive",
value: "pastSubjunctive perfect",
}];
// type Filters = {
@ -86,9 +86,9 @@ function VerbPicker({ onChange, verb, verbs }: { verbs: VerbEntry[], verb: VerbS
}
onChange(makeVerbSelection(v, verb));
}
function onTenseSelect({ value }: { label: string, value: VerbTense | EquativeTense }) {
function onTenseSelect({ value }: { label: string, value: VerbTense | PerfectTense }) {
if (verb) {
if (isEquativeTense(value)) {
if (isPerfectTense(value)) {
onChange({
...verb,
tense: value,
@ -117,13 +117,13 @@ function VerbPicker({ onChange, verb, verbs }: { verbs: VerbEntry[], verb: VerbS
onChange({
...verb,
tenseCategory: value,
tense: isEquativeTense(verb.tense) ? verb.tense : "present",
tense: isPerfectTense(verb.tense) ? verb.tense : "present perfect",
});
} else {
onChange({
...verb,
tenseCategory: value,
tense: isEquativeTense(verb.tense) ? "presentVerb" : verb.tense,
tense: isPerfectTense(verb.tense) ? "presentVerb" : verb.tense,
});
}
}
@ -180,10 +180,10 @@ function VerbPicker({ onChange, verb, verbs }: { verbs: VerbEntry[], verb: VerbS
onChange={onTenseSelect}
className="mb-2"
// @ts-ignore
options={verb?.tenseCategory === "perfect" ? equativeTenseOptions : tenseOptions}
options={verb?.tenseCategory === "perfect" ? perfectTenseOptions : tenseOptions}
placeholder={verb ? (() => {
const label = (verb.tenseCategory === "perfect")
? equativeTenseOptions.find(o => o.value === verb.tense)?.label
? perfectTenseOptions.find(o => o.value === verb.tense)?.label
: tenseOptions.find(o => o.value === verb.tense)?.label;
return label || "Select Tense...";
})() : undefined}

View File

@ -115,28 +115,28 @@ export function renderEnglishVPBase({ subjectPerson, object, vs }: {
]),
};
const perfectBuilders: Record<
EquativeTense,
PerfectTense,
(s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => string[]
> = {
present: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
"present perfect": (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ ${engHave(s)}${n ? " not" : ""} ${v[4]}`,
]),
past: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
"past perfect": (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ had${n ? " not" : ""} ${v[4]}`,
]),
habitual: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
"habitual perfect": (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ ${engHave(s)}${n ? " not" : ""} ${v[4]}`,
]),
subjunctive: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
"subjunctive perfect": (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`that $SUBJ will have${n ? " not" : ""} ${v[4]}`,
]),
future: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
"future perfect": (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ will${n ? " not" : ""} have ${v[4]}`,
]),
wouldBe: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
"wouldBe perfect": (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ would${n ? " not" : ""} have ${v[4]}`,
]),
pastSubjunctive: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
"pastSubjunctive perfect": (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ would${n ? " not" : ""} have ${v[4]}`,
`$SUBJ should${n ? " not" : ""} have ${v[4]}`,
]),

View File

@ -19,7 +19,7 @@ import {
getPersonFromNP,
removeBa,
isPastTense,
isEquativeTense,
isPerfectTense,
} from "./vp-tools";
import { isPattern4Entry } from "../type-predicates";
import { renderEnglishVPBase } from "./english-vp-rendering";
@ -152,7 +152,7 @@ function getPsVerbConjugation(conj: T.VerbConjugation, vs: VerbSelection, person
},
hasBa: boolean,
} {
const f = getTenseVerbForm(conj, vs.tense, vs.tenseCategory);
const f = getTenseVerbForm(conj, vs.tense);
const block = getMatrixBlock(f, objectPerson, person);
const perfective = isPerfective(vs.tense);
const verbForm = getVerbFromBlock(block, person);
@ -254,81 +254,75 @@ function getMatrixBlock<U>(f: {
return f[personToLabel(person)];
}
function getTenseVerbForm(conj: T.VerbConjugation, tense: VerbTense | EquativeTense, tenseCategory: "basic" | "modal" | "perfect"): T.VerbForm {
if (tenseCategory === "basic") {
if (tense === "presentVerb") {
return conj.imperfective.nonImperative;
}
if (tense === "subjunctiveVerb") {
return conj.perfective.nonImperative;
}
if (tense === "imperfectiveFuture") {
return conj.imperfective.future;
}
if (tense === "perfectiveFuture") {
return conj.perfective.future;
}
if (tense === "imperfectivePast") {
return conj.imperfective.past;
}
if (tense === "perfectivePast") {
return conj.perfective.past;
}
if (tense === "habitualImperfectivePast") {
return conj.imperfective.habitualPast;
}
if (tense === "habitualPerfectivePast") {
return conj.perfective.habitualPast;
}
function getTenseVerbForm(conj: T.VerbConjugation, tense: VerbTense | PerfectTense): T.VerbForm {
if (tense === "presentVerb") {
return conj.imperfective.nonImperative;
}
if (tenseCategory === "perfect") {
if (tense === "present") {
return conj.perfect.present;
}
if (tense === "past") {
return conj.perfect.past;
}
if (tense === "future") {
return conj.perfect.future;
}
if (tense === "habitual") {
return conj.perfect.habitual;
}
if (tense === "subjunctive") {
return conj.perfect.subjunctive;
}
if (tense === "wouldBe") {
return conj.perfect.affirmational;
}
if (tense === "pastSubjunctive") {
return conj.perfect.pastSubjunctiveHypothetical;
}
if (tense === "subjunctiveVerb") {
return conj.perfective.nonImperative;
}
if (tenseCategory === "modal") {
if (tense === "presentVerb") {
return conj.imperfective.modal.nonImperative;
}
if (tense === "subjunctiveVerb") {
return conj.perfective.modal.nonImperative;
}
if (tense === "imperfectiveFuture") {
return conj.imperfective.modal.future;
}
if (tense === "perfectiveFuture") {
return conj.perfective.modal.future;
}
if (tense === "imperfectivePast") {
return conj.imperfective.modal.past;
}
if (tense === "perfectivePast") {
return conj.perfective.modal.past;
}
if (tense === "habitualImperfectivePast") {
return conj.imperfective.modal.habitualPast;
}
if (tense === "habitualPerfectivePast") {
return conj.perfective.modal.habitualPast;
}
if (tense === "imperfectiveFuture") {
return conj.imperfective.future;
}
if (tense === "perfectiveFuture") {
return conj.perfective.future;
}
if (tense === "imperfectivePast") {
return conj.imperfective.past;
}
if (tense === "perfectivePast") {
return conj.perfective.past;
}
if (tense === "habitualImperfectivePast") {
return conj.imperfective.habitualPast;
}
if (tense === "habitualPerfectivePast") {
return conj.perfective.habitualPast;
}
if (tense === "present perfect") {
return conj.perfect.present;
}
if (tense === "past perfect") {
return conj.perfect.past;
}
if (tense === "future perfect") {
return conj.perfect.future;
}
if (tense === "habitual perfect") {
return conj.perfect.habitual;
}
if (tense === "subjunctive perfect") {
return conj.perfect.subjunctive;
}
if (tense === "wouldBe perfect") {
return conj.perfect.affirmational;
}
if (tense === "pastSubjunctive perfect") {
return conj.perfect.pastSubjunctiveHypothetical;
}
if (tense === "presentVerb") {
return conj.imperfective.modal.nonImperative;
}
if (tense === "subjunctiveVerb") {
return conj.perfective.modal.nonImperative;
}
if (tense === "imperfectiveFuture") {
return conj.imperfective.modal.future;
}
if (tense === "perfectiveFuture") {
return conj.perfective.modal.future;
}
if (tense === "imperfectivePast") {
return conj.imperfective.modal.past;
}
if (tense === "perfectivePast") {
return conj.perfective.modal.past;
}
if (tense === "habitualImperfectivePast") {
return conj.imperfective.modal.habitualPast;
}
if (tense === "habitualPerfectivePast") {
return conj.perfective.modal.habitualPast;
}
throw new Error("unknown tense");
}
@ -400,8 +394,8 @@ function isFirstOrSecondPersPronoun(o: "none" | NPSelection | T.Person.ThirdPlur
return [0,1,2,3,6,7,8,9].includes(o.person);
}
function isPerfective(t: VerbTense | EquativeTense): boolean {
if (isEquativeTense(t)) return false;
function isPerfective(t: VerbTense | PerfectTense): boolean {
if (isPerfectTense(t)) return false;
if (t === "presentVerb" || t === "imperfectiveFuture" || t === "imperfectivePast" || t === "habitualImperfectivePast") {
return false;
}

View File

@ -27,14 +27,23 @@ export function removeBa(ps: T.PsString): T.PsString {
return psRemove(ps, concatPsString(grammarUnits.baParticle, " "));
}
export function isEquativeTense(t: VerbTense | EquativeTense): t is EquativeTense {
export function isEquativeTense(t: VerbTense | EquativeTense | PerfectTense): t is EquativeTense {
return (t === "present" || t === "future" || t === "habitual" || t === "past" || t === "wouldBe" || t === "subjunctive" || t === "pastSubjunctive");
}
export function isPastTense(tense: VerbTense | EquativeTense): boolean {
if (isEquativeTense(tense)) {
// equative tenses are used HERE for the perfect forms, which are all considered past tense
return true;
}
export function isPerfectTense(t: VerbTense | EquativeTense | PerfectTense): t is PerfectTense {
return (
t === "present perfect" ||
t === "habitual perfect" ||
t === "future perfect" ||
t === "past perfect" ||
t === "wouldBe perfect" ||
t === "subjunctive perfect" ||
t === "pastSubjunctive perfect"
);
}
export function isPastTense(tense: VerbTense | PerfectTense): boolean {
if (isPerfectTense(tense)) return true;
return tense.toLowerCase().includes("past");
}

View File

@ -35,6 +35,8 @@ type VerbTense = "presentVerb"
| "habitualPerfectivePast"
| "habitualImperfectivePast";
type PerfectTense = `${EquativeTense} perfect`;
type VerbSelection = {
type: "verb",
verb: VerbEntry,
@ -51,7 +53,7 @@ type VerbSelection = {
tense: VerbTense,
tenseCategory: "basic" | "modal",
} | {
tense: EquativeTense,
tense: PerfectTense,
tenseCategory: "perfect"
});