feat: Implement the Lev. Distance into the review
This commit is contained in:
parent
e555b89f8f
commit
1e313915ce
2
src/config.ts
Normal file
2
src/config.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Maximum distance from the answer to be still considered correct
|
||||||
|
export const LEVENSHTEIN_MAX_DISTANCE = 2;
|
@ -13,6 +13,9 @@ import { Redirect } from "react-router-dom";
|
|||||||
|
|
||||||
import { IVocab, ReviewMode, VocabType } from "../models/vocab";
|
import { IVocab, ReviewMode, VocabType } from "../models/vocab";
|
||||||
|
|
||||||
|
import { levW } from "../algorithms/levenshtein";
|
||||||
|
import { LEVENSHTEIN_MAX_DISTANCE } from "../config";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
levelId: number;
|
levelId: number;
|
||||||
vocabByLevel: (level: number) => IVocab[];
|
vocabByLevel: (level: number) => IVocab[];
|
||||||
@ -60,13 +63,14 @@ export default class ReviewPage extends React.Component<IProps, IState> {
|
|||||||
const current = this.currentVocab();
|
const current = this.currentVocab();
|
||||||
|
|
||||||
// Check if the given answer is somewhere in the german words
|
// Check if the given answer is somewhere in the german words
|
||||||
const german = this.currentVocab().german.map((str) => str.toLowerCase());
|
const { input } = this.state;
|
||||||
const found = german.find((el) => el === this.state.input.toLowerCase());
|
const german = current.german.map((str) => str.toLowerCase());
|
||||||
|
const dists = german.map((ger) => levW(input.toLowerCase(), ger));
|
||||||
|
const minDist = Math.min(...dists);
|
||||||
|
|
||||||
// Check if the user's answer was correct
|
// Check if the user's answer was correct
|
||||||
// TODO: Levensthein-Distance?
|
if (minDist === 0) {
|
||||||
if (found) {
|
// TODO: Show it's correct?
|
||||||
// TODO: Show it's correct
|
|
||||||
// Show the next vocab word
|
// Show the next vocab word
|
||||||
if (this.state.current + 1 >= this.vocab.length) {
|
if (this.state.current + 1 >= this.vocab.length) {
|
||||||
// TODO: Set some data that the summary screen will show
|
// TODO: Set some data that the summary screen will show
|
||||||
@ -80,6 +84,9 @@ export default class ReviewPage extends React.Component<IProps, IState> {
|
|||||||
input: "",
|
input: "",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} else if (minDist <= LEVENSHTEIN_MAX_DISTANCE) {
|
||||||
|
// TODO: Show a hint
|
||||||
|
console.log("Partially correct");
|
||||||
} else {
|
} else {
|
||||||
this.setState({
|
this.setState({
|
||||||
popoverOpen: true,
|
popoverOpen: true,
|
||||||
|
Reference in New Issue
Block a user