Skip to content

Commit

Permalink
Merge pull request #2474 from JacquesCarette/addingStoSentenceCombina…
Browse files Browse the repository at this point in the history
…tors

Importing Sentence Combinators as qualified
  • Loading branch information
JacquesCarette authored May 17, 2021
2 parents baf85fd + 8689aaf commit c188cda
Show file tree
Hide file tree
Showing 60 changed files with 646 additions and 646 deletions.
14 changes: 7 additions & 7 deletions code/drasil-example/Drasil/DblPendulum/Assumptions.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Drasil.DblPendulum.Assumptions (pend2DMotion, cartCoord, cartCoordRight, yAxisDir, startOrigin, assumptions) where

import Language.Drasil
import Utils.Drasil.Sentence
import qualified Utils.Drasil.Sentence as S

import Data.Drasil.Concepts.Documentation (assumpDom)
import Data.Drasil.Concepts.Math (cartesian, xAxis, yAxis, direction, origin, positive)
Expand All @@ -20,18 +20,18 @@ yAxisDir = cic "yAxisDir" yAxisDirDesc "yAxisDir"
startOrigin = cic "startOrigin" startOriginDesc "startOrigin" assumpDom

pend2DMotionDesc :: Sentence
pend2DMotionDesc = S "The" +:+ phrase pendulum +:+ phrase motion `sIs` phrase twoD +:+. sParen (getAcc twoD)
pend2DMotionDesc = S "The" +:+ phrase pendulum +:+ phrase motion `S.sIs` phrase twoD +:+. sParen (getAcc twoD)

cartCoordDesc :: Sentence
cartCoordDesc = S "A" +:+ (phrase cartesian `sIs` S "used")
cartCoordDesc = S "A" +:+ (phrase cartesian `S.sIs` S "used")

cartCoordRightDesc :: Sentence
cartCoordRightDesc = S "The" +:+ phrase cartesian `sIs` S "right-handed where" +:+ phrase positive +:+.
phrase xAxis `sAnd` phrase yAxis +:+ S "point right up"
cartCoordRightDesc = S "The" +:+ phrase cartesian `S.sIs` S "right-handed where" +:+ phrase positive +:+.
phrase xAxis `S.sAnd` phrase yAxis +:+ S "point right up"

yAxisDirDesc :: Sentence
yAxisDirDesc = phrase direction `the_ofThe'` phrase yAxis `sIs` S "directed opposite to" +:+. phrase gravity
yAxisDirDesc = phrase direction `S.the_ofThe'` phrase yAxis `S.sIs` S "directed opposite to" +:+. phrase gravity

startOriginDesc :: Sentence
startOriginDesc = S "The" +:+. (phrase pendulum `sIs` S "attached" `toThe` phrase origin)
startOriginDesc = S "The" +:+. (phrase pendulum `S.sIs` S "attached" `S.toThe` phrase origin)

14 changes: 7 additions & 7 deletions code/drasil-example/Drasil/DblPendulum/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Database.Drasil (Block, ChunkDB, ReferenceDB, SystemInformation(SI),
_datadefs, _configFiles, _definitions, _defSequence, _inputs, _kind, _outputs,
_quants, _sys, _sysinfodb, _usedinfodb)
import Utils.Drasil
import Utils.Drasil.Sentence
import qualified Utils.Drasil.Sentence as S
import Data.Drasil.People (olu)
import Data.Drasil.SI_Units (metre, second, newton, kilogram, degree, radian, hertz)
import Data.Drasil.Concepts.Software (program, errMsg)
Expand Down Expand Up @@ -47,7 +47,7 @@ import Drasil.Projectile.References (hibbeler2004)


srs :: Document
srs = mkDoc mkSRS (sFor'' titleize phrase) si
srs = mkDoc mkSRS (S.sFor'' titleize phrase) si

printSetting :: PrintingInformation
printSetting = PI symbMap Equational defaultConfiguration
Expand Down Expand Up @@ -91,14 +91,14 @@ mkSRS = [RefSec $ --This creates the Reference section of the SRS
]

justification :: Sentence
justification = foldlSent [S "A", phrase pendulum, S "consists" `sOf` phrase mass,
S "attached to the end of a", phrase rod `andIts` S "moving curve" `sIs`
justification = foldlSent [S "A", phrase pendulum, S "consists" `S.sOf` phrase mass,
S "attached to the end of a", phrase rod `S.andIts` S "moving curve" `S.sIs`
(S "highly sensitive to initial conditions" !.), S "Therefore" `sC`
S "it is useful to have a", phrase program, S "to simulate", phrase motion
`the_ofThe` phrase pendulum, (S "to exhibit its chaotic characteristics" !.),
`S.the_ofThe` phrase pendulum, (S "to exhibit its chaotic characteristics" !.),
S "The", phrase program, S "documented here is called", phrase pendulum]
scope :: Sentence
scope = foldlSent [S "the", phrase analysis `sOf` S "a", phrase twoD,
scope = foldlSent [S "the", phrase analysis `S.sOfA` phrase twoD,
sParen (getAcc twoD), phrase pendulum, phrase motion, phrase problem,
S "with various initial conditions"]

Expand Down Expand Up @@ -158,7 +158,7 @@ concIns = assumptions ++ goals ++ funcReqs ++ nonFuncReqs
------------------------------------

prob :: Sentence
prob = foldlSent_ [ S "efficiently and correctly to predict the", phrase motion, S "of a",
prob = foldlSent_ [ S "efficiently and correctly to predict the", phrase motion `S.sOfA`
phrase pendulum]

---------------------------------
Expand Down
16 changes: 8 additions & 8 deletions code/drasil-example/Drasil/DblPendulum/DataDefs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Drasil.DblPendulum.DataDefs (dataDefs, positionIY, positionIX, angFrequen

import Prelude hiding (sin, cos, sqrt)
import Language.Drasil
import Utils.Drasil.Sentence
import qualified Utils.Drasil.Sentence as S
import Data.Drasil.SI_Units (second)
import Theory.Drasil (DataDefinition, ddNoRefs)
import Drasil.DblPendulum.Figures (figMotion)
Expand All @@ -30,10 +30,10 @@ positionIXEqn :: Expr
positionIXEqn = sy lenRod * sin (sy initialPendAngle)

figRef :: Sentence
figRef = ch QP.ixPos `sIs` S "shown in" +:+. makeRef2S figMotion
figRef = ch QP.ixPos `S.sIs` S "shown in" +:+. makeRef2S figMotion

positionRef :: Sentence
positionRef = ch QP.ixPos `isThe` phrase horizontal +:+ phrase QP.position
positionRef = ch QP.ixPos `S.isThe` phrase horizontal +:+ phrase QP.position

------------------------------------------------------
positionIY :: DataDefinition
Expand All @@ -46,10 +46,10 @@ positionIYEqn :: Expr
positionIYEqn = negate (sy lenRod * cos (sy initialPendAngle))

figReff :: Sentence
figReff = ch QP.iyPos `sIs` S "shown in" +:+. makeRef2S figMotion
figReff = ch QP.iyPos `S.sIs` S "shown in" +:+. makeRef2S figMotion

positionReff :: Sentence
positionReff = ch QP.iyPos `isThe` phrase vertical +:+ phrase QP.position
positionReff = ch QP.iyPos `S.isThe` phrase vertical +:+ phrase QP.position

------------------------------------------------------

Expand All @@ -64,7 +64,7 @@ frequencyDDEqn = 1 / sy QP.period


frequencyRef :: Sentence
frequencyRef = ch QP.frequency `isThe` S "number of back and forth swings in one" +:+ phrase second
frequencyRef = ch QP.frequency `S.isThe` S "number of back and forth swings in one" +:+ phrase second

------------------------------------------------------

Expand All @@ -78,7 +78,7 @@ angFrequencyDDEqn :: Expr
angFrequencyDDEqn = 2 * sy QM.pi_ / sy QP.period

angFrequencyRef :: Sentence
angFrequencyRef = ch QP.period `sIs` S "from" +:+ makeRef2S periodSHMDD
angFrequencyRef = ch QP.period `S.sIs` S "from" +:+ makeRef2S periodSHMDD

------------------------------------------------------

Expand All @@ -92,4 +92,4 @@ periodSHMDDEqn :: Expr
periodSHMDDEqn = 1 / sy QP.frequency

periodSHMRef :: Sentence
periodSHMRef = ch QP.period `sIs` S "from" +:+ makeRef2S frequencyDD
periodSHMRef = ch QP.period `S.sIs` S "from" +:+ makeRef2S frequencyDD
34 changes: 17 additions & 17 deletions code/drasil-example/Drasil/DblPendulum/GenDefs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Prelude hiding (cos, sin, sqrt)
import Language.Drasil
import Theory.Drasil (GenDefn, gdNoRefs, ModelKinds (OthModel, EquationalModel))
import Utils.Drasil
import Utils.Drasil.Sentence
import qualified Utils.Drasil.Sentence as S

-- import Data.Drasil.Concepts.Documentation (coordinate, symbol_)
import Data.Drasil.Concepts.Math (xComp, yComp, equation, component, direction, angle)
Expand Down Expand Up @@ -37,7 +37,7 @@ velocityIXGD = gdNoRefs (EquationalModel velocityIXQD) (getUnit velocity)

velocityIXQD :: QDefinition
velocityIXQD = mkQuantDef' xVel (nounPhraseSent $ foldlSent_
[phrase xComp `sOf` phrase velocity `the_ofThe` phrase pendulum])
[phrase xComp `S.sOf` phrase velocity `S.the_ofThe` phrase pendulum])
velocityIXExpr

velocityIXExpr :: Expr
Expand All @@ -63,7 +63,7 @@ velocityIXDerivSent2 = S "We also know the" +:+ phrase horizontal +:+ phrase pos
velocityIXDerivEqn2 = sy xPos $= sy lenRod * sin (sy pendDisplacementAngle)
velocityIXDerivSent3 = S "Applying this,"
velocityIXDerivEqn3 = sy xVel $= deriv (sy lenRod * sin (sy pendDisplacementAngle)) time
velocityIXDerivSent4 = E (sy lenRod) `sIs` S "constant" `wrt` S "time, so"
velocityIXDerivSent4 = E (sy lenRod) `S.sIs` S "constant" `S.wrt` S "time, so"
velocityIXDerivEqn4 = sy xVel $= sy lenRod * deriv (sin (sy pendDisplacementAngle)) time
velocityIXDerivSent5 = S "Therefore, using the chain rule,"

Expand All @@ -74,7 +74,7 @@ velocityIYGD = gdNoRefs (EquationalModel velocityIYQD) (getUnit velocity)

velocityIYQD :: QDefinition
velocityIYQD = mkQuantDef' yVel (nounPhraseSent $ foldlSent_
[phrase yComp `sOf` phrase velocity `the_ofThe` phrase pendulum]) velocityIYExpr
[phrase yComp `S.sOf` phrase velocity `S.the_ofThe` phrase pendulum]) velocityIYExpr

velocityIYExpr :: Expr
velocityIYExpr = sy angularVelocity * sy lenRod * sin (sy pendDisplacementAngle)
Expand All @@ -99,7 +99,7 @@ velocityIYDerivSent2 = S "We also know the" +:+ phrase vertical +:+ phrase posit
velocityIYDerivEqn2 = sy yPos $= negate (sy lenRod * cos (sy pendDisplacementAngle))
velocityIYDerivSent3 = S "Applying this again,"
velocityIYDerivEqn3 = sy yVel $= negate (deriv (sy lenRod * cos (sy pendDisplacementAngle)) time)
velocityIYDerivSent4 = E (sy lenRod) `sIs` S "constant" `wrt` S "time, so"
velocityIYDerivSent4 = E (sy lenRod) `S.sIs` S "constant" `S.wrt` S "time, so"
velocityIYDerivEqn4 = sy yVel $= negate (sy lenRod * deriv (cos (sy pendDisplacementAngle)) time)
velocityIYDerivSent5 = S "Therefore, using the chain rule,"

Expand All @@ -110,7 +110,7 @@ accelerationIXGD = gdNoRefs (EquationalModel accelerationIXQD) (getUnit accelera

accelerationIXQD :: QDefinition
accelerationIXQD = mkQuantDef' xAccel (nounPhraseSent $ foldlSent_
[phrase xComp `sOf` phrase acceleration `the_ofThe` phrase pendulum]) accelerationIXExpr
[phrase xComp `S.sOf` phrase acceleration `S.the_ofThe` phrase pendulum]) accelerationIXExpr

accelerationIXExpr :: Expr
accelerationIXExpr = negate (square (sy angularVelocity) * sy lenRod * sin (sy pendDisplacementAngle))
Expand Down Expand Up @@ -148,7 +148,7 @@ accelerationIYGD = gdNoRefs (EquationalModel accelerationIYQD) (getUnit accelera

accelerationIYQD :: QDefinition
accelerationIYQD = mkQuantDef' yAccel (nounPhraseSent $ foldlSent_
[phrase yComp `sOf` phrase acceleration `the_ofThe` phrase pendulum]) accelerationIYExpr
[phrase yComp `S.sOf` phrase acceleration `S.the_ofThe` phrase pendulum]) accelerationIYExpr

accelerationIYExpr :: Expr
accelerationIYExpr = (square (sy angularVelocity) * sy lenRod * cos (sy pendDisplacementAngle))
Expand Down Expand Up @@ -216,7 +216,7 @@ angFrequencyGD = gdNoRefs (OthModel angFrequencyRC) (getUnit angularFrequency)

angFrequencyRC :: RelationConcept
angFrequencyRC = makeRC "angFrequencyRC" (nounPhraseSent $ foldlSent_
[ phrase angularFrequency `the_ofThe` phrase pendulum]) EmptyS angFrequencyRel
[ phrase angularFrequency `S.the_ofThe` phrase pendulum]) EmptyS angFrequencyRel

angFrequencyRel :: Relation
angFrequencyRel = sy angularFrequency $= sqrt (sy gravitationalAccel / sy lenRod )
Expand All @@ -242,11 +242,11 @@ angFrequencyDerivEqn1, angFrequencyDerivEqn2, angFrequencyDerivEqn3, angFrequenc


angFrequencyDerivSent1 = foldlSentCol [S "Consider the", phrase torque, S "on a", phrase pendulum +:+. definedIn'' newtonSLR,
S "The", phrase force, S "providing the restoring", phrase torque `sIs` (phrase component `sOf`
phrase weight `the_ofThe` phrase pendulum), S "bob that acts along the" +:+. phrase arcLen,
(phrase torque `isThe` phrase len) `the_ofThe'` S "string", ch lenRod, S "multiplied by", S "component"
`the_ofThe` S "net", phrase force, S "that is perpendicular to", S "radius" `the_ofThe` (S "arc" !.),
S "The minus sign indicates the", phrase torque, S "acts in the opposite", phrase direction `ofThe` phrase angularDisplacement]
S "The", phrase force, S "providing the restoring", phrase torque `S.sIs` (phrase component `S.sOf`
phrase weight `S.the_ofThe` phrase pendulum), S "bob that acts along the" +:+. phrase arcLen,
(phrase torque `S.isThe` phrase len) `S.the_ofThe'` S "string", ch lenRod, S "multiplied by", S "component"
`S.the_ofThe` S "net", phrase force, S "that is perpendicular to", S "radius" `S.the_ofThe` (S "arc" !.),
S "The minus sign indicates the", phrase torque, S "acts in the opposite", phrase direction `S.ofThe` phrase angularDisplacement]


angFrequencyDerivEqn1 = sy torque $= negate (sy lenRod) * (sy mass * sy gravitationalAccel * sin (sy pendDisplacementAngle))
Expand All @@ -258,15 +258,15 @@ angFrequencyDerivEqn3 = sy momentOfInertia * deriv (deriv (sy pendDisplacementAn
angFrequencyDerivSent4 = S "Substituting for" +:+ ch momentOfInertia
angFrequencyDerivEqn4 = sy mass * sy lenRod $^ 2 * deriv (deriv (sy pendDisplacementAngle) time) time $= negate (sy lenRod)
* sy mass * sy gravitationalAccel * sin (sy pendDisplacementAngle)
angFrequencyDerivSent5 = S "Crossing out" +:+ ch mass `sAnd` ch lenRod +:+ S "we have"
angFrequencyDerivSent5 = S "Crossing out" +:+ ch mass `S.sAnd` ch lenRod +:+ S "we have"
angFrequencyDerivEqn5 = deriv (deriv (sy pendDisplacementAngle) time) time $= negate(sy gravitationalAccel/ sy lenRod) * sin (sy pendDisplacementAngle)
angFrequencyDerivSent6 = S "For small" +:+ plural angle `sC` S "we approximate" +:+ S "sin" +:+ ch pendDisplacementAngle +:+ S "to" +:+ ch pendDisplacementAngle
angFrequencyDerivEqn6 = deriv (deriv (sy pendDisplacementAngle) time) time $= negate(sy gravitationalAccel/ sy lenRod) * sy pendDisplacementAngle
angFrequencyDerivSent7 = S "Because this" +:+ phrase equation `sC` S "has the same form as the" +:+ phrase equation +:+
S "for" +:+ phrase shm +:+. S "the solution is easy to find" +:+ S " The" +:+ phrase angularFrequency
angFrequencyDerivEqn7 = sy angularFrequency $= sqrt (sy gravitationalAccel / sy lenRod)
angFrequencyGDNotes :: Sentence
angFrequencyGDNotes = S "The" +:+ phrase torque `sIs` definedIn'' newtonSLR `sAnd` phrase frequency `sIs` definedIn frequencyDD
angFrequencyGDNotes = S "The" +:+ phrase torque `S.sIs` definedIn'' newtonSLR `S.sAnd` phrase frequency `S.sIs` definedIn frequencyDD



Expand Down Expand Up @@ -296,14 +296,14 @@ periodPendDerivEqns = [periodPendDerivEqn1, periodPendDerivEqn2]

periodPendDerivEqn1, periodPendDerivEqn2 :: Expr

periodPendDerivSent1 = phrase period `the_ofThe'` phrase pendulum +:+ S "can be defined from" +:+
periodPendDerivSent1 = phrase period `S.the_ofThe'` phrase pendulum +:+ S "can be defined from" +:+
makeRef2S angFrequencyGD +:+ phrase equation
periodPendDerivEqn1 = sy angularFrequency $= sqrt (sy gravitationalAccel / sy lenRod)
periodPendDerivSent2 = S "Therefore from the" +:+ phrase equation +:+ makeRef2S angFrequencyDD `sC` S "we have"

periodPendDerivEqn2 = sy period $= 2 * sy QM.pi_ * sqrt (sy lenRod/ sy gravitationalAccel)

periodPendNotes :: Sentence
periodPendNotes = S "The" +:+ phrase frequency `sAnd` phrase period +:+ S "are defined in" +:+ makeRef2S frequencyDD +:+
periodPendNotes = S "The" +:+ phrase frequency `S.sAnd` phrase period +:+ S "are defined in" +:+ makeRef2S frequencyDD +:+
makeRef2S periodSHMDD +:+ S "respectively"

6 changes: 3 additions & 3 deletions code/drasil-example/Drasil/DblPendulum/Goals.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Drasil.DblPendulum.Goals (goals, goalsInputs) where

import Language.Drasil
import Utils.Drasil.Sentence
import qualified Utils.Drasil.Sentence as S
import Data.Drasil.Concepts.Documentation (goalStmtDom)
import qualified Data.Drasil.Concepts.PhysicalProperties as CPP (mass, len)
import Data.Drasil.Concepts.Physics (gravitationalConst, motion)
Expand All @@ -14,11 +14,11 @@ goals = [motionMass]


goalsInputs :: [Sentence]
goalsInputs = [(phrase CPP.mass `sAnd` phrase CPP.len `the_ofThe` phrase rod) `sC` phrase iAngle `ofThe` phrase CPP.mass `andThe` phrase gravitationalConst ]
goalsInputs = [(phrase CPP.mass `S.sAnd` phrase CPP.len `S.the_ofThe` phrase rod) `sC` phrase iAngle `S.ofThe` phrase CPP.mass `S.andThe` phrase gravitationalConst ]

motionMass :: ConceptInstance
motionMass = cic "motionMass"
(S "Calculate" +:+ (phrase motion `the_ofThe` phrase CPP.mass))
(S "Calculate" +:+ (phrase motion `S.the_ofThe` phrase CPP.mass))
"Motion-of-the-mass" goalStmtDom


20 changes: 10 additions & 10 deletions code/drasil-example/Drasil/DblPendulum/IMods.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Language.Drasil
import Theory.Drasil (InstanceModel, imNoRefs, qwC, ModelKinds (OthModel))
--imNoDerivNoRefs, )
import Utils.Drasil
import Utils.Drasil.Sentence
import qualified Utils.Drasil.Sentence as S
import Data.Drasil.Quantities.Physics (gravitationalAccel,
angularAccel, momentOfInertia,
time, angularDisplacement, angularFrequency, torque, angularDisplacement, time)
Expand Down Expand Up @@ -48,23 +48,23 @@ angularDisplacementDerivSents = [angularDisplacementDerivSent1, angularDisplacem
angularDisplacementDerivSent1, angularDisplacementDerivSent2, angularDisplacementDerivSent3,
angularDisplacementDerivSent4, angularDisplacementDerivSent5 :: Sentence

angularDisplacementDerivSent1 = foldlSentCol [S "When the", phrase pendulum `sIs` S "displaced to an", phrase iAngle `sAnd` S "released" `sC`
angularDisplacementDerivSent1 = foldlSentCol [S "When the", phrase pendulum `S.sIs` S "displaced to an", phrase iAngle `S.sAnd` S "released" `sC`
S "the", phrase pendulum, S "swings back and forth with periodic" +:+. phrase motion,
S "By applying", phrase newtonSLRRC `sIn` makeRef2S newtonSLR `sC`
S "the", phrase equation `sOf` phrase motion, S "for the", phrase pendulum, S "may be obtained"]
S "By applying", phrase newtonSLRRC `S.sIn` makeRef2S newtonSLR `sC`
S "the", phrase equation `S.sOf` phrase motion, S "for the", phrase pendulum, S "may be obtained"]


angularDisplacementDerivSent2 = foldlSentCol [S "Where", ch torque `denotes` phrase torque `sC`
ch momentOfInertia `denotes` phrase momentOfInertia `sAnd` ch angularAccel `denotes`
angularDisplacementDerivSent2 = foldlSentCol [S "Where", ch torque `S.denotes` phrase torque `sC`
ch momentOfInertia `S.denotes` phrase momentOfInertia `S.sAnd` ch angularAccel `S.denotes`
(phrase angularAccel !.), S "This implies"]


angularDisplacementDerivSent3 = foldlSentCol [S "And rearranged as" ]

angularDisplacementDerivSent4 = foldlSentCol [S "If the", phrase amplitude `sOf` phrase angularDisplacement, S "is small enough" `sC`
angularDisplacementDerivSent4 = foldlSentCol [S "If the", phrase amplitude `S.sOf` phrase angularDisplacement, S "is small enough" `sC`
S "we can approximate", E (sin (sy pendDisplacementAngle) $= sy pendDisplacementAngle), S "for the purpose of a simple", phrase pendulum,
S "at very small" +:+. plural angle,
S "Then the", phrase equation `sOf` phrase motion, S "reduces to the", phrase equation `sOf` phrase shm]
S "Then the", phrase equation `S.sOf` phrase motion, S "reduces to the", phrase equation `S.sOf` phrase shm]

angularDisplacementDerivSent5 = foldlSentCol [S "Thus the", phrase shm, S "is" ]

Expand Down Expand Up @@ -97,8 +97,8 @@ angularDispConstraintNote :: Sentence


angularDispConstraintNote = S "The" +:+ phrase constraint +:+
E ( sy initialPendAngle $> 0) `sIs` S "required" +:+.
S "The" +:+ phrase angularFrequency `sIs` definedIn'' angFrequencyGD
E ( sy initialPendAngle $> 0) `S.sIs` S "required" +:+.
S "The" +:+ phrase angularFrequency `S.sIs` definedIn'' angFrequencyGD

--gravitationalAccelConstNote, landAndTargPosConsNote, landPosNote,
-- landPosConsNote, offsetNote, offsetConsNote, targPosConsNote,
Expand Down
Loading

0 comments on commit c188cda

Please sign in to comment.