-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathresStepFlex.flex
More file actions
225 lines (166 loc) · 6.68 KB
/
resStepFlex.flex
File metadata and controls
225 lines (166 loc) · 6.68 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
taskName: ResolutionStepReverse
=============================================
module Global where
import LogicTasks.Config (StepInst)
import Formula.Types (Clause)
type Submission = Clause
type TaskData = StepInst
=============================================
module TaskSettings where
import LogicTasks.Config (dBaseConf, StepConfig(..))
import Control.OutputCapable.Blocks (LangM, OutputCapable)
import LogicTasks.Semantics.Step (verifyQuiz)
stepConf :: StepConfig
stepConf = StepConfig
{ baseConf = dBaseConf
, useSetNotation = False
, printSolution = True
, extraText = Nothing
, offerUnicodeInput = True
}
validateSettings :: OutputCapable m => LangM m
validateSettings = verifyQuiz stepConf
=============================================
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
module TaskData (getTask) where
import Control.Monad.Random (MonadRandom)
import Data.List (isSubsequenceOf)
import Data.String.Interpolate (i)
import FlexTask.Generic.Form
import FlexTask.GenUtil (fromGen)
import FlexTask.YesodConfig (Rendered, Widget)
import LogicTasks.Config (StepInst(..))
import LogicTasks.Formula (Formula(literals))
import LogicTasks.Semantics.Step (genStepInst)
import Test.QuickCheck (suchThat)
import Global
import TaskSettings
getTask :: MonadRandom m => m (TaskData, String, Rendered Widget)
getTask = do
resInst <- fromGen $ genStepInst stepConf `suchThat` (\StepInst{..} ->
not $ literals (snd solution) `isSubsequenceOf` literals clause1
)
pure (resInst, checkers, form)
form :: Rendered Widget
form = formify (Nothing :: Maybe String) [[single ""]]
checkers :: String
checkers = [i|
{-\# LANGUAGE ApplicativeDo \#-}
module Check (checkSyntax, checkSemantics) where
import Control.Monad (when)
import LogicTasks.Config (StepInst(..))
import Control.OutputCapable.Blocks
import Formula.Resolution (resolve)
import LogicTasks.Semantics.Step (showClause)
import Global
checkSyntax :: OutputCapable m => TaskData -> Submission -> LangM m
checkSyntax _ _ = pure ()
checkSemantics :: OutputCapable m => FilePath -> TaskData -> Submission -> Rated m
checkSemantics _ taskData submittedClause =
case resolve (clause1 taskData) submittedClause (fst (solution taskData)) of
Nothing -> do
refuse $ indent $ do
translate $ do
german "Das Literal mit welchem der Schritt durchgeführt wird, fehlt in der Klausel!"
english "The literal used to perform the step is missing from the clause!"
displaySolution
pure ()
pure 0.0
Just solClause ->
if solClause == snd (solution taskData)
then pure 1.0
else do
refuse $ indent $ translate $ do
german "Die Resolution ist nicht korrekt."
english "Die Resolution is not correct."
pure 0.0
where
displaySolution = when (showSolution taskData) $ do
translate $ do
german "Eine mögliche Lösung für die Aufgabe ist:"
english "A possible solution for this task is:"
code (showClause (usesSetNotation taskData) (clause2 taskData))
pure ()
|]
=============================================
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE RecordWildCards #-}
module Description (description) where
import Control.OutputCapable.Blocks
import LogicTasks.Config (StepInst(..))
import LogicTasks.Semantics.Step (showClause)
import LogicTasks.Keys
import Global
description :: OutputCapable m => FilePath -> TaskData -> LangM m
description _ StepInst{..} = do
paragraph $ do
translate $ do
german "Betrachten Sie diese Resolvente als das Ergebnis eines Resolutionsschritts:"
english "Consider this resolvent as a result of a resolution step:"
indent $ code $ show' $ snd solution
translate $ do
german "Eine der zur Resolution verwendeten Klauseln ist:"
english "One of the clauses used for the resolution is:"
indent $ code $ show' clause1
pure ()
paragraph $ indent $ translate $ do
german $ "Geben Sie eine mögliche zweite Klausel an, " ++
"so dass ein Resolutionsschritt mit dieser und der gegebenen Klausel die obige Resolvente erzeugt."
english "Provide a feasible second clause such that resolving it with the given clause results in the above resolvent."
paragraph $ indent $ do
translate notationText
translatedCode $ flip localise $ translations example
pure ()
keyHeading
negationKey unicodeAllowed
key
pure ()
where
show' = showClause usesSetNotation
setExample = do
german $ if unicodeAllowed then "{¬B, C}" else "{nicht B, C}"
english $ if unicodeAllowed then "{¬B, C}" else "{not B, C}"
exampleCode = do
german $ if unicodeAllowed then "¬B ∨ C" else "nicht B oder C"
english $ if unicodeAllowed then "¬B ∨ C" else "not B or C"
(notationText,key,example) = if usesSetNotation
then (
do german "Nutzen Sie zur Angabe der Klausel die Mengenschreibweise! Ein Lösungsversuch könnte beispielsweise so aussehen: "
english "Specify the clause using set notation! A valid solution could look like this: "
, paragraph $ indent $ do
translate $ do
german "Nicht-leere Klausel:"
english "Non-empty clause:"
code "{ ... }"
pure ()
, setExample
)
else (
do german "Nutzen Sie zur Angabe der Klausel eine Formel! Ein Lösungsversuch könnte beispielsweise so aussehen: "
english "Specify the clause using a formula! A valid solution could look like this: "
, orKey unicodeAllowed
, exampleCode
)
=============================================
module Parse (parseSubmission) where
import LogicTasks.Config (StepConfig(..))
import Control.OutputCapable.Blocks
import FlexTask.Generic.Parse
import Formula.Parsing (clauseFormulaParser, clauseSetParser)
import Formula.Types (Clause(..))
import Global
import TaskSettings
instance Parse Clause where
formParser
= escaped clauseParser
where
clauseParser
| useSetNotation stepConf = clauseSetParser
| otherwise = clauseFormulaParser
parseSubmission ::
(Monad m, OutputCapable (ReportT o m))
=> String
-> LangM' (ReportT o m) Submission
parseSubmission = parseWithOrReport formParser reportWithFieldNumber