added modals 💪

This commit is contained in:
lingdocs 2022-03-29 16:31:37 +05:00
parent 4d7fec9813
commit 40794345b7
8 changed files with 236 additions and 131 deletions

View File

@ -5,7 +5,7 @@
"dependencies": {
"@fortawesome/fontawesome-free": "^5.15.4",
"@lingdocs/lingdocs-main": "^0.2.0",
"@lingdocs/pashto-inflector": "^1.5.9",
"@lingdocs/pashto-inflector": "^1.6.2",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",

View File

@ -11,30 +11,30 @@ import {
} from "@lingdocs/pashto-inflector";
// import { useState } from "react";
const tenseOptions: { label: string, value: VerbTense }[] = [{
label: "present",
const tenseOptions: { label: string | JSX.Element, value: VerbTense }[] = [{
label: <div><i className="fas fa-video mr-2" />present</div>,
value: "present",
}, {
label: "subjunctive",
label: <div><i className="fas fa-camera mr-2" />subjunctive</div>,
value: "subjunctive",
}, {
label: "imperf. future",
label: <div><i className="fas fa-video mr-2" />imperf. future</div>,
value: "imperfectiveFuture",
}, {
label: "perf. future",
label: <div><i className="fas fa-camera mr-2" />perf. future</div>,
value: "perfectiveFuture",
}, {
label: "simple past",
value: "perfectivePast",
}, {
label: "continuous past",
label: <div><i className="fas fa-video mr-2" />continuous past</div>,
value: "imperfectivePast",
}, {
label: "habitual simp. past.",
value: "habitualPerfectivePast",
label: <div><i className="fas fa-camera mr-2" />simple past</div>,
value: "perfectivePast",
}, {
label: "habitual cont. past.",
label: <div><i className="fas fa-video mr-2" />habitual cont. past.</div>,
value: "habitualImperfectivePast",
}, {
label: <div><i className="fas fa-camera mr-2" />habitual simp. past.</div>,
value: "habitualPerfectivePast",
}];
// type Filters = {
@ -78,6 +78,14 @@ function VerbPicker({ onChange, verb, verbs }: { verbs: VerbEntry[], verb: VerbS
});
}
}
function onTenseCategorySelect(value: "basic" | "modal") {
if (verb) {
onChange({
...verb,
tenseCategory: value,
});
}
}
function notInstransitive(t: "transitive" | "intransitive" | "grammatically transitive"): "transitive" | "grammatically transitive" {
return t === "intransitive" ? "transitive" : t;
}
@ -91,7 +99,7 @@ function VerbPicker({ onChange, verb, verbs }: { verbs: VerbEntry[], verb: VerbS
onChange(verb.changeStatDyn(c));
}
}
return <div style={{ maxWidth: "225px", minWidth: "125px" }}>
return <div style={{ maxWidth: "225px", minWidth: "175px" }}>
<div>Verb:</div>
<Select
value={verb && verb.verb.entry.ts.toString()}
@ -105,6 +113,20 @@ function VerbPicker({ onChange, verb, verbs }: { verbs: VerbEntry[], verb: VerbS
placeholder={verb ? options.find(o => o.value === (verb.verb.entry).ts.toString())?.label : "Select Verb..."}
{...zIndexProps}
/>
{verb && <div className="text-center my-3">
<ButtonSelect
small
value={verb.tenseCategory}
options={[{
label: "Basic",
value: "basic",
}, {
label: "Modal",
value: "modal",
}]}
handleChange={onTenseCategorySelect}
/>
</div>}
<div>Tense:</div>
<Select
isSearchable={false}
@ -205,6 +227,7 @@ function makeVerbSelection(verb: VerbEntry, oldVerbSelection?: VerbSelection): V
object,
transitivity,
isCompound,
tenseCategory: oldVerbSelection ? oldVerbSelection.tenseCategory : "basic",
negative: oldVerbSelection ? oldVerbSelection.negative : false,
...("grammaticallyTransitive" in info) ? {
changeTransitivity: function (t) {

View File

@ -0,0 +1,110 @@
import {
Types as T,
getVerbBlockPosFromPerson,
grammarUnits,
parseEc,
} from "@lingdocs/pashto-inflector";
export function renderEnglishVPBase({ subjectPerson, object, vs }: {
subjectPerson: T.Person,
object: NPSelection | ObjectNP,
vs: VerbSelection,
}): string[] {
const ec = parseEc(vs.verb.entry.ec || "");
const ep = vs.verb.entry.ep;
const tense = vs.tense;
function engEquative(tense: "past" | "present", s: T.Person): string {
const [row, col] = getVerbBlockPosFromPerson(s);
return grammarUnits.englishEquative[tense][row][col];
}
function engPresC(s: T.Person, ec: T.EnglishVerbConjugationEc | [string, string]): string {
function isThirdPersonSing(p: T.Person): boolean {
return (
p === T.Person.ThirdSingMale ||
p === T.Person.ThirdSingFemale
);
}
return isThirdPersonSing(s) ? ec[1] : ec[0];
}
function isToBe(v: T.EnglishVerbConjugationEc): boolean {
return (v[2] === "being");
}
const futureEngBuilder: T.EnglishBuilder = (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ will${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
]);
// TODO: Pull these out to a seperate entity and import it
const builders: Record<
VerbTense,
(s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => string[]
> = {
present: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ ${isToBe(ec)
? `${engEquative("present", s)}${n ? " not" : ""}`
: `${n ? engPresC(s, ["don't", "doesn't"]) : ""} ${n ? ec[0] : engPresC(s, ec)}`}`,
`$SUBJ ${engEquative("present", s)}${n ? " not" : ""} ${ec[2]}`,
]),
subjunctive: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`that $SUBJ ${n ? " won't" : " will"} ${isToBe(ec) ? "be" : ec[0]}`,
`should $SUBJ ${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
]),
imperfectiveFuture: futureEngBuilder,
perfectiveFuture: futureEngBuilder,
imperfectivePast: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
// - subj pastEquative (N && "not") ec.2 obj
`$SUBJ ${engEquative("past", s)}${n ? " not" : ""} ${ec[2]}`,
// - subj "would" (N && "not") ec.0 obj
`$SUBJ would${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
// - subj pastEquative (N && "not") going to" ec.0 obj
`$SUBJ ${engEquative("past", s)}${n ? " not" : ""} going to ${isToBe(ec) ? "be" : ec[0]}`,
]),
perfectivePast: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ${isToBe(ec)
? ` ${engEquative("past", s)}${n ? " not" : ""}`
: (n ? ` did not ${ec[0]}` : ` ${ec[3]}`)
}`
]),
habitualPerfectivePast: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ would${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
`$SUBJ used to${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
]),
habitualImperfectivePast: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ would${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
`$SUBJ used to${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
]),
};
const modalBuilders: Record<
VerbTense,
(s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => string[]
> = {
present: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ can${n ? "'t" : ""} ${isToBe(v) ? "be" : v[0]}`,
]),
subjunctive: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`that $SUBJ can${n ? "'t" : ""} ${isToBe(v) ? "be" : v[0]}`,
]),
imperfectiveFuture: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ will${n ? " not" : ""} be able to ${isToBe(v) ? "be" : v[0]}`,
]),
perfectiveFuture: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ will${n ? " not" : ""} be able to ${isToBe(v) ? "be" : v[0]}`,
]),
imperfectivePast: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ ${engEquative("past", s)} ${n ? " not" : ""} able to ${isToBe(v) ? "be" : v[0]}`,
`$SUBJ could${n ? " not" : ""} ${v[0]}`,
]),
perfectivePast: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ ${engEquative("past", s)} ${n ? " not" : ""} able to ${isToBe(v) ? "be" : v[0]}`,
`$SUBJ could${n ? " not" : ""} ${isToBe(v) ? "be" : v[0]}`,
]),
habitualImperfectivePast: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ used to ${n ? " not" : ""} be able to ${isToBe(v) ? "be" : v[0]}`,
`$SUBJ would ${n ? " not" : ""} be able to ${isToBe(v) ? "be" : v[0]}`,
]),
habitualPerfectivePast: (s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ used to ${n ? " not" : ""} be able to ${isToBe(v) ? "be" : v[0]}`,
`$SUBJ would ${n ? " not" : ""} be able to ${isToBe(v) ? "be" : v[0]}`,
]),
};
const base = (vs.tenseCategory === "basic" ? builders : modalBuilders)[tense](subjectPerson, ec, vs.negative);
return base.map(b => `${b}${typeof object === "object" ? " $OBJ" : ""}${ep ? ` ${ep}` : ""}`);
}

View File

@ -21,6 +21,7 @@ import {
isPastTense,
} from "./vp-tools";
import { isPattern4Entry } from "../type-predicates";
import { renderEnglishVPBase } from "./english-vp-rendering";
// TODO: ISSUE GETTING SPLIT HEAD NOT MATCHING WITH FUTURE VERBS
@ -139,89 +140,18 @@ function renderVerbSelection(vs: VerbSelection, person: T.Person, objectPerson:
return {
...vs,
person,
...getPsVerbConjugation(conj, vs.tense, person, objectPerson),
...getPsVerbConjugation(conj, vs.tense, vs.tenseCategory, person, objectPerson),
}
}
function renderEnglishVPBase({ subjectPerson, object, vs }: {
subjectPerson: T.Person,
object: NPSelection | ObjectNP,
vs: VerbSelection,
}): string[] {
const ec = parseEc(vs.verb.entry.ec || "");
const ep = vs.verb.entry.ep;
const tense = vs.tense;
function engEquative(tense: "past" | "present", s: T.Person): string {
const [row, col] = getVerbBlockPosFromPerson(s);
return grammarUnits.englishEquative[tense][row][col];
}
function engPresC(s: T.Person, ec: T.EnglishVerbConjugationEc | [string, string]): string {
function isThirdPersonSing(p: T.Person): boolean {
return (
p === T.Person.ThirdSingMale ||
p === T.Person.ThirdSingFemale
);
}
return isThirdPersonSing(s) ? ec[1] : ec[0];
}
function isToBe(v: T.EnglishVerbConjugationEc): boolean {
return (v[2] === "being");
}
const futureEngBuilder: T.EnglishBuilder = (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ will${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
]);
// TODO: Pull these out to a seperate entity and import it
const builders: Record<
VerbTense,
(s: T.Person, v: T.EnglishVerbConjugationEc, n: boolean) => string[]
> = {
present: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ ${isToBe(ec)
? `${engEquative("present", s)}${n ? " not" : ""}`
: `${n ? engPresC(s, ["don't", "doesn't"]) : ""} ${n ? ec[0] : engPresC(s, ec)}`}`,
`$SUBJ ${engEquative("present", s)}${n ? " not" : ""} ${ec[2]}`,
]),
subjunctive: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`that $SUBJ ${n ? " won't" : " will"} ${isToBe(ec) ? "be" : ec[0]}`,
`should $SUBJ ${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
]),
imperfectiveFuture: futureEngBuilder,
perfectiveFuture: futureEngBuilder,
imperfectivePast: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
// - subj pastEquative (N && "not") ec.2 obj
`$SUBJ ${engEquative("past", s)}${n ? " not" : ""} ${ec[2]}`,
// - subj "would" (N && "not") ec.0 obj
`$SUBJ would${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
// - subj pastEquative (N && "not") going to" ec.0 obj
`$SUBJ ${engEquative("past", s)}${n ? " not" : ""} going to ${isToBe(ec) ? "be" : ec[0]}`,
]),
perfectivePast: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ${isToBe(ec)
? ` ${engEquative("past", s)}${n ? " not" : ""}`
: (n ? ` did not ${ec[0]}` : ` ${ec[3]}`)
}`
]),
habitualPerfectivePast: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ would${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
`$SUBJ used to${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
]),
habitualImperfectivePast: (s: T.Person, ec: T.EnglishVerbConjugationEc, n: boolean) => ([
`$SUBJ would${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
`$SUBJ used to${n ? " not" : ""} ${isToBe(ec) ? "be" : ec[0]}`,
]),
};
const base = builders[tense](subjectPerson, ec, vs.negative);
return base.map(b => `${b}${typeof object === "object" ? " $OBJ" : ""}${ep ? ` ${ep}` : ""}`);
}
function getPsVerbConjugation(conj: T.VerbConjugation, tense: VerbTense, person: T.Person, objectPerson: T.Person | undefined): {
function getPsVerbConjugation(conj: T.VerbConjugation, tense: VerbTense, tenseCategory: "basic" | "modal", person: T.Person, objectPerson: T.Person | undefined): {
ps: {
head: T.PsString | undefined,
rest: T.SingleOrLengthOpts<T.PsString[]>,
},
hasBa: boolean,
} {
const f = getTenseVerbForm(conj, tense);
const f = getTenseVerbForm(conj, tense, tenseCategory);
const block = getMatrixBlock(f, objectPerson, person);
const perfective = isPerfective(tense);
const verbForm = getVerbFromBlock(block, person);
@ -233,12 +163,10 @@ function getPsVerbConjugation(conj: T.VerbConjugation, tense: VerbTense, person:
// TODO: Either solve this in the inflector or here, it seems silly (or redundant)
// to have a length option in the perfective split stem??
const [splitHead] = getLong(getMatrixBlock(splitInfo, objectPerson, person));
const ps = getHeadAndRest(splitHead, verbForm);
return {
hasBa,
ps: {
head: splitHead,
rest: removeHead(splitHead, verbForm),
},
ps,
};
}
return { hasBa, ps: { head: undefined, rest: verbForm }};
@ -261,30 +189,42 @@ function getVerbFromBlock(block: T.SingleOrLengthOpts<T.VerbBlock>, person: T.Pe
return grabFromBlock(block, pos);
}
function removeHead(head: T.PsString, rest: T.PsString[]): T.PsString[];
function removeHead(head: T.PsString, rest: T.SingleOrLengthOpts<T.PsString[]>): T.SingleOrLengthOpts<T.PsString[]>;
function removeHead(head: T.PsString, rest: T.SingleOrLengthOpts<T.PsString[]>): T.SingleOrLengthOpts<T.PsString[]> {
function getHeadAndRest(head: T.PsString, rest: T.PsString[]): { head: T.PsString | undefined, rest: T.PsString[] };
function getHeadAndRest(head: T.PsString, rest: T.SingleOrLengthOpts<T.PsString[]>): { head: T.PsString | undefined, rest: T.SingleOrLengthOpts<T.PsString[]> };
function getHeadAndRest(head: T.PsString, rest: T.SingleOrLengthOpts<T.PsString[]>): { head: T.PsString | undefined, rest: T.SingleOrLengthOpts<T.PsString[]> } {
if ("long" in rest) {
return {
long: removeHead(head, rest.long),
short: removeHead(head, rest.short),
...rest.mini ? {
mini: removeHead(head, rest.mini),
} : {},
}
// whether or not to include the head (for irreg tlul) -- eww // TODO: make nicer?
head: removeBa(rest.long[0]).p.slice(0, head.p.length) === head.p
? head : undefined,
rest: {
long: getHeadAndRest(head, rest.long).rest,
short: getHeadAndRest(head, rest.short).rest,
...rest.mini ? {
mini: getHeadAndRest(head, rest.mini).rest,
} : {},
},
};
}
return rest.map((psRaw) => {
let headMismatch = false;
const restM = rest.map((psRaw) => {
const ps = removeBa(psRaw);
const pMatches = removeAccents(ps.p.slice(0, head.p.length)) === head.p
const fMatches = removeAccents(ps.f.slice(0, head.f.length)) === removeAccents(head.f);
if (!(pMatches && fMatches)) {
throw new Error(`split head does not match - ${JSON.stringify(ps)} ${JSON.stringify(head)}`);
headMismatch = true;
return psRaw;
// throw new Error(`split head does not match - ${JSON.stringify(ps)} ${JSON.stringify(head)}`);
}
return {
p: ps.p.slice(head.p.length),
f: ps.f.slice(head.f.length),
}
});
return {
head: headMismatch ? undefined : head,
rest: restM,
}
}
function getMatrixBlock<U>(f: {
@ -313,30 +253,58 @@ function getMatrixBlock<U>(f: {
return f[personToLabel(person)];
}
function getTenseVerbForm(conj: T.VerbConjugation, tense: VerbTense): T.VerbForm {
if (tense === "present") {
return conj.imperfective.nonImperative;
function getTenseVerbForm(conj: T.VerbConjugation, tense: VerbTense, tenseCategory: "basic" | "modal"): T.VerbForm {
if (tenseCategory === "basic") {
if (tense === "present") {
return conj.imperfective.nonImperative;
}
if (tense === "subjunctive") {
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;
}
}
if (tense === "subjunctive") {
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;
if (tenseCategory === "modal") {
if (tense === "present") {
return conj.imperfective.modal.nonImperative;
}
if (tense === "subjunctive") {
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");
}

View File

@ -40,6 +40,7 @@ type VerbSelection = {
verb: VerbEntry,
dynAuxVerb?: VerbEntry,
tense: VerbTense,
tenseCategory: "basic" | "modal",
object: VerbObject, // TODO: should have a locked in (but number changeable noun) here for dynamic compounds
transitivity: import("@lingdocs/pashto-inflector").Types.Transitivity,
isCompound: "stative" | "dynamic" | false,

View File

@ -0,0 +1,3 @@
module.exports = [
{ ts: 1527816016, e: "Pashto" }, // پښټو
]

File diff suppressed because one or more lines are too long

View File

@ -1684,10 +1684,10 @@
pbf "^3.2.1"
rambda "^6.7.0"
"@lingdocs/pashto-inflector@^1.5.9":
version "1.5.9"
resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.5.9.tgz#a5d13b71b39f989aab97fc86aff8e586404a5cde"
integrity sha512-ApWnlTwutQbgbXzh7kCwUJ3nVUISgd8C4O0pkIMIZwkXX8/3ItBEm4+9tHuvuIqBW3qrIDa7+iUNk957Lr39mw==
"@lingdocs/pashto-inflector@^1.6.2":
version "1.6.2"
resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.6.2.tgz#956fa4c27af9d0d6e2643cfbd8a3ff1c76edffc5"
integrity sha512-sCjuzznCmqLkd8U7xr6JMNu7OMgNyAbInC2Szx7JROSOAByv2le3ldeidt/ZuzQN8Plq+oMkIti+VoJ9R7Tg1w==
dependencies:
classnames "^2.2.6"
pbf "^3.2.1"