{-# Language TemplateHaskell #-}
module Language.Drasil.Chunk.UncertainQuantity (
UncertQ, UncertainChunk(..),
uq, uqc,
uqcND, uncrtnChunk, uvc, uncrtnw) where
import Language.Drasil.Chunk.DefinedQuantity (dqdWr)
import Language.Drasil.Chunk.Constrained (ConstrConcept(..), ConstrainedChunk, cuc', cnstrw, cvc)
import Language.Drasil.Symbol
import Language.Drasil.Classes (NamedIdea(term), Idea(getA), Express(express),
Definition(defn), ConceptDomain(cdom), Concept, Quantity,
IsUnit, Constrained(constraints), HasReasVal(reasVal))
import Language.Drasil.Constraint (ConstraintE)
import Language.Drasil.Chunk.UnitDefn (MayHaveUnit(getUnit))
import Language.Drasil.Expr.Lang (Expr)
import Language.Drasil.Expr.Class (sy)
import Language.Drasil.NounPhrase.Core (NP)
import Language.Drasil.Space (Space, HasSpace(..))
import Language.Drasil.Uncertainty
import Language.Drasil.UID (HasUID(..))
import Control.Lens ((^.), makeLenses, view)
data UncertainChunk = UCh { UncertainChunk -> ConstrainedChunk
_conc :: ConstrainedChunk , UncertainChunk -> Uncertainty
_unc' :: Uncertainty }
makeLenses ''UncertainChunk
instance HasUID UncertainChunk where uid :: Getter UncertainChunk UID
uid = (ConstrainedChunk -> f ConstrainedChunk)
-> UncertainChunk -> f UncertainChunk
Lens' UncertainChunk ConstrainedChunk
conc ((ConstrainedChunk -> f ConstrainedChunk)
-> UncertainChunk -> f UncertainChunk)
-> ((UID -> f UID) -> ConstrainedChunk -> f ConstrainedChunk)
-> (UID -> f UID)
-> UncertainChunk
-> f UncertainChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID -> f UID) -> ConstrainedChunk -> f ConstrainedChunk
forall c. HasUID c => Getter c UID
Getter ConstrainedChunk UID
uid
instance Eq UncertainChunk where UncertainChunk
c1 == :: UncertainChunk -> UncertainChunk -> Bool
== UncertainChunk
c2 = (UncertainChunk
c1 UncertainChunk -> Getting UID UncertainChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID UncertainChunk UID
forall c. HasUID c => Getter c UID
Getter UncertainChunk UID
uid) UID -> UID -> Bool
forall a. Eq a => a -> a -> Bool
== (UncertainChunk
c2 UncertainChunk -> Getting UID UncertainChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID UncertainChunk UID
forall c. HasUID c => Getter c UID
Getter UncertainChunk UID
uid)
instance NamedIdea UncertainChunk where term :: Lens' UncertainChunk NP
term = (ConstrainedChunk -> f ConstrainedChunk)
-> UncertainChunk -> f UncertainChunk
Lens' UncertainChunk ConstrainedChunk
conc ((ConstrainedChunk -> f ConstrainedChunk)
-> UncertainChunk -> f UncertainChunk)
-> ((NP -> f NP) -> ConstrainedChunk -> f ConstrainedChunk)
-> (NP -> f NP)
-> UncertainChunk
-> f UncertainChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NP -> f NP) -> ConstrainedChunk -> f ConstrainedChunk
forall c. NamedIdea c => Lens' c NP
Lens' ConstrainedChunk NP
term
instance Idea UncertainChunk where getA :: UncertainChunk -> Maybe String
getA (UCh ConstrainedChunk
n Uncertainty
_) = ConstrainedChunk -> Maybe String
forall c. Idea c => c -> Maybe String
getA ConstrainedChunk
n
instance HasSpace UncertainChunk where typ :: Getter UncertainChunk Space
typ = (ConstrainedChunk -> f ConstrainedChunk)
-> UncertainChunk -> f UncertainChunk
Lens' UncertainChunk ConstrainedChunk
conc ((ConstrainedChunk -> f ConstrainedChunk)
-> UncertainChunk -> f UncertainChunk)
-> ((Space -> f Space) -> ConstrainedChunk -> f ConstrainedChunk)
-> (Space -> f Space)
-> UncertainChunk
-> f UncertainChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Space -> f Space) -> ConstrainedChunk -> f ConstrainedChunk
forall c. HasSpace c => Getter c Space
Getter ConstrainedChunk Space
typ
instance HasSymbol UncertainChunk where symbol :: UncertainChunk -> Stage -> Symbol
symbol UncertainChunk
c = ConstrainedChunk -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol (UncertainChunk
cUncertainChunk
-> Getting ConstrainedChunk UncertainChunk ConstrainedChunk
-> ConstrainedChunk
forall s a. s -> Getting a s a -> a
^.Getting ConstrainedChunk UncertainChunk ConstrainedChunk
Lens' UncertainChunk ConstrainedChunk
conc)
instance Quantity UncertainChunk where
instance Constrained UncertainChunk where constraints :: Lens' UncertainChunk [ConstraintE]
constraints = (ConstrainedChunk -> f ConstrainedChunk)
-> UncertainChunk -> f UncertainChunk
Lens' UncertainChunk ConstrainedChunk
conc ((ConstrainedChunk -> f ConstrainedChunk)
-> UncertainChunk -> f UncertainChunk)
-> (([ConstraintE] -> f [ConstraintE])
-> ConstrainedChunk -> f ConstrainedChunk)
-> ([ConstraintE] -> f [ConstraintE])
-> UncertainChunk
-> f UncertainChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([ConstraintE] -> f [ConstraintE])
-> ConstrainedChunk -> f ConstrainedChunk
forall c. Constrained c => Lens' c [ConstraintE]
Lens' ConstrainedChunk [ConstraintE]
constraints
instance HasReasVal UncertainChunk where reasVal :: Lens' UncertainChunk (Maybe Expr)
reasVal = (ConstrainedChunk -> f ConstrainedChunk)
-> UncertainChunk -> f UncertainChunk
Lens' UncertainChunk ConstrainedChunk
conc ((ConstrainedChunk -> f ConstrainedChunk)
-> UncertainChunk -> f UncertainChunk)
-> ((Maybe Expr -> f (Maybe Expr))
-> ConstrainedChunk -> f ConstrainedChunk)
-> (Maybe Expr -> f (Maybe Expr))
-> UncertainChunk
-> f UncertainChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Expr -> f (Maybe Expr))
-> ConstrainedChunk -> f ConstrainedChunk
forall c. HasReasVal c => Lens' c (Maybe Expr)
Lens' ConstrainedChunk (Maybe Expr)
reasVal
instance HasUncertainty UncertainChunk where unc :: Lens' UncertainChunk Uncertainty
unc = (Uncertainty -> f Uncertainty)
-> UncertainChunk -> f UncertainChunk
Lens' UncertainChunk Uncertainty
unc'
instance MayHaveUnit UncertainChunk where getUnit :: UncertainChunk -> Maybe UnitDefn
getUnit = ConstrainedChunk -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit (ConstrainedChunk -> Maybe UnitDefn)
-> (UncertainChunk -> ConstrainedChunk)
-> UncertainChunk
-> Maybe UnitDefn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting ConstrainedChunk UncertainChunk ConstrainedChunk
-> UncertainChunk -> ConstrainedChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting ConstrainedChunk UncertainChunk ConstrainedChunk
Lens' UncertainChunk ConstrainedChunk
conc
uncrtnChunk :: (Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) =>
c -> Uncertainty -> UncertainChunk
uncrtnChunk :: forall c.
(Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) =>
c -> Uncertainty -> UncertainChunk
uncrtnChunk c
q = ConstrainedChunk -> Uncertainty -> UncertainChunk
UCh (c -> ConstrainedChunk
forall c.
(Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) =>
c -> ConstrainedChunk
cnstrw c
q)
uvc :: String -> NP -> Symbol -> Space -> [ConstraintE] -> Expr -> Uncertainty -> UncertainChunk
uvc :: String
-> NP
-> Symbol
-> Space
-> [ConstraintE]
-> Expr
-> Uncertainty
-> UncertainChunk
uvc String
nam NP
trm Symbol
sym Space
space [ConstraintE]
cs Expr
val = ConstrainedChunk -> Uncertainty -> UncertainChunk
forall c.
(Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) =>
c -> Uncertainty -> UncertainChunk
uncrtnChunk (String
-> NP
-> Symbol
-> Space
-> [ConstraintE]
-> Maybe Expr
-> ConstrainedChunk
cvc String
nam NP
trm Symbol
sym Space
space [ConstraintE]
cs (Expr -> Maybe Expr
forall a. a -> Maybe a
Just Expr
val))
uncrtnw :: (HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => c -> UncertainChunk
uncrtnw :: forall c.
(HasUncertainty c, Quantity c, Constrained c, HasReasVal c,
MayHaveUnit c) =>
c -> UncertainChunk
uncrtnw c
c = ConstrainedChunk -> Uncertainty -> UncertainChunk
UCh (c -> ConstrainedChunk
forall c.
(Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) =>
c -> ConstrainedChunk
cnstrw c
c) (c
c c -> Getting Uncertainty c Uncertainty -> Uncertainty
forall s a. s -> Getting a s a -> a
^. Getting Uncertainty c Uncertainty
forall c. HasUncertainty c => Lens' c Uncertainty
Lens' c Uncertainty
unc)
data UncertQ = UQ { UncertQ -> ConstrConcept
_coco :: ConstrConcept , UncertQ -> Uncertainty
_unc'' :: Uncertainty }
makeLenses ''UncertQ
instance Eq UncertQ where UncertQ
a == :: UncertQ -> UncertQ -> Bool
== UncertQ
b = (UncertQ
a UncertQ -> Getting UID UncertQ UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID UncertQ UID
forall c. HasUID c => Getter c UID
Getter UncertQ UID
uid) UID -> UID -> Bool
forall a. Eq a => a -> a -> Bool
== (UncertQ
b UncertQ -> Getting UID UncertQ UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID UncertQ UID
forall c. HasUID c => Getter c UID
Getter UncertQ UID
uid)
instance HasUID UncertQ where uid :: Getter UncertQ UID
uid = (ConstrConcept -> f ConstrConcept) -> UncertQ -> f UncertQ
Lens' UncertQ ConstrConcept
coco ((ConstrConcept -> f ConstrConcept) -> UncertQ -> f UncertQ)
-> ((UID -> f UID) -> ConstrConcept -> f ConstrConcept)
-> (UID -> f UID)
-> UncertQ
-> f UncertQ
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID -> f UID) -> ConstrConcept -> f ConstrConcept
forall c. HasUID c => Getter c UID
Getter ConstrConcept UID
uid
instance NamedIdea UncertQ where term :: Lens' UncertQ NP
term = (ConstrConcept -> f ConstrConcept) -> UncertQ -> f UncertQ
Lens' UncertQ ConstrConcept
coco ((ConstrConcept -> f ConstrConcept) -> UncertQ -> f UncertQ)
-> ((NP -> f NP) -> ConstrConcept -> f ConstrConcept)
-> (NP -> f NP)
-> UncertQ
-> f UncertQ
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NP -> f NP) -> ConstrConcept -> f ConstrConcept
forall c. NamedIdea c => Lens' c NP
Lens' ConstrConcept NP
term
instance Idea UncertQ where getA :: UncertQ -> Maybe String
getA (UQ ConstrConcept
q Uncertainty
_) = ConstrConcept -> Maybe String
forall c. Idea c => c -> Maybe String
getA ConstrConcept
q
instance HasSpace UncertQ where typ :: Getter UncertQ Space
typ = (ConstrConcept -> f ConstrConcept) -> UncertQ -> f UncertQ
Lens' UncertQ ConstrConcept
coco ((ConstrConcept -> f ConstrConcept) -> UncertQ -> f UncertQ)
-> ((Space -> f Space) -> ConstrConcept -> f ConstrConcept)
-> (Space -> f Space)
-> UncertQ
-> f UncertQ
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Space -> f Space) -> ConstrConcept -> f ConstrConcept
forall c. HasSpace c => Getter c Space
Getter ConstrConcept Space
typ
instance HasSymbol UncertQ where symbol :: UncertQ -> Stage -> Symbol
symbol UncertQ
c = ConstrConcept -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol (UncertQ
cUncertQ
-> Getting ConstrConcept UncertQ ConstrConcept -> ConstrConcept
forall s a. s -> Getting a s a -> a
^.Getting ConstrConcept UncertQ ConstrConcept
Lens' UncertQ ConstrConcept
coco)
instance Quantity UncertQ where
instance HasUncertainty UncertQ where unc :: Lens' UncertQ Uncertainty
unc = (Uncertainty -> f Uncertainty) -> UncertQ -> f UncertQ
Lens' UncertQ Uncertainty
unc''
instance Constrained UncertQ where constraints :: Lens' UncertQ [ConstraintE]
constraints = (ConstrConcept -> f ConstrConcept) -> UncertQ -> f UncertQ
Lens' UncertQ ConstrConcept
coco ((ConstrConcept -> f ConstrConcept) -> UncertQ -> f UncertQ)
-> (([ConstraintE] -> f [ConstraintE])
-> ConstrConcept -> f ConstrConcept)
-> ([ConstraintE] -> f [ConstraintE])
-> UncertQ
-> f UncertQ
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([ConstraintE] -> f [ConstraintE])
-> ConstrConcept -> f ConstrConcept
forall c. Constrained c => Lens' c [ConstraintE]
Lens' ConstrConcept [ConstraintE]
constraints
instance HasReasVal UncertQ where reasVal :: Lens' UncertQ (Maybe Expr)
reasVal = (ConstrConcept -> f ConstrConcept) -> UncertQ -> f UncertQ
Lens' UncertQ ConstrConcept
coco ((ConstrConcept -> f ConstrConcept) -> UncertQ -> f UncertQ)
-> ((Maybe Expr -> f (Maybe Expr))
-> ConstrConcept -> f ConstrConcept)
-> (Maybe Expr -> f (Maybe Expr))
-> UncertQ
-> f UncertQ
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Expr -> f (Maybe Expr)) -> ConstrConcept -> f ConstrConcept
forall c. HasReasVal c => Lens' c (Maybe Expr)
Lens' ConstrConcept (Maybe Expr)
reasVal
instance Definition UncertQ where defn :: Lens' UncertQ Sentence
defn = (ConstrConcept -> f ConstrConcept) -> UncertQ -> f UncertQ
Lens' UncertQ ConstrConcept
coco ((ConstrConcept -> f ConstrConcept) -> UncertQ -> f UncertQ)
-> ((Sentence -> f Sentence) -> ConstrConcept -> f ConstrConcept)
-> (Sentence -> f Sentence)
-> UncertQ
-> f UncertQ
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sentence -> f Sentence) -> ConstrConcept -> f ConstrConcept
forall c. Definition c => Lens' c Sentence
Lens' ConstrConcept Sentence
defn
instance ConceptDomain UncertQ where cdom :: UncertQ -> [UID]
cdom = ConstrConcept -> [UID]
forall c. ConceptDomain c => c -> [UID]
cdom (ConstrConcept -> [UID])
-> (UncertQ -> ConstrConcept) -> UncertQ -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting ConstrConcept UncertQ ConstrConcept
-> UncertQ -> ConstrConcept
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting ConstrConcept UncertQ ConstrConcept
Lens' UncertQ ConstrConcept
coco
instance MayHaveUnit UncertQ where getUnit :: UncertQ -> Maybe UnitDefn
getUnit = ConstrConcept -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit (ConstrConcept -> Maybe UnitDefn)
-> (UncertQ -> ConstrConcept) -> UncertQ -> Maybe UnitDefn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting ConstrConcept UncertQ ConstrConcept
-> UncertQ -> ConstrConcept
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting ConstrConcept UncertQ ConstrConcept
Lens' UncertQ ConstrConcept
coco
instance Express UncertQ where express :: UncertQ -> ModelExpr
express = UncertQ -> ModelExpr
forall c. (HasUID c, HasSymbol c) => c -> ModelExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy
uq :: (Quantity c, Constrained c, Concept c, HasReasVal c, MayHaveUnit c) =>
c -> Uncertainty -> UncertQ
uq :: forall c.
(Quantity c, Constrained c, Concept c, HasReasVal c,
MayHaveUnit c) =>
c -> Uncertainty -> UncertQ
uq c
q = ConstrConcept -> Uncertainty -> UncertQ
UQ (DefinedQuantityDict -> [ConstraintE] -> Maybe Expr -> ConstrConcept
ConstrConcept (c -> DefinedQuantityDict
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> DefinedQuantityDict
dqdWr c
q) (c
q c -> Getting [ConstraintE] c [ConstraintE] -> [ConstraintE]
forall s a. s -> Getting a s a -> a
^. Getting [ConstraintE] c [ConstraintE]
forall c. Constrained c => Lens' c [ConstraintE]
Lens' c [ConstraintE]
constraints) (c
q c -> Getting (Maybe Expr) c (Maybe Expr) -> Maybe Expr
forall s a. s -> Getting a s a -> a
^. Getting (Maybe Expr) c (Maybe Expr)
forall c. HasReasVal c => Lens' c (Maybe Expr)
Lens' c (Maybe Expr)
reasVal))
uqc :: (IsUnit u) => String -> NP -> String -> Symbol -> u -> Space
-> [ConstraintE] -> Expr -> Uncertainty -> UncertQ
uqc :: forall u.
IsUnit u =>
String
-> NP
-> String
-> Symbol
-> u
-> Space
-> [ConstraintE]
-> Expr
-> Uncertainty
-> UncertQ
uqc String
nam NP
trm String
desc Symbol
sym u
un Space
space [ConstraintE]
cs Expr
val = ConstrConcept -> Uncertainty -> UncertQ
forall c.
(Quantity c, Constrained c, Concept c, HasReasVal c,
MayHaveUnit c) =>
c -> Uncertainty -> UncertQ
uq (String
-> NP
-> String
-> Symbol
-> u
-> Space
-> [ConstraintE]
-> Expr
-> ConstrConcept
forall u.
IsUnit u =>
String
-> NP
-> String
-> Symbol
-> u
-> Space
-> [ConstraintE]
-> Expr
-> ConstrConcept
cuc' String
nam NP
trm String
desc Symbol
sym u
un Space
space [ConstraintE]
cs Expr
val)
uqcND :: (IsUnit u) => String -> NP -> Symbol -> u -> Space -> [ConstraintE]
-> Expr -> Uncertainty -> UncertQ
uqcND :: forall u.
IsUnit u =>
String
-> NP
-> Symbol
-> u
-> Space
-> [ConstraintE]
-> Expr
-> Uncertainty
-> UncertQ
uqcND String
nam NP
trm Symbol
sym u
un Space
space [ConstraintE]
cs Expr
val = ConstrConcept -> Uncertainty -> UncertQ
forall c.
(Quantity c, Constrained c, Concept c, HasReasVal c,
MayHaveUnit c) =>
c -> Uncertainty -> UncertQ
uq (String
-> NP
-> String
-> Symbol
-> u
-> Space
-> [ConstraintE]
-> Expr
-> ConstrConcept
forall u.
IsUnit u =>
String
-> NP
-> String
-> Symbol
-> u
-> Space
-> [ConstraintE]
-> Expr
-> ConstrConcept
cuc' String
nam NP
trm String
"" Symbol
sym u
un Space
space [ConstraintE]
cs Expr
val)