From 02ff8735368e5c9bfff5ae6f1198aafe2b9f577e Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Sun, 17 Oct 2021 20:58:50 -0400 Subject: [PATCH] expose accent counting functions and allow for plural forms on non inflecting nouns --- package.json | 2 +- src/lib/accent-helpers.ts | 11 ++++++++--- src/lib/pashto-inflector.test.ts | 11 +++++++++++ src/lib/pashto-inflector.ts | 15 ++++++++++++--- src/library.ts | 4 ++++ 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 7c017a7..38d9d79 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "1.2.5", + "version": "1.2.6", "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/accent-helpers.ts b/src/lib/accent-helpers.ts index 83a7b5c..e170c43 100644 --- a/src/lib/accent-helpers.ts +++ b/src/lib/accent-helpers.ts @@ -6,7 +6,7 @@ * */ -import { makePsString } from "./p-text-helpers"; +import { makePsString, removeFVarients } from "./p-text-helpers"; import * as T from "../types"; /** @@ -54,8 +54,13 @@ export function accentPastParticiple(s: T.PsString): T.PsString { return makePsString(s.p, accentedF); } -export function splitUpSyllables(s: string): string[] { - return s.match(/ |([^a|e|i|o|u| ]*(aa|a|ey|ee|e|oo|o|i|u)[^a|e|i|o|u| ]*)/g) as string[]; +export function splitUpSyllables(f: string): string[] { + return f.match(/ |([^a|e|i|o|u| ]*(aa|a|ey|ee|e|oo|o|i|u)[^a|e|i|o|u| ]*)/g) as string[]; +} + +export function countSyllables(f: T.PsString | string): number { + if (typeof f !== "string") return countSyllables(f.f); + return splitUpSyllables(removeFVarients(f)).length; } /** diff --git a/src/lib/pashto-inflector.test.ts b/src/lib/pashto-inflector.test.ts index 1c7f500..594c52d 100644 --- a/src/lib/pashto-inflector.test.ts +++ b/src/lib/pashto-inflector.test.ts @@ -584,6 +584,17 @@ const nouns: Array<{ }, }, }, + { + in: {"ts":1527813508,"i":7058,"p":"زړه","f":"zRu","g":"zRu","e":"heart","c":"n. m.","noInf":true}, + out: { + plural: { + masc: [ + [{ p: "زړونه", f: "zRóona" }], + [{ p: "زړونو", f: "zRóono" }], + ], + }, + }, + }, // fem plural { in: {"ts":1527815129,"i":1013,"p":"اوبه","f":"oobú","g":"oobu","e":"water","c":"n. f. pl."}, diff --git a/src/lib/pashto-inflector.ts b/src/lib/pashto-inflector.ts index a32a6d2..3ae85a1 100644 --- a/src/lib/pashto-inflector.ts +++ b/src/lib/pashto-inflector.ts @@ -35,9 +35,6 @@ export function inflectWord(word: T.DictionaryEntry): T.InflectorOutput { // If it's a noun/adj, inflect accordingly // TODO: What about n. f. / adj. that end in ي ?? const w = removeFVarients(word); - if (w.noInf) { - return false; - } if (w.c?.includes("doub.")) { const words = splitDoubleWord(w); const inflected = words.map((x) => ensureUnisexInflections(inflectWord(x), x)); @@ -70,6 +67,9 @@ function handleUnisexWord(word: T.DictionaryEntryNoFVars): T.InflectorOutput { // TODO: !!! Handle weird endings / symbols ' etc. const pEnd = word.p.slice(-1); const plurals = makePlural(word); + if (word.noInf) { + return !plurals ? false : { ...plurals }; + } if (word.infap && word.infaf && word.infbp && word.infbf) { return { inflections: inflectIrregularUnisex(word.p, word.f, [ @@ -104,6 +104,9 @@ function handleUnisexWord(word: T.DictionaryEntryNoFVars): T.InflectorOutput { function handlePluralNoun(w: T.DictionaryEntryNoFVars): T.InflectorOutput { if (!w.c || !w.c.includes("n.")) return false; const plurals = makePlural(w); + if (w.noInf) { + return !plurals ? false : { ...plurals }; + } if (!plurals) return false; return { ...plurals }; } @@ -112,6 +115,9 @@ function handleMascNoun(w: T.DictionaryEntryNoFVars): T.InflectorOutput { // Get last letter of Pashto and last two letters of phonetics // TODO: !!! Handle weird endings / symbols ' etc. const plurals = makePlural(w); + if (w.noInf) { + return !plurals ? false : { ...plurals }; + } const pEnd = w.p.slice(-1); const fEnd = w.f.slice(-2); if (w.infap && w.infaf && w.infbp && w.infbf) { @@ -144,6 +150,9 @@ function handleFemNoun(word: T.DictionaryEntryNoFVars): T.InflectorOutput { const pEnd = word.p.slice(-1); const plurals = makePlural(word); + if (word.noInf) { + return !plurals ? false : { ...plurals }; + } if (endingInHeyOrAynRegex.test(word.p) && endingInSingleARegex.test(word.f)) { return { inflections: inflectRegularAFem(word.p, word.f), ...plurals }; diff --git a/src/library.ts b/src/library.ts index 575346e..9589bf4 100644 --- a/src/library.ts +++ b/src/library.ts @@ -91,6 +91,8 @@ import { import { removeAccents, hasAccents, + splitUpSyllables, + countSyllables, } from "./lib/accent-helpers"; import defaultTextOptions from "./lib/default-text-options"; import * as grammarUnits from "./lib/grammar-units"; @@ -134,6 +136,8 @@ export { addEnglish, parseEc, endsWith, + splitUpSyllables, + countSyllables, // protobuf helpers readDictionary, writeDictionary,