This commit is contained in:
lingdocs 2021-10-05 18:51:44 -04:00
parent 6aa7c9a36e
commit 0594185d8c
3 changed files with 17 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@lingdocs/pashto-inflector",
"version": "1.0.8",
"version": "1.0.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",

View File

@ -49,7 +49,12 @@ test("getEnglishWord", () => {
in: {"ts":1527815008,"i":8433,"p":"شودې","f":"shoodé","g":"shoode","e":"milk","c":"n. f. pl."},
out: { plural: "milk" },
},
]
// adjective
{
in: {"ts":1527815306,"i":7530,"p":"ستړی","f":"stúRey","g":"stuRey","e":"tired","c":"adj."},
out: "tired",
},
];
tests.forEach((t) => {
expect(getEnglishWord(t.in)).toEqual(t.out);
});

View File

@ -4,15 +4,20 @@ import * as T from "../types";
* returns the singular and plural english word for a Pashto entry if possible
* NOTE: only works with nouns and adjectives
*
* @param entry
* @returns
* @param entry dictionary entry
* @returns undefined if not possible, string for adjective, { singular?: string, plural: string } for noun
*/
export function getEnglishWord(entry: T.DictionaryEntry): {
singular?: string,
plural: string,
} | undefined {
if (!entry.c || !entry.c.includes("n.") || entry.c.includes("adj.")) {
return undefined;
} | string | undefined {
if (!entry.c) return undefined;
const isNoun = entry.c.includes("n.");
const isAdj = entry.c.includes("adj.");
if (!isNoun && !isAdj) return undefined;
const base = entry.e.split(",")[0].split(";")[0].split("(")[0].trim();
if (isAdj && !isNoun) {
return base;
}
if (entry.ec && entry.ep) {
return {
@ -20,7 +25,6 @@ export function getEnglishWord(entry: T.DictionaryEntry): {
plural: entry.ep,
};
}
const base = entry.e.split(",")[0].split(";")[0].split("(")[0].trim();
if (entry.c.includes("pl.")) {
return {
plural: base,