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", "name": "@lingdocs/pashto-inflector",
"version": "2.5.4", "version": "2.5.5",
"author": "lingdocs.com", "author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com", "homepage": "https://verbs.lingdocs.com",

View File

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

View File

@ -71,7 +71,7 @@ export function getEnglishParticiple(entry: T.DictionaryEntry): string {
throw new Error("no english information for participle"); throw new Error("no english information for participle");
} }
const ec = parseEc(entry.ec); const ec = parseEc(entry.ec);
const participle = ec[2]; const participle = `${ec[2]} / to ${ec[0]}`;
return (entry.ep) return (entry.ep)
? `${participle} ${entry.ep}` ? `${participle} ${entry.ep}`
: participle; : 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 { function removeArticles(s: string): string {
return s.replace("(the) ", "").replace("(a/the) ", ""); return s.replace("(the) ", "").replace("(a/the) ", "");
} }
if (!base) return undefined; if (!base) return undefined;
if (!possesor) return base; if (!possesor) return base;
if (possesor.type === "pronoun") { 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); const possesorE = getEnglishFromRendered(possesor);
if (!possesorE) return undefined; 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 { 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") { if (r.type === "loc. adv." || r.type === "adjective") {
return r.e; return r.e;
} }
if (r.type === "noun") { if (r.type !== "pronoun") {
// TODO: shouldn't have to do this 'as' - should be automatically narrowing // TODO: shouldn't have to do this 'as' - should be automatically narrowing
const np = r as T.Rendered<T.NounSelection>; 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! // TODO: possesives in English for participles and pronouns too!
return r.e; return r.e;

View File

@ -23,6 +23,7 @@ export function renderEP(EP: T.EPSelectionComplete): T.EPRendered {
: EP.predicate.type === "NP" : EP.predicate.type === "NP"
? getPersonFromNP(EP.predicate.selection) ? getPersonFromNP(EP.predicate.selection)
: getPersonFromNP(EP.subject); : getPersonFromNP(EP.subject);
const kingIsParticiple = EP[king].type === "participle";
return { return {
type: "EPRendered", type: "EPRendered",
king: EP.predicate.type === "Complement" ? "subject" : "predicate", 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") ? renderNPSelection(EP.predicate.selection, false, true, "subject", "king")
: renderEqCompSelection(EP.predicate.selection, kingPerson), : renderEqCompSelection(EP.predicate.selection, kingPerson),
equative: renderEquative(EP.equative, 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, omitSubject: EP.omitSubject,
}; };
} }

View File

@ -9,7 +9,9 @@ import {
concatPsString, concatPsString,
psStringFromEntry, psStringFromEntry,
} from "../p-text-helpers"; } from "../p-text-helpers";
import { parseEc } from "../misc-helpers"; import {
getEnglishParticiple,
} from "../../lib/np-tools";
import { getEnglishWord } from "../get-english-word"; import { getEnglishWord } from "../get-english-word";
import { renderAdjectiveSelection } from "./render-adj"; import { renderAdjectiveSelection } from "./render-adj";
import { isPattern5Entry, isUnisexAnimNounEntry } from "../type-predicates"; 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 // 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), ps: [psStringFromEntry(p.verb.entry)].map(ps => inflected ? concatPsString(ps, { p: "و", f: "o" }) : ps),
e: getEnglishParticiple(p.verb.entry), 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; if (!possesor) return undefined;
const isSingUnisexAnim5PatternNoun = (possesor.np.type === "noun" const isSingUnisexAnim5PatternNoun = (possesor.np.type === "noun"
&& possesor.np.number === "singular" && possesor.np.number === "singular"
@ -99,9 +101,9 @@ function renderPossesor(possesor: T.PossesorSelection | undefined, possesorRole:
np: renderNPSelection( np: renderNPSelection(
possesor.np, possesor.np,
!isSingUnisexAnim5PatternNoun, !isSingUnisexAnim5PatternNoun,
false, possesorRole === "subj/obj" ? true : false,
"subject", "subject",
possesorRole, possesorRole === "subj/obj" ? "none" : possesorRole,
), ),
}; };
} }
@ -118,20 +120,6 @@ function getInf(infs: T.InflectorOutput, t: "plural" | "arabicPlural" | "inflect
return []; 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 { function getEnglishFromNoun(entry: T.DictionaryEntry, number: T.NounNumber): string {
const articles = { const articles = {
singular: "(a/the)", singular: "(a/the)",