From 2fa773ab60223343a7d021a9be9005b244f60a0e Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Thu, 2 Sep 2021 17:09:07 +0400 Subject: [PATCH] add unisex gender game --- package.json | 2 +- scripts/misc-query.js | 2 +- src/components/GenderGame.tsx | 5 +- src/components/UnisexNounGame.tsx | 128 ++++++++++++++++++ .../inflection/inflection-patterns.mdx | 11 +- src/content/nouns/nouns-unisex.mdx | 11 +- src/words/noun-adj-categories/aanu-unisex.js | 1 - src/words/noun-adj-categories/nouns-unisex.js | 79 +++++++++++ src/words/nouns-adjs.ts | 2 +- yarn.lock | 20 +-- 10 files changed, 240 insertions(+), 21 deletions(-) create mode 100644 src/components/UnisexNounGame.tsx create mode 100644 src/words/noun-adj-categories/nouns-unisex.js diff --git a/package.json b/package.json index 7f11e82..991bd66 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "dependencies": { "@fortawesome/fontawesome-free": "^5.15.2", - "@lingdocs/pashto-inflector": "^0.8.3", + "@lingdocs/pashto-inflector": "^0.9.3", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", diff --git a/scripts/misc-query.js b/scripts/misc-query.js index 41c727b..5309c2e 100644 --- a/scripts/misc-query.js +++ b/scripts/misc-query.js @@ -16,7 +16,7 @@ const pConsonants = ["ب", "پ", "ت", "ټ", "ث", "ج", "چ", "ح", "خ", "څ", fetch(process.env.LINGDOCS_DICTIONARY_URL).then(res => res.arrayBuffer()).then(data => { const { entries } = readDictionary(data); const filtered = entries.filter(e => ( - e.c === "n. m." && ["ا", "ه", "ي"].includes(e.p.slice(-1)) && (!["u", "h"].includes(e.g.slice(-1))) + e.c?.includes("n. m. unisex") )); const content = `module.exports = [ ${filtered.reduce((text, entry) => ( diff --git a/src/components/GenderGame.tsx b/src/components/GenderGame.tsx index eb8ed5e..1216a06 100644 --- a/src/components/GenderGame.tsx +++ b/src/components/GenderGame.tsx @@ -56,7 +56,10 @@ export default function({level}: { level: 1 | 2 }) { ? wordPool : getRandomFromList([wordPool, exceptions]); const gender = getRandomFromList(Object.keys(base)); - const typeToUse = getRandomFromList(Object.keys(base[gender])); + let typeToUse: string; + do { + typeToUse = getRandomFromList(Object.keys(base[gender])); + } while (!base[gender].length); const question = getRandomFromList(base[gender][typeToUse]).entry; base[gender][typeToUse] = base[gender][typeToUse].filter(({ entry }) => entry.ts !== question.ts); yield { diff --git a/src/components/UnisexNounGame.tsx b/src/components/UnisexNounGame.tsx new file mode 100644 index 0000000..c9aae9f --- /dev/null +++ b/src/components/UnisexNounGame.tsx @@ -0,0 +1,128 @@ +import React, { useState } from "react"; +import { + getRandomFromList, + makeProgress, +} from "../lib/game-utils"; +import genderColors from "../lib/gender-colors"; +import Game from "./Game"; +import { + Types as T, + Examples, + defaultTextOptions as opts, + inflectWord, + standardizePashto, + removeAccents, + // pashtoConsonants, +} from "@lingdocs/pashto-inflector"; +import words from "../words/nouns-adjs"; +import { + firstVariation, +} from "../lib/text-tools"; + +const nouns = words.filter((w) => w.category === "nouns-unisex").map(x => x.entry); +// type NType = "consonant" | "eyUnstressed" | "eyStressed" | "pashtun" | "withu" +// const types: Record = { +// consonant: nouns.filter((w) => pashtoConsonants.includes(w.p.slice(-1))), +// eyUnstressed: nouns.filter((w) => w.f.slice(-2) === "ey"), +// eyStressed: nouns.filter((w) => w.f.slice(-2) === "éy"), +// pashtun: nouns.filter((w) => w.infaf?.includes("aa")), +// withu: nouns.filter((w) => w.infaf?.slice(-1) === "u" && !!w.infaf?.includes("aa")), +// } +const genders: T.Gender[] = ["masc", "fem"]; + +const amount = 20; + +type Question = { entry: T.DictionaryEntry, gender: T.Gender }; + +export default function() { + function* questions (): Generator> { + let pool = [...nouns]; + for (let i = 0; i < amount; i++) { + // const keys = Object.keys(types) as NType[]; + // let type: NType + // do { + // type = getRandomFromList(keys); + // } while (!pool[type].length); + const entry = getRandomFromList(pool); + const gender = getRandomFromList(genders) as T.Gender; + pool = pool.filter((x) => x.ts !== entry.ts); + yield { + progress: makeProgress(i, amount), + question: { + entry, + gender, + }, + }; + } + } + + function Display({ question, callback }: QuestionDisplayProps) { + function flipGender(g: T.Gender): T.Gender { + return g === "masc" ? "fem" : "masc"; + } + const [answer, setAnswer] = useState(""); + const inflected = inflectWord(question.entry) as T.UnisexInflections; + const givenGender = question.gender === "masc" ? "masculine" : "feminine"; + const requiredGender = question.gender === "fem" ? "masculine" : "feminine"; + if (!inflected || !inflected.masc || !inflected.fem) { + return
WORD ERROR
; + } + function handleInput({ target: { value }}: React.ChangeEvent) { + setAnswer(value); + } + function handleSubmit(e: React.FormEvent) { + e.preventDefault(); + const given = standardizePashto(answer.trim()); + const correct = inflected[flipGender(question.gender)][0].some((ps) => ( + (given === ps.p) || (removeAccents(given) === removeAccents(ps.f)) + )); + if (correct) { + setAnswer(""); + } + callback(correct); + } + + return
+
+ {[ + { + ...inflected[question.gender][0][0], + e: firstVariation(question.entry.e), + } + ]} +
+
Is {givenGender}. Make it {requiredGender}.
+
+
+ +
+
+ +
+
+ +
+ } + + function Instructions() { + return
+ Change the gender of a given word +
+ } + + return +}; diff --git a/src/content/inflection/inflection-patterns.mdx b/src/content/inflection/inflection-patterns.mdx index 226b000..81602da 100644 --- a/src/content/inflection/inflection-patterns.mdx +++ b/src/content/inflection/inflection-patterns.mdx @@ -73,15 +73,24 @@ Notice how it does not use the first feminine inflection +This is very similar to pattern #2, but with the stress on the last syllable the feminine inflection changes. + ## 4. Words with the "Pashtun" pattern +These words are a little irregular but you can see a common patten based around: + +- lengthening the 1st masculine inflection with +- shortening the other forms and adding the , , endings + **Note**: Nouns in this pattern will often only use the first inflection for the plural. Adjectives will use the 1st inflection for all 3 reasons. -## 5. Shorter irregular words +## 5. Shorter words that take + +These are also a little irregular but instead of lengthening the 1st masculine inflection they compress it as well and take just an on the end. diff --git a/src/content/nouns/nouns-unisex.mdx b/src/content/nouns/nouns-unisex.mdx index e6e05e1..fb84c39 100644 --- a/src/content/nouns/nouns-unisex.mdx +++ b/src/content/nouns/nouns-unisex.mdx @@ -10,6 +10,7 @@ import { import Table from "../../components/Table"; import Link from "../../components/Link"; import GenderTable from "../../components/GenderTable"; +import UnisexNounGame from "../../components/UnisexNounGame"; There are many words for people and animals in Pashto that can be used in both masculine and feminine forms. @@ -104,8 +105,6 @@ If the accent comes on the end of the word, the femine form is a little differen ### 4. Words with the "Pashtun" pattern -Well... - -### 5. Shorter irregular words - -You get the idea... +### 5. Shorter words that take +**🕹 Here's a game to practice changing the genders of nouns** + + +