more on roots/stems

This commit is contained in:
adueck 2023-04-05 15:54:00 +04:00
parent 93776bb98d
commit 1dbe0a42f4
7 changed files with 1100 additions and 192 deletions

View File

@ -14,6 +14,7 @@ import {
import { entryFeeder } from "./entryFeeder";
import { renderVerb } from "../lib/src/new-verb-engine/render-verb";
import NPPronounPicker from "../components/src/np-picker/NPPronounPicker";
import { getAllRs } from "../lib/src/new-verb-engine/rs-helpers";
const transitivities: T.Transitivity[] = [
@ -152,6 +153,7 @@ function VPBuilderDemo({ opts }: {
person: testPerson.person,
voice: testVoice,
}) : undefined;
const rs = v ? getAllRs(v.verb as T.VerbEntry) : undefined
return <div className="mt-4">
<div className="d-block mx-auto card" style={{ maxWidth: "700px", background: "var(--closer)"}}>
<div className="card-body">
@ -249,7 +251,10 @@ function VPBuilderDemo({ opts }: {
pronoun={testPerson}
role="subject"
opts={opts}
/>
/>
<pre>
{JSON.stringify(rs, null, " ")}
</pre>
<pre>
{JSON.stringify(rv, null, " ")}
</pre>

View File

@ -0,0 +1,4 @@
export function assertNever(x: never) {
throw new Error("unexpected object: "+x);
return x;
}

View File

@ -1,14 +1,6 @@
import * as T from "../../../types";
import { renderVerb } from "./render-verb";
export function vEntry(e: any, c?: any): T.VerbEntry {
return {
entry: e,
...c ? {
c,
} : {},
} as T.VerbEntry;
}
import { vEntry } from "./rs-helpers";
const wahul = vEntry({"ts":1527815399,"i":15049,"p":"وهل","f":"wahul","g":"wahul","e":"to hit","r":4,"c":"v. trans.","tppp":"واهه","tppf":"waahu","ec":"hit,hits,hitting,hit,hit"});
const achawul = vEntry({"ts":1527811872,"i":224,"p":"اچول","f":"achawul","g":"achawul","e":"to put, pour, drop, throw, put on","r":4,"c":"v. trans.","ec":"put,puts,putting,put,put"});

File diff suppressed because it is too large Load Diff

View File

@ -12,8 +12,7 @@ import {
import * as T from "../../../types";
import { makePsString, removeFVarientsFromVerb } from "../accent-and-ps-utils";
import { accentOnNFromEnd, removeAccents } from "../accent-helpers";
type RootStemOutput = (T.PH | T.SingleOrLengthOpts<T.PsString[]>)[];
import { assertNever } from "../assert-never";
export function getRootStem({ verb, part, type, person }: {
verb: T.VerbEntry,
@ -28,19 +27,17 @@ export function getRootStem({ verb, part, type, person }: {
gender: T.Gender,
number: T.NounNumber,
} | undefined,
}): RootStemOutput {
}): T.RootStemOutput {
const v = removeFVarientsFromVerb(verb);
if ("participle" in part) {
return [];
}
if (part.rs === "stem") {
return getStem(v, part.aspect);
} else {
return getRoot(v, part.aspect);
}
return part.rs === "stem"
? getStem(v, part.aspect)
: getRoot(v, part.aspect);
}
function getRoot(verb: T.VerbEntryNoFVars, aspect: T.Aspect): RootStemOutput {
function getRoot(verb: T.VerbEntryNoFVars, aspect: T.Aspect): T.RootStemOutput {
if (aspect === "imperfective") {
const infinitive = accentOnNFromEnd(makePsString(verb.entry.p, verb.entry.f), 0);
return [
@ -50,33 +47,43 @@ function getRoot(verb: T.VerbEntryNoFVars, aspect: T.Aspect): RootStemOutput {
},
];
}
if (aspect === "perfective") {
const base = removeAccents(
(verb.entry.prp && verb.entry.prf)
? makePsString(verb.entry.prp, verb.entry.prf)
: makePsString(verb.entry.p, verb.entry.f)
);
const [perfectiveHead, rest] = getPerfectiveHead(base, verb);
return [
...perfectiveHead ? [perfectiveHead] : [],
{
long: [rest],
short: [removeL(rest)],
},
];
}
throw new Error("unknown aspect");
// aspect === "perfective"
const base = removeAccents(
(verb.entry.prp && verb.entry.prf)
? makePsString(verb.entry.prp, verb.entry.prf)
: makePsString(verb.entry.p, verb.entry.f)
);
const [perfectiveHead, rest] = getPerfectiveHead(base, verb);
return [
...perfectiveHead ? [perfectiveHead] : [],
{
long: [rest],
short: [removeL(rest)],
},
];
}
function getStem(verb: T.VerbEntryNoFVars, aspect: T.Aspect): RootStemOutput {
function getStem(verb: T.VerbEntryNoFVars, aspect: T.Aspect): T.RootStemOutput {
if (aspect === "imperfective") {
const base = (verb.entry.psp && verb.entry.psf)
// with irregular imperfective stem
? makePsString(verb.entry.psp, verb.entry.psf)
// with regular infinitive based imperfective stem
: removeL(makePsString(verb.entry.p, verb.entry.f));
if (verb.entry.psp && verb.entry.psf) {
return [[makePsString(verb.entry.psp, verb.entry.psf)]];
}
const rawBase = removeL(makePsString(verb.entry.p, verb.entry.f));
if (verb.entry.c?.includes("intrans.") && rawBase.p.endsWith("ېد")) {
const long: T.PsString[] = [{
p: rawBase.p.slice(0, -1) + "ږ",
f: rawBase.f.slice(0, -2) + "éG",
}];
const short: T.PsString[] | undefined = (verb.entry.shortIntrans)
? [{
p: rawBase.p.slice(0, -2),
f: rawBase.f.slice(0, -2),
}]
: undefined;
return short ? [{ long, short }] : [long]
}
return [
[base],
[rawBase],
];
}
if (aspect === "perfective") {
@ -101,6 +108,20 @@ function getPerfectiveHead(base: T.PsString, { entry }: T.VerbEntry): [T.PH, T.P
// if ((verb.entry.ssp && verb.entry.ssf) || verb.entry.separationAtP) {
// // handle split
// }
if (entry.separationAtP && entry.separationAtF) {
const ph: T.PH = {
type: "PH",
ps: accentOnNFromEnd({
p: base.p.slice(0, entry.separationAtP),
f: base.f.slice(0, entry.separationAtF),
}, 0),
};
const rest = {
p: base.p.slice(entry.separationAtP),
f: base.f.slice(entry.separationAtF),
};
return [ph, rest];
}
const [ph, rest]: [T.PH | undefined, T.PsString] = entry.noOo
? [undefined, base]
: entry.sepOo

View File

@ -0,0 +1,33 @@
import * as T from "../../../types";
import { getRootStem } from "./roots-and-stems";
export function vEntry(e: any, c?: any): T.VerbEntry {
return {
entry: e,
...c ? {
c,
} : {},
} as T.VerbEntry;
}
export function getAllRs(verb: T.VerbEntry): {
stem: {
perfective: T.RootStemOutput,
imperfective: T.RootStemOutput,
},
root: {
perfective: T.RootStemOutput,
imperfective: T.RootStemOutput,
},
} {
return {
stem: {
perfective: getRootStem({ verb, type: "basic", part: { rs: "stem", aspect: "perfective" }, person: undefined }),
imperfective: getRootStem({ verb, type: "basic", part: { rs: "stem", aspect: "imperfective" }, person: undefined }),
},
root: {
perfective: getRootStem({ verb, type: "basic", part: { rs: "root", aspect: "perfective" }, person: undefined }),
imperfective: getRootStem({ verb, type: "basic", part: { rs: "root", aspect: "imperfective" }, person: undefined }),
},
};
}

View File

@ -1140,3 +1140,4 @@ export type Welded = {
right: VA | PT | VI,
};
export type RootStemOutput = (PH | SingleOrLengthOpts<PsString[]>)[];