Skip to content

Commit

Permalink
finishing parsing noun words
Browse files Browse the repository at this point in the history
  • Loading branch information
adueck committed Aug 23, 2024
1 parent 32f7618 commit 1abc83e
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 9 deletions.
23 changes: 16 additions & 7 deletions src/lib/src/parsing/parse-fem-noun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FemNounBaseParse>((entry) => ({
inflection: [0],
gender: ["fem"],
Expand All @@ -84,12 +84,21 @@ function parsePattern1(
}))
: [];
const inflected = first.s.endsWith("ې")
? p1Lookup(first.s.slice(0, -1) + "ه").map<FemNounBaseParse>((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<FemNounBaseParse>((entry) => ({
inflection: [1],
gender: ["fem"],
entry,
given: first.s,
}));
})()
: [];
const doubleInflected = first.s.endsWith("و")
? p1Lookup(first.s.slice(0, -1) + "ه").map<FemNounBaseParse>((entry) => ({
Expand Down
11 changes: 10 additions & 1 deletion src/lib/src/parsing/parse-irregular-plural.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -16,7 +17,10 @@ export function parseIrregularPlural(
.filter(tp.isNounEntry)
.map<T.ParsedNounWord<T.NounEntry>>((entry) => ({
entry,
gender: tp.isFemNounEntry(entry) ? "fem" : "masc",
gender:
tp.isFemNounEntry(entry) && !hasMasculineArabicPlural(entry)
? "fem"
: "masc",
inflected: false,
given: first.s,
plural: true,
Expand Down Expand Up @@ -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 });
}
104 changes: 103 additions & 1 deletion src/lib/src/parsing/parse-noun-new.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 تسبیج, هټکرۍ, مایع
Expand Down Expand Up @@ -1625,6 +1714,19 @@ const tests: {
},
],
},
{
input: "تجارب",
output: [
{
inflected: false,
selection: {
...makeNounSelection(tajraba, undefined),
number: "plural",
gender: "masc",
},
},
],
},
],
},
];
Expand Down
3 changes: 3 additions & 0 deletions vocab/mini-dict-tss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ export const entries: T.DictionaryEntry["ts"][] = [
1527812582, // دعا
1591803598624, // هتکړۍ
1527812861, // لور - loor
1589023873660, // فتح - fatha
1527814342, // نفع - nafa
1527815329, // تجربه
];

0 comments on commit 1abc83e

Please sign in to comment.