Skip to content

Commit

Permalink
added vocatives!
Browse files Browse the repository at this point in the history
  • Loading branch information
adueck committed Jul 24, 2024
1 parent 635a2cd commit b9269b8
Show file tree
Hide file tree
Showing 17 changed files with 1,070 additions and 144 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pashto-inflector",
"version": "7.1.7",
"version": "7.2.0",
"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",
Expand Down
4 changes: 2 additions & 2 deletions src/components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lingdocs/ps-react",
"version": "7.1.7",
"version": "7.2.0",
"description": "Pashto inflector library module with React components",
"main": "dist/components/library.js",
"module": "dist/components/library.js",
Expand Down
4 changes: 4 additions & 0 deletions src/components/src/InflectionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ const InflectionTable = ({
inf,
textOptions,
hideTitle,
vocative,
}: {
inf: T.Inflections | T.PluralInflections;
textOptions: T.TextOptions;
hideTitle?: boolean;
vocative?: boolean;
}) => {
// const [showingExplanation, setShowingExplanation] = useState(false);
/* istanbul ignore next */ // Insanely can't see the modal to close it
Expand Down Expand Up @@ -105,6 +107,8 @@ const InflectionTable = ({
<tbody>
{(!isPluralInfs
? ["Plain", "1st", "2nd"]
: vocative
? ["Voc.", "Plur. Voc."]
: ["Plural", "2nd Inf."]
).map((title, i) => (
<tr key={title}>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lingdocs/inflect",
"version": "7.1.7",
"version": "7.2.0",
"description": "Pashto inflector library",
"main": "dist/index.js",
"types": "dist/lib/library.d.ts",
Expand Down
34 changes: 34 additions & 0 deletions src/lib/src/accent-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
splitUpSyllables,
hasAccents,
countSyllables,
getAccentPos,
} from "./accent-helpers";

const toAccentFront = [
Expand All @@ -40,6 +41,27 @@ test(`accentOnFront should work`, () => {
});
});

const toGetAccentPos = [
{
input: makePsString("کورنۍ", "koranúy"),
output: 0,
},
{
input: makePsString("ستړی", "stúRay"),
output: 1,
},
{
input: makePsString("لیدلی", "leedulay"),
output: -1,
},
];

test(`getAccentPos should work`, () => {
toGetAccentPos.forEach((item) => {
expect(getAccentPos(item.input)).toEqual(item.output);
});
});

const toAccentPastParticiple = [
{
input: makePsString("پرېښی", "prexay"),
Expand All @@ -59,6 +81,8 @@ test(`accentPastParticiple should work`, () => {

test(`splitUpSyllables should work`, () => {
expect(splitUpSyllables("akheestul")).toEqual(["akh", "eest", "ul"]);
expect(splitUpSyllables("kh")).toEqual([]);
expect(splitUpSyllables("x")).toEqual([]);
});

test("countSyllables", () => {
Expand All @@ -74,9 +98,19 @@ test("countSyllables", () => {
test(`accentOnFSylsOnNFromEnd should work`, () => {
expect(accentFSylsOnNFromEnd(["pu", "xtaa", "nu"], 0)).toBe("puxtaanú");
expect(accentFSylsOnNFromEnd(["leed", "ul", "ay"], 1)).toBe("leedúlay");
expect(accentFSylsOnNFromEnd([], 0)).toBe("");
expect(accentFSylsOnNFromEnd("x", 0)).toBe("x");
});

test(`accentOnNFromEnd should work`, () => {
expect(accentOnNFromEnd({ p: "ښه", f: "xu" }, 0)).toEqual({
p: "ښه",
f: "xú",
});
expect(accentOnNFromEnd({ p: "ښ", f: "x" }, 0)).toEqual({
p: "ښ",
f: "x",
});
expect(accentOnNFromEnd({ p: "پښتانه", f: "puxtaanu" }, 0)).toEqual({
p: "پښتانه",
f: "puxtaanú",
Expand Down
32 changes: 28 additions & 4 deletions src/lib/src/accent-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ export function accentFSylsOnNFromEnd(
n: number
): string {
if (typeof syls === "string") {
return accentFSylsOnNFromEnd(splitUpSyllables(syls), n);
const s = splitUpSyllables(syls);
if (s.length === 0) {
return syls;
}
return accentFSylsOnNFromEnd(s, n);
}
if (syls.length === 0) {
return "";
Expand All @@ -100,9 +104,9 @@ export function accentFSylsOnNFromEnd(
export function accentOnNFromEnd(ps: T.PsString, n: number): T.PsString {
const fNoAccents = removeAccents(ps.f);
const fSyls = splitUpSyllables(fNoAccents);
// TODO: enable this and fix the tests it breaks!!!
// don't add accent if only one syllable
// if (fSyls.length === 1) return makePsString(ps.p, fNoAccents);
if (fSyls.length === 0) {
return ps;
}
return makePsString(ps.p, accentFSylsOnNFromEnd(fSyls, n));
}

Expand All @@ -127,6 +131,26 @@ export function accentLetter(s: string): string {
});
}

/**
* returns the position of an accent on a word, 0 being the last syllable
* -1 means there is no accent
*
* @param ps
*/
export function getAccentPos(ps: T.PsString): number {
const syls = splitUpSyllables(ps.f);
for (let i = 0; i < syls.length; i++) {
if (hasAccents(syls.at(-(i + 1)) || "")) {
return i;
}
}
return -1;
}

export function accentIsOnEnd(ps: T.PsString): boolean {
return getAccentPos(ps) === 0;
}

export function accentPsSyllable(ps: T.PsString): T.PsString {
return {
p: ps.p,
Expand Down
36 changes: 36 additions & 0 deletions src/lib/src/fp-ps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,42 @@ export function pureSingleOrLengthOpts<A>(a: A): T.SingleOrLengthOpts<A> {
return a;
}

export function applyPsString(
f:
| {
p: (x: string) => string;
}
| {
f: (x: string) => string;
}
| {
p: (x: string) => string;
f: (x: string) => string;
},
x: T.PsString
): T.PsString {
if ("p" in f && "f" in f) {
return {
p: f.p(x.p),
f: f.f(x.f),
};
}
if ("p" in f) {
return {
p: f.p(x.p),
f: x.f,
};
}
return {
p: x.p,
f: f.f(x.f),
};
}

export function mapGen<A, B>(f: (x: A) => B, x: A): B {
return f(x);
}

/**
* like and applicative <*> operator for SingleOrLengthOpts
*
Expand Down
2 changes: 1 addition & 1 deletion src/lib/src/inflection-pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "./type-predicates";

export function getInflectionPattern(
e: T.NounEntry | T.AdjectiveEntry
e: T.InflectableEntry
): T.InflectionPattern {
return isPattern1Entry(e)
? T.InflectionPattern.Basic
Expand Down
8 changes: 0 additions & 8 deletions src/lib/src/p-text-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
splitDoubleWord,
endsInConsonant,
addOEnding,
endsInShwa,
splitPsByVarients,
endsWith,
trimOffPs,
Expand Down Expand Up @@ -1596,13 +1595,6 @@ test("addOEnding", () => {
});
});

test("endsInShwa", () => {
expect(endsInShwa({ p: "ښایسته", f: "xaaystú" })).toBe(true);
expect(endsInShwa({ p: "ښایسته", f: "xaaystu" })).toBe(true);
expect(endsInShwa({ p: "ښایسته", f: "xaaysta" })).toBe(false);
expect(endsInShwa({ p: "کور", f: "kor" })).toBe(false);
});

test("splitPsByVarients", () => {
expect(
splitPsByVarients({ p: "حوادث, حادثات", f: "hawáadis, haadisáat" })
Expand Down
Loading

0 comments on commit b9269b8

Please sign in to comment.