Skip to content

Commit

Permalink
fixed up determiners for a beta rollout
Browse files Browse the repository at this point in the history
  • Loading branch information
adueck committed Aug 7, 2024
1 parent 6451cee commit c5a238a
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 30 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
yarn install-r
yarn build-library
yarn test --silent
yarn check-all-inflections
cp .npmrc src/lib
cp .npmrc src/components
cd src/lib
Expand Down
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.5.0",
"version": "7.5.1",
"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.5.0",
"version": "7.5.1",
"description": "Pashto inflector library module with React components",
"main": "dist/components/library.js",
"module": "dist/components/library.js",
Expand Down
15 changes: 10 additions & 5 deletions src/components/src/blocks/Block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,20 @@ function Determiners({
script: "p" | "f";
children: T.Rendered<T.DeterminersSelection> | undefined;
}) {
if (!children) {
if (!children || children.determiners.length === 0) {
return null;
}
return (
<div className="text-center">
Determiners here!
{/* <Border padding={"1rem"}>{children.ps[script]}</Border>
<div>DEM</div>
<SubText>{children.e}</SubText> */}
<div className={`d-flex flex-row${script === "p" ? "-reverse" : ""}`}>
{children.determiners.map((d) => (
<div className="mx-1">
<Border padding={"1rem"}>{d.ps[0][script]}</Border>
<div>{"demonstrative" in d.determiner ? "DEM" : "DET"}</div>
<SubText>{d.e}</SubText>
</div>
))}
</div>
</div>
);
}
Expand Down
8 changes: 7 additions & 1 deletion src/components/src/np-picker/DeterminersPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ export default function DeterminersPicker({
opts: T.TextOptions;
negative: boolean;
}) {
const hasDemonstrative =
determiners &&
determiners.determiners.some((d) => "demonstrative" in d.determiner);
function allowed(d: T.Determiner): boolean {
if (d.p === "هیڅ" && !negative) {
return false;
}
if (hasDemonstrative && "demonstrative" in d) {
return false;
}
return true;
}
function handleWithNounChange(e: React.ChangeEvent<HTMLInputElement>) {
Expand Down Expand Up @@ -93,7 +99,7 @@ export default function DeterminersPicker({
checked={determiners?.withNoun}
onChange={handleWithNounChange}
id="withNoun"
disabled={!determiners}
disabled={!hasDemonstrative}
/>
<label className="form-check-label text-muted" htmlFor="withNoun">
with noun
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.5.0",
"version": "7.5.1",
"description": "Pashto inflector library",
"main": "dist/index.js",
"types": "dist/lib/library.d.ts",
Expand Down
15 changes: 8 additions & 7 deletions src/lib/src/phrase-building/blocks-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ export function removeHeetsDet<B extends T.VPSBlock[] | T.EPSBlock[]>(
})) as B;
}

// TODO: Could use lenses for this
function removeHeetsDetFromBlock<
B extends T.VPSBlock["block"] | T.EPSBlock["block"]
>(block: B): B {
Expand Down Expand Up @@ -512,10 +513,7 @@ function removeHeetsFromNoun(n: T.NounSelection): T.NounSelection {
adjectives: n.adjectives.map(removeHeetsFromAdjective),
...(n.determiners
? {
determiners: {
...n.determiners,
determiners: removeHeetsFromDets(n.determiners.determiners),
},
determiners: removeHeetsFromDets(n.determiners),
}
: {}),
};
Expand All @@ -532,10 +530,13 @@ function removeHeetsFromNP(np: T.NPSelection): T.NPSelection {
}

function removeHeetsFromDets(
dets: T.DeterminerSelection[]
): T.DeterminerSelection[] {
dets: T.DeterminersSelection | undefined
): T.DeterminersSelection | undefined {
if (!dets) {
return dets;
}
return dets.filter((d) => d.determiner.p !== "هیڅ");
return {
...dets,
determiners: dets.determiners.filter((d) => d.determiner.p !== "هیڅ"),
};
}
9 changes: 6 additions & 3 deletions src/lib/src/phrase-building/np-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function getBaseWDetsAndAdjs({
const detWOutNoun =
"determiners" in selection &&
selection.determiners &&
!selection.determiners.type;
!selection.determiners.withNoun;
const adjs = (("adjectives" in selection && selection.adjectives) || []).map(
(x) => x.ps
);
Expand Down Expand Up @@ -208,10 +208,13 @@ function addArticlesAndAdjs(
? " (f.)"
: " (m.)"
: "";
const moreThanOneDet = (np.determiners?.determiners.length || 0) > 1;
const determiners =
np.determiners && np.determiners.determiners
? // @ts-ignore - weird, ts is not recognizing this as rendered
np.determiners.determiners.map((x) => `(${x.e})`).join(" ")
? np.determiners.determiners
// @ts-ignore - weird, ts is not recognizing this as rendered
.map((x) => (moreThanOneDet ? `(${x.e})` : x.e))
.join(" ")
: "";
const detsWithoutNoun = np.determiners && !np.determiners.withNoun;
return `${np.determiners ? "" : articles}${determiners}${
Expand Down
6 changes: 2 additions & 4 deletions src/lib/src/phrase-building/render-np.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,9 @@ function renderDeterminer({
? "such/like these"
: "such/like this"
: determiner.f === "daghase"
? number === "plural"
? "just such/just like these"
: "just such/just like this"
? `just such/just like ${number === "plural" ? "these" : "this"}`
: determiner.f === "hase"
? `such/like ${number === "plural"} ? "those" : "that"`
? `such/like ${number === "plural" ? "those" : "that"}`
: number === "plural"
? "just such/just like these"
: "just such/just like this";
Expand Down
10 changes: 5 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,18 +909,18 @@ export type DeterminersSelection = {
};

export const determiners = [
{ p: "دا", f: "daa", type: "det" },
{ p: "دغه", f: "dágha", type: "det" },
{ p: "هغه", f: "hágha", type: "det" },
{ p: "دا", f: "daa", type: "det", demonstrative: true },
{ p: "دغه", f: "dágha", type: "det", demonstrative: true },
{ p: "هغه", f: "hágha", type: "det", demonstrative: true },
{ p: "کوم", f: "koom", type: "det" },
{ p: "داسې", f: "dáase", type: "det" },
{ p: "دغسې", f: "daghase", type: "det" },
{ p: "هسې", f: "hase", type: "det" },
{ p: "هغسې", f: "hagháse", type: "det" },
{ p: "کوم", f: "koom", type: "det" },
{ p: "هر", f: "har", type: "det" },
{ p: "ټول", f: "Tol", type: "det" },
{ p: "هیڅ", f: "heets", type: "det", noInf: true },
{ p: "بل", f: "bul", type: "det" },
{ p: "هیڅ", f: "heets", type: "det", noInf: true },
] as const;

export type Determiner = (typeof determiners)[number];
Expand Down

0 comments on commit c5a238a

Please sign in to comment.