Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove instance of HasSymbol for DataDefinition #3628

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ helperSources rs = [mkParagraph $ foldlList Comma List $ map (\r -> Ref (r ^. u
-- | Creates the fields for a definition from a 'QDefinition' (used by 'ddefn').
mkDDField :: DataDefinition -> SystemInformation -> Field -> ModRow -> ModRow
mkDDField d _ l@Label fs = (show l, [mkParagraph $ atStart d]) : fs
mkDDField d _ l@Symbol fs = (show l, [mkParagraph . P $ eqSymb d]) : fs
mkDDField d _ l@Symbol fs = (show l, [mkParagraph . P $ eqSymb $ d ^. defLhs]) : fs
mkDDField d _ l@Units fs = (show l, [mkParagraph $ toSentenceUnitless d]) : fs
mkDDField d _ l@DefiningEquation fs = (show l, [unlbldExpr $ express d]) : fs
mkDDField d m l@(Description v u) fs = (show l, buildDDescription' v u d m) : fs
Expand Down Expand Up @@ -203,9 +203,9 @@ mkIMField _ _ l _ = error $ "Label " ++ show l ++ " not supported " ++
-- | Used for making definitions. The first pair is the symbol of the quantity we are
-- defining.
firstPair' :: InclUnits -> DataDefinition -> ListTuple
firstPair' IgnoreUnits d = (P $ eqSymb d, Flat $ phrase d, Nothing)
firstPair' IgnoreUnits d = (P $ eqSymb $ d ^. defLhs, Flat $ phrase d, Nothing)
firstPair' IncludeUnits d =
(P $ eqSymb d, Flat $ phrase d +:+ sParen (toSentenceUnitless d), Nothing)
(P $ eqSymb $ d ^. defLhs, Flat $ phrase d +:+ sParen (toSentenceUnitless d), Nothing)

-- | Creates the descriptions for each symbol in the relation/equation.
descPairs :: (Quantity q, MayHaveUnit q) => InclUnits -> [q] -> [ListTuple]
Expand Down
6 changes: 4 additions & 2 deletions code/drasil-example/dblpend/lib/Drasil/DblPend/DataDefs.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Drasil.DblPend.DataDefs where

import Control.Lens ((^.))

import Prelude hiding (sin, cos, sqrt)
import Language.Drasil
import qualified Language.Drasil.Sentence.Combinators as S
Expand Down Expand Up @@ -71,7 +73,7 @@ positionXQD_2 :: SimpleQDef
positionXQD_2 = mkQuantDef xPos_2 positionXEqn_2

positionXEqn_2 :: PExpr
positionXEqn_2 = sy positionXDD_1 `addRe` (sy lenRod_2 `mulRe` sin (sy pendDisAngle_2))
positionXEqn_2 = sy (positionXDD_1 ^. defLhs) `addRe` (sy lenRod_2 `mulRe` sin (sy pendDisAngle_2))

positionXFigRef_2 :: Sentence
positionXFigRef_2 = ch xPos_2 `S.is` S "shown in" +:+. refS figMotion
Expand All @@ -89,7 +91,7 @@ positionYQD_2 :: SimpleQDef
positionYQD_2 = mkQuantDef yPos_2 positionYEqn_2

positionYEqn_2 :: PExpr
positionYEqn_2 = sy positionYDD_1 `addRe` neg (sy lenRod_2 `mulRe` cos (sy pendDisAngle_2))
positionYEqn_2 = sy (positionYDD_1 ^. defLhs) `addRe` neg (sy lenRod_2 `mulRe` cos (sy pendDisAngle_2))

positionYFigRef_2 :: Sentence
positionYFigRef_2 = ch yPos_2 `S.is` S "shown in" +:+. refS figMotion
Expand Down
2 changes: 1 addition & 1 deletion code/drasil-example/glassbr/lib/Drasil/GlassBR/IMods.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ calofCapacity = imNoDeriv (equationalModelN (lRe ^. term) calofCapacityQD)
[dRef astm2009] "calofCapacity" [lrCap, nonFLRef, gtfRef]

calofCapacityQD :: SimpleQDef
calofCapacityQD = mkQuantDef lRe (sy nonFL `mulRe` sy glaTyFac `mulRe` sy loadSF)
calofCapacityQD = mkQuantDef lRe (sy nonFL `mulRe` sy (glaTyFac ^. defLhs) `mulRe` sy loadSF)

{--}

Expand Down
8 changes: 4 additions & 4 deletions code/drasil-example/swhs/lib/Drasil/SWHS/Requirements.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ oIDQVals :: [Sentence]
oIDQVals = map foldlSent_ [
[pluralNP (the value), fromSource (inReq EmptyS)],
[pluralNP (the mass), fromSource findMass],
[ch balanceDecayRate, fromSource balanceDecayRate],
[ch balanceDecayTime, fromSource balanceDecayTime],
[ch balanceSolidPCM, fromSource balanceSolidPCM],
[ch balanceLiquidPCM, fromSource balanceLiquidPCM]
[ch (balanceDecayRate ^. defLhs), fromSource balanceDecayRate],
[ch (balanceDecayTime ^. defLhs), fromSource balanceDecayTime],
[ch (balanceSolidPCM ^. defLhs), fromSource balanceSolidPCM],
[ch (balanceLiquidPCM ^. defLhs), fromSource balanceLiquidPCM]
]

--
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Drasil.SWHSNoPCM.Requirements (funcReqs, inputInitValsTable) where

import Control.Lens ((^.))

import Language.Drasil
import Drasil.DocLang (mkInputPropsTable)
import Language.Drasil.Chunk.Concept.NamedCombinators
Expand Down Expand Up @@ -42,7 +44,7 @@ oIDQVals :: [Sentence]
oIDQVals = map foldlSent_ [
[pluralNP (the value), fromSource inputInitVals],
[phraseNP (the mass), fromSource findMass],
[ch balanceDecayRate, fromSource balanceDecayRate]
[ch (balanceDecayRate ^. defLhs), fromSource balanceDecayRate]
]

inputInitValsTable :: LabelledContent
Expand Down
13 changes: 7 additions & 6 deletions code/drasil-lang/lib/Language/Drasil/Document/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Language.Drasil.Document.Combinators (
) where

import Language.Drasil.Chunk.Concept.Core ( ConceptChunk )
import Language.Drasil.Chunk.Quantity (DefinesQuantity(defLhs))
import Language.Drasil.Chunk.UnitDefn ( UnitDefn, MayHaveUnit(..) )
import Language.Drasil.Chunk.Unital ( UnitalChunk )
import Language.Drasil.Classes
Expand Down Expand Up @@ -93,17 +94,17 @@ fromReplace :: (Referable r, HasShortName r) => r -> UnitalChunk -> Sentence
fromReplace src c = S "From" +:+ refS src `sC` S "we can replace" +: ch c

-- | Takes a list of 'Referable's and 'Symbol's and outputs as a Sentence "By substituting @symbols@, this can be written as:".
substitute :: (Referable r, HasShortName r, HasSymbol r) => [r] -> Sentence
substitute :: (Referable r, HasShortName r, DefinesQuantity r) => [r] -> Sentence
substitute s = S "By substituting" +: (foldlList Comma List l `sC` S "this can be written as")
where l = map (\x -> ch x +:+ fromSource x) s
where l = map (\x -> ch (x ^. defLhs) +:+ fromSource x) s

-- | Takes a 'HasSymbol' that is also 'Referable' and outputs as a 'Sentence': "@symbol@ is defined in @reference@."
definedIn :: (Referable r, HasShortName r, HasSymbol r) => r -> Sentence
definedIn q = ch q `S.is` S "defined in" +:+. refS q
definedIn :: (Referable r, HasShortName r, DefinesQuantity r) => r -> Sentence
definedIn q = ch (q ^. defLhs) `S.is` S "defined in" +:+. refS q

-- | Same as 'definedIn', but allows for additional information to be appended to the 'Sentence'.
definedIn' :: (Referable r, HasShortName r, HasSymbol r) => r -> Sentence -> Sentence
definedIn' q info = ch q `S.is` S "defined" `S.in_` refS q +:+. info
definedIn' :: (Referable r, HasShortName r, DefinesQuantity r) => r -> Sentence -> Sentence
definedIn' q info = ch (q ^. defLhs) `S.is` S "defined" `S.in_` refS q +:+. info

-- | Takes a 'Referable' and outputs as a 'Sentence' "defined in @reference@" (no 'HasSymbol').
definedIn'' :: (Referable r, HasShortName r) => r -> Sentence
Expand Down
2 changes: 1 addition & 1 deletion code/drasil-printers/lib/Language/Drasil/Log/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mkTableDataDef pinfo = mkTableFromLenses pinfo (view dataDefnTable)
"Data Definitions" "UID" "Term" "Symbol"
(text . showUID)
(sentenceDoc (pinfo ^. ckdb) (pinfo ^. stg) Nonlinear . phraseNP . view term)
(symbolDoc . flip L.symbol (pinfo ^. stg))
(symbolDoc . flip L.symbol (pinfo ^. stg) . view defLhs)

-- | Makes a table with all general definitions in the SRS.
mkTableGenDef :: PrintingInformation -> Doc
Expand Down
5 changes: 3 additions & 2 deletions code/drasil-theory/lib/Theory/Drasil/DataDefinition.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ instance HasUID DataDefinition where uid = ddQD uid uid
instance NamedIdea DataDefinition where term = ddQD term term
-- | Finds the idea contained in the 'QDefinition' used to make the 'DataDefinition where'.
instance Idea DataDefinition where getA = either getA getA . qdFromDD
-- | Finds the 'Quantity' defined by the 'DataDefinition'
instance DefinesQuantity DataDefinition where
defLhs = ddQDGetter defLhs defLhs
-- | Finds the output variable of the 'DataDefinition'
instance HasOutput DataDefinition where
output = ddQDGetter defLhs defLhs
out_constraints = to (const [])
-- | Finds the Symbol of the 'QDefinition' used to make the 'DataDefinition where'.
instance HasSymbol DataDefinition where symbol = either symbol symbol . qdFromDD
-- | Converts the defining expression of a 'DataDefinition where' into the model expression language.
instance Express DataDefinition where express = either express express . qdFromDD
{-- Finds 'Reference's contained in the 'DataDefinition where'.
Expand Down
3 changes: 3 additions & 0 deletions code/drasil-theory/lib/Theory/Drasil/InstanceModel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ instance CommonIdea InstanceModel where abrv _ = abrv inModel
instance Referable InstanceModel where
refAdd = ra
renderRef l = RP (prepend $ abrv l) (refAdd l)
-- | Finds the 'Quantity' of an 'InstanceModel'
instance DefinesQuantity InstanceModel where
defLhs = imOutput . _1
-- | Finds the inputs of an 'InstanceModel'.
instance HasInputs InstanceModel where
inputs = imInputs
Expand Down