-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathIllegalFormulas.hs
More file actions
167 lines (132 loc) · 5.43 KB
/
IllegalFormulas.hs
File metadata and controls
167 lines (132 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TupleSections #-}
module LogicTasks.Syntax.IllegalFormulas where
import Capabilities.Cache (MonadCache)
import Capabilities.LatexSvg (MonadLatexSvg)
import Control.OutputCapable.Blocks (
GenericOutputCapable (code, image, indent),
LangM,
OutputCapable,
($=<<),
english,
german,
Rated,
multipleChoice,
ArticleToUse (DefiniteArticle),
paragraph,
translations,
reRefuse,
multipleChoiceSyntax,
)
import Data.List.Extra (nubSort)
import LogicTasks.Helpers (example, extra, focus, indexed, instruct)
import Tasks.LegalProposition.Config (
LegalPropositionInst(..),
LegalPropositionConfig(..),
checkLegalPropositionConfig,
propFormulaIsErroneous,
PropFormulaInfo (..),
PropErrorReason (..),
)
import Control.Monad (when)
import Trees.Print (transferToPicture)
import LogicTasks.Syntax.TreeToFormula (cacheTree)
import Data.Foldable (for_)
import Data.Maybe (isJust, fromMaybe)
import qualified Data.Map as Map (fromAscList)
import Control.Applicative (Alternative)
import Data.Tuple.Extra (thd3)
description :: OutputCapable m => Bool -> LegalPropositionInst -> LangM m
description inputHelp LegalPropositionInst{..} = do
instruct $ do
english "Consider the following propositional (pseudo) formulas:"
german "Betrachten Sie die folgenden aussagenlogischen (Pseudo-)Formeln:"
focus $ unlines $ indexed $ map thd3 formulaInfos
instruct $ do
english "Some of these are syntactically wrong. Which of these formulas are correctly formed?"
german "Einige davon enthalten syntaktische Fehler. Geben Sie an, welche Formeln korrekt geformt sind."
when inputHelp $ do
instruct $ do
english "Enter a list containing the indices of the syntactically correct formulas to submit your answer."
german "Geben Sie eine Liste der Indizes aller syntaktisch korrekten Formeln als Ihre Lösung an."
example "[2,3]" $ do
english "For example, if only choices 2 and 3 are correctly formed, then the solution is:"
german "Sind beispielsweise nur Auswahlmöglichkeiten 2 und 3 richtig geformt, dann ist diese Lösung korrekt:"
pure()
extra addText
pure ()
verifyInst :: OutputCapable m => LegalPropositionInst -> LangM m
verifyInst _ = pure ()
verifyConfig :: OutputCapable m => LegalPropositionConfig -> LangM m
verifyConfig = checkLegalPropositionConfig
start :: [Int]
start = []
partialGrade :: OutputCapable m => LegalPropositionInst -> [Int] -> LangM m
partialGrade LegalPropositionInst{..} = multipleChoiceSyntax False [1..length formulaInfos]
-- jscpd:ignore-start
completeGrade
:: (OutputCapable m, MonadCache m, MonadLatexSvg m, Alternative m)
=> FilePath
-> LegalPropositionInst
-> [Int]
-> Rated m
completeGrade path LegalPropositionInst{..} sol = reRefuse
(multipleChoice
what
simpleSolutionDisplay
(Map.fromAscList solution)
sol)
$ when (hasWrongSolution && detailedSolution) $ do
instruct $ do
german "Die Lösung dieser Aufgabe sieht wie folgt aus:"
english "The solution for this task looks like this:"
for_ formulaInfos $ \(i,info, formula) -> paragraph $ indent $ do
code (show i ++ ". " ++ formula)
case info of
Correct tree -> do
instruct $ do
german "ist korrekt geformt. "
german "Der zugehörige Syntaxbaum sieht so aus:"
english "is correctly formed. "
english "The corresponding syntax tree looks like this:"
image $=<< cacheTree (transferToPicture tree) path
pure ()
Erroneous err -> do
instruct $ do
german "ist nicht korrekt geformt. "
english "is not correctly formed. "
case err of
IllegalParentheses -> do
german "Die Anzahl an öffnenden und schließenden Klammern stimmt nicht überein."
english "The amount of opening and closing parentheses does not match."
IllegalOperator -> do
german "Es werden zwei Teilformeln falsch miteinander verknüpft."
english "Two subformulas are combined incorrectly."
IllegalOperand -> do
german "Nicht alle Operatoren verfügen über gültige Teilformeln."
english "Not all operators have valid subformulas."
MissingOperator -> do
german "Nicht alle Teilformeln werden verknüpft."
english "There are uncombined subformulas."
MissingOperand -> do
german "Nicht alle Operatoren verfügen über die korrekte Anzahl an Teilformeln."
english "Not all operators have the correct number of subformulas."
pure ()
instruct $ do
german "Hinweis: Für manche Fehler gibt es auch andere Interpretationen."
english "Note: There are also other interpretations for some errors."
pure ()
where
detailedSolution = fromMaybe False showSolution
what = translations $ do
german "Indizes"
english "indices"
solution = map (\(i,info,_) -> (i, not (propFormulaIsErroneous info))) formulaInfos
hasWrongSolution = filter snd solution /= nubSort (map (,True) sol)
simpleSolutionDisplay
| isJust showSolution && not detailedSolution
= Just (DefiniteArticle, show [ i | (i,True) <- solution])
| otherwise = Nothing
-- jscpd:ignore-end