better accent comparison

This commit is contained in:
lingdocs 2021-09-03 16:05:05 +04:00
parent 34701cd572
commit a7cfc4bcbc
3 changed files with 22 additions and 5 deletions

View File

@ -2,6 +2,7 @@ import React, { useState } from "react";
import { import {
getRandomFromList, getRandomFromList,
makeProgress, makeProgress,
compareF,
} from "../lib/game-utils"; } from "../lib/game-utils";
import genderColors from "../lib/gender-colors"; import genderColors from "../lib/gender-colors";
import Game from "./Game"; import Game from "./Game";
@ -11,7 +12,6 @@ import {
defaultTextOptions as opts, defaultTextOptions as opts,
inflectWord, inflectWord,
standardizePashto, standardizePashto,
removeAccents,
// pashtoConsonants, // pashtoConsonants,
} from "@lingdocs/pashto-inflector"; } from "@lingdocs/pashto-inflector";
import words from "../words/nouns-adjs"; import words from "../words/nouns-adjs";
@ -74,7 +74,7 @@ export default function() {
e.preventDefault(); e.preventDefault();
const given = standardizePashto(answer.trim()); const given = standardizePashto(answer.trim());
const correct = inflected[flipGender(question.gender)][0].some((ps) => ( 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) { if (correct) {
setAnswer(""); setAnswer("");

View File

@ -1,3 +1,8 @@
import {
removeAccents,
hasAccents,
} from "@lingdocs/pashto-inflector";
export function makeRandomQs<Q>( export function makeRandomQs<Q>(
amount: number, amount: number,
makeQuestion: () => Q makeQuestion: () => Q
@ -27,4 +32,16 @@ export function getRandomFromList<T>(list: T[]): T {
export function makeProgress(i: number, total: number): Progress { export function makeProgress(i: number, total: number): Progress {
return { current: i + 1, total }; 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));
} }

View File

@ -1567,9 +1567,9 @@
chalk "^4.0.0" chalk "^4.0.0"
"@lingdocs/pashto-inflector@^0.9.3": "@lingdocs/pashto-inflector@^0.9.3":
version "0.9.4" version "0.9.5"
resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-0.9.4.tgz#a05aa5151ec57550e1364377dff1b593039be76c" resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-0.9.5.tgz#fc2cba942932a5870bdbbb326c9e1112560f8028"
integrity sha512-sn1TMGf8myoBr0NfRF5JtP//Y3A6cxwhVC8PtrZYgocYWA6lyB3H/R+ZblcUx7TCPwoH/aHIA365oKOpRDNMgw== integrity sha512-dMT8C16umXz9A6Sxo7H9QP5FI/EkazxFiMPZCymetK++o3JbGJZe1ffLl3TZphl1odpE/NzXgtKdd2paAwmEuQ==
dependencies: dependencies:
classnames "^2.2.6" classnames "^2.2.6"
pbf "^3.2.1" pbf "^3.2.1"