From 0594185d8c50505711c2af932d45144d06187134 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Tue, 5 Oct 2021 18:51:44 -0400 Subject: [PATCH] w adsj --- package.json | 2 +- src/lib/get-english-word.test.ts | 7 ++++++- src/lib/get-english-word.ts | 16 ++++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 33ad4dd..789cdd0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/get-english-word.test.ts b/src/lib/get-english-word.test.ts index 86011ca..37a7d60 100644 --- a/src/lib/get-english-word.test.ts +++ b/src/lib/get-english-word.test.ts @@ -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); }); diff --git a/src/lib/get-english-word.ts b/src/lib/get-english-word.ts index a071af7..fb3e203 100644 --- a/src/lib/get-english-word.ts +++ b/src/lib/get-english-word.ts @@ -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,