touchup on applySingleOrLengthOpts
This commit is contained in:
parent
ce0dbb1f18
commit
730369a3e6
|
@ -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
|
||||||
|
|
|
@ -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");
|
|
||||||
// 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 {
|
return {
|
||||||
...vb,
|
...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
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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: {
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue