inflecting adverbs

This commit is contained in:
adueck 2022-11-01 19:30:05 +05:00
parent 3303920b8c
commit 64265e9e20
9 changed files with 45 additions and 29 deletions

4
package-lock.json generated
View File

@ -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": {

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -19,7 +19,7 @@ function chooseInflection(inflections: T.UnisexSet<T.InflectionSet>, pers: T.Per
return inflections[gender][infNumber];
}
export function inflectAdjective(a: T.AdjectiveSelection, person: T.Person, inflected: boolean): T.ArrayOneOrMore<T.PsString> {
export function inflectAdvAdj(a: T.AdjectiveSelection | T.AdverbSelection, person: T.Person, inflected: boolean): T.ArrayOneOrMore<T.PsString> {
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<T.PsString> {
return inflectAdvAdj(a, person, inflected)
}
export function renderAdjectiveSelection(a: T.AdjectiveSelection, person: T.Person, inflected: boolean, isLocationSingSandwich?: boolean): T.Rendered<T.AdjectiveSelection> {
const eWord = getEnglishWord(a.entry);
const e = !eWord

View File

@ -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<T.APSelection> {
export function renderAPSelection({ selection }: T.APSelection, person: T.Person): T.Rendered<T.APSelection> {
if (selection.type === "sandwich") {
return {
type: "AP",
@ -13,7 +14,7 @@ export function renderAPSelection({ selection }: T.APSelection): T.Rendered<T.AP
}
return {
type: "AP",
selection: renderAdverbSelection(selection),
selection: renderAdverbSelection(selection, person),
};
}
@ -32,4 +33,22 @@ export function renderLocativeAdverbSelection({ entry }: T.LocativeAdverbSelecti
person: T.Person.FirstSingMale,
role: "none",
};
}
export function renderAdverbSelection(a: T.AdverbSelection, person: T.Person): T.Rendered<T.AdverbSelection> {
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,
};
}

View File

@ -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<T.AdverbSelection> {
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<T.EquativeTense, (p: T.Person, n: boolean) => string[]> = {
present: (p, n) => {
return [

View File

@ -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 [

View File

@ -744,7 +744,7 @@ export type Rendered<
: T extends APSelection
? {
type: "AP",
selection: Rendered<APSelection["selection"]>
selection: Rendered<APSelection["selection"]>,
}
: T extends ComplementSelection
? {
@ -768,6 +768,7 @@ export type Rendered<
? {
type: "adverb",
entry: AdverbEntry,
person: Person,
ps: PsString[],
e?: string,
}