ability to have tppp varients

This commit is contained in:
adueck 2023-08-14 15:01:00 +04:00
parent 8da9f9ce53
commit 0a10b1e9dc
4 changed files with 24 additions and 27 deletions

View File

@ -6,8 +6,11 @@ import {
personToGenNum, personToGenNum,
} from "../misc-helpers"; } from "../misc-helpers";
import { fmapSingleOrLengthOpts } from "../fp-ps"; import { fmapSingleOrLengthOpts } from "../fp-ps";
import { concatPsString, getLength } from "../p-text-helpers"; import {
import { zipWith } from "rambda"; concatPsString,
getLength,
splitPsByVarients,
} from "../p-text-helpers";
import { import {
presentEndings, presentEndings,
pastEndings, pastEndings,
@ -363,9 +366,9 @@ function ensure3rdPast(
]; ];
} }
if (verb.entry.tppp && verb.entry.tppf) { if (verb.entry.tppp && verb.entry.tppf) {
const tppp = verb.entry.tppp.split(",").map((x) => x.trim()); const tpps = splitPsByVarients(
const tppf = verb.entry.tppf.split(",").map((x) => x.trim()); makePsString(verb.entry.tppp, verb.entry.tppf)
const tpps = zipWith((p, f) => ({ p, f }), tppp, tppf); );
return tpps.map(({ p, f }) => { return tpps.map(({ p, f }) => {
const tip = removeAccents( const tip = removeAccents(
verb.entry.separationAtP !== undefined verb.entry.separationAtP !== undefined

View File

@ -16,6 +16,7 @@ import { hasAccents, removeAccents } from "./accent-helpers";
import { phoneticsConsonants } from "./pashto-consonants"; import { phoneticsConsonants } from "./pashto-consonants";
import { simplifyPhonetics } from "./simplify-phonetics"; import { simplifyPhonetics } from "./simplify-phonetics";
import { makePsString, removeFVarients } from "./accent-and-ps-utils"; import { makePsString, removeFVarients } from "./accent-and-ps-utils";
import { zipWith } from "rambda";
// export function concatPsStringWithVars(...items: Array<T.PsString | " " | "">): T.PsString[] { // export function concatPsStringWithVars(...items: Array<T.PsString | " " | "">): T.PsString[] {
@ -1086,14 +1087,8 @@ export function splitPsByVarients(w: T.PsString): T.ArrayOneOrMore<T.PsString> {
function cut(s: string) { function cut(s: string) {
return s.split(/[,|،]/).map((s) => s.trim()); return s.split(/[,|،]/).map((s) => s.trim());
} }
const ps = mapPsString(w, cut); const { p, f } = mapPsString(w, cut);
return ps.p.map((p, i) => { return zipWith(makePsString, p, f) as T.ArrayOneOrMore<T.PsString>;
if (!ps.f[i])
throw new Error(
"uneven comma seperated ps varients: " + JSON.stringify(w)
);
return makePsString(p, ps.f[i]);
}) as T.ArrayOneOrMore<T.PsString>;
} }
export function removeEndTick(w: T.PsString): T.PsString; export function removeEndTick(w: T.PsString): T.PsString;

View File

@ -1,7 +1,6 @@
import * as T from "../../../types"; import * as T from "../../../types";
import { verbLookup } from "./lookup"; import { verbLookup } from "./lookup";
import { parseNP } from "./parse-np"; import { parseNP } from "./parse-np";
import { parseVerb } from "./parse-verb";
import { parseVP } from "./parse-vp"; import { parseVP } from "./parse-vp";
export function parsePhrase( export function parsePhrase(

View File

@ -488,19 +488,19 @@ const tests: {
], ],
}, },
// TODO: should do کاته as well... what to do, have multiple tpp forms ? YES! // TODO: should do کاته as well... what to do, have multiple tpp forms ? YES!
{ // {
input: "وکوت", // input: "وکوت",
output: [ // output: [
{ // {
ph: "و", // ph: "و",
root: { // root: {
persons: [T.Person.ThirdSingMale], // persons: [T.Person.ThirdSingMale],
aspects: ["perfective"], // aspects: ["perfective"],
}, // },
verb: katul, // verb: katul,
}, // },
], // ],
}, // },
], ],
}, },
{ {