phonetics update
This commit is contained in:
parent
ddf967ae63
commit
c82fc04821
|
@ -20,28 +20,32 @@ const amount = 8;
|
|||
const timeLimit = 300;
|
||||
|
||||
type Question = {
|
||||
entry: T.NounEntry | T.AdjectiveEntry,
|
||||
inflections: T.Inflections,
|
||||
entry: T.NounEntry | T.AdjectiveEntry;
|
||||
inflections: T.Inflections;
|
||||
};
|
||||
|
||||
type InfFormContent = {
|
||||
masc: [string, string, string],
|
||||
fem: [string, string, string],
|
||||
masc: [string, string, string];
|
||||
fem: [string, string, string];
|
||||
};
|
||||
|
||||
export default function InflectionsWriting({ inChapter, id, link, level }: {
|
||||
inChapter: boolean,
|
||||
id: string,
|
||||
link: string,
|
||||
level: T.InflectionPattern,
|
||||
export default function InflectionsWriting({
|
||||
inChapter,
|
||||
id,
|
||||
link,
|
||||
level,
|
||||
}: {
|
||||
inChapter: boolean;
|
||||
id: string;
|
||||
link: string;
|
||||
level: T.InflectionPattern;
|
||||
}) {
|
||||
const wordPool = makePool(
|
||||
[...nouns, ...adjectives]
|
||||
.filter(x => {
|
||||
[...nouns, ...adjectives].filter((x) => {
|
||||
if (isAdverbEntry(x)) return false;
|
||||
const infs = inflectWord(x);
|
||||
if (!infs || !infs.inflections) return false;
|
||||
return (getInflectionPattern(x) === level);
|
||||
return getInflectionPattern(x) === level;
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -55,41 +59,54 @@ export default function InflectionsWriting({ inChapter, id, link, level }: {
|
|||
entry: word,
|
||||
inflections: r.inflections,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function Display({ question, callback }: QuestionDisplayProps<Question>) {
|
||||
function handleAnswer(inf: InfFormContent) {
|
||||
callback(infAnswerCorrect(inf, question.inflections));
|
||||
}
|
||||
return <div>
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-2" style={{ maxWidth: "300px", margin: "0 auto" }}>
|
||||
<Examples opts={opts}>{[
|
||||
<Examples opts={opts}>
|
||||
{[
|
||||
{
|
||||
p: firstVariation(question.entry.p),
|
||||
f: firstVariation(question.entry.f),
|
||||
e: `${firstVariation(question.entry.e)} - ${question.entry.c}`,
|
||||
}
|
||||
]}</Examples>
|
||||
},
|
||||
]}
|
||||
</Examples>
|
||||
</div>
|
||||
<InflectionTableForm
|
||||
onSubmit={handleAnswer}
|
||||
question={question}
|
||||
genders={isUnisexSet(question.inflections)
|
||||
genders={
|
||||
isUnisexSet(question.inflections)
|
||||
? "unisex"
|
||||
: "masc" in question.inflections
|
||||
? "masc"
|
||||
: "fem"}
|
||||
: "fem"
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Instructions() {
|
||||
return <div>
|
||||
<p className="lead">Complete the inflections for the <strong>{HumanReadableInflectionPattern(level, opts)}</strong> pattern word</p>
|
||||
return (
|
||||
<div>
|
||||
<p className="lead">
|
||||
Complete the inflections for the{" "}
|
||||
<strong>{HumanReadableInflectionPattern(level, opts)}</strong> pattern
|
||||
word
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return <GameCore
|
||||
return (
|
||||
<GameCore
|
||||
inChapter={inChapter}
|
||||
studyLink={link}
|
||||
getQuestion={getQuestion}
|
||||
|
@ -100,14 +117,22 @@ export default function InflectionsWriting({ inChapter, id, link, level }: {
|
|||
amount={amount}
|
||||
Instructions={Instructions}
|
||||
/>
|
||||
};
|
||||
);
|
||||
}
|
||||
|
||||
function InflectionTableForm({ onSubmit, genders, question }: {
|
||||
onSubmit: (i: InfFormContent) => void,
|
||||
genders: T.Gender | "unisex",
|
||||
question: Question,
|
||||
function InflectionTableForm({
|
||||
onSubmit,
|
||||
genders,
|
||||
question,
|
||||
}: {
|
||||
onSubmit: (i: InfFormContent) => void;
|
||||
genders: T.Gender | "unisex";
|
||||
question: Question;
|
||||
}) {
|
||||
const [inf, setInf] = useState<InfFormContent>({ fem: ["", "", ""], masc: ["", "", ""] });
|
||||
const [inf, setInf] = useState<InfFormContent>({
|
||||
fem: ["", "", ""],
|
||||
masc: ["", "", ""],
|
||||
});
|
||||
const mascInputRef = useRef<HTMLInputElement>(null);
|
||||
const femInputRef = useRef<HTMLInputElement>(null);
|
||||
useEffect(() => {
|
||||
|
@ -129,20 +154,30 @@ function InflectionTableForm({ onSubmit, genders, question }: {
|
|||
e.preventDefault();
|
||||
onSubmit(inf);
|
||||
}
|
||||
return <form onSubmit={handleSubmit}>
|
||||
return (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<table className="table" style={{ tableLayout: "fixed" }}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" style={{ width: "3.5rem" }}></th>
|
||||
{genders !== "fem" && <th scope="col" style={{ maxWidth: "10rem", textAlign: "left" }}>Masculine</th>}
|
||||
{genders !== "masc" && <th scope="col" style={{ maxWidth: "10rem", textAlign: "left" }}>Feminine</th>}
|
||||
{genders !== "fem" && (
|
||||
<th scope="col" style={{ maxWidth: "10rem", textAlign: "left" }}>
|
||||
Masculine
|
||||
</th>
|
||||
)}
|
||||
{genders !== "masc" && (
|
||||
<th scope="col" style={{ maxWidth: "10rem", textAlign: "left" }}>
|
||||
Feminine
|
||||
</th>
|
||||
)}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{["Plain", "1st", "2nd"].map((title, i) => (
|
||||
<tr key={title}>
|
||||
<th scope="row">{title}</th>
|
||||
{genders !== "fem" && <td>
|
||||
{genders !== "fem" && (
|
||||
<td>
|
||||
<input
|
||||
ref={i === 0 ? mascInputRef : undefined}
|
||||
type="text"
|
||||
|
@ -155,8 +190,10 @@ function InflectionTableForm({ onSubmit, genders, question }: {
|
|||
onChange={handleInfInput("masc", i)}
|
||||
style={{ maxWidth: "12rem" }}
|
||||
/>
|
||||
</td>}
|
||||
{genders !== "masc" && <td>
|
||||
</td>
|
||||
)}
|
||||
{genders !== "masc" && (
|
||||
<td>
|
||||
<input
|
||||
ref={i === 0 ? femInputRef : undefined}
|
||||
type="text"
|
||||
|
@ -169,39 +206,54 @@ function InflectionTableForm({ onSubmit, genders, question }: {
|
|||
onChange={handleInfInput("fem", i)}
|
||||
style={{ maxWidth: "12rem" }}
|
||||
/>
|
||||
</td>}
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<div className="text-center">
|
||||
<button type="button" className="btn btn-secondary mx-3" onClick={handleClearInf}>Clear</button>
|
||||
<button type="submit" className="btn btn-primary mx-3">Submit</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary mx-3"
|
||||
onClick={handleClearInf}
|
||||
>
|
||||
Clear
|
||||
</button>
|
||||
<button type="submit" className="btn btn-primary mx-3">
|
||||
Submit
|
||||
</button>
|
||||
</div>
|
||||
</form>;
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
function DisplayCorrectAnswer({ question }: { question: Question }): JSX.Element {
|
||||
return <div>
|
||||
function DisplayCorrectAnswer({
|
||||
question,
|
||||
}: {
|
||||
question: Question;
|
||||
}): JSX.Element {
|
||||
return (
|
||||
<div>
|
||||
<InflectionsTable
|
||||
inf={question.inflections}
|
||||
textOptions={opts}
|
||||
hideTitle
|
||||
/>
|
||||
</div>;
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function infAnswerCorrect(answer: InfFormContent, inf: T.Inflections): boolean {
|
||||
function genInfCorrect(gender: T.Gender): boolean {
|
||||
// @ts-ignore
|
||||
const genInf = inf[gender] as T.InflectionSet;
|
||||
return genInf.every((x, i) => (
|
||||
x.some(ps => comparePs(answer[gender][i], ps))
|
||||
));
|
||||
return genInf.every((x, i) =>
|
||||
x.some((ps) => comparePs(answer[gender][i], [ps]))
|
||||
);
|
||||
}
|
||||
if (isUnisexSet(inf)) {
|
||||
return genInfCorrect("masc") && genInfCorrect("fem");
|
||||
}
|
||||
return genInfCorrect("masc" in inf ? "masc" : "fem");
|
||||
}
|
||||
|
||||
|
|
|
@ -414,8 +414,8 @@ function addUserAnswer(
|
|||
function addBa(x: T.PsString) {
|
||||
if (!a.withBa) return x;
|
||||
return {
|
||||
p: x.p.replace(kidsBlank.p, baParticle.p),
|
||||
f: x.f.replace(kidsBlank.f, baParticle.f),
|
||||
p: x.p.replace(kidsBlank.p, baParticle.p + " "),
|
||||
f: x.f.replace(kidsBlank.f, baParticle.f + " "),
|
||||
};
|
||||
}
|
||||
function addAnswer(x: T.PsString): T.PsString {
|
||||
|
|
|
@ -9,9 +9,7 @@ import {
|
|||
import { removeAShort } from "./misc-helpers";
|
||||
|
||||
export function getPercentageDone(current: number, total: number): number {
|
||||
return Math.round(
|
||||
(current / (total + 1)) * 100
|
||||
);
|
||||
return Math.round((current / (total + 1)) * 100);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +26,10 @@ export function compareF(input: string, answer: string): boolean {
|
|||
return inp === (hasAccents(inp) ? ans : removeAccents(ans));
|
||||
}
|
||||
|
||||
export function comparePs(inputRaw: string, answer: T.SingleOrLengthOpts<T.PsString | T.PsString[]>): boolean {
|
||||
export function comparePs(
|
||||
inputRaw: string,
|
||||
answer: T.SingleOrLengthOpts<T.PsString[]>
|
||||
): boolean {
|
||||
function cleanSpaces(s: string): string {
|
||||
return s.replace(/\s+/g, " ");
|
||||
}
|
||||
|
@ -36,11 +37,8 @@ export function comparePs(inputRaw: string, answer: T.SingleOrLengthOpts<T.PsStr
|
|||
if ("long" in answer) {
|
||||
return comparePs(input, flattenLengths(answer));
|
||||
}
|
||||
if (Array.isArray(answer)) {
|
||||
return answer.some(a => comparePs(input, a));
|
||||
}
|
||||
const stand = standardizePhonetics(
|
||||
standardizePashto(input)
|
||||
).trim();
|
||||
return stand === cleanSpaces(answer.p) || compareF(stand, cleanSpaces(answer.f));
|
||||
return answer.some((a) => {
|
||||
const stand = standardizePhonetics(standardizePashto(input)).trim();
|
||||
return stand === cleanSpaces(a.p) || compareF(stand, cleanSpaces(a.f));
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue