expose accent counting functions and allow for plural forms on non inflecting nouns

This commit is contained in:
lingdocs 2021-10-17 20:58:50 -04:00
parent c1fd83b8de
commit 02ff873536
5 changed files with 36 additions and 7 deletions

View File

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

View File

@ -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;
}
/**

View File

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

View File

@ -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 };

View File

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