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 {
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("");

View File

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

View File

@ -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"