more work on parser and fixed some verb conjugation bugs

This commit is contained in:
adueck 2023-08-30 17:32:54 +04:00
parent 035e59ae19
commit f59e3c6550
13 changed files with 112 additions and 39 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 KiB

After

Width:  |  Height:  |  Size: 149 KiB

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "6.0.6", "version": "6.0.7",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "6.0.6", "version": "6.0.7",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "6.0.6", "version": "6.0.7",
"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

@ -1,12 +1,12 @@
{ {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "6.0.6", "version": "6.0.7",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "6.0.6", "version": "6.0.7",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@formkit/auto-animate": "^1.0.0-beta.3", "@formkit/auto-animate": "^1.0.0-beta.3",

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "6.0.6", "version": "6.0.7",
"description": "Pashto inflector library module with React components", "description": "Pashto inflector library module with React components",
"main": "dist/components/library.js", "main": "dist/components/library.js",
"module": "dist/components/library.js", "module": "dist/components/library.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/inflect", "name": "@lingdocs/inflect",
"version": "6.0.6", "version": "6.0.7",
"description": "Pashto inflector library", "description": "Pashto inflector library",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/lib/library.d.ts", "types": "dist/lib/library.d.ts",

View File

@ -97,6 +97,9 @@ const sturayKawul = wordQuery("ستړی کول", "verb");
const raawrul = wordQuery("راوړل", "verb"); const raawrul = wordQuery("راوړل", "verb");
const ooPh: T.PH = { type: "PH", ps: { p: "و", f: "óo" } }; const ooPh: T.PH = { type: "PH", ps: { p: "و", f: "óo" } };
// TODO: test all cases of یوړ یوړه یووړ یووړه
// and then parsing of all those!!
const tests: { const tests: {
label: string; label: string;
cases: { cases: {
@ -1115,6 +1118,7 @@ test("special endings", () => {
{ p: "خوت", f: "khot" }, { p: "خوت", f: "khot" },
// // TODO: is this even right? // // TODO: is this even right?
// { p: "خوته", f: "khotu" }, // { p: "خوته", f: "khotu" },
// { p: "خته", f: "khatu" }, ???
// { p: "خوتو", f: "khoto" }, // { p: "خوتو", f: "khoto" },
], ],
}, },
@ -1142,8 +1146,7 @@ test("special endings", () => {
short: [ short: [
{ p: "لید", f: "léed" }, { p: "لید", f: "léed" },
// // TODO: is this even right? // // TODO: is this even right?
// { p: "خوته", f: "khotu" }, { p: "لیده", f: "leedú" },
// { p: "خوتو", f: "khoto" },
], ],
}, },
person: 4, person: 4,
@ -1167,7 +1170,10 @@ test("special endings", () => {
type: "VB", type: "VB",
ps: { ps: {
long: [{ p: "وړلو", f: "wRulo" }], long: [{ p: "وړلو", f: "wRulo" }],
short: [{ p: "ووړ", f: "woR" }], short: [
{ p: "ووړ", f: "woR" },
{ p: "وړه", f: "wRu" },
],
}, },
person: 4, person: 4,
info: { info: {
@ -1180,6 +1186,32 @@ test("special endings", () => {
], ],
], ],
}, },
{
verb: raawrul,
tense: "imperfectivePast",
result: [
[],
[
{
type: "VB",
ps: {
long: [{ p: "راوړلو", f: "raawRúlo" }],
short: [
{ p: "راووړ", f: "raawóR" },
{ p: "راوړه", f: "raawRú" },
],
},
person: 4,
info: {
type: "verb",
aspect: "imperfective",
base: "root",
verb: raawrul,
},
},
],
],
},
// verbs ending in a dental ت or د // verbs ending in a dental ت or د
{ {
verb: rasedul, verb: rasedul,

View File

@ -8,7 +8,9 @@ import {
import { applySingleOrLengthOpts, fmapSingleOrLengthOpts } from "../fp-ps"; import { applySingleOrLengthOpts, fmapSingleOrLengthOpts } from "../fp-ps";
import { import {
concatPsString, concatPsString,
endsInConsonant,
getLength, getLength,
lastVowelNotAorO,
splitPsByVarients, splitPsByVarients,
} from "../p-text-helpers"; } from "../p-text-helpers";
import { import {
@ -116,7 +118,8 @@ const formulas: Record<
}, },
}; };
// TODO: dynamic and stative compounds // TODO: is وخوته masc ok ??
// TODO: what to do with khatu, khot, khotu - bi-directional
export function renderVerb({ export function renderVerb({
verb, verb,
tense, tense,
@ -375,17 +378,40 @@ function ensure3rdPast(
const tpps = splitPsByVarients( const tpps = splitPsByVarients(
makePsString(verb.entry.tppp, verb.entry.tppf) makePsString(verb.entry.tppp, verb.entry.tppf)
); );
return tpps.map(({ p, f }) => { if (verb.entry.p === "وړل" && aspect === "perfective") {
const tip = removeAccents( return [
verb.entry.separationAtP !== undefined { p: "ړ", f: "R" },
{ p: "ړ", f: "Ru" },
{ p: "وړ", f: "wuR" },
{ p: "وړه", f: "wRu" },
];
}
return tpps
.flatMap(({ p, f }) => {
if (p.endsWith("ووړ")) {
return [
{ p, f },
{ p: p.slice(0, -2) + "ړه", f: f.slice(0, -2) + "Ru" },
];
}
return [{ p, f }];
})
.map(({ p, f }) =>
verb.entry.separationAtP !== undefined && aspect === "perfective"
? makePsString( ? makePsString(
p.slice(verb.entry.separationAtP), p.slice(verb.entry.separationAtP),
f.slice(verb.entry.separationAtF) f.slice(verb.entry.separationAtF)
) )
: makePsString(p, f) : makePsString(p, f)
)
.flatMap((ps) =>
endsInConsonant(ps) && lastVowelNotAorO(ps.f)
? [ps, concatPsString(ps, { p: "ه", f: "u" })]
: [ps]
)
.map((ps) =>
aspect === "imperfective" ? accentOnNFromEnd(ps, 0) : removeAccents(ps)
); );
return aspect === "imperfective" ? accentOnNFromEnd(tip, 0) : tip;
});
// if it ends in a consonant, the special form will also have another // if it ends in a consonant, the special form will also have another
// variation ending with a ه - u // variation ending with a ه - u
// const endsInAConsonant = (pashtoConsonants.includes(tip.p.slice(-1)) || tip.f.slice(-1) === "w"); // const endsInAConsonant = (pashtoConsonants.includes(tip.p.slice(-1)) || tip.f.slice(-1) === "w");

View File

@ -1250,3 +1250,13 @@ export function lastVowelNotA(g: string): boolean {
} }
return matches[matches.length - 1] !== "a"; return matches[matches.length - 1] !== "a";
} }
export function lastVowelNotAorO(g: string): boolean {
const matches = g.match(/ee|aa|i|u|o|oo|U|e|a/g);
if (!matches) {
return true;
}
return (
matches[matches.length - 1] !== "a" && matches[matches.length - 1] !== "o"
);
}

View File

@ -6,7 +6,7 @@ import {
} from "../p-text-helpers"; } from "../p-text-helpers";
import { negativeParticle } from "../grammar-units"; import { negativeParticle } from "../grammar-units";
import * as grammarUnits from "../grammar-units"; import * as grammarUnits from "../grammar-units";
import { removeDuplicates } from "./vp-tools"; import { ensureNoHangingR, removeDuplicates } from "./vp-tools";
import { getEnglishFromRendered, getPashtoFromRendered } from "./np-tools"; import { getEnglishFromRendered, getPashtoFromRendered } from "./np-tools";
import { completeEPSelection, renderEP } from "./render-ep"; import { completeEPSelection, renderEP } from "./render-ep";
import { completeVPSelection } from "./vp-tools"; import { completeVPSelection } from "./vp-tools";
@ -391,7 +391,7 @@ function putKidsInKidsSection(
return [ return [
first, first,
...(enforceKidsSectionBlankout ? [kidsBlank] : kids), ...(enforceKidsSectionBlankout ? [kidsBlank] : kids),
...rest, ...ensureNoHangingR(rest),
]; ];
} }
return blocksWVars.map(insert); return blocksWVars.map(insert);

View File

@ -20,6 +20,8 @@ import { accentOnNFromEnd } from "../accent-helpers";
// like زما د ښځو لیدل // like زما د ښځو لیدل
// my seeing women... // my seeing women...
// seeing my women...
// the women seeing me...
export function renderNPSelection( export function renderNPSelection(
NP: T.NPSelection, NP: T.NPSelection,

View File

@ -1,7 +1,7 @@
import * as T from "../../../types"; import * as T from "../../../types";
import { mapVerbRenderedOutput } from "../fp-ps"; import { mapVerbRenderedOutput } from "../fp-ps";
import { removeAccents } from "../accent-helpers"; import { removeAccents } from "../accent-helpers";
import { getPersonFromNP, isPastTense } from "./vp-tools"; import { ensureNoHangingR, getPersonFromNP, isPastTense } from "./vp-tools";
import { isImperativeTense, isPattern4Entry } from "../type-predicates"; import { isImperativeTense, isPattern4Entry } from "../type-predicates";
import { renderVerb } from "../new-verb-engine/render-verb"; import { renderVerb } from "../new-verb-engine/render-verb";
import { renderEnglishVPBase } from "./english-vp-rendering"; import { renderEnglishVPBase } from "./english-vp-rendering";
@ -21,6 +21,9 @@ import {
import { renderComplementSelection } from "./render-complement"; import { renderComplementSelection } from "./render-complement";
import { statVerb } from "../new-verb-engine/roots-and-stems"; import { statVerb } from "../new-verb-engine/roots-and-stems";
// TODO: Issue with yo me R -- both in rendering (what to do - یوړ مې)
// and in parsing!
export function renderVP(VP: T.VPSelectionComplete): T.VPRendered { export function renderVP(VP: T.VPSelectionComplete): T.VPRendered {
const subject = getSubjectSelection(VP.blocks).selection; const subject = getSubjectSelection(VP.blocks).selection;
const object = getObjectSelection(VP.blocks).selection; const object = getObjectSelection(VP.blocks).selection;
@ -172,25 +175,6 @@ export function insertNegative(
} }
} }
function ensureNoHangingR(b: T.Block[]): T.Block[] {
return b.map((x) =>
x.block.type === "VB" &&
"short" in x.block.ps &&
x.block.ps.short.find((x) => x.p === "ړ")
? {
...x,
block: {
...x.block,
ps: {
...x.block.ps,
short: x.block.ps.short.filter((ps) => ps.p !== "ړ"),
},
},
}
: x
);
}
function swapEndingBlocks<X>(arr: X[], n: number = 1): X[] { function swapEndingBlocks<X>(arr: X[], n: number = 1): X[] {
return [ return [
...arr.slice(0, arr.length - (n + 1)), ...arr.slice(0, arr.length - (n + 1)),

View File

@ -361,3 +361,22 @@ export function ensure2ndPersSubjPronounAndNoConflict(
} }
throw new Error("error ensuring compatible VPSelection for imperative verb"); throw new Error("error ensuring compatible VPSelection for imperative verb");
} }
export function ensureNoHangingR(b: T.Block[]): T.Block[] {
return b.map((x) =>
x.block.type === "VB" &&
"short" in x.block.ps &&
x.block.ps.short.find((x) => x.p === "ړ")
? {
...x,
block: {
...x.block,
ps: {
...x.block.ps,
short: x.block.ps.short.filter((ps) => ps.p !== "ړ"),
},
},
}
: x
);
}