From a7cfc4bcbc266f6783c29ae48c6a4cd81e2b0b7e Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Fri, 3 Sep 2021 16:05:05 +0400 Subject: [PATCH] better accent comparison --- src/components/UnisexNounGame.tsx | 4 ++-- src/lib/game-utils.ts | 17 +++++++++++++++++ yarn.lock | 6 +++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/components/UnisexNounGame.tsx b/src/components/UnisexNounGame.tsx index 627763a..9d5bf7e 100644 --- a/src/components/UnisexNounGame.tsx +++ b/src/components/UnisexNounGame.tsx @@ -2,6 +2,7 @@ import React, { useState } from "react"; import { getRandomFromList, makeProgress, + compareF, } from "../lib/game-utils"; import genderColors from "../lib/gender-colors"; import Game from "./Game"; @@ -11,7 +12,6 @@ import { defaultTextOptions as opts, inflectWord, standardizePashto, - removeAccents, // pashtoConsonants, } from "@lingdocs/pashto-inflector"; import words from "../words/nouns-adjs"; @@ -74,7 +74,7 @@ export default function() { e.preventDefault(); const given = standardizePashto(answer.trim()); const correct = inflected[flipGender(question.gender)][0].some((ps) => ( - (given === ps.p) || (removeAccents(given) === removeAccents(ps.f)) + (given === ps.p) || compareF(given, ps.f) )); if (correct) { setAnswer(""); diff --git a/src/lib/game-utils.ts b/src/lib/game-utils.ts index 5bd51a2..d1d94b7 100644 --- a/src/lib/game-utils.ts +++ b/src/lib/game-utils.ts @@ -1,3 +1,8 @@ +import { + removeAccents, + hasAccents, +} from "@lingdocs/pashto-inflector"; + export function makeRandomQs( amount: number, makeQuestion: () => Q @@ -27,4 +32,16 @@ export function getRandomFromList(list: T[]): T { export function makeProgress(i: number, total: number): Progress { return { current: i + 1, total }; +} + +/** + * Says if an input written in phonetics by the user is correct/the same as a given answer + * + * The user is allowed to leave out the accents, but if they include them they must be the same as the answer + * + * @param input - the answer given by the user in phonetics + * @param answer - the correct answer in phonetics + */ +export function compareF(input: string, answer: string): boolean { + return input === (hasAccents(input) ? answer : removeAccents(answer)); } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 2eee451..2935193 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1567,9 +1567,9 @@ chalk "^4.0.0" "@lingdocs/pashto-inflector@^0.9.3": - version "0.9.4" - resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-0.9.4.tgz#a05aa5151ec57550e1364377dff1b593039be76c" - integrity sha512-sn1TMGf8myoBr0NfRF5JtP//Y3A6cxwhVC8PtrZYgocYWA6lyB3H/R+ZblcUx7TCPwoH/aHIA365oKOpRDNMgw== + version "0.9.5" + resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-0.9.5.tgz#fc2cba942932a5870bdbbb326c9e1112560f8028" + integrity sha512-dMT8C16umXz9A6Sxo7H9QP5FI/EkazxFiMPZCymetK++o3JbGJZe1ffLl3TZphl1odpE/NzXgtKdd2paAwmEuQ== dependencies: classnames "^2.2.6" pbf "^3.2.1"