Commit b9d6d33a authored by Georgi Angelov's avatar Georgi Angelov
Browse files

Endpoints for explanations added

parent d04b21c2
......@@ -19,4 +19,12 @@ main = simpleHTTP serverConf $ msum [ dir "solve" $ path $ \clue -> path $ \word
-> ok $ show (solveWithAnswerReturn (clue, wordLength) answer)
, dir "solveWithAnswers" $ path $ \clue -> path $ \wordLength -> path $ \answers
-> ok $ show (solveAnswers clue wordLength answers)
, dir "solveAndExplain" $ path $ \clue -> path $ \wordLength
-> ok $ show (solveReturnExpl (clue, wordLength))
, dir "solveAllAndExplain" $ path $ \clue -> path $ \wordLength
-> ok $ show (solveAllReturnExpl (clue, wordLength))
, dir "solveWithAnswerAndExplain" $ path $ \clue -> path $ \wordLength -> path $ \answer
-> ok $ show (solveWithAnswerReturnExpl (clue, wordLength) answer)
, dir "solveWithAnswersAndExplain" $ path $ \clue -> path $ \wordLength -> path $ \answers
-> ok $ show (solveAnswersAndExplain clue wordLength answers)
]
......@@ -47,6 +47,7 @@ solve clue
solveReturn clue
= returnSolutions False clue "" id head' False
-- Returns list of answers with explanations in the format "<answer>: <explanation>"
solveReturnExpl clue
= returnSolutionsAndExplanations False clue "" id head' False
......@@ -66,6 +67,9 @@ solveWithAnswer clue answer
solveWithAnswerReturn clue answer
= returnSolutions False clue answer id head' False
solveWithAnswerReturnExpl clue answer
= returnSolutionsAndExplanations False clue answer id head' False
solveOne n clue
= showSolutions True clue "" (\ps -> [ps !! n]) head' False
......@@ -78,6 +82,9 @@ solveAll clue
solveAllReturn clue
= returnSolutions False clue "" id id False
solveAllReturnExpl clue
= returnSolutionsAndExplanations False clue "" id id False
solveAllWithCache clue
= showSolutions False clue "" id id True
......@@ -123,7 +130,7 @@ returnSolutions displayFull clue answer prefilter postProcess evalCacheOn = extr
extractSol (_,_,_, R (sol, _)) = sol
-- Same as returnSolutions but also gives the explanation to each answer
returnSolutionsAndExplanations displayFull clue answer prefilter postProcess evalCacheOn
= map formatSolution (zip extractSols (map (showSol pCache) sols'))
where
......
......@@ -13,6 +13,16 @@ solveAnswers clue wordLength answers
| otherwise
= head (solveWithAnswerReturn (clue, wordLength) a) : solveEach clue wordLength as
solveAnswersAndExplain clue wordLength answers
= solveEach clue wordLength (wordsWhen (==',') answers)
where
solveEach _ _ [] = []
solveEach clue wordLength (a:as)
| null (solveWithAnswerReturnExpl (clue, wordLength) a)
= solveEach clue wordLength as
| otherwise
= head (solveWithAnswerReturnExpl (clue, wordLength) a) : solveEach clue wordLength as
-- Helper function to split string by character into a list of strings
wordsWhen :: (Char -> Bool) -> String -> [String]
wordsWhen p s = case dropWhile p s of
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment