Commit 7a7d7973 authored by Angelov, Georgi's avatar Angelov, Georgi
Browse files

Merge branch 'return_explanations' into 'master'

Return explanations with answers

See merge request !2
parents c3850bbc 3ebcbb8c
......@@ -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,10 @@ 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
solveFull clue
= showSolutions True clue "" id head' False
......@@ -63,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
......@@ -75,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
......@@ -120,6 +130,24 @@ 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
formatSolution (sol, expl) = sol ++ ": " ++ expl
acceptAnyDef = not (null answer)
(parses, pCache) = if null answer
then prunedParses clue
else prunedParsesWithAnswer clue answer
parses' = prefilter parses
sols = evaluate parses' pCache clue answer evalCacheOn
sols' = postProcess sols
extractSols = map extractSol sols'
extractSol (_,_,_, R (sol, _)) = sol
dumpIndicators :: (IndicatorPredicateSet, String, [String]) -> IO ()
dumpIndicators (inds, textString, stemmedTextWords)
......
......@@ -3,15 +3,20 @@ module Utils where
import Solver
-- Receives a list of possible answers to a clue and returns a list of all valid answers
solveAnswers clue wordLength answers
solveAnswers = genericSolveAnswers solveWithAnswerReturn
-- Receives a list of possible answers to a clue and returns a list of all valid answers with explanations
solveAnswersAndExplain = genericSolveAnswers solveWithAnswerReturnExpl
genericSolveAnswers solveVariation clue wordLength answers
= solveEach clue wordLength (wordsWhen (==',') answers)
where
solveEach _ _ [] = []
solveEach clue wordLength (a:as)
| null (solveWithAnswerReturn (clue, wordLength) a)
| null (solveVariation (clue, wordLength) a)
= solveEach clue wordLength as
| otherwise
= head (solveWithAnswerReturn (clue, wordLength) a) : solveEach clue wordLength as
= head (solveVariation (clue, wordLength) a) : solveEach clue wordLength as
-- Helper function to split string by character into a list of strings
wordsWhen :: (Char -> Bool) -> String -> [String]
......
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