proper english rendering of participles

This commit is contained in:
lingdocs 2022-05-15 16:39:21 -05:00
parent fcefb9e5dc
commit 92b80c3b6a
6 changed files with 27 additions and 30 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@lingdocs/pashto-inflector",
"version": "2.5.4",
"version": "2.5.5",
"author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com",

View File

@ -90,6 +90,7 @@ function NPPicker(props: {
const clearButton = (!props.cantClear && !props.is2ndPersonPicker && !isDynamicComplement)
? <button className="btn btn-sm btn-light mb-2" onClick={handleClear}>X</button>
: <div></div>;
const possesiveLabel = props.np?.type === "participle" ? "Subj/Obj" : "Possesor";
return <>
<div className="d-flex flex-row justify-content-between">
<div></div>
@ -124,7 +125,7 @@ function NPPicker(props: {
background: (props.np.possesor?.shrunken && !props.isShrunk) ? shrunkenBackground : "inherit",
}}>
<div className="d-flex flex-row text-muted mb-2">
<div>Possesive:</div>
<div>{possesiveLabel}:</div>
{(props.np.possesor && !props.isShrunk) && <div className="clickable ml-3 mr-2" onClick={handleToggleShrunken}>
{!props.np.possesor.shrunken ? "🪄" : "👶"}
</div>}
@ -147,7 +148,7 @@ function NPPicker(props: {
/>
</div>}
{(npType === "noun" || npType === "participle") && props.np && !addingPoss && <div>
<span className="clickable text-muted" onClick={() => setAddingPoss(true)}>+ Possesive</span>
<span className="clickable text-muted" onClick={() => setAddingPoss(true)}>+ {possesiveLabel}</span>
</div>}
{(npType === "pronoun" && props.np?.type === "pronoun")
? <PronounPicker

View File

@ -71,7 +71,7 @@ export function getEnglishParticiple(entry: T.DictionaryEntry): string {
throw new Error("no english information for participle");
}
const ec = parseEc(entry.ec);
const participle = ec[2];
const participle = `${ec[2]} / to ${ec[0]}`;
return (entry.ep)
? `${participle} ${entry.ep}`
: participle;

View File

@ -102,18 +102,22 @@ function addArticlesAndAdjs(np: T.Rendered<T.NounSelection>): string | undefined
}
}
function addPossesors(possesor: T.Rendered<T.NPSelection> | undefined, base: string | undefined): string | undefined {
function addPossesors(possesor: T.Rendered<T.NPSelection> | undefined, base: string | undefined, type: "noun" | "participle"): string | undefined {
function removeArticles(s: string): string {
return s.replace("(the) ", "").replace("(a/the) ", "");
}
if (!base) return undefined;
if (!possesor) return base;
if (possesor.type === "pronoun") {
return `${pronounPossEng(possesor.person)} ${removeArticles(base)}`;
return type === "noun"
? `${pronounPossEng(possesor.person)} ${removeArticles(base)}`
: `(${pronounPossEng(possesor.person)}) ${removeArticles(base)} (${possesor.e})`
}
const possesorE = getEnglishFromRendered(possesor);
if (!possesorE) return undefined;
return `${possesorE}'s ${removeArticles(base)}`;
return type === "noun"
? `${possesorE}'s ${removeArticles(base)}`
: `(${possesorE}'s) ${removeArticles(base)} (${possesorE})`;
}
function pronounPossEng(p: T.Person): string {
@ -143,10 +147,10 @@ export function getEnglishFromRendered(r: T.Rendered<T.NPSelection | T.EqCompSel
if (r.type === "loc. adv." || r.type === "adjective") {
return r.e;
}
if (r.type === "noun") {
if (r.type !== "pronoun") {
// TODO: shouldn't have to do this 'as' - should be automatically narrowing
const np = r as T.Rendered<T.NounSelection>;
return addPossesors(np.possesor?.np, addArticlesAndAdjs(np));
return addPossesors(np.possesor?.np, addArticlesAndAdjs(np), r.type);
}
// TODO: possesives in English for participles and pronouns too!
return r.e;

View File

@ -23,6 +23,7 @@ export function renderEP(EP: T.EPSelectionComplete): T.EPRendered {
: EP.predicate.type === "NP"
? getPersonFromNP(EP.predicate.selection)
: getPersonFromNP(EP.subject);
const kingIsParticiple = EP[king].type === "participle";
return {
type: "EPRendered",
king: EP.predicate.type === "Complement" ? "subject" : "predicate",
@ -31,7 +32,10 @@ export function renderEP(EP: T.EPSelectionComplete): T.EPRendered {
? renderNPSelection(EP.predicate.selection, false, true, "subject", "king")
: renderEqCompSelection(EP.predicate.selection, kingPerson),
equative: renderEquative(EP.equative, kingPerson),
englishBase: equativeBuilders[EP.equative.tense](kingPerson, EP.equative.negative),
englishBase: equativeBuilders[EP.equative.tense](
kingIsParticiple ? T.Person.ThirdSingMale : kingPerson,
EP.equative.negative,
),
omitSubject: EP.omitSubject,
};
}
@ -133,7 +137,7 @@ function isThirdPersonSing(p: T.Person): boolean {
return p === T.Person.ThirdSingMale || p === T.Person.ThirdPlurFemale;
}
function not(n: boolean): string {
return n ? "not " : "";
return n ? " not " : "";
}
function getEnglishConj(p: T.Person, e: string | T.EnglishBlock): string {

View File

@ -9,7 +9,9 @@ import {
concatPsString,
psStringFromEntry,
} from "../p-text-helpers";
import { parseEc } from "../misc-helpers";
import {
getEnglishParticiple,
} from "../../lib/np-tools";
import { getEnglishWord } from "../get-english-word";
import { renderAdjectiveSelection } from "./render-adj";
import { isPattern5Entry, isUnisexAnimNounEntry } from "../type-predicates";
@ -83,11 +85,11 @@ function renderParticipleSelection(p: T.ParticipleSelection, inflected: boolean,
// TODO: More robust inflection of inflecting pariticiples - get from the conjugation engine
ps: [psStringFromEntry(p.verb.entry)].map(ps => inflected ? concatPsString(ps, { p: "و", f: "o" }) : ps),
e: getEnglishParticiple(p.verb.entry),
possesor: renderPossesor(p.possesor, role),
possesor: renderPossesor(p.possesor, "subj/obj"),
};
}
function renderPossesor(possesor: T.PossesorSelection | undefined, possesorRole: "servant" | "king" | "none"): T.RenderedPossesorSelection | undefined {
function renderPossesor(possesor: T.PossesorSelection | undefined, possesorRole: "servant" | "king" | "none" | "subj/obj"): T.RenderedPossesorSelection | undefined {
if (!possesor) return undefined;
const isSingUnisexAnim5PatternNoun = (possesor.np.type === "noun"
&& possesor.np.number === "singular"
@ -99,9 +101,9 @@ function renderPossesor(possesor: T.PossesorSelection | undefined, possesorRole:
np: renderNPSelection(
possesor.np,
!isSingUnisexAnim5PatternNoun,
false,
possesorRole === "subj/obj" ? true : false,
"subject",
possesorRole,
possesorRole === "subj/obj" ? "none" : possesorRole,
),
};
}
@ -118,20 +120,6 @@ function getInf(infs: T.InflectorOutput, t: "plural" | "arabicPlural" | "inflect
return [];
}
function getEnglishParticiple(entry: T.DictionaryEntry): string {
if (!entry.ec) {
console.log("errored participle");
console.log(entry);
throw new Error("no english information for participle");
}
const ec = parseEc(entry.ec);
const participle = ec[2];
return (entry.ep)
? `${participle} ${entry.ep}`
: participle;
}
function getEnglishFromNoun(entry: T.DictionaryEntry, number: T.NounNumber): string {
const articles = {
singular: "(a/the)",