From d2083c9c96760bc77ab4ddab0d6eac1fbd7a29e5 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Thu, 24 Feb 2022 18:57:55 +0400 Subject: [PATCH] add accent on uy endings --- package.json | 2 +- src/lib/misc-helpers.ts | 8 ++++---- src/lib/pashto-inflector.test.ts | 35 +++++++++++++++++++++++++++----- src/lib/pashto-inflector.ts | 12 +++++------ 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 0d955d4..2f62805 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "1.5.0", + "version": "1.5.1", "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/lib/misc-helpers.ts b/src/lib/misc-helpers.ts index 5066dce..86c1057 100644 --- a/src/lib/misc-helpers.ts +++ b/src/lib/misc-helpers.ts @@ -158,15 +158,15 @@ export function randomNumber(minInclusive: number, maxExclusive: number): number * @param possiblePerson * @param existingPerson */ -export function personIsAllowed(possiblePerson: T.Person, existingPerson: T.Person): boolean { +export function personIsAllowed(possiblePerson: T.Person, existingPerson?: T.Person): boolean { const isFirstPerson = (p: T.Person) => [0, 1, 6, 7].includes(p); const isSecondPerson = (p: T.Person) => [2, 3, 8, 9].includes(p); // can't have both subject and object be 1st person - if (isFirstPerson(possiblePerson) && isFirstPerson(existingPerson)) { + if (isFirstPerson(possiblePerson) && (existingPerson && isFirstPerson(existingPerson))) { return false; } // can't have both subject and object be 2nd person - if (isSecondPerson(possiblePerson) && isSecondPerson(existingPerson)) { + if (isSecondPerson(possiblePerson) && (existingPerson && isSecondPerson(existingPerson))) { return false; } // otherwise it's ok @@ -178,7 +178,7 @@ export function personIsAllowed(possiblePerson: T.Person, existingPerson: T.Pers * * @param other */ -export function randomPerson(other: T.Person): T.Person { +export function randomPerson(other?: T.Person): T.Person { let newPerson: T.Person; do { newPerson = randomNumber(0, 12); diff --git a/src/lib/pashto-inflector.test.ts b/src/lib/pashto-inflector.test.ts index d6391d1..289ae85 100644 --- a/src/lib/pashto-inflector.test.ts +++ b/src/lib/pashto-inflector.test.ts @@ -202,6 +202,31 @@ const adjectives: Array<{ }, }, }, + { + in: { + ts: 1527812792, + p: "ښایسته", + f: "xaaystu", + g: "xaaystu", + e: "beautiful", + c: "adj.", + i: 1, + }, + out: { + inflections: { + masc: [ + [{p: "ښایسته", f: "xaaystu"}], + [{p: "ښایسته", f: "xaaystu"}], + [{p: "ښایستو", f: "xaaysto"}], + ], + fem: [ + [{p: "ښایسته", f: "xaaysta"}], + [{p: "ښایستې", f: "xaayste"}], + [{p: "ښایستو", f: "xaaysto"}], + ], + }, + }, + }, // numbers should inflect just like adjectives { in: {"ts":1588688995113,"i":8176,"p":"شپږ","f":"shpuG","g":"shpug","e":"six","c":"num."}, @@ -1018,8 +1043,8 @@ const nouns: Array<{ inflections: { fem: [ [{p: "دوستي", f: "dostee"}], - [{p: "دوستۍ", f: "dostuy"}], - [{p: "دوستیو", f: "dostuyo"}], + [{p: "دوستۍ", f: "dostúy"}], + [{p: "دوستیو", f: "dostúyo"}], ], }, }, @@ -1038,9 +1063,9 @@ const nouns: Array<{ out: { inflections: { fem: [ - [{p: "کرسۍ", f: "kUrsuy"}], - [{p: "کرسۍ", f: "kUrsuy"}], - [{p: "کرسیو", f: "kUrsuyo"}, { p: "کرسو", f: "kUrso"}], + [{p: "کرسۍ", f: "kUrsúy"}], + [{p: "کرسۍ", f: "kUrsúy"}], + [{p: "کرسیو", f: "kUrsúyo"}, { p: "کرسو", f: "kUrso"}], ], }, }, diff --git a/src/lib/pashto-inflector.ts b/src/lib/pashto-inflector.ts index e84f53e..1775979 100644 --- a/src/lib/pashto-inflector.ts +++ b/src/lib/pashto-inflector.ts @@ -379,21 +379,21 @@ function inflectRegularInanEeFem(p: string, f: string): T.Inflections { return { fem: [ [{p, f}], - [{p: `${baseP}ۍ`, f: `${baseF}uy`}], - [{p: `${baseP}یو`, f: `${baseF}uyo`}], + [{p: `${baseP}ۍ`, f: `${baseF}úy`}], + [{p: `${baseP}یو`, f: `${baseF}úyo`}], ], }; } function inflectRegularUyFem(p: string, f: string): T.Inflections { const baseP = p.slice(0, -1); - const baseF = f.slice(0, -2); + const baseF = removeAccents(f.slice(0, -2)); return { fem: [ - [{p, f}], - [{p, f}], + [{p, f: `${baseF}úy`}], + [{p, f: `${baseF}úy`}], [ - {p: `${baseP}یو`, f: `${baseF}uyo`}, + {p: `${baseP}یو`, f: `${baseF}úyo`}, {p: `${baseP}و`, f: `${baseF}o`}, ], ],