From 6c8831484bb7eb4d1ebf50daf4ff00274ac59d2f Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Sun, 20 Feb 2022 10:50:09 +0400 Subject: [PATCH] fix equatives --- src/components/equative-explorer/testme.nnb | 0 src/components/np-picker/NPPicker.tsx | 51 +++++++ src/components/np-picker/NPPronounPicker.tsx | 136 ++++++++++++++++++ src/content/equatives/other-equatives.mdx | 4 +- src/content/index.ts | 6 + src/content/practice-tools/phrase-builder.mdx | 18 +++ src/content/practice-tools/pronoun-picker.mdx | 15 +- src/lib/np-tools.ts | 8 ++ src/{ => types}/gen-g.d.ts | 16 ++- 9 files changed, 235 insertions(+), 19 deletions(-) delete mode 100644 src/components/equative-explorer/testme.nnb create mode 100644 src/components/np-picker/NPPicker.tsx create mode 100644 src/components/np-picker/NPPronounPicker.tsx create mode 100644 src/content/practice-tools/phrase-builder.mdx rename src/{ => types}/gen-g.d.ts (79%) diff --git a/src/components/equative-explorer/testme.nnb b/src/components/equative-explorer/testme.nnb deleted file mode 100644 index e69de29..0000000 diff --git a/src/components/np-picker/NPPicker.tsx b/src/components/np-picker/NPPicker.tsx new file mode 100644 index 0000000..37d35c6 --- /dev/null +++ b/src/components/np-picker/NPPicker.tsx @@ -0,0 +1,51 @@ +import PronounPicker from "./NPPronounPicker"; +// import { ButtonSelect } from "@lingdocs/pashto-inflector"; +import { randomPerson } from "../../lib/np-tools"; +import { useState } from "react"; + +const npTypes: NPType[] = ["noun", "pronoun", "participle"]; + +function NPPicker({ np, onChange }: { onChange: (nps: NPSelection | undefined) => void, np: NPSelection | undefined }) { + // eslint-disable-next-line + const [npType, setNpType] = useState(np ? np.type : undefined); + function handleClear() { + setNpType(undefined); + onChange(undefined); + } + function handleNPTypeChange(ntp: NPType) { + if (ntp === "pronoun") { + const pronoun: PronounSelection = { + type: "pronoun", + e: "not done", + person: randomPerson(), + distance: "far", + }; + onChange(pronoun); + } else { + setNpType(ntp); + } + } + return
+ {!np ? +
+ {npTypes.map((npt) => ( + + ))} +
+ :
X
} + {np && + (np.type === "pronoun" + ? + :
Not Implemented
) + } +
; +} + +export default NPPicker; \ No newline at end of file diff --git a/src/components/np-picker/NPPronounPicker.tsx b/src/components/np-picker/NPPronounPicker.tsx new file mode 100644 index 0000000..e3212cf --- /dev/null +++ b/src/components/np-picker/NPPronounPicker.tsx @@ -0,0 +1,136 @@ +import { + Types as T, + ButtonSelect, +} from "@lingdocs/pashto-inflector"; +import useStickyState from "../../useStickyState"; + +const gColors = { + masc: "LightSkyBlue", + fem: "pink", +}; + +const labels = { + persons: [ + ["1st", "1st pl."], + ["2nd", "2nd pl."], + ["3rd", "3rd pl."], + ], + e: [ + ["I", "We"], + ["You", "You pl."], + [{ masc: "He/It", fem: "She/It"}, "They"], + ], + p: { + far: [ + ["زه", "مونږ"], + ["ته", "تاسو"], + ["هغه", "هغوي"], + ], + near: [ + ["زه", "مونږ"], + ["ته", "تاسو"], + [{ masc: "دی", fem: "دا" }, "دوي"], + ], + }, +}; + + +type PickerState = { row: number, col: number, gender: T.Gender }; + +function personToPickerState(person: T.Person): PickerState { + const col = person > 5 ? 1 : 0; + const row = Math.floor((person > 5 ? (person - 6) : person) / 2); + const gender: T.Gender = (person % 2) ? "fem" : "masc"; + return { col, row, gender }; +} + +function pickerStateToPerson(s: PickerState): T.Person { + return (s.row * 2) + + (s.gender === "masc" ? 0 : 1) + + (6 * s.col); +} + +function PronounPicker({ onChange, pronoun }: { pronoun: PronounSelection, onChange: (p: PronounSelection) => void }) { + const [display, setDisplay] = useStickyState<"persons" | "p" | "e">("persons", "prounoun-picker-display"); + + const p = personToPickerState(pronoun.person); + function handleClick(row: number, col: number) { + onChange({ + ...pronoun, + person: pickerStateToPerson({ + ...p, + row, + col, + }), + }); + } + function handleGenderChange(gender: T.Gender) { + onChange({ + ...pronoun, + person: pickerStateToPerson({ + ...p, + gender, + }), + }); + } + function handlePronounTypeChange(distance: "far" | "near") { + onChange({ + ...pronoun, + distance, + }); + } + function handleDisplayChange() { + const newPerson = display === "persons" + ? "p" + : display === "p" + ? "e" + : "persons"; + setDisplay(newPerson); + } + const prs = labels[display]; + const pSpec = "near" in prs ? prs[pronoun.distance] : prs; + return
+
+ handlePronounTypeChange(g as "far" | "near")} + /> + +
+ + + {pSpec.map((rw, i) => ( + + {rw.map((r, j) => { + const active = (p.row === i && p.col === j) + return ; + })} + + ))} + +
handleClick(i, j)} + className={active ? "table-active" : ""} + style={active ? { backgroundColor: gColors[p.gender] } : {}} + > + {typeof r === "string" ? r : r[p.gender]} +
+
+ handleGenderChange(g as T.Gender)} + /> +
+
; +}; + +export default PronounPicker; \ No newline at end of file diff --git a/src/content/equatives/other-equatives.mdx b/src/content/equatives/other-equatives.mdx index 5608399..998cb19 100644 --- a/src/content/equatives/other-equatives.mdx +++ b/src/content/equatives/other-equatives.mdx @@ -160,7 +160,7 @@ This is used for: { p: "...", f: "..." }, " ", ], - grammarUnits.equativeEndings.subjunctive, + grammarUnits.equativeEndings.habitual, ), english: [ ["I will be ...", "We will be ..."], @@ -177,7 +177,7 @@ This is used for: " ", { p: "...", f: "..." }, " ", - ], grammarUnits.equativeEndings.subjunctive) + ], grammarUnits.equativeEndings.habitual) }, }} opts={opts} diff --git a/src/content/index.ts b/src/content/index.ts index 55f1be7..fdd7d47 100644 --- a/src/content/index.ts +++ b/src/content/index.ts @@ -80,6 +80,8 @@ import * as games from "!babel-loader!@lingdocs/mdx-loader!./games.mdx"; // @ts-ignore import * as pronounPicker from "!babel-loader!@lingdocs/mdx-loader!./practice-tools/pronoun-picker.mdx"; +// @ts-ignore +import * as phraseBuilder from "!babel-loader!@lingdocs/mdx-loader!./practice-tools/phrase-builder.mdx"; const contentTree = [ { @@ -256,6 +258,10 @@ const contentTree = [ import: pronounPicker, slug: "pronoun-picker", }, + { + import: phraseBuilder, + slug: "phrase-builder", + }, ], }, ]; diff --git a/src/content/practice-tools/phrase-builder.mdx b/src/content/practice-tools/phrase-builder.mdx new file mode 100644 index 0000000..d7251a6 --- /dev/null +++ b/src/content/practice-tools/phrase-builder.mdx @@ -0,0 +1,18 @@ +--- +title: Phrase Builder +--- + +import NPPicker from "../../components/np-picker/NPPicker"; +import { useState } from "react"; + +export function Display() { + const [np, setNp] = useState(undefined); + return
+ +
+            {JSON.stringify(np, null, "  ")}
+        
+
+} + + \ No newline at end of file diff --git a/src/content/practice-tools/pronoun-picker.mdx b/src/content/practice-tools/pronoun-picker.mdx index 895fbaf..168f358 100644 --- a/src/content/practice-tools/pronoun-picker.mdx +++ b/src/content/practice-tools/pronoun-picker.mdx @@ -8,19 +8,14 @@ import { InlinePs, } from "@lingdocs/pashto-inflector"; import { useState } from "react"; - -export function randomP(p) { - let newP = 0; - do { - newP = Math.floor(Math.random() * 12); - } while (newP === p); - return newP; -} +import { + randomPerson, +} from "../../lib/np-tools"; export function RPicker() { - const [pronoun, setPronoun] = useState({ type: "pronoun", pronounType: "far", person: randomP() }); + const [pronoun, setPronoun] = useState({ type: "pronoun", pronounType: "far", person: randomPerson() }); function handleRandom() { - const person = randomP(pronoun.person); + const person = randomPerson(pronoun.person); setPronoun({ ...pronoun, person, diff --git a/src/lib/np-tools.ts b/src/lib/np-tools.ts index 9d75e1a..84d058a 100644 --- a/src/lib/np-tools.ts +++ b/src/lib/np-tools.ts @@ -11,6 +11,14 @@ import { psStringFromEntry, } from "./text-tools"; +export function randomPerson(p?: T.Person) { + let newP = 0; + do { + newP = Math.floor(Math.random() * 12); + } while (newP === p); + return newP; +} + export function personFromNP(np: NounPhrase): T.Person { if (np.type === "participle") { return T.Person.ThirdPlurMale; diff --git a/src/gen-g.d.ts b/src/types/gen-g.d.ts similarity index 79% rename from src/gen-g.d.ts rename to src/types/gen-g.d.ts index 6110b59..ac0af83 100644 --- a/src/gen-g.d.ts +++ b/src/types/gen-g.d.ts @@ -6,10 +6,13 @@ type NPSelection = NounSelection | PronounSelection | ParticipleSelection; +type NPType = "noun" | "pronoun" | "participle"; + // TODO require/import Person and PsString type NounSelection = { type: "noun", - ps: string, + ps: import("@lingdocs/pashto-inflector").Types.PsString, + entry: import("@lingdocs/pashto-inflector").Types.DictionaryEntry, // BETTER TO USE (or keep handy) FULL ENTRY FOR USE WITH INFLECTING e: { sing: string, @@ -22,23 +25,22 @@ type NounSelection = { // TODO: Implement // possesor: NPSelection | undefined, /* method only present if it's possible to change gender */ - changeGender?: (gender: "masc" | "fem") => NounWord, + changeGender?: (gender: "masc" | "fem") => NounSelection, /* method only present if it's possible to change number */ - changeNumber?: (number: "sing" | "plur") => NounWord, + changeNumber?: (number: "sing" | "plur") => NounSelection, }; // take an argument for subject/object in rendering English type PronounSelection = { type: "pronoun", e: string, - person: Person, + person: import("@lingdocs/pashto-inflector").Types.Person, distance: "near" | "far", - changeDistance: (distance: "near" | "far") => PronounSelection, }; type ParticipleSelection = { type: "participle", - ps: string, + ps: import("@lingdocs/pashto-inflector").Types.PsString, e: string | undefined, // entry in here } @@ -52,7 +54,7 @@ type ReplaceKey = T extends Record ? (Omit = ReplaceKey< Omit, "e", - string, + string > & { inflected: boolean }; // TODO: recursive changing this down into the possesor etc.