BIG error fixed - the charts were picking up on the negative option left over from the phrase builder and only displaying the imperfective imperative when the negative was selected. Also allowed passive voice on ability verbs.

This commit is contained in:
adueck 2023-01-24 13:48:49 +05:00
parent f7a80efb5e
commit 8c7c89611e
11 changed files with 51 additions and 49 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.4.3", "version": "5.5.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.4.3", "version": "5.5.0",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.4.3", "version": "5.5.0",
"author": "lingdocs.com", "author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com", "homepage": "https://verbs.lingdocs.com",

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "5.4.3", "version": "5.5.0",
"description": "Pashto inflector library module with React components", "description": "Pashto inflector library module with React components",
"main": "dist/components/library.js", "main": "dist/components/library.js",
"module": "dist/components/library.js", "module": "dist/components/library.js",

View File

@ -3,7 +3,7 @@ import ChartDisplay from "./VPChartDisplay";
import Hider from "../Hider"; import Hider from "../Hider";
import * as T from "../../../types"; import * as T from "../../../types";
import useStickyState from "../useStickyState"; import useStickyState from "../useStickyState";
import { isModalTense, isPerfectTense, isVerbTense } from "../../../lib/src/type-predicates"; import { conjugateVerb } from "../../dist/lib/src/verb-conjugation";
function AllTensesDisplay({ VS, opts }: { VS: T.VerbSelection, opts: T.TextOptions }) { function AllTensesDisplay({ VS, opts }: { VS: T.VerbSelection, opts: T.TextOptions }) {
const [showing, setShowing] = useStickyState<string[]>([], "VPTensesShowing"); const [showing, setShowing] = useStickyState<string[]>([], "VPTensesShowing");
@ -22,6 +22,15 @@ function AllTensesDisplay({ VS, opts }: { VS: T.VerbSelection, opts: T.TextOptio
: VS.tenseCategory === "modal" : VS.tenseCategory === "modal"
? abilityTenseOptions ? abilityTenseOptions
: imperativeTenseOptions; : imperativeTenseOptions;
const rawConjugations = conjugateVerb(VS.verb.entry, VS.verb.complement);
const conjugations = ("stative" in rawConjugations)
? rawConjugations[VS.isCompound === "stative" ? "stative" : "dynamic"]
: ("transitive" in rawConjugations)
? rawConjugations[VS.transitivity === "grammatically transitive" ? "grammaticallyTransitive" : "transitive"]
: rawConjugations;
function getTense(baseTense: T.VerbTense | T.PerfectTense | T.ImperativeTense): T.VerbTense | T.PerfectTense | T.ImperativeTense | T.ModalTense {
return VS.tenseCategory === "modal" ? `${baseTense}Modal` as T.ModalTense : baseTense;
}
return <div> return <div>
<div className="clickable mb-2 small text-center" onClick={() => setShowFormulas(x => !x)}> <div className="clickable mb-2 small text-center" onClick={() => setShowFormulas(x => !x)}>
🧪 {!showFormulas ? "Show" : "Hide"} Formulas 🧪 {!showFormulas ? "Show" : "Hide"} Formulas
@ -37,17 +46,9 @@ function AllTensesDisplay({ VS, opts }: { VS: T.VerbSelection, opts: T.TextOptio
<samp>{tense.formula}</samp> <samp>{tense.formula}</samp>
</div>} </div>}
<ChartDisplay <ChartDisplay
VS={{ conjugations={conjugations}
...VS, tense={getTense(tense.value)}
[isVerbTense(tense.value) voice={VS.voice}
? "verbTense"
: isPerfectTense(tense.value)
? "perfectTense"
: isModalTense(tense.value)
? "modalTense"
: "imperativeTense"
]: tense.value,
}}
opts={opts} opts={opts}
/> />
</Hider> </Hider>

View File

@ -5,7 +5,7 @@ import { isImperativeTense, isModalTense, isPerfectTense, isVerbTense } from "..
import useStickyState from "../useStickyState"; import useStickyState from "../useStickyState";
import { customStyles } from "../EntrySelect"; import { customStyles } from "../EntrySelect";
import { import {
VpsReducerAction VpsReducerAction,
} from "../../../lib/src/phrase-building/vps-reducer"; } from "../../../lib/src/phrase-building/vps-reducer";
import { imperativeTenseOptions, perfectTenseOptions, verbTenseOptions } from "./verbTenseOptions"; import { imperativeTenseOptions, perfectTenseOptions, verbTenseOptions } from "./verbTenseOptions";
@ -106,7 +106,6 @@ function TensePicker(props: ({
: verbTenseOptions; : verbTenseOptions;
const showImperativeOption = ("vps" in props && props.vps.verb.voice === "active") const showImperativeOption = ("vps" in props && props.vps.verb.voice === "active")
|| ("vpsComplete" in props && props.vpsComplete.verb.voice !== "active"); || ("vpsComplete" in props && props.vpsComplete.verb.voice !== "active");
const inPassiveVoice = ("vps" in props && props.vps.verb.voice === "passive") || ("vpsComplete" in props && props.vpsComplete.verb.voice === "passive");;
const inAllTensesMode = props.mode === "charts"; const inAllTensesMode = props.mode === "charts";
const canHaveFormula = "vps" in props const canHaveFormula = "vps" in props
&& props.mode !== "quiz" && props.mode !== "quiz"
@ -151,7 +150,7 @@ function TensePicker(props: ({
}, { }, {
label: "Ability", label: "Ability",
value: "modal", value: "modal",
}].filter(x => !(inPassiveVoice && x.value === "modal"))} }]}
handleChange={props.mode !== "quiz" ? onTenseCategorySelect : () => null} handleChange={props.mode !== "quiz" ? onTenseCategorySelect : () => null}
/> />
</div>} </div>}

View File

@ -1,22 +1,16 @@
import { import {
getTenseVerbForm, getTenseVerbForm,
getTenseFromVerbSelection,
} from "../../../lib/src/phrase-building/vp-tools"; } from "../../../lib/src/phrase-building/vp-tools";
import VerbFormDisplay from "../VerbFormDisplay"; import VerbFormDisplay from "../VerbFormDisplay";
import { conjugateVerb } from "../../../lib/src/verb-conjugation";
import * as T from "../../../types"; import * as T from "../../../types";
function ChartDisplay({ VS, opts }: { VS: T.VerbSelection, opts: T.TextOptions }) { function ChartDisplay({ conjugations, tense, opts, voice }: {
const rawConjugations = conjugateVerb(VS.verb.entry, VS.verb.complement); conjugations: T.VerbConjugation,
if (!rawConjugations) { tense: T.VerbTense | T.PerfectTense | T.ModalTense | T.ImperativeTense,
return <div>Error conjugating verb</div>; opts: T.TextOptions,
} voice: T.VerbSelection["voice"],
const conjugations = ("stative" in rawConjugations) }) {
? rawConjugations[VS.isCompound === "stative" ? "stative" : "dynamic"] const form = getTenseVerbForm(conjugations, tense, voice, "charts", false);
: ("transitive" in rawConjugations)
? rawConjugations[VS.transitivity === "grammatically transitive" ? "grammaticallyTransitive" : "transitive"]
: rawConjugations;
const form = getTenseVerbForm(conjugations, getTenseFromVerbSelection(VS), VS.voice, VS.negative);
return <div className="mb-4"> return <div className="mb-4">
<VerbFormDisplay <VerbFormDisplay
displayForm={form} displayForm={form}

View File

@ -104,7 +104,7 @@ function VerbPicker(props: {
<ButtonSelect <ButtonSelect
small small
value={props.vps.verb.voice} value={props.vps.verb.voice}
options={(props.vps.verb.tenseCategory === "imperative" || props.vps.verb.tenseCategory === "modal") options={(props.vps.verb.tenseCategory === "imperative") // || props.vps.verb.tenseCategory === "modal")
? [{ ? [{
label: "Active", label: "Active",
value: "active", value: "active",

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/inflect", "name": "@lingdocs/inflect",
"version": "5.4.3", "version": "5.5.0",
"description": "Pashto inflector library", "description": "Pashto inflector library",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/lib/library.d.ts", "types": "dist/lib/library.d.ts",

View File

@ -554,7 +554,7 @@ function getPsVerbConjugation(conj: T.VerbConjugation, vs: T.VerbSelectionComple
hasBa: boolean, hasBa: boolean,
} { } {
// TODO: handle the imperative form here // TODO: handle the imperative form here
const f = getTenseVerbForm(conj, vs.tense, vs.voice, vs.negative); const f = getTenseVerbForm(conj, vs.tense, vs.voice, "phrase-building", vs.negative);
const block = getMatrixBlock(f, objectPerson, person); const block = getMatrixBlock(f, objectPerson, person);
const perfective = (vs.tense === "perfectiveImperative" && vs.negative) const perfective = (vs.tense === "perfectiveImperative" && vs.negative)
? false ? false

View File

@ -29,10 +29,18 @@ export function isInvalidSubjObjCombo(subj: T.Person, obj: T.Person): boolean {
); );
} }
/**
* @param conjR
* @param tense
* @param voice
* @param negative
* @returns
*/
export function getTenseVerbForm( export function getTenseVerbForm(
conjR: T.VerbConjugation, conjR: T.VerbConjugation,
tense: T.VerbTense | T.PerfectTense | T.ModalTense | T.ImperativeTense, tense: T.VerbTense | T.PerfectTense | T.ModalTense | T.ImperativeTense,
voice: "active" | "passive", voice: "active" | "passive",
mode: "charts" | "phrase-building",
negative: boolean, negative: boolean,
): T.VerbForm | T.ImperativeForm { ): T.VerbForm | T.ImperativeForm {
const conj = (voice === "passive" && conjR.passive) ? conjR.passive : conjR; const conj = (voice === "passive" && conjR.passive) ? conjR.passive : conjR;
@ -42,7 +50,8 @@ export function getTenseVerbForm(
throw impPassError; throw impPassError;
} }
if (!conj.imperfective.imperative || !conj.perfective.imperative) throw impPassError; if (!conj.imperfective.imperative || !conj.perfective.imperative) throw impPassError;
return (tense === "perfectiveImperative" && !negative) // charts can't display negative form
return (tense === "perfectiveImperative" && (!negative || mode === "charts"))
? conj.perfective.imperative ? conj.perfective.imperative
: conj.imperfective.imperative; : conj.imperfective.imperative;
} }

View File

@ -152,7 +152,7 @@ export function vpsReducer(vps: T.VPSelectionState, action: VpsReducerAction, se
verb: { verb: {
...vps.verb, ...vps.verb,
voice, voice,
tenseCategory: vps.verb.tenseCategory === "modal" ? "basic" : vps.verb.tenseCategory, // tenseCategory: vps.verb.tenseCategory === "modal" ? "basic" : vps.verb.tenseCategory,
}, },
}; };
} else { } else {
@ -243,7 +243,6 @@ export function vpsReducer(vps: T.VPSelectionState, action: VpsReducerAction, se
verb: { verb: {
...vps.verb, ...vps.verb,
tenseCategory: category, tenseCategory: category,
voice: "active",
}, },
} }
} }