finishing parsing noun words

This commit is contained in:
adueck 2024-08-23 10:21:17 -04:00
parent 32f7618fff
commit 1abc83ee01
4 changed files with 132 additions and 9 deletions

View File

@ -67,7 +67,7 @@ function parsePattern1(
dictionary dictionary
.queryP(p) .queryP(p)
.filter(andSuccTp(tp.isFemNounEntry, tp.isPattern1Entry)); .filter(andSuccTp(tp.isFemNounEntry, tp.isPattern1Entry));
const plain = first.s.endsWith("ه") const plain = ["ه", "ع"].some((v) => first.s.endsWith(v))
? p1Lookup(first.s).map<FemNounBaseParse>((entry) => ({ ? p1Lookup(first.s).map<FemNounBaseParse>((entry) => ({
inflection: [0], inflection: [0],
gender: ["fem"], gender: ["fem"],
@ -84,12 +84,21 @@ function parsePattern1(
})) }))
: []; : [];
const inflected = first.s.endsWith("ې") const inflected = first.s.endsWith("ې")
? p1Lookup(first.s.slice(0, -1) + "ه").map<FemNounBaseParse>((entry) => ({ ? (() => {
inflection: [1], const base = first.s.slice(0, -1);
gender: ["fem"], const lookups = [
entry, ...p1Lookup(base + "ه"),
given: first.s, ...(["ح", "ع"].some((v) => first.s.at(-2) === v)
})) ? p1Lookup(base)
: []),
];
return lookups.map<FemNounBaseParse>((entry) => ({
inflection: [1],
gender: ["fem"],
entry,
given: first.s,
}));
})()
: []; : [];
const doubleInflected = first.s.endsWith("و") const doubleInflected = first.s.endsWith("و")
? p1Lookup(first.s.slice(0, -1) + "ه").map<FemNounBaseParse>((entry) => ({ ? p1Lookup(first.s.slice(0, -1) + "ه").map<FemNounBaseParse>((entry) => ({

View File

@ -1,5 +1,6 @@
import * as T from "../../../types"; import * as T from "../../../types";
import { DictionaryAPI } from "../dictionary/dictionary"; import { DictionaryAPI } from "../dictionary/dictionary";
import { endsInConsonant } from "../p-text-helpers";
import * as tp from "../type-predicates"; import * as tp from "../type-predicates";
import { returnParseResults } from "./utils"; import { returnParseResults } from "./utils";
@ -16,7 +17,10 @@ export function parseIrregularPlural(
.filter(tp.isNounEntry) .filter(tp.isNounEntry)
.map<T.ParsedNounWord<T.NounEntry>>((entry) => ({ .map<T.ParsedNounWord<T.NounEntry>>((entry) => ({
entry, entry,
gender: tp.isFemNounEntry(entry) ? "fem" : "masc", gender:
tp.isFemNounEntry(entry) && !hasMasculineArabicPlural(entry)
? "fem"
: "masc",
inflected: false, inflected: false,
given: first.s, given: first.s,
plural: true, plural: true,
@ -75,3 +79,8 @@ export function parseIrregularPlural(
...inflectedAfterLongSep, ...inflectedAfterLongSep,
]; ];
} }
function hasMasculineArabicPlural(e: T.FemNounEntry): boolean {
if (!e.app || !e.apf) return false;
return endsInConsonant({ p: e.app, f: e.apf });
}

View File

@ -44,10 +44,12 @@ const zooy = testDictionary.nounLookup("زوی")[0];
const loor = testDictionary.nounLookup("لور")[0]; const loor = testDictionary.nounLookup("لور")[0];
const nabee = testDictionary.nounLookup("نبي")[0]; const nabee = testDictionary.nounLookup("نبي")[0];
const lafz = 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 // TODO: test for adjective errors etc
// bundled plural // bundled plural
// TODO: منابع
const tests: { const tests: {
category: string; 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", category: "group/plural nouns",
// to do fem plural تسبیج, هټکرۍ, مایع // to do fem plural تسبیج, هټکرۍ, مایع
@ -1625,6 +1714,19 @@ const tests: {
}, },
], ],
}, },
{
input: "تجارب",
output: [
{
inflected: false,
selection: {
...makeNounSelection(tajraba, undefined),
number: "plural",
gender: "masc",
},
},
],
},
], ],
}, },
]; ];

View File

@ -47,4 +47,7 @@ export const entries: T.DictionaryEntry["ts"][] = [
1527812582, // دعا 1527812582, // دعا
1591803598624, // هتکړۍ 1591803598624, // هتکړۍ
1527812861, // لور - loor 1527812861, // لور - loor
1589023873660, // فتح - fatha
1527814342, // نفع - nafa
1527815329, // تجربه
]; ];