working more with dynamic / passive

This commit is contained in:
lingdocs 2022-04-03 13:19:08 +05:00
parent 12039e6cb8
commit 91458c0114
4 changed files with 34 additions and 12 deletions

View File

@ -69,7 +69,13 @@ const perfectTenseOptions: { label: string | JSX.Element, value: PerfectTense }[
// grammaticallyTransitive: boolean, // grammaticallyTransitive: boolean,
// } // }
function VerbPicker({ onChange, verb, verbs }: { verbs: VerbEntry[], verb: VerbSelection | undefined, onChange: (p: VerbSelection) => void }) { function VerbPicker({ onChange, subject, changeSubject, verb, verbs }: {
verbs: VerbEntry[],
verb: VerbSelection | undefined,
subject: NPSelection | undefined,
onChange: (p: VerbSelection) => void,
changeSubject: (p: NPSelection | undefined) => void,
}) {
// const [filters, useFilters] = useState<Filters>({ // const [filters, useFilters] = useState<Filters>({
// stative: true, // stative: true,
// dynamic: true, // dynamic: true,
@ -84,7 +90,7 @@ function VerbPicker({ onChange, verb, verbs }: { verbs: VerbEntry[], verb: VerbS
console.error("entry not found"); console.error("entry not found");
return; return;
} }
onChange(makeVerbSelection(v, verb)); onChange(makeVerbSelection(v, changeSubject, verb));
} }
function onTenseSelect({ value }: { label: string | JSX.Element, value: VerbTense | PerfectTense }) { function onTenseSelect({ value }: { label: string | JSX.Element, value: VerbTense | PerfectTense }) {
if (verb) { if (verb) {
@ -146,7 +152,13 @@ function VerbPicker({ onChange, verb, verbs }: { verbs: VerbEntry[], verb: VerbS
} }
function onVoiceSelect(value: "active" | "passive") { function onVoiceSelect(value: "active" | "passive") {
if (verb && verb.changeVoice) { if (verb && verb.changeVoice) {
onChange(verb.changeVoice(value)); if (value === "passive" && (typeof verb.object === "object")) {
changeSubject(verb.object);
}
if (value === "active") {
changeSubject(undefined);
}
onChange(verb.changeVoice(value, value === "active" ? subject : undefined));
} }
} }
function notInstransitive(t: "transitive" | "intransitive" | "grammatically transitive"): "transitive" | "grammatically transitive" { function notInstransitive(t: "transitive" | "intransitive" | "grammatically transitive"): "transitive" | "grammatically transitive" {
@ -275,7 +287,7 @@ function VerbPicker({ onChange, verb, verbs }: { verbs: VerbEntry[], verb: VerbS
</div>; </div>;
} }
function makeVerbSelection(verb: VerbEntry, oldVerbSelection?: VerbSelection): VerbSelection { function makeVerbSelection(verb: VerbEntry, changeSubject: (s: NPSelection | undefined) => void, oldVerbSelection?: VerbSelection): VerbSelection {
const info = getVerbInfo(verb.entry, verb.complement); const info = getVerbInfo(verb.entry, verb.complement);
function getTransObjFromOldVerbSelection() { function getTransObjFromOldVerbSelection() {
if ( if (
@ -292,11 +304,14 @@ function makeVerbSelection(verb: VerbEntry, oldVerbSelection?: VerbSelection): V
: info.transitivity; : info.transitivity;
const object = (transitivity === "grammatically transitive") const object = (transitivity === "grammatically transitive")
? T.Person.ThirdPlurMale ? T.Person.ThirdPlurMale
: info.type === "dynamic compound" : (info.type === "dynamic compound" && oldVerbSelection?.voice !== "passive")
? makeNounSelection(info.objComplement.entry as NounEntry, true) ? makeNounSelection(info.objComplement.entry as NounEntry, true)
: (transitivity === "transitive" && oldVerbSelection?.voice !== "passive") : (transitivity === "transitive" && oldVerbSelection?.voice !== "passive")
? getTransObjFromOldVerbSelection() ? getTransObjFromOldVerbSelection()
: "none"; : "none";
if (oldVerbSelection?.voice === "passive" && info.type === "dynamic compound") {
changeSubject(makeNounSelection(info.objComplement.entry as NounEntry, true));
}
const isCompound = ("stative" in info || info.type === "stative compound") const isCompound = ("stative" in info || info.type === "stative compound")
? "stative" ? "stative"
: info.type === "dynamic compound" : info.type === "dynamic compound"
@ -361,11 +376,11 @@ function makeVerbSelection(verb: VerbEntry, oldVerbSelection?: VerbSelection): V
} }
} : {}, } : {},
...(transitivity === "transitive") ? { ...(transitivity === "transitive") ? {
changeVoice: function(v) { changeVoice: function(v, s) {
return { return {
...this, ...this,
voice: v, voice: v,
object: v === "passive" ? "none" : undefined, object: v === "active" ? s : "none",
}; };
}, },
} : {}, } : {},

View File

@ -18,8 +18,8 @@ const servantEmoji = "🙇‍♂️";
export function PhraseBuilder() { export function PhraseBuilder() {
const [subject, setSubject] = useState<NPSelection | undefined>(undefined); const [subject, setSubject] = useState<NPSelection | undefined>(undefined);
const [verb, setVerb] = useState<VerbSelection | undefined>(undefined); const [verb, setVerb] = useState<VerbSelection | undefined>(undefined);
function handleSubjectChange(subject: NPSelection | undefined) { function handleSubjectChange(subject: NPSelection | undefined, skipPronounConflictCheck?: boolean) {
if (hasPronounConflict(subject, verb?.object)) { if (!skipPronounConflictCheck && hasPronounConflict(subject, verb?.object)) {
alert("That combination of pronouns is not allowed"); alert("That combination of pronouns is not allowed");
return; return;
} }
@ -74,7 +74,13 @@ export function PhraseBuilder() {
</div>} </div>}
<div className="my-2"> <div className="my-2">
<div className="h4">Verb</div> <div className="h4">Verb</div>
<VerbPicker verbs={verbs} verb={verb} onChange={setVerb} /> <VerbPicker
verbs={verbs}
verb={verb}
subject={subject}
changeSubject={(s) => handleSubjectChange(s, true)}
onChange={setVerb}
/>
</div> </div>
</div> </div>
{verbPhrase && <div> {verbPhrase && <div>

View File

@ -30,7 +30,8 @@ export function compileVP(VP: VPRendered, form: Form, combineLengths?: true): {
}); });
return { return {
ps: combineLengths ? flattenLengths(psResult) : psResult, ps: combineLengths ? flattenLengths(psResult) : psResult,
e: compileEnglish(VP), // TODO: English doesn't quite work for dynamic compounds in passive voice
e: (VP.verb.voice === "passive" && VP.isCompound === "dynamic") ? undefined : compileEnglish(VP),
}; };
} }

View File

@ -47,7 +47,7 @@ type VerbSelection = {
voice: "active" | "passive", voice: "active" | "passive",
changeTransitivity?: (t: "transitive" | "grammatically transitive") => VerbSelection, changeTransitivity?: (t: "transitive" | "grammatically transitive") => VerbSelection,
changeStatDyn?: (t: "stative" | "dynamic") => VerbSelection, changeStatDyn?: (t: "stative" | "dynamic") => VerbSelection,
changeVoice?: (v: "active" | "passive") => VerbSelection, changeVoice?: (v: "active" | "passive", subj?: NPSelection) => VerbSelection,
// TODO: changeStativeDynamic // TODO: changeStativeDynamic
// TODO: add in aspect element here?? // TODO: add in aspect element here??
negative: boolean, negative: boolean,