From 539f7eefdbf896889cfafb282ef633c644ec8610 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Mon, 18 Oct 2021 10:41:21 -0400 Subject: [PATCH] =?UTF-8?q?Plural=20inflection=20of=20Pattern=203=20animat?= =?UTF-8?q?ed=20nouns=20ie=20-=20=D8=B3=DB=8C=D9=84=D8=A7=D9=86=DB=8C?= =?UTF-8?q?=D8=A7=D9=86=20=D8=B3=DB=8C=D9=84=D8=A7=D9=86=DB=8C=D8=A7=D9=86?= =?UTF-8?q?=DB=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/lib/p-text-helpers.test.ts | 4 ++ src/lib/p-text-helpers.ts | 2 +- src/lib/pashto-inflector.test.ts | 85 +++++++++++++++++++------------- src/lib/pashto-inflector.ts | 36 ++++++++++++++ src/types.ts | 2 + 6 files changed, 96 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index 1c11ac6..2c85615 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "1.2.8", + "version": "1.2.9", "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/p-text-helpers.test.ts b/src/lib/p-text-helpers.test.ts index d382104..0ffbff5 100644 --- a/src/lib/p-text-helpers.test.ts +++ b/src/lib/p-text-helpers.test.ts @@ -1127,6 +1127,10 @@ test("splitPsByVarients", () => { test("endsWith", () => { expect(endsWith({ p: "ی", f: "ey" }, { p: "سړی", f: "saRey" })) .toBe(true); + expect(endsWith({ p: "ی", f: "éy" }, { p: "سړی", f: "saRey" })) + .toBe(true); + expect(endsWith({ p: "ی", f: "éy" }, { p: "سړی", f: "saRey" }, true)) + .toBe(false); // f variations should be removed in case of using DictionaryEntry expect(endsWith({ p: "ی", f: "ey" }, { p: "سړی", f: "saRey, saRaayyy" })) .toBe(true); diff --git a/src/lib/p-text-helpers.ts b/src/lib/p-text-helpers.ts index 9f8371f..095e7d8 100644 --- a/src/lib/p-text-helpers.ts +++ b/src/lib/p-text-helpers.ts @@ -1004,7 +1004,7 @@ export function endsWith( (("p" in ending) ? ps.p.slice(-ending.p.length) === ending.p : true) && ((fEnd) ? - ((matchAccent ? f.slice(-fEnd.length) : removeAccents(f.slice(-fEnd.length))) === fEnd) + ((matchAccent ? f.slice(-fEnd.length) : removeAccents(f.slice(-fEnd.length))) === (matchAccent ? fEnd : removeAccents(fEnd))) : true) ); } \ No newline at end of file diff --git a/src/lib/pashto-inflector.test.ts b/src/lib/pashto-inflector.test.ts index 594c52d..7f40c45 100644 --- a/src/lib/pashto-inflector.test.ts +++ b/src/lib/pashto-inflector.test.ts @@ -412,42 +412,41 @@ const nouns: Array<{ }, }, }, - // with irregular Pashto plural - // TODO: This should work with words like پلویان but not with words like ترورزامن - // { - // in: {"ts":1527820130,"i":2561,"p":"پلوی","f":"palawéy","g":"palawey","e":"adherent, supporter; the outside or further ox in a team of oxes grinding or threshing","c":"n. m. anim. unisex","ppp":"پلویان","ppf":"palawiyáan"}, - // out: { - // inflections: { - // masc: [ - // [{ p: "پلوی", f: "palawéy" }], - // [{ p: "پلوي", f: "palawée" }], - // [{ p: "پلویو", f: "palawiyo" }, { p: "پلوو", f: "palawó" }], - // ], - // fem: [ - // [{ p: "پلوۍ", f: "palawúy" }], - // [{ p: "پلوۍ", f: "palawúy" }], - // [{ p: "پلویو", f: "palawúyo" }, { p: "پلوو", f: "palawó" }], - // ], - // }, - // plural: { - // masc: [ - // [{ p: "پلویان", f: "palawiyáan" }], - // [{ p: "پلویانو", f: "palawiyáano" }], - // ], - // fem: [ - // [{ p: "پلویانې", f: "palawiyáane" }], - // [{ p: "پلویانو", f: "palawiyáano" }], - // ], - // }, - // }, - // }, + // with #3 pattern anim unisex + { + in: {"ts":1527820130,"i":2561,"p":"پلوی","f":"palawéy","g":"palawey","e":"adherent, supporter; the outside or further ox in a team of oxes grinding or threshing","c":"n. m. anim. unisex"}, + out: { + inflections: { + masc: [ + [{ p: "پلوی", f: "palawéy" }], + [{ p: "پلوي", f: "palawée" }], + [{ p: "پلویو", f: "palawiyo" }, { p: "پلوو", f: "palawó" }], + ], + fem: [ + [{ p: "پلوۍ", f: "palawúy" }], + [{ p: "پلوۍ", f: "palawúy" }], + [{ p: "پلویو", f: "palawúyo" }, { p: "پلوو", f: "palawó" }], + ], + }, + plural: { + masc: [ + [{ p: "پلویان", f: "palawiyáan" }], + [{ p: "پلویانو", f: "palawiyáano" }], + ], + fem: [ + [{ p: "پلویانې", f: "palawiyáane" }], + [{ p: "پلویانو", f: "palawiyáano" }], + ], + }, + }, + }, // ## MASCULINE // Masculine regular ending in ی { in: { ts: 1527815251, p: "سړی", - f: "saRey", + f: "saRéy", g: "", e: "man", c: "n. m.", @@ -456,11 +455,31 @@ const nouns: Array<{ out: { inflections: { masc: [ - [{p: "سړی", f: "saRey"}], - [{p: "سړي", f: "saRee"}], + [{p: "سړی", f: "saRéy"}], + [{p: "سړي", f: "saRée"}], [{p: "سړیو", f: "saRiyo"}, {p: "سړو", f: "saRo"}], ], - } + }, + }, + }, + // Masculine #3 anim + // TODO: Also do Fem #3 anim! + { + in: {"ts":1527819801,"i":8082,"p":"سیلانی","f":"seylaanéy","g":"seylaaney","e":"tourist, sightseer, visitor","c":"n. m. anim."}, + out: { + inflections: { + masc: [ + [{ p: "سیلانی", f: "seylaanéy" }], + [{ p: "سیلاني", f: "seylaanée" }], + [{ p: "سیلانیو", f: "seylaaniyo" }, { p: "سیلانو", f: "seylaano" }], + ], + }, + plural: { + masc: [ + [{ p: "سیلانیان", f: "seylaaniyáan" }], + [{ p: "سیلانیانو", f: "seylaaniyáano" }], + ], + }, }, }, // Masculine regular ending in ی with emphasis on end diff --git a/src/lib/pashto-inflector.ts b/src/lib/pashto-inflector.ts index 3ae85a1..b8d7668 100644 --- a/src/lib/pashto-inflector.ts +++ b/src/lib/pashto-inflector.ts @@ -20,6 +20,7 @@ import { endsInShwa, splitPsByVarients, removeEndTick, + endsWith, } from "./p-text-helpers"; import { hasAccents, @@ -463,6 +464,24 @@ function makePlural(w: T.DictionaryEntryNoFVars): { plural: T.PluralInflections fem: addSecondInf(concatPsString(base, { p: "انې", f: "áane" })), }; } + function addAnimN3UnisexPluralSuffix(): T.UnisexSet { + const b = removeAccents(w); + const base = { + p: b.p.slice(0, -1), + f: b.f.slice(0, -2), + }; + return { + masc: [ + [concatPsString(base, { p: "یان", f: "iyáan" })], + [concatPsString(base, { p: "یانو", f: "iyáano" })], + // TODO: or use addSecondInf method above? + ], + fem: [ + [concatPsString(base, { p: "یانې", f: "iyáane" })], + [concatPsString(base, { p: "یانو", f: "iyáano" })], + ], + }; + } function addFemLongVowelSuffix(): T.PluralInflectionSet { const base = removeEndTick(makePsString(w.p, w.f)); const baseWOutAccents = removeAccents(base); @@ -513,6 +532,10 @@ function makePlural(w: T.DictionaryEntryNoFVars): { plural: T.PluralInflections if (shortSquish && !anim) { return { arabicPlural, plural: { masc: addMascPluralSuffix(anim, shortSquish) }}; } + // TODO: Does the amount of syllables matter for this? + if (endsWith({ p: "ی", f: "éy" }, w, true) && w.c?.includes("anim.")) { + return { arabicPlural, plural: addAnimN3UnisexPluralSuffix() }; + } // usually shortSquish nouns would never have arabicPlurals -- so we don't have to worry about catching // arabic plurals for the animat ones, right? } @@ -528,6 +551,19 @@ function makePlural(w: T.DictionaryEntryNoFVars): { plural: T.PluralInflections }, }; } + if ( + type === "masc noun" && + endsWith({ p: "ی", f: "éy" }, w, true) && + anim + ) { + const { masc, ...rest } = addAnimN3UnisexPluralSuffix(); + return { + arabicPlural, + plural: { + masc, + }, + }; + } // TODO: What about endings in long ee / animate at inanimate if (type === "fem noun" && endsInAaOrOo(w) && (!w.infap)) { return { diff --git a/src/types.ts b/src/types.ts index 467f854..9fc5cc9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -408,6 +408,8 @@ export interface ArrayFixed extends Array { length: L; } +export type Wrapper = T & { __brand: "wrapped" }; + export type ArrayOneOrMore = { 0: T } & Array