From 1abc83ee01dfb7dfb56e908526dfb9ebf05d716d Mon Sep 17 00:00:00 2001 From: adueck Date: Fri, 23 Aug 2024 10:21:17 -0400 Subject: [PATCH] finishing parsing noun words --- src/lib/src/parsing/parse-fem-noun.ts | 23 ++-- src/lib/src/parsing/parse-irregular-plural.ts | 11 +- src/lib/src/parsing/parse-noun-new.test.ts | 104 +++++++++++++++++- vocab/mini-dict-tss.ts | 3 + 4 files changed, 132 insertions(+), 9 deletions(-) diff --git a/src/lib/src/parsing/parse-fem-noun.ts b/src/lib/src/parsing/parse-fem-noun.ts index 5e95d53..26d47b6 100644 --- a/src/lib/src/parsing/parse-fem-noun.ts +++ b/src/lib/src/parsing/parse-fem-noun.ts @@ -67,7 +67,7 @@ function parsePattern1( dictionary .queryP(p) .filter(andSuccTp(tp.isFemNounEntry, tp.isPattern1Entry)); - const plain = first.s.endsWith("ه") + const plain = ["ه", "ع"].some((v) => first.s.endsWith(v)) ? p1Lookup(first.s).map((entry) => ({ inflection: [0], gender: ["fem"], @@ -84,12 +84,21 @@ function parsePattern1( })) : []; const inflected = first.s.endsWith("ې") - ? p1Lookup(first.s.slice(0, -1) + "ه").map((entry) => ({ - inflection: [1], - gender: ["fem"], - entry, - given: first.s, - })) + ? (() => { + const base = first.s.slice(0, -1); + const lookups = [ + ...p1Lookup(base + "ه"), + ...(["ح", "ع"].some((v) => first.s.at(-2) === v) + ? p1Lookup(base) + : []), + ]; + return lookups.map((entry) => ({ + inflection: [1], + gender: ["fem"], + entry, + given: first.s, + })); + })() : []; const doubleInflected = first.s.endsWith("و") ? p1Lookup(first.s.slice(0, -1) + "ه").map((entry) => ({ diff --git a/src/lib/src/parsing/parse-irregular-plural.ts b/src/lib/src/parsing/parse-irregular-plural.ts index c88e1b6..fa791c8 100644 --- a/src/lib/src/parsing/parse-irregular-plural.ts +++ b/src/lib/src/parsing/parse-irregular-plural.ts @@ -1,5 +1,6 @@ import * as T from "../../../types"; import { DictionaryAPI } from "../dictionary/dictionary"; +import { endsInConsonant } from "../p-text-helpers"; import * as tp from "../type-predicates"; import { returnParseResults } from "./utils"; @@ -16,7 +17,10 @@ export function parseIrregularPlural( .filter(tp.isNounEntry) .map>((entry) => ({ entry, - gender: tp.isFemNounEntry(entry) ? "fem" : "masc", + gender: + tp.isFemNounEntry(entry) && !hasMasculineArabicPlural(entry) + ? "fem" + : "masc", inflected: false, given: first.s, plural: true, @@ -75,3 +79,8 @@ export function parseIrregularPlural( ...inflectedAfterLongSep, ]; } + +function hasMasculineArabicPlural(e: T.FemNounEntry): boolean { + if (!e.app || !e.apf) return false; + return endsInConsonant({ p: e.app, f: e.apf }); +} diff --git a/src/lib/src/parsing/parse-noun-new.test.ts b/src/lib/src/parsing/parse-noun-new.test.ts index 51900cc..61256d1 100644 --- a/src/lib/src/parsing/parse-noun-new.test.ts +++ b/src/lib/src/parsing/parse-noun-new.test.ts @@ -44,10 +44,12 @@ const zooy = testDictionary.nounLookup("زوی")[0]; const loor = testDictionary.nounLookup("لور")[0]; const nabee = testDictionary.nounLookup("نبي")[0]; const lafz = testDictionary.nounLookup("لفظ")[0]; +const fatha = testDictionary.nounLookup("فتح")[0]; +const nafa = testDictionary.nounLookup("نفع")[0]; +const tajraba = testDictionary.nounLookup("تجربه")[0]; // TODO: test for adjective errors etc // bundled plural -// TODO: منابع const tests: { category: string; @@ -216,6 +218,93 @@ const tests: { }, ], }, + { + category: "pattern 1 fem nouns with ح ه etc", + cases: [ + { + input: "فتح", + output: [ + { + inflected: false, + selection: { + ...makeNounSelection(fatha, undefined), + }, + }, + ], + }, + { + input: "فتحې", + output: [ + { + inflected: true, + selection: { + ...makeNounSelection(fatha, undefined), + }, + }, + { + inflected: false, + selection: { + ...makeNounSelection(fatha, undefined), + number: "plural", + }, + }, + ], + }, + { + input: "فتحو", + output: [ + { + inflected: true, + selection: { + ...makeNounSelection(fatha, undefined), + number: "plural", + }, + }, + ], + }, + { + input: "نفع", + output: [ + { + inflected: false, + selection: { + ...makeNounSelection(nafa, undefined), + }, + }, + ], + }, + { + input: "نفعې", + output: [ + { + inflected: true, + selection: { + ...makeNounSelection(nafa, undefined), + }, + }, + { + inflected: false, + selection: { + ...makeNounSelection(nafa, undefined), + number: "plural", + }, + }, + ], + }, + { + input: "نفعو", + output: [ + { + inflected: true, + selection: { + ...makeNounSelection(nafa, undefined), + number: "plural", + }, + }, + ], + }, + ], + }, { category: "group/plural nouns", // to do fem plural تسبیج, هټکرۍ, مایع @@ -1625,6 +1714,19 @@ const tests: { }, ], }, + { + input: "تجارب", + output: [ + { + inflected: false, + selection: { + ...makeNounSelection(tajraba, undefined), + number: "plural", + gender: "masc", + }, + }, + ], + }, ], }, ]; diff --git a/vocab/mini-dict-tss.ts b/vocab/mini-dict-tss.ts index c91fe1d..b9a75c1 100644 --- a/vocab/mini-dict-tss.ts +++ b/vocab/mini-dict-tss.ts @@ -47,4 +47,7 @@ export const entries: T.DictionaryEntry["ts"][] = [ 1527812582, // دعا 1591803598624, // هتکړۍ 1527812861, // لور - loor + 1589023873660, // فتح - fatha + 1527814342, // نفع - nafa + 1527815329, // تجربه ];