From 64265e9e20de27c2a802301b5070405fe17f096f Mon Sep 17 00:00:00 2001 From: adueck Date: Tue, 1 Nov 2022 19:30:05 +0500 Subject: [PATCH] inflecting adverbs --- package-lock.json | 4 ++-- package.json | 2 +- src/components/package.json | 2 +- src/lib/package.json | 2 +- src/lib/src/phrase-building/render-adj.ts | 6 +++++- src/lib/src/phrase-building/render-ap.ts | 25 ++++++++++++++++++++--- src/lib/src/phrase-building/render-ep.ts | 22 ++++---------------- src/lib/src/phrase-building/render-vp.ts | 8 +++++++- src/types.ts | 3 ++- 9 files changed, 45 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9879aa0..1ed39b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pashto-inflector", - "version": "5.1.3", + "version": "5.1.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "pashto-inflector", - "version": "5.1.3", + "version": "5.1.5", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 8e5cdea..0aaa936 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pashto-inflector", - "version": "5.1.4", + "version": "5.1.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", diff --git a/src/components/package.json b/src/components/package.json index b7b8760..30ebdb8 100644 --- a/src/components/package.json +++ b/src/components/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/ps-react", - "version": "5.1.3", + "version": "5.1.4", "description": "Pashto inflector library module with React components", "main": "dist/components/library.js", "module": "dist/components/library.js", diff --git a/src/lib/package.json b/src/lib/package.json index 67a283f..40df375 100644 --- a/src/lib/package.json +++ b/src/lib/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/inflect", - "version": "5.1.3", + "version": "5.1.4", "description": "Pashto inflector library", "main": "dist/index.js", "types": "dist/lib/library.d.ts", diff --git a/src/lib/src/phrase-building/render-adj.ts b/src/lib/src/phrase-building/render-adj.ts index f602cba..ab2fe44 100644 --- a/src/lib/src/phrase-building/render-adj.ts +++ b/src/lib/src/phrase-building/render-adj.ts @@ -19,7 +19,7 @@ function chooseInflection(inflections: T.UnisexSet, pers: T.Per return inflections[gender][infNumber]; } -export function inflectAdjective(a: T.AdjectiveSelection, person: T.Person, inflected: boolean): T.ArrayOneOrMore { +export function inflectAdvAdj(a: T.AdjectiveSelection | T.AdverbSelection, person: T.Person, inflected: boolean): T.ArrayOneOrMore { const infs = inflectWord(a.entry); if (!infs) { return [psStringFromEntry(a.entry)]; @@ -30,6 +30,10 @@ export function inflectAdjective(a: T.AdjectiveSelection, person: T.Person, infl return chooseInflection(infs.inflections, person, inflected); } +export function inflectAdjective(a: T.AdjectiveSelection, person: T.Person, inflected: boolean): T.ArrayOneOrMore { + return inflectAdvAdj(a, person, inflected) +} + export function renderAdjectiveSelection(a: T.AdjectiveSelection, person: T.Person, inflected: boolean, isLocationSingSandwich?: boolean): T.Rendered { const eWord = getEnglishWord(a.entry); const e = !eWord diff --git a/src/lib/src/phrase-building/render-ap.ts b/src/lib/src/phrase-building/render-ap.ts index 7c01703..9ca8f04 100644 --- a/src/lib/src/phrase-building/render-ap.ts +++ b/src/lib/src/phrase-building/render-ap.ts @@ -1,10 +1,11 @@ import * as T from "../../../types"; import { getEnglishWord } from "../get-english-word"; import { psStringFromEntry } from "../p-text-helpers"; -import { renderAdverbSelection } from "./render-ep"; +import { isAdjectiveEntry } from "../type-predicates"; +import { inflectAdvAdj } from "./render-adj"; import { renderSandwich } from "./render-sandwich"; -export function renderAPSelection({ selection }: T.APSelection): T.Rendered { +export function renderAPSelection({ selection }: T.APSelection, person: T.Person): T.Rendered { if (selection.type === "sandwich") { return { type: "AP", @@ -13,7 +14,7 @@ export function renderAPSelection({ selection }: T.APSelection): T.Rendered { + const ew = getEnglishWord(a.entry); + const e = typeof ew === "object" + ? (ew.singular || "") + : !ew + ? "" + : ew; + return { + type: "adverb", + entry: a.entry, + ps: isAdjectiveEntry(a.entry) + ? inflectAdvAdj(a, person, false) + : [psStringFromEntry(a.entry)], + person, + e, + }; } \ No newline at end of file diff --git a/src/lib/src/phrase-building/render-ep.ts b/src/lib/src/phrase-building/render-ep.ts index 1c89920..473edac 100644 --- a/src/lib/src/phrase-building/render-ep.ts +++ b/src/lib/src/phrase-building/render-ep.ts @@ -6,8 +6,7 @@ import { import { renderNPSelection } from "./render-np"; import { getPersonFromVerbForm } from "../misc-helpers"; import { getVerbBlockPosFromPerson } from "../misc-helpers"; -import { getEnglishWord } from "../get-english-word"; -import { psStringFromEntry } from "../p-text-helpers"; +import { renderAdverbSelection } from "./render-ap"; import { renderSandwich } from "./render-sandwich"; import { EPSBlocksAreComplete, getSubjectSelection, makeBlock, makeKid } from "./blocks-utils"; import { removeAccentsWLength } from "../accent-helpers"; @@ -102,12 +101,14 @@ export function getEquativeForm(tense: T.EquativeTense): { hasBa: boolean, form: } function renderEPSBlocks(blocks: T.EPSBlockComplete[]): T.Block[] { + const subject = getSubjectSelection(blocks).selection; + const subjectPerson = getPersonFromNP(subject); return blocks.map(({ block }): T.Block => { if (block.type === "AP") { if (block.selection.type === "adverb") { return makeBlock({ type: "AP", - selection: renderAdverbSelection(block.selection), + selection: renderAdverbSelection(block.selection, subjectPerson), }); } // if (block.selection.type === "sandwich") { @@ -135,21 +136,6 @@ function renderEquative(es: T.EquativeSelection, person: T.Person): T.EquativeRe }; } -export function renderAdverbSelection(a: T.AdverbSelection): T.Rendered { - const ew = getEnglishWord(a.entry); - const e = typeof ew === "object" - ? (ew.singular || "") - : !ew - ? "" - : ew; - return { - type: "adverb", - entry: a.entry, - ps: [psStringFromEntry(a.entry)], - e, - }; -} - const equativeBuilders: Record string[]> = { present: (p, n) => { return [ diff --git a/src/lib/src/phrase-building/render-vp.ts b/src/lib/src/phrase-building/render-vp.ts index b379b60..b592038 100644 --- a/src/lib/src/phrase-building/render-vp.ts +++ b/src/lib/src/phrase-building/render-vp.ts @@ -281,12 +281,18 @@ function shrinkServant(np: T.NPSelection): T.MiniPronoun { }; } + function renderVPBlocks(blocks: T.VPSBlockComplete[], config: { inflectSubject: boolean, inflectObject: boolean, king: "subject" | "object", complementPerson: T.Person | undefined, }): T.Block[] { + const object = getObjectSelection(blocks); + const subject = getSubjectSelection(blocks); + const adverbPerson = typeof object.selection === "object" + ? getPersonFromNP(object.selection) + : getPersonFromNP(subject.selection); return blocks.reduce((blocks, { block }): T.Block[] => { if (block.type === "subjectSelection") { return [ @@ -320,7 +326,7 @@ function renderVPBlocks(blocks: T.VPSBlockComplete[], config: { if (block.type === "AP") { return [ ...blocks, - makeBlock(renderAPSelection(block)), + makeBlock(renderAPSelection(block, adverbPerson ?? 0)), ]; } return [ diff --git a/src/types.ts b/src/types.ts index 31e52c3..07d6de4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -744,7 +744,7 @@ export type Rendered< : T extends APSelection ? { type: "AP", - selection: Rendered + selection: Rendered, } : T extends ComplementSelection ? { @@ -768,6 +768,7 @@ export type Rendered< ? { type: "adverb", entry: AdverbEntry, + person: Person, ps: PsString[], e?: string, }