better inflection on irregulars

This commit is contained in:
adueck 2023-01-26 17:19:59 +05:00
parent 803ad8c78e
commit f25ebaaf62
6 changed files with 41 additions and 23 deletions

4
package-lock.json generated
View File

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

View File

@ -1,6 +1,6 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.7.4", "version": "5.7.5",
"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,6 +1,6 @@
{ {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "5.7.4", "version": "5.7.5",
"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": "5.7.4", "version": "5.7.5",
"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

@ -600,7 +600,7 @@ const nouns: {
masc: [ masc: [
[{ p: "غر", f: "ghar" }], [{ p: "غر", f: "ghar" }],
[{ p: "غره", f: "ghru" }], [{ p: "غره", f: "ghru" }],
[{ p: "غرو", f: "ghró" }], [{ p: "غرو", f: "ghro" }],
], ],
}, },
plural: { plural: {
@ -625,13 +625,13 @@ const nouns: {
// TODO: use smarter system using new isType5Entry predicates, to allow for not using the redundant one syllable accents with these // TODO: use smarter system using new isType5Entry predicates, to allow for not using the redundant one syllable accents with these
masc: [ masc: [
[{ p: "خر", f: "khur" }], [{ p: "خر", f: "khur" }],
[{ p: "خره", f: "khrú" }], [{ p: "خره", f: "khru" }],
[{ p: "خرو", f: "khró" }], [{ p: "خرو", f: "khro" }],
], ],
fem: [ fem: [
[{ p: "خره", f: "khrá" }], [{ p: "خره", f: "khra" }],
[{ p: "خرې", f: "khré" }], [{ p: "خرې", f: "khre" }],
[{ p: "خرو", f: "khró" }], [{ p: "خرو", f: "khro" }],
], ],
}, },
}, },
@ -1232,6 +1232,23 @@ const nouns: {
}, },
out: false, out: false,
}, },
{
in: {"ts":1610795367898,"i":6978,"p":"رشوت خور","f":"rishwat khór","g":"rishwatkhor","e":"bribe-taker, corrupt","r":4,"c":"n. m. anim. unisex / adj.","infap":"رشوت خواره","infaf":"rishwat khwaaru","infbp":"رشوت خور","infbf":"rishwat khwar"},
out: {
inflections: {
masc: [
[{p: "رشوت خور", f: "rishwat khór"}],
[{p: "رشوت خواره", f: "rishwat khwaarú"}],
[{p: "رشوت خورو", f: "rishwat khwaró"}],
],
fem: [
[{p: "رشوت خوره", f: "rishwat khwará"}],
[{p: "رشوت خورې", f: "rishwat khwaré"}],
[{p: "رشوت خورو", f: "rishwat khwaró"}],
],
},
},
},
]; ];
const others: T.DictionaryEntry[] = [ const others: T.DictionaryEntry[] = [

View File

@ -31,6 +31,7 @@ import {
} from "./accent-helpers"; } from "./accent-helpers";
import * as T from "../../types"; import * as T from "../../types";
import { splitFIntoPhonemes } from "./phonetics-to-diacritics"; import { splitFIntoPhonemes } from "./phonetics-to-diacritics";
import { splitPsString } from "./splitPsString";
const endingInSingleARegex = /[^a]'??[aá]'??$/; const endingInSingleARegex = /[^a]'??[aá]'??$/;
const endingInHeyOrAynRegex = /[^ا][هع]$/; const endingInHeyOrAynRegex = /[^ا][هع]$/;
@ -184,18 +185,18 @@ function handleFemNoun(word: T.DictionaryEntryNoFVars): T.InflectorOutput {
// LEVEL 3 FUNCTIONS // LEVEL 3 FUNCTIONS
function inflectIrregularUnisex(p: string, f: string, inflections: Array<{p: string, f: string}>): T.Inflections { function inflectIrregularUnisex(p: string, f: string, inflections: Array<{p: string, f: string}>): T.Inflections {
const inf1 = removeAccents(inflections[1]); const inf1 = removeAccents(inflections[1]);
const inf0syls = splitFIntoPhonemes(inflections[0].f); const inf0 = removeAccents(inflections[0]);
const inf0f = accentFSylsOnNFromEnd(inf0syls, 0); const inf0fSyls = splitUpSyllables(inf0.f).length;
return { return {
masc: [ masc: [
[{p, f}], [{p, f}],
[{p: inflections[0].p, f: inf0f, }], [{p: inflections[0].p, f: `${inf0.f.slice(0, -1)}${inf0fSyls === 1 ? "u" : "ú"}` }],
[{p: `${inf1.p}و`, f: `${inf1.f}ó`}], [{p: `${inf1.p}و`, f: `${inf1.f}${inf0fSyls === 1 ? "o" : "ó"}`}],
], ],
fem: [ fem: [
[{p: `${inf1.p}ه`, f: `${inf1.f}á`}], [{p: `${inf1.p}ه`, f: `${inf1.f}${inf0fSyls === 1 ? "a" : "á"}`}],
[{p: `${inf1.p}ې`, f: `${inf1.f}é`}], [{p: `${inf1.p}ې`, f: `${inf1.f}${inf0fSyls === 1 ? "e" : "é"}`}],
[{p: `${inf1.p}و`, f: `${inf1.f}ó`}], [{p: `${inf1.p}و`, f: `${inf1.f}${inf0fSyls === 1 ? "o" : "ó"}`}],
], ],
}; };
} }
@ -324,14 +325,14 @@ function inflectRegularEmphasizedYeyMasc(p: string, f: string): T.Inflections {
} }
function inflectIrregularMasc(p: string, f: string, inflections: Array<{p: string, f: string}>): T.Inflections { function inflectIrregularMasc(p: string, f: string, inflections: Array<{p: string, f: string}>): T.Inflections {
const inf0f = splitUpSyllables(inflections[0].f).length > 1 let inf0f = removeAccents(inflections[0].f);
? accentFSylsOnNFromEnd(inflections[0].f, 0) const inf0syls = splitUpSyllables(f).length;
: inflections[0].f const inf1f = removeAccents(inflections[1].f);
return { return {
masc: [ masc: [
[{p, f}], [{p, f}],
[{p: inflections[0].p, f: inf0f}], [{p: inflections[0].p, f: `${inf0f.slice(0, -1)}${inf0syls === 1 ? "u" : "ú"}`}],
[{p: `${inflections[1].p}و`, f: `${removeAccents(inflections[1].f)}ó`}], [{p: `${inflections[1].p}و`, f: `${inf1f}${inf0syls === 1 ? "o" : "ó"}`}],
], ],
}; };
} }