Skip to content

Commit

Permalink
mayo working on sandwiches
Browse files Browse the repository at this point in the history
  • Loading branch information
adueck committed Jan 23, 2025
1 parent 8980421 commit ba06fdf
Show file tree
Hide file tree
Showing 16 changed files with 343 additions and 184 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-website",
"version": "7.7.9",
"version": "7.7.10",
"type": "module",
"scripts": {
"patch": "npm version patch --no-git-tag-version && cd src/lib && npm version patch --no-git-tag-version && cd ../components && npm version patch --no-git-tag-version",
Expand Down
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.7.9",
"version": "7.7.10",
"description": "Pashto inflector library module with React components",
"main": "dist/components/library-cjs.js",
"module": "dist/components/library.js",
Expand Down
3 changes: 2 additions & 1 deletion src/components/src/vp-explorer/NPDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ function NPDisplay({
false,
"subject",
"none",
false
false,
"no"
);
const english = getEnglishFromRendered(rendered);
const pashto = getPashtoFromRendered(rendered, false);
Expand Down
2 changes: 1 addition & 1 deletion src/components/src/vp-explorer/chart-builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function buildVerbChart({
: ([...Array(12).keys()] as T.Person[]);
const isPast = isPastTense(tense);
const objNP: T.Rendered<T.NPSelection> | undefined = objectNP
? renderNPSelection(objectNP, false, false, "object", "none", false)
? renderNPSelection(objectNP, false, false, "object", "none", false, "no")
: undefined;
function conjugateAllPers(
p?: T.Person
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.7.9",
"version": "7.7.10",
"description": "Pashto inflector library",
"main": "dist/lib/library.cjs",
"module": "dist/lib/library.js",
Expand Down
29 changes: 29 additions & 0 deletions src/lib/src/phrase-building/mayo-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as T from "../../../types";
import { endsWith, psStringFromEntry } from "../p-text-helpers";
import { isPattern1Entry } from "../type-predicates";
import { accentOnNFromEnd, countSyllables } from "../accent-helpers";
import { monoidPsString } from "../fp-ps";
import { concatAll } from "fp-ts/lib/Monoid";

export function mayoOnWord(
isMayoSandwich: "req" | "opt" | "no" | undefined,
entry: T.InflectableEntry,
gender: T.Gender,
number: T.NounNumber
): "req" | "opt" | "no" {
return isMayoSandwich &&
isMayoSandwich !== "no" &&
isPattern1Entry(entry) &&
number === "singular" &&
gender === "masc" &&
!endsWith(entry, { p: "ه", f: "u" })
? isMayoSandwich
: "no";
}

export function addMayo(entry: T.InflectableEntry, req: boolean): T.PsString[] {
const base = psStringFromEntry(entry);
const ps1 = concatAll(monoidPsString)([base, { p: "ه", f: "a" }]);
const ps = countSyllables(base) === 1 ? accentOnNFromEnd(ps1, 1) : ps1;
return [ps, ...(!req ? [base] : [])];
}
121 changes: 73 additions & 48 deletions src/lib/src/phrase-building/render-adj.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,85 @@
import * as T from "../../../types";
import { inflectWord } from "../pashto-inflector";
import {
psStringFromEntry,
isUnisexSet,
} from "../p-text-helpers";
import { psStringFromEntry, isUnisexSet } from "../p-text-helpers";
import { getEnglishWord } from "../get-english-word";
import {
personGender,
personIsPlural,
} from "../misc-helpers";
import { personGender, personIsPlural } from "../misc-helpers";
import { renderSandwich } from "./render-sandwich";
import { isPattern1Entry } from "../type-predicates";
import { addMayo, mayoOnWord } from "./mayo-utils";

function chooseInflection(inflections: T.UnisexSet<T.InflectionSet>, pers: T.Person, inflected?: boolean): T.ArrayOneOrMore<T.PsString> {
const gender = personGender(pers);
const plural = personIsPlural(pers);
const infNumber = (plural ? 1 : 0) + (inflected ? 1 : 0);
return inflections[gender][infNumber];
function chooseInflection(
inflections: T.UnisexSet<T.InflectionSet>,
pers: T.Person,
inflected?: boolean
): T.ArrayOneOrMore<T.PsString> {
const gender = personGender(pers);
const plural = personIsPlural(pers);
const infNumber = (plural ? 1 : 0) + (inflected ? 1 : 0);
return inflections[gender][infNumber];
}

export function inflectAdvAdj(a: T.AdjectiveSelection | T.AdverbSelection, person: T.Person, inflected: boolean): T.ArrayOneOrMore<T.PsString> {
const infs = inflectWord(a.entry);
if (!infs) {
return [psStringFromEntry(a.entry)];
}
if (!infs.inflections || !isUnisexSet(infs.inflections)) {
throw new Error("error getting inflections for adjective, looks like a noun's inflections");
}
return chooseInflection(infs.inflections, person, inflected);
export function inflectAdvAdj(
a: T.AdjectiveSelection | T.AdverbSelection,
person: T.Person,
inflected: boolean,
mayo: "req" | "opt" | "no"
): T.ArrayOneOrMore<T.PsString> {
if (mayo !== "no") {
return addMayo(a.entry, mayo === "req") as T.ArrayOneOrMore<T.PsString>;
}
const infs = inflectWord(a.entry);
if (!infs) {
return [psStringFromEntry(a.entry)];
}
if (!infs.inflections || !isUnisexSet(infs.inflections)) {
throw new Error(
"error getting inflections for adjective, looks like a noun's inflections"
);
}
return chooseInflection(infs.inflections, person, inflected);
}

export function inflectAdjective(a: T.AdjectiveSelection, person: T.Person, inflected: boolean): T.ArrayOneOrMore<T.PsString> {
return inflectAdvAdj(a, person, inflected)
export function inflectAdjective(
a: T.AdjectiveSelection,
person: T.Person,
inflected: boolean,
mayo: "req" | "opt" | "no"
): T.ArrayOneOrMore<T.PsString> {
return inflectAdvAdj(a, person, inflected, mayo);
}

export function renderAdjectiveSelection(a: T.AdjectiveSelection, person: T.Person, inflected: boolean, isLocationSingSandwich?: boolean): T.Rendered<T.AdjectiveSelection> {
const eWord = getEnglishWord(a.entry);
const e = !eWord
? undefined
: typeof eWord === "string"
? eWord
: (eWord.singular || undefined);
const ps = inflectAdjective(
a,
person,
isLocationSingSandwich && isPattern1Entry(a.entry)
? false
: inflected,
);
return {
type: "adjective",
entry: a.entry,
ps,
e,
inflected,
person,
sandwich: a.sandwich ? renderSandwich(a.sandwich) : undefined,
};
}
export function renderAdjectiveSelection(
a: T.AdjectiveSelection,
person: T.Person,
inflected: boolean,
isLocationSingSandwich: boolean,
mayo: "req" | "opt" | "no"
): T.Rendered<T.AdjectiveSelection> {
const eWord = getEnglishWord(a.entry);
const e = !eWord
? undefined
: typeof eWord === "string"
? eWord
: eWord.singular || undefined;
const toAddMayo = mayoOnWord(
mayo,
a.entry,
personGender(person),
personIsPlural(person) ? "plural" : "singular"
);
const ps = inflectAdjective(
a,
person,
isLocationSingSandwich && isPattern1Entry(a.entry) ? false : inflected,
toAddMayo
);
return {
type: "adjective",
entry: a.entry,
ps,
e,
inflected,
person,
sandwich: a.sandwich ? renderSandwich(a.sandwich) : undefined,
};
}
86 changes: 45 additions & 41 deletions src/lib/src/phrase-building/render-ap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,54 @@ import { isAdjectiveEntry } from "../type-predicates";
import { inflectAdvAdj } from "./render-adj";
import { renderSandwich } from "./render-sandwich";

export function renderAPSelection({ selection }: T.APSelection, person: T.Person): T.Rendered<T.APSelection> {
if (selection.type === "sandwich") {
return {
type: "AP",
selection: renderSandwich(selection),
};
}
export function renderAPSelection(
{ selection }: T.APSelection,
person: T.Person
): T.Rendered<T.APSelection> {
if (selection.type === "sandwich") {
return {
type: "AP",
selection: renderAdverbSelection(selection, person),
type: "AP",
selection: renderSandwich(selection),
};
}
return {
type: "AP",
selection: renderAdverbSelection(selection, person),
};
}

export function renderLocativeAdverbSelection({ entry }: T.LocativeAdverbSelection): T.Rendered<T.LocativeAdverbSelection> {
const e = getEnglishWord(entry);
if (!e || typeof e !== "string") {
throw new Error("error getting english for compliment");
}
return {
type: "loc. adv.",
entry: entry,
ps: [psStringFromEntry(entry)],
e,
inflected: false,
// TODO: don't use persons for these
person: T.Person.FirstSingMale,
role: "none",
};
export function renderLocativeAdverbSelection({
entry,
}: T.LocativeAdverbSelection): T.Rendered<T.LocativeAdverbSelection> {
const e = getEnglishWord(entry);
if (!e || typeof e !== "string") {
throw new Error("error getting english for compliment");
}
return {
type: "loc. adv.",
entry: entry,
ps: [psStringFromEntry(entry)],
e,
inflected: false,
// TODO: don't use persons for these
person: T.Person.FirstSingMale,
role: "none",
};
}

export function renderAdverbSelection(a: T.AdverbSelection, person: T.Person): T.Rendered<T.AdverbSelection> {
const ew = getEnglishWord(a.entry);
const e = typeof ew === "object"
? (ew.singular || "")
: !ew
? ""
: ew;
return {
type: "adverb",
entry: a.entry,
ps: isAdjectiveEntry(a.entry)
? inflectAdvAdj(a, person, false)
: [psStringFromEntry(a.entry)],
person,
e,
};
}
export function renderAdverbSelection(
a: T.AdverbSelection,
person: T.Person
): T.Rendered<T.AdverbSelection> {
const ew = getEnglishWord(a.entry);
const e = typeof ew === "object" ? ew.singular || "" : !ew ? "" : ew;
return {
type: "adverb",
entry: a.entry,
ps: isAdjectiveEntry(a.entry)
? inflectAdvAdj(a, person, false, "no")
: [psStringFromEntry(a.entry)],
person,
e,
};
}
Loading

0 comments on commit ba06fdf

Please sign in to comment.