forked from fmidue/logic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomposeFormula.flex
More file actions
234 lines (180 loc) · 6.39 KB
/
composeFormula.flex
File metadata and controls
234 lines (180 loc) · 6.39 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
226
227
228
229
230
231
232
233
234
taskName: ComposeFormula
=============================================
module Global where
import Tasks.ComposeFormula.Config (ComposeFormulaInst)
import Trees.Types (TreeFormulaAnswer)
type Submission = [TreeFormulaAnswer]
type TaskData = ComposeFormulaInst
=============================================
module TaskSettings where
import Control.OutputCapable.Blocks (LangM, Language(..), OutputCapable)
import Data.Map (Map)
import Tasks.ComposeFormula.Config (
ComposeFormulaConfig(..),
TreeDisplayMode (TreeDisplay),
checkComposeFormulaConfig,
)
import Tasks.SynTree.Config (SynTreeConfig(..))
import Trees.Types (BinOp(..))
import qualified Data.Map as Map (fromList)
-- 2025: Weight 0.33 (in Logik)
task03 :: ComposeFormulaConfig
task03 = ComposeFormulaConfig
{ syntaxTreeConfig = SynTreeConfig
{ minNodes = 10
, maxNodes = 14
, minDepth = 4
, maxDepth = 6
, availableAtoms = "ABCDE"
, minAmountOfUniqueAtoms = 5
, binOpFrequencies = listToFM
[ (And, 1)
, (Or, 1)
, (Impl, 1)
, (BackImpl, 1)
, (Equi, 1)
]
, negOpFrequency = 1
, maxConsecutiveNegations = 2
, minUniqueBinOperators = 2
}
, treeDisplayModes = (TreeDisplay, TreeDisplay)
, extraText = Just $ listToFM
[ (German, "Sie dürfen bei dieser Aufgabe nicht Klammern durch Verwendung von Assoziativität weglassen.")
, (English, "Do not try to use associativity in order to omit brackets in this task.")
]
, printSolution = True
, offerUnicodeInput = True
}
listToFM :: Ord k => [(k, a)] -> Map k a
listToFM = Map.fromList
validateSettings :: OutputCapable m => LangM m
validateSettings = checkComposeFormulaConfig task03
=============================================
{-# language OverloadedStrings #-}
{-# Language QuasiQuotes #-}
module TaskData where
import Control.Monad.Random (MonadRandom)
import Data.String.Interpolate (i)
import FlexTask.FormUtil (addCss, addCssClass)
import FlexTask.Generic.Form
import FlexTask.GenUtil (fromGen)
import FlexTask.YesodConfig (Rendered, Widget)
import Tasks.ComposeFormula.Quiz (generateComposeFormulaInst)
import Yesod (RenderMessage(..), cassius, fieldSettingsLabel)
import Global (TaskData)
import TaskSettings (task03)
data InputLabel = First | Second
instance RenderMessage app InputLabel where
renderMessage _ ("en":_) First = "First Formula"
renderMessage _ _ First = "Erste Formel"
renderMessage _ ("en":_) Second = "Second Formula"
renderMessage _ _ Second = "Zweite Formel"
getTask :: MonadRandom m => m (TaskData, String, Rendered Widget)
getTask = fromGen $ do
inst <- generateComposeFormulaInst task03
pure (inst, checkers, form)
fields :: [[FieldInfo]]
fields = [[list Horizontal $ map (addCssClass "formula-input" . fieldSettingsLabel) [First, Second]]]
form :: Rendered Widget
form = addCss inputCss $ formify (Nothing :: Maybe [String]) fields
where
inputCss = [cassius|
.flex-form-span
--margin: 1em
display: inline-block
margin-top: var(--margin)
margin-right: var(--margin)
width: min(calc(100% - var(--margin)), 25em)
.formula-input
width: 100%
margin-left: 0.5em
label
display: block
|]
checkers :: String
checkers = [i|
{-\# language ApplicativeDo \#-}
module Check where
import Capabilities.Cache (MonadCache)
import Capabilities.LatexSvg (MonadLatexSvg)
import Control.Applicative (Alternative)
import Control.OutputCapable.Blocks
import LogicTasks.Syntax.ComposeFormula (partialGrade', completeGrade')
import Global (TaskData, Submission)
checkSyntax
:: OutputCapable m
=> a
-> TaskData
-> Submission
-> LangM m
checkSyntax _ = partialGrade'
checkSemantics
:: (Alternative m, MonadCache m, MonadLatexSvg m, OutputCapable m)
=> FilePath
-> TaskData
-> Submission
-> Rated m
checkSemantics = completeGrade'
|]
=============================================
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE RecordWildCards #-}
module Description (description) where
import Global (TaskData)
import Capabilities.Cache (MonadCache)
import Capabilities.LatexSvg (MonadLatexSvg)
import Control.OutputCapable.Blocks
import Tasks.ComposeFormula.Config (ComposeFormulaInst(..))
import qualified LogicTasks.Syntax.ComposeFormula as LT
description :: (OutputCapable m, MonadCache m, MonadLatexSvg m) => FilePath -> TaskData -> LangM m
description path inst@ComposeFormulaInst{..} = do
LT.description False path inst
paragraph $ do
translate $ do
german "Ein Lösungsversuch könnte beispielsweise aus den folgenden beiden Eingaben bestehen: "
english "For instance, a solution attempt could consist of the following two inputs: "
translatedCode $ flip localise $ translations exampleCode
pure()
pure()
where
(fixedEng, fixedGer) = ("C and (A or not B)","C und (A oder nicht B)")
exampleCode
| unicodeAllowed = do
english $ unlines ["(A ∨ ¬B) and C", fixedEng]
german $ unlines ["(A ∨ ¬B) und C", fixedGer]
| otherwise = do
english $ unlines ["(A or not B) and C", fixedEng]
german $ unlines ["(A oder nicht B) und C", fixedGer]
=============================================
module Parse (parseSubmission) where
import Control.OutputCapable.Blocks (
LangM',
OutputCapable,
ReportT,
)
import Control.OutputCapable.Blocks.Generic (
($>>=),
)
import FlexTask.Generic.Parse (
displayInputAnd,
formParser,
parseWithFallback,
parseInfallibly,
)
import Formula.Parsing.Delayed (
complainAboutMissingParenthesesIfNotFailingOn,
)
import LogicTasks.Parsing (formulaSymbolParser, parser)
import ParsingHelpers (fully)
import Global (Submission)
parseSubmission ::
(Monad m, OutputCapable (ReportT o m))
=> String
-> LangM' (ReportT o m) Submission
parseSubmission input = parseInfallibly formParser input $>>= traverse parseIt
where
parseIt = parseWithFallback
(fully parser)
(displayInputAnd complainAboutMissingParenthesesIfNotFailingOn)
(fully formulaSymbolParser)