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,
x: T.SingleOrLengthOpts<A>
): T.SingleOrLengthOpts<B> {
if ("long" in x) {
if (x && typeof x === "object" && "long" in x) {
return {
long: f(x.long),
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(
f: (x: T.PsString) => T.PsString,
inf: T.UnisexInflections

View File

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

View File

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

View File

@ -21,7 +21,7 @@ import { isFirstOrSecondPersPronoun } from "../phrase-building/render-vp";
// وامې نه اخیست
// 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