fixed big bugs with trans/gramm trans and stative/dynamic combo verbs not rendering!

This commit is contained in:
lingdocs 2021-07-14 14:31:13 +03:00
parent 28ce6fd214
commit 1a0af4ab94
5 changed files with 68 additions and 62 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/pashto-inflector", "name": "@lingdocs/pashto-inflector",
"version": "0.7.4", "version": "0.7.5",
"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

@ -172,11 +172,10 @@ const initialState: State = {
formsOpened: [], formsOpened: [],
}; };
function ConjugationViewer({ entry, complement, textOptions, aayTailType, showOnly, highlightInRootsAndStems, hidePastParticiple, sentenceLevel }: { function ConjugationViewer({ entry, complement, textOptions, showOnly, highlightInRootsAndStems, hidePastParticiple, sentenceLevel }: {
entry: T.DictionaryEntry, entry: T.DictionaryEntry,
complement?: T.DictionaryEntry, complement?: T.DictionaryEntry,
textOptions: T.TextOptions, textOptions: T.TextOptions,
aayTailType?: T.AayTail,
showOnly?: string | string[], showOnly?: string | string[],
highlightInRootsAndStems?: T.RootsOrStemsToHighlight, highlightInRootsAndStems?: T.RootsOrStemsToHighlight,
hidePastParticiple?: boolean, hidePastParticiple?: boolean,
@ -197,12 +196,13 @@ function ConjugationViewer({ entry, complement, textOptions, aayTailType, showOn
useEffect(() => { useEffect(() => {
localStorage.setItem(stateLocalStorageName, JSON.stringify(state)); localStorage.setItem(stateLocalStorageName, JSON.stringify(state));
}); });
const conjugation = (() => { const conjugation = (() => {
if (!(entry.c && entry.c.slice(0, 2) === "v.")) return undefined; if (!(entry.c && entry.c.slice(0, 2) === "v.")) return undefined;
try { try {
return conjugateVerb(entry, aayTailType ? aayTailType : "aay", complement); console.log("my entry is", entry);
return conjugateVerb(entry, complement);
} catch(e) { } catch(e) {
console.log("conjugation error", e);
return undefined; return undefined;
} }
})(); })();

View File

@ -142,12 +142,12 @@ export const pastEndings: T.VerbBlock = [
// TODO: MAKE THIS VARIABLE FOR DIALECTS! // TODO: MAKE THIS VARIABLE FOR DIALECTS!
export const aayTail: T.PsString = { p: "ی", f: "ey" }; export const aayTail: T.PsString[] = [{p: "ای", f: "aay" }, { p: "ی", f: "ey" }];
export const subjPastEquative: T.PsString = { export const subjPastEquative: T.ArrayOneOrMore<T.PsString> = aayTail.map((a) => ({
p: "و" + aayTail.p, p: "و" + a.p,
f: "w" + aayTail.f, f: "w" + a.f,
}; })) as T.ArrayOneOrMore<T.PsString>;
export const englishEquative: { export const englishEquative: {
past: T.EnglishBlock, past: T.EnglishBlock,
@ -438,12 +438,12 @@ export const equativeEndings: {
], ],
], ],
hypothetical: [ hypothetical: [
[[subjPastEquative], [subjPastEquative]], [subjPastEquative, subjPastEquative],
[[subjPastEquative], [subjPastEquative]], [subjPastEquative, subjPastEquative],
[[subjPastEquative], [subjPastEquative]], [subjPastEquative, subjPastEquative],
[[subjPastEquative], [subjPastEquative]], [subjPastEquative, subjPastEquative],
[[subjPastEquative], [subjPastEquative]], [subjPastEquative, subjPastEquative],
[[subjPastEquative], [subjPastEquative]], [subjPastEquative, subjPastEquative],
], ],
}; };
@ -509,16 +509,17 @@ export const passiveStativeBridge = [
short: ksPerf.long, short: ksPerf.long,
long: ksPerf.long, long: ksPerf.long,
}, },
{ // PK VARIATION - NOT BEING USED - ADD TO FORMS NOT ADDING THE SECOND FORM FOR SOME REASON
short: { // {
p: ksPerf.short.p + aayTail.p, // short: {
f: ksPerf.short.f + aayTail.f, // p: ksPerf.short.p + aayTail[1].p,
}, // f: ksPerf.short.f + aayTail[1].f,
long: { // },
p: ksPerf.long.p + aayTail.p, // long: {
f: ksPerf.long.f + aayTail.f, // p: ksPerf.long.p + aayTail[1].p,
}, // f: ksPerf.long.f + aayTail[1].f,
}, // },
// },
]; ];
const basePlainPronouns = [ const basePlainPronouns = [

View File

@ -16,6 +16,10 @@ import {
} from "./misc-helpers"; } from "./misc-helpers";
import * as T from "../types"; import * as T from "../types";
// export function concatPsStringWithVars(...items: Array<T.PsString | " " | "">): T.PsString[] {
// }
/** /**
* Concats sections of Pashto text with Pashto and Phonetics * Concats sections of Pashto text with Pashto and Phonetics
* in PsString type, also accepts spaces as " " * in PsString type, also accepts spaces as " "
@ -267,7 +271,7 @@ export function isInflectionSet(x: any): boolean {
} }
type toAddToForm = Array<" " | T.SingleOrLengthOpts<T.PsString> | T.SingleOrLengthOpts<T.UnisexInflections> | T.SingleOrLengthOpts<T.PsString>[] | T.OptionalPersonInflections<T.PsString> | T.VerbBlock>; type toAddToForm = Array<" " | T.SingleOrLengthOpts<T.PsString> | T.SingleOrLengthOpts<T.UnisexInflections> | T.SingleOrLengthOpts<T.PsString>[] | T.SingleOrLengthOpts<T.PsString[]> | T.OptionalPersonInflections<T.PsString> | T.VerbBlock>;
type toAddToFormLengthChosen = Array<" " | T.PsString | T.UnisexInflections | T.PsString[] | T.OptionalPersonInflections<T.PsString> | T.VerbBlock>; type toAddToFormLengthChosen = Array<" " | T.PsString | T.UnisexInflections | T.PsString[] | T.OptionalPersonInflections<T.PsString> | T.VerbBlock>;
export function addToForm( export function addToForm(
toAdd: toAddToForm, toAdd: toAddToForm,
@ -324,7 +328,7 @@ export function addToForm(
const multiplyEachVariationBy = toAdd.reduce((acc, cur) => ( const multiplyEachVariationBy = toAdd.reduce((acc, cur) => (
// make sure we don't make 6 variations when concating a verb block to a verb block! // make sure we don't make 6 variations when concating a verb block to a verb block!
(Array.isArray(cur) && !isVerbBlock(cur)) ? Math.max(acc, cur.length) : acc (Array.isArray(cur) && !isVerbBlock(cur)) ? Math.max(acc, cur.length) : acc
), 1) ), 1);
const b = "long" in base const b = "long" in base
? base[length] || base.short // in case mini does not exist ? base[length] || base.short // in case mini does not exist
: base; : base;

View File

@ -15,7 +15,6 @@ import {
equativeEndings, equativeEndings,
emptyVerbBlock, emptyVerbBlock,
passiveStativeBridge, passiveStativeBridge,
aayTail,
} from "./grammar-units"; } from "./grammar-units";
import { import {
addToForm, addToForm,
@ -47,13 +46,9 @@ import * as T from "../types";
const dummyEntry: T.DictionaryEntry = { i: 0, p: "", f: "", g: "", e: "", c: "", ts: 0 }; const dummyEntry: T.DictionaryEntry = { i: 0, p: "", f: "", g: "", e: "", c: "", ts: 0 };
const getAayTail = (type: T.AayTail): T.PsString => ( const aayTail = [{p: "ای", f: "aay" }, { p: "ی", f: "ey" }];
type === "ey"
? { p: "ی", f: "ey" }
: { p: "ای", f: "aay" }
);
export function conjugateVerb(entry: T.DictionaryEntry, aayTailType: T.AayTail, complement?: T.DictionaryEntry, verbInfo?: T.NonComboVerbInfo): T.VerbOutput { export function conjugateVerb(entry: T.DictionaryEntry, complement?: T.DictionaryEntry, verbInfo?: T.NonComboVerbInfo): T.VerbOutput {
if (!(entry.c && entry.c.slice(0, 2) === "v.")) { if (!(entry.c && entry.c.slice(0, 2) === "v.")) {
throw new Error("not a verb"); throw new Error("not a verb");
}; };
@ -65,21 +60,21 @@ export function conjugateVerb(entry: T.DictionaryEntry, aayTailType: T.AayTail,
if (info.type === "transitive or grammatically transitive simple") { if (info.type === "transitive or grammatically transitive simple") {
return { return {
info, info,
transitive: conjugateVerb(dummyEntry, aayTailType, dummyEntry, info.transitive) as T.VerbConjugation, transitive: conjugateVerb({ ...entry, c: entry.c ? entry.c.replace("/gramm. trans.", "") : "" }, dummyEntry, info.transitive) as T.VerbConjugation,
grammaticallyTransitive: conjugateVerb(dummyEntry, aayTailType, dummyEntry, info.grammaticallyTransitive) as T.VerbConjugation, grammaticallyTransitive: conjugateVerb({ ...entry, c: entry.c ? entry.c?.replace("trans./", "") : "" }, dummyEntry, info.grammaticallyTransitive) as T.VerbConjugation,
}; };
} }
if (info.type === "dynamic or stative compound" || info.type === "dynamic or generative stative compound") { if (info.type === "dynamic or stative compound" || info.type === "dynamic or generative stative compound") {
return { return {
info, info,
stative: conjugateVerb(dummyEntry, aayTailType, dummyEntry, info.stative) as T.VerbConjugation, stative: conjugateVerb({ ...entry, c: entry.c ? entry.c.replace("dyn./", "") : "" }, dummyEntry, info.stative) as T.VerbConjugation,
dynamic: conjugateVerb(dummyEntry, aayTailType, dummyEntry, info.dynamic) as T.VerbConjugation, dynamic: conjugateVerb({ ...entry, c: entry.c ? entry.c.replace("/stat.", "") : "" }, dummyEntry, info.dynamic) as T.VerbConjugation,
}; };
} }
if (info.type === "dynamic compound") { if (info.type === "dynamic compound") {
return conjugateDynamicCompound(info, aayTailType); return conjugateDynamicCompound(info);
} }
const nonComboInfo = info as T.NonComboVerbInfo; const nonComboInfo = info as T.NonComboVerbInfo;
@ -87,13 +82,13 @@ export function conjugateVerb(entry: T.DictionaryEntry, aayTailType: T.AayTail,
// TODO: Handle verbs like چيغه کول // TODO: Handle verbs like چيغه کول
const conjugation: T.VerbConjugation = { const conjugation: T.VerbConjugation = {
info: nonComboInfo, info: nonComboInfo,
imperfective: makeAspectContent(nonComboInfo, "imperfective", aayTailType), imperfective: makeAspectContent(nonComboInfo, "imperfective"),
perfective: makeAspectContent(nonComboInfo, "perfective", aayTailType), perfective: makeAspectContent(nonComboInfo, "perfective"),
hypothetical: makeHypotheticalContent(nonComboInfo), hypothetical: makeHypotheticalContent(nonComboInfo),
participle: makeParticipleContent(nonComboInfo), participle: makeParticipleContent(nonComboInfo),
perfect: makePerfectContent(nonComboInfo), perfect: makePerfectContent(nonComboInfo),
..."singularForm" in info ? { ..."singularForm" in info ? {
singularForm: conjugateVerb(entry, aayTailType, complement, info.singularForm) as T.VerbConjugation, singularForm: conjugateVerb(entry, complement, info.singularForm) as T.VerbConjugation,
} : {}, } : {},
// if transitive include passive voice // if transitive include passive voice
...info.transitivity !== "intransitive" ? { ...info.transitivity !== "intransitive" ? {
@ -109,14 +104,14 @@ export function conjugateVerb(entry: T.DictionaryEntry, aayTailType: T.AayTail,
: conjugation; : conjugation;
} }
function conjugateDynamicCompound(info: T.DynamicCompoundVerbInfo, aayTailType: "ey" | "aay"): T.VerbConjugation { function conjugateDynamicCompound(info: T.DynamicCompoundVerbInfo): T.VerbConjugation {
const willUseImperative = !( const willUseImperative = !(
info.type === "dynamic compound" info.type === "dynamic compound"
&& info.transitivity === "intransitive" && info.transitivity === "intransitive"
&& info.auxVerb.p === "کېدل" && info.auxVerb.p === "کېدل"
); );
const auxConj = enforceObject( const auxConj = enforceObject(
conjugateVerb(info.auxVerb, aayTailType, info.auxVerbComplement) as T.VerbConjugation, conjugateVerb(info.auxVerb, info.auxVerbComplement) as T.VerbConjugation,
info.objComplement.person, info.objComplement.person,
); );
const complement = info.objComplement.plural const complement = info.objComplement.plural
@ -200,17 +195,17 @@ function conjugateDynamicCompound(info: T.DynamicCompoundVerbInfo, aayTailType:
}, },
} : {}, } : {},
...info.singularForm ? { ...info.singularForm ? {
singularForm: conjugateDynamicCompound(info.singularForm, aayTailType) singularForm: conjugateDynamicCompound(info.singularForm)
} : {}, } : {},
...info.intransitiveForm ? { ...info.intransitiveForm ? {
intransitiveForm: conjugateDynamicCompound(info.intransitiveForm, aayTailType) intransitiveForm: conjugateDynamicCompound(info.intransitiveForm)
} : {}, } : {},
}; };
} }
function makeAspectContent(info: T.NonComboVerbInfo, aspect: T.Aspect, aayTailType: T.AayTail): T.AspectContent { function makeAspectContent(info: T.NonComboVerbInfo, aspect: T.Aspect): T.AspectContent {
if ((info.type === "stative compound") && spaceInForm(info.root[aspect])) { if ((info.type === "stative compound") && spaceInForm(info.root[aspect])) {
return makeStativeCompoundSeperatedAspectContent(info, aspect, aayTailType); return makeStativeCompoundSeperatedAspectContent(info, aspect);
} }
const stem = noPersInfs(info.stem[aspect]); const stem = noPersInfs(info.stem[aspect]);
const root = noPersInfs(info.root[aspect]); const root = noPersInfs(info.root[aspect]);
@ -225,17 +220,16 @@ function makeAspectContent(info: T.NonComboVerbInfo, aspect: T.Aspect, aayTailTy
future, // به - ba + nonImperative future, // به - ba + nonImperative
imperative, // stem + imperative endings imperative, // stem + imperative endings
past, // root + past endings past, // root + past endings
modal: makeJoinedModalContent(info, aspect, aayTailType), modal: makeJoinedModalContent(info, aspect),
}; };
} }
function makeJoinedModalContent(info: T.NonComboVerbInfo, aspectIn: T.Aspect, aayTailType: T.AayTail): T.ModalContent { function makeJoinedModalContent(info: T.NonComboVerbInfo, aspectIn: T.Aspect): T.ModalContent {
const aspect: T.Aspect = noPerfectiveModal(info) ? "imperfective" : aspectIn; const aspect: T.Aspect = noPerfectiveModal(info) ? "imperfective" : aspectIn;
const aayTail = getAayTail(aayTailType);
const aux = stativeAux.intransitive.perfective; const aux = stativeAux.intransitive.perfective;
const rAndT = info.yulEnding const rAndT = info.yulEnding
? concatPsString(noPersInfs(info.root[aspect]).long, aayTail) ? concatPsString(noPersInfs(info.root[aspect]).long, aayTail[1])
: concatPsString(noPersInfs(info.root[aspect]), aayTail); : concatPsString(noPersInfs(info.root[aspect]), aayTail[1]);
const rootAndTail = aspect === "imperfective" const rootAndTail = aspect === "imperfective"
? accentImperfectiveModalRootAndTail(info, rAndT) ? accentImperfectiveModalRootAndTail(info, rAndT)
: rAndT; : rAndT;
@ -256,7 +250,7 @@ function makeJoinedModalContent(info: T.NonComboVerbInfo, aspectIn: T.Aspect, aa
}; };
} }
function makeStativeCompoundSeperatedAspectContent(info: T.StativeCompoundVerbInfo, aspect: T.Aspect, aayTailType: T.AayTail): T.AspectContent { function makeStativeCompoundSeperatedAspectContent(info: T.StativeCompoundVerbInfo, aspect: T.Aspect): T.AspectContent {
const transitivity = getTransitivity(info); const transitivity = getTransitivity(info);
const presentComplement = (transitivity === "transitive" && complementInflects(info.complement)) const presentComplement = (transitivity === "transitive" && complementInflects(info.complement))
? unisexInfToObjectMatrix(info.complement) // transitive verb requires an object matrix for the complex ? unisexInfToObjectMatrix(info.complement) // transitive verb requires an object matrix for the complex
@ -296,7 +290,7 @@ function makeStativeCompoundSeperatedAspectContent(info: T.StativeCompoundVerbIn
} : {}, } : {},
modal: info.transitivity === "transitive" modal: info.transitivity === "transitive"
? makeTransitiveStativeModalContent() ? makeTransitiveStativeModalContent()
: makeJoinedModalContent(info, "imperfective", aayTailType), : makeJoinedModalContent(info, "imperfective"),
}; };
} }
@ -314,20 +308,27 @@ function makeHypotheticalContent(info: T.NonComboVerbInfo): T.VerbForm {
if (("complement" in info) && spaceInForm(info.root.imperfective)) { if (("complement" in info) && spaceInForm(info.root.imperfective)) {
return makeStativeCompoundSepHypotheticalContent(info as T.StativeCompoundVerbInfo); return makeStativeCompoundSepHypotheticalContent(info as T.StativeCompoundVerbInfo);
} }
const makeHypothetical = (root: T.OptionalPersonInflections<T.LengthOptions<T.PsString>>, length: "short" | "long"): T.PsString => { const makeHypothetical = (root: T.OptionalPersonInflections<T.LengthOptions<T.PsString>>, length: "short" | "long"): T.PsString[] => {
if ("mascSing" in root) { if ("mascSing" in root) {
// BIG TODO: SHOULD THERE BE PERS INFS HERE?? IGNORING THEM NOW IF THEY EXIST // BIG TODO: SHOULD THERE BE PERS INFS HERE?? IGNORING THEM NOW IF THEY EXIST
return makeHypothetical(root.mascSing, length) as T.PsString; return makeHypothetical(root.mascSing, length) as T.PsString[];
} }
return accentOnNFromEnd( return [
concatPsString(root[length], aayTail), accentOnNFromEnd(
(length === "long" ? 1 : 0) + (info.yulEnding ? 1 : 0), concatPsString(root[length], aayTail[0]),
) (length === "long" ? 1 : 0) + (info.yulEnding ? 1 : 0),
),
accentOnNFromEnd(
concatPsString(root[length], aayTail[1]),
(length === "long" ? 1 : 0) + (info.yulEnding ? 1 : 0),
),
];
}; };
const hyp = { const hyp = {
short: makeHypothetical(info.root.imperfective, "short"), short: makeHypothetical(info.root.imperfective, "short"),
long: makeHypothetical(info.root.imperfective, "long"), long: makeHypothetical(info.root.imperfective, "long"),
}; };
// TODO: ADD TO FORM IS NOT ADDING THE SECOND VARIATION PASSED IN!
return addToForm([hyp], emptyVerbBlock); return addToForm([hyp], emptyVerbBlock);
} }