Skip to content

Commit

Permalink
removed error implementation from QDefinition (#549); created error i…
Browse files Browse the repository at this point in the history
…mplementation for RelationConcept
  • Loading branch information
niazim3 committed Jun 7, 2018
1 parent 4de5e05 commit fdf90d9
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 33 deletions.
8 changes: 4 additions & 4 deletions code/Data/Drasil/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@ unwrap Nothing = EmptyS
mkDataDef :: (Quantity c) => c -> Expr -> QDefinition
mkDataDef cncpt equation = datadef $ getUnit cncpt --should references be passed in at this point?
where datadef (Just a) = fromEqn (cncpt ^. uid) (cncpt ^. term) EmptyS
(eqSymb cncpt) a equation []
(eqSymb cncpt) a equation [] (cncpt ^. uid) --shortname
datadef Nothing = fromEqn' (cncpt ^. uid) (cncpt ^. term) EmptyS
(eqSymb cncpt) equation []
(eqSymb cncpt) equation [] (cncpt ^. uid) --shortname

-- Same as 'mkDataDef', but with an additional Sentence that can be taken as "extra information"; issue #350
mkDataDef' :: (Quantity c) => c -> Expr -> Sentence -> References -> QDefinition
mkDataDef' cncpt equation extraInfo refs = datadef $ getUnit cncpt
where datadef (Just a) = fromEqn (cncpt ^. uid) (cncpt ^. term) (extraInfo)
(eqSymb cncpt) a equation refs
(eqSymb cncpt) a equation refs (cncpt ^. uid) --shortname
datadef Nothing = fromEqn' (cncpt ^. uid) (cncpt ^. term) (extraInfo)
(eqSymb cncpt) equation refs
(eqSymb cncpt) equation refs (cncpt ^. uid) --shortname

prodUCTbl :: [[Sentence]] -> Contents
prodUCTbl cases = Table [S "Actor", titleize input_ +:+ S "and" +:+ titleize output_]
Expand Down
4 changes: 2 additions & 2 deletions code/Example/Drasil/GlassBR/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ glassSystInfo = SI {
_quants = this_symbols,
_concepts = [] :: [DefinedQuantityDict],
_definitions = dataDefns ++
(map (relToQD gbSymbMap) iModels) ++
(map (relToQD gbSymbMap) tModels) ++
(map (relToQD gbSymbMap) iModels {-[RelationConcept]-}) ++
(map (relToQD gbSymbMap) tModels {-[RelationConcept]-}) ++
[wtntWithEqn, sdWithEqn], -- wtntWithEqn is defined in Unitals but only appears
-- in the description of the Calculation of Demand instance model;
-- should this be included as a Data Definition?
Expand Down
4 changes: 3 additions & 1 deletion code/Example/Drasil/HGHC/HeatTransfer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ htTransCladCool, htTransCladFuel :: QDefinition
htTransCladCool = fromEqn "htTransCladCool" (nounPhraseSP
"convective heat transfer coefficient between clad and coolant")
EmptyS
(lH `sub` lC) heat_transfer_coef htTransCladCool_eq []
(lH `sub` lC) heat_transfer_coef htTransCladCool_eq []
"htTransCladCool" --shortname

htTransCladCool_eq =
(2 * (sy cladCond) * (sy coolFilmCond) / (2 * (sy cladCond) + (sy cladThick)
Expand All @@ -44,6 +45,7 @@ htTransCladFuel = fromEqn "htTransCladFuel" (nounPhraseSP
"effective heat transfer coefficient between clad and fuel surface")
EmptyS
(lH `sub` lG) heat_transfer_coef htTransCladFuel_eq []
"htTransCladFuel" --shortname

htTransCladFuel_eq = (2 * (sy cladCond) * (sy gapFilmCond)) / (2 * (sy cladCond)
+ ((sy cladThick) * (sy gapFilmCond)))
Expand Down
4 changes: 2 additions & 2 deletions code/Example/Drasil/SSP/DataDefs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ soilStiffnessEqn = (case_ [case1,case2])
-----------------

fixme1 :: QDefinition
fixme1 = ec ufixme1 (inxi intNormForce + inxiM1 intNormForce)
fixme1 = ec ufixme1 (inxi intNormForce + inxiM1 intNormForce) (shortname' "ufixme1")

fixme2 :: QDefinition
fixme2 = ec ufixme2 (inxi watrForce + inxiM1 watrForce)
fixme2 = ec ufixme2 (inxi watrForce + inxiM1 watrForce) (shortname' "ufixme2")

-----------------
-- Derivations --
Expand Down
2 changes: 1 addition & 1 deletion code/Example/Drasil/SWHS/DataDefs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ htFusionEqn = (sy latent_heat) / (sy mass)
dd4MeltFrac :: QDefinition
dd4MeltFrac = fromEqn' (melt_frac ^. uid) -- FIXME Should (^. id) be used
(melt_frac ^. term) (S "fraction of the PCM that is liquid")
(eqSymb melt_frac) melt_frac_eqn []
(eqSymb melt_frac) melt_frac_eqn [] "meltFrac"
--FIXME: "Phi is the melt fraction" is produced;
--"Phi is the fraction of the PCM that is liquid" is what is supposed to be
-- produced according to CaseStudies' original
Expand Down
30 changes: 15 additions & 15 deletions code/Language/Drasil/Chunk/Eq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Language.Drasil.Chunk.Eq
(QDefinition, fromEqn, fromEqn', fromEqn'', equat, getVC
, ec) where

import Control.Lens ((^.), makeLenses)
import Control.Lens ((^.), makeLenses, view)
import Language.Drasil.Expr (Expr)
import Language.Drasil.Classes (HasUID(uid),NamedIdea(term), Idea(getA), DOM,
HasSymbol(symbol), IsUnit, ExprRelat(relat), HasDerivation(derivations),
Expand All @@ -28,6 +28,7 @@ data QDefinition = EC
, _equat :: Expr
, _ref :: References
, _deri :: Derivation
, _refName :: ShortName
}
makeLenses ''QDefinition

Expand All @@ -37,41 +38,40 @@ instance NamedIdea QDefinition where term = qua . term
instance Idea QDefinition where getA c = getA $ c ^. qua
instance HasSpace QDefinition where typ = qua . typ
instance HasSymbol QDefinition where symbol e st = symbol (e^.qua) st
instance Quantity QDefinition where getUnit (EC a _ _ _) = getUnit a
instance Quantity QDefinition where getUnit (EC a _ _ _ _) = getUnit a
instance ExprRelat QDefinition where relat = equat
instance HasReference QDefinition where getReferences = ref
instance Eq QDefinition where a == b = (a ^. uid) == (b ^. uid)
instance HasDerivation QDefinition where derivations = deri
-- error used below is on purpose. These shortnames should be made explicit as necessary
instance HasShortName QDefinition where -- FIXME: This could lead to trouble; need
-- to ensure sanity checking when building
-- Refs. Double-check QDef is a DD before allowing
shortname _ = error "No explicit name given for data definition -- build a custom Ref"
shortname = view refName

-- | Create a 'QDefinition' with an uid, noun phrase (term), definition, symbol,
-- | Create a 'QDefinition' with a uid, noun phrase (term), definition, symbol,
-- unit, and defining equation. And it ignores the definition...
--FIXME: Space hack
fromEqn :: (IsUnit u, DOM u ~ ConceptChunk) =>
String -> NP -> Sentence -> Symbol -> u -> Expr -> References -> QDefinition
fromEqn nm desc _ symb un eqn refs =
EC (mkQuant nm desc symb Real (Just $ unitWrapper un) Nothing) eqn refs []
String -> NP -> Sentence -> Symbol -> u -> Expr -> References -> String -> QDefinition
fromEqn nm desc _ symb un eqn refs sn =
EC (mkQuant nm desc symb Real (Just $ unitWrapper un) Nothing) eqn refs [] (shortname' sn)

-- | Same as fromEqn, but has no units.
--FIXME: Space hack
fromEqn' :: String -> NP -> Sentence -> Symbol -> Expr -> References -> QDefinition
fromEqn' nm desc _ symb eqn refs = EC (mkQuant nm desc symb Real Nothing Nothing) eqn refs []
fromEqn' :: String -> NP -> Sentence -> Symbol -> Expr -> References -> String -> QDefinition
fromEqn' nm desc _ symb eqn refs sn = EC (mkQuant nm desc symb Real Nothing Nothing) eqn refs [] (shortname' sn)

-- | Create a 'QDefinition' with an uid, noun phrase (term), symbol,
-- abbreviation, unit, and defining equation.
fromEqn'' :: (IsUnit u, DOM u ~ ConceptChunk) => String -> NP -> Sentence ->
Symbol -> String -> Maybe u -> Expr -> References -> QDefinition
fromEqn'' nm desc _ symb abbr u eqn refs =
EC (mkQuant nm desc symb Real (fmap unitWrapper u) (Just abbr)) eqn refs []
Symbol -> String -> Maybe u -> Expr -> References -> String -> QDefinition
fromEqn'' nm desc _ symb abbr u eqn refs sn =
EC (mkQuant nm desc symb Real (fmap unitWrapper u) (Just abbr)) eqn refs [] (shortname' sn)

-- | Smart constructor for QDefinitions. Requires a quantity and its defining
-- equation
ec :: (Quantity c) => c -> Expr -> QDefinition
ec c eqn = EC (qw c) eqn [] []
ec :: (Quantity c) => c -> Expr -> ShortName -> QDefinition
ec c eqn sn = EC (qw c) eqn [] [] sn --hack?

-- | Returns a 'VarChunk' from a 'QDefinition'.
-- Currently only used in example /Modules/ which are being reworked.
Expand Down
4 changes: 4 additions & 0 deletions code/Language/Drasil/Chunk/Relation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Language.Drasil.Classes (HasUID(uid),NamedIdea(term),Idea(getA),
Definition(defn), ConceptDomain(cdom, DOM), Concept, ExprRelat(relat))
import Language.Drasil.Chunk.Concept
import Language.Drasil.Spec (Sentence(..))
import Language.Drasil.Chunk.ShortName

import Language.Drasil.NounPhrase (NP)

Expand All @@ -28,6 +29,9 @@ instance ConceptDomain RelationConcept where
instance Concept RelationConcept where
instance ExprRelat RelationConcept where relat = rel
instance Eq RelationConcept where a == b = (a ^. uid) == (b ^. uid)
instance HasShortName RelationConcept where
shortname _ = error "No explicit name given for relation concept -- build a custom Ref"
--should this be an instance of HasShortName?

-- | Create a RelationConcept from a given id, term, defn, and relation.
makeRC :: String -> NP -> Sentence -> Relation -> RelationConcept
Expand Down
2 changes: 1 addition & 1 deletion code/Language/Drasil/Chunk/UncertainQuantity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ uqNU :: (Quantity c, Constrained c, Concept c, HasReasVal c, DOM c ~ ConceptChun
c -> UncertQ
uqNU q = UQ (ConstrConcept (dqd' (cw q) (symbol q) (q ^. typ) (getUnit q)) (q ^. constraints) (q ^. reasVal)) Nothing

-- this is kind of crazy and probably shouldn't be used!
--FIXME: this is kind of crazy and probably shouldn't be used!
uqc :: (IsUnit u, DOM u ~ ConceptChunk) => String -> NP -> String -> Symbol -> u -> Space
-> [Constraint] -> Expr -> Double -> UncertQ
uqc nam trm desc sym un space cs val uncrt = uq (cuc' nam trm desc sym un space cs val) uncrt
Expand Down
11 changes: 6 additions & 5 deletions code/Language/Drasil/CodeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Language.Drasil.Chunk.Code
import Language.Drasil.Chunk.Eq
import Language.Drasil.Chunk.Quantity -- for hack
import Language.Drasil.Chunk.SymbolForm (codeSymb)
import Language.Drasil.Chunk.ShortName
import Language.Drasil.NounPhrase
import Language.Drasil.Symbol
import Language.Drasil.Spec
Expand Down Expand Up @@ -150,12 +151,12 @@ defaultChoices = Choices {
type Name = String

-- medium hacks ---
relToQD :: (ExprRelat c, HasSymbolTable ctx) => ctx -> c -> QDefinition
relToQD sm r = convertRel sm $ r ^. relat
relToQD :: (ExprRelat c, HasShortName c, HasSymbolTable ctx) => ctx -> c -> QDefinition
relToQD sm r = convertRel sm (r ^. relat) (shortname r)

convertRel :: HasSymbolTable ctx => ctx -> Expr -> QDefinition
convertRel sm (BinaryOp Eq (C x) r) = ec (symbLookup x (sm ^. symbolTable)) r
convertRel _ _ = error "Conversion failed"
convertRel :: (HasSymbolTable ctx) => ctx -> Expr -> ShortName -> QDefinition
convertRel sm (BinaryOp Eq (C x) r) sn = ec (symbLookup x (sm ^. symbolTable)) r sn
convertRel _ _ _ = error "Conversion failed"

data Mod = Mod Name [Func]

Expand Down
3 changes: 1 addition & 2 deletions code/Language/Drasil/Printing/Import.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import qualified Language.Drasil.Printing.LayoutObj as T
import Language.Drasil.Classes (term, defn, usymb, relat)
import qualified Language.Drasil.Chunk.SymbolForm as SF
import Language.Drasil.Chunk.AssumpChunk
import Language.Drasil.Chunk.Attribute (getShortName)
import Language.Drasil.Chunk.ShortName
import Language.Drasil.Chunk.Attribute (getShortName, snToSentence)
import Language.Drasil.Chunk.Change (chng, chngType, ChngType(Likely))
import Language.Drasil.Chunk.Eq
import Language.Drasil.Chunk.Quantity (Quantity(..))
Expand Down

0 comments on commit fdf90d9

Please sign in to comment.