{-# LANGUAGE OverloadedStrings #-}

-- | This module provides utilities for constructing exercise generators.
module Study.Framework.Eberban.ExerciseGenerators
( generateLexiconProvidingExercise
) where

import Core
import Language.Eberban.Core
import Util (combineGenerators, combineGeneratorsUniformly)
import System.Random (StdGen)
import qualified Data.Text as T

-- Exercise: provide the lexicon
generateLexiconProvidingExercise :: T.Text -> EntryGenerator -> ExerciseGenerator
generateLexiconProvidingExercise :: Text -> EntryGenerator -> ExerciseGenerator
generateLexiconProvidingExercise Text
lexiconCategory EntryGenerator
entryGenerator StdGen
r0 = Text -> [ExerciseSentence] -> (Text -> Bool) -> Text -> Exercise
TypingExercise Text
title [ExerciseSentence]
sentences Text -> Bool
validator Text
canonicalAnswer where
    (Entry
entry, StdGen
r1) = EntryGenerator
entryGenerator StdGen
r0
    title :: Text
title = Text
"Provide the " Text -> Text -> Text
`T.append` Text
lexiconCategory
    sentences :: [ExerciseSentence]
sentences = [Bool -> Text -> ExerciseSentence
ExerciseSentence Bool
True (Entry -> Text
entryEnglishLong Entry
entry)]
    validator :: Text -> Bool
validator Text
attemptedSolution = (Text -> Text
T.toLower (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text
attemptedSolution) Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Text -> Text
T.toLower (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text
canonicalAnswer)
    canonicalAnswer :: Text
canonicalAnswer = Entry -> Text
entryText Entry
entry