touchup on applySingleOrLengthOpts

This commit is contained in:
adueck 2023-08-27 14:43:11 +04:00
parent ce0dbb1f18
commit 730369a3e6
4 changed files with 56 additions and 30 deletions

View File

@ -53,11 +53,11 @@ export function fmapParseResult<A extends object, B extends object>(
})); }));
} }
export function fmapSingleOrLengthOpts<A extends object, B extends object>( export function fmapSingleOrLengthOpts<A, B>(
f: (x: A) => B, f: (x: A) => B,
x: T.SingleOrLengthOpts<A> x: T.SingleOrLengthOpts<A>
): T.SingleOrLengthOpts<B> { ): T.SingleOrLengthOpts<B> {
if ("long" in x) { if (x && typeof x === "object" && "long" in x) {
return { return {
long: f(x.long), long: f(x.long),
short: f(x.short), short: f(x.short),
@ -72,6 +72,42 @@ export function fmapSingleOrLengthOpts<A extends object, B extends object>(
} }
} }
export function pureSingleOrLengthOpts<A>(a: A): T.SingleOrLengthOpts<A> {
return a;
}
/**
* like and applicative <*> operator for SingleOrLengthOpts
*
* applies the appropriate length function for each type of given length, otherwise applies
* the long version as the default
*
* allows us to put transformation functions in the SingleOrLengthOpts data structure
* instead of
*/
export function applySingleOrLengthOpts<A, B>(
f: T.SingleOrLengthOpts<(a: A) => B>,
a: T.SingleOrLengthOpts<A>
): T.SingleOrLengthOpts<B> {
if (f && "long" in f) {
if (a && typeof a === "object" && "long" in a) {
return {
long: fmapSingleOrLengthOpts(f.long, a.long) as B,
short: fmapSingleOrLengthOpts(f.short, a.short) as B,
...(a.mini
? {
mini: fmapSingleOrLengthOpts(f.mini || f.short, a.mini) as B,
}
: {}),
};
} else {
return fmapSingleOrLengthOpts(f.long, a);
}
} else {
return fmapSingleOrLengthOpts(f, a);
}
}
export function mapInflections( export function mapInflections(
f: (x: T.PsString) => T.PsString, f: (x: T.PsString) => T.PsString,
inf: T.UnisexInflections inf: T.UnisexInflections

View File

@ -5,7 +5,7 @@ import {
personNumber, personNumber,
personToGenNum, personToGenNum,
} from "../misc-helpers"; } from "../misc-helpers";
import { fmapSingleOrLengthOpts } from "../fp-ps"; import { applySingleOrLengthOpts, fmapSingleOrLengthOpts } from "../fp-ps";
import { import {
concatPsString, concatPsString,
getLength, getLength,
@ -269,41 +269,31 @@ function addEnding({
vb: T.VBBasic, vb: T.VBBasic,
end: T.SingleOrLengthOpts<T.PsString[]> end: T.SingleOrLengthOpts<T.PsString[]>
): T.VBBasic { ): T.VBBasic {
// exceptional ending for راتلل, ورتلل, درتلل
if ("long" in vb.ps) { if ("long" in vb.ps) {
// TODO: do we need a more thorough check?
if (vb.ps.short[0].f === "ghl" && pastThird && basicForm) { if (vb.ps.short[0].f === "ghl" && pastThird && basicForm) {
return { return {
...vb, ...vb,
ps: [{ p: "غی", f: "ghay" }], ps: [{ p: "غی", f: "ghay" }],
}; };
} }
const endLong = getLength(end, "long"); }
const endShort = getLength(end, "short"); const endShort = getLength(end, "short");
// TODO: this is hacky
return { return {
...vb, ...vb,
ps: { ps: applySingleOrLengthOpts(
long: verbEndingConcat(vb.ps.long, endLong), {
short: long: (ps) => verbEndingConcat(ps, getLength(end, "long")),
short: (ps) =>
pastThird && basicForm pastThird && basicForm
? ensure3rdPast(vb.ps.short, endShort, verb, aspect) ? ensure3rdPast(ps, endShort, verb, aspect)
: verbEndingConcat(vb.ps.short, endShort), : verbEndingConcat(ps, endShort),
...(vb.ps.mini mini: (ps) => verbEndingConcat(ps, endShort),
? {
mini: verbEndingConcat(vb.ps.mini, endShort),
}
: {}),
}, },
}; vb.ps
} ),
/* istanbul ignore next */
if ("long" in end) {
throw new Error(
"should not be using verb stems with long and short endings"
);
}
return {
...vb,
ps: verbEndingConcat(vb.ps, end),
}; };
} }
} }

View File

@ -7,7 +7,7 @@ export const tlul = wordQuery("tlul", "verb");
export const wartlul = wordQuery("ورتلل", "verb"); export const wartlul = wordQuery("ورتلل", "verb");
export const dartlul = wordQuery("درتلل", "verb") as T.VerbEntry; export const dartlul = wordQuery("درتلل", "verb");
export const kedulStat = { export const kedulStat = {
entry: { entry: {

View File

@ -21,7 +21,7 @@ import { isFirstOrSecondPersPronoun } from "../phrase-building/render-vp";
// وامې نه اخیست // وامې نه اخیست
// waa-me nú akheest // waa-me nú akheest
// TODO: WHY IS NETLIFY TESTING FAILING - getting a different version of tlul // TODO: word query for kawul/kedul/stat/dyn
// map over transitivities, to give transitive / gramm. transitive optionns // map over transitivities, to give transitive / gramm. transitive optionns