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

View File

@ -115,28 +115,28 @@ export function renderEnglishVPBase({ subjectPerson, object, vs }: {
]), ]),
}; };
const perfectBuilders: Record< const perfectBuilders: Record<
EquativeTense, PerfectTense,
(s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => string[] (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]}`, `$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]}`, `$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]}`, `$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]}`, `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]}`, `$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]}`, `$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 would${n ? " not" : ""} have ${v[4]}`,
`$SUBJ should${n ? " not" : ""} have ${v[4]}`, `$SUBJ should${n ? " not" : ""} have ${v[4]}`,
]), ]),

View File

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

View File

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

View File

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