{-# Language TemplateHaskell #-}
module Language.Drasil.Document.ConceptInstance (
ConceptInstance,
cic
) where
import Control.Lens (makeLenses, (^.), view)
import Drasil.Database (UID, HasUID(..), declareHasChunkRefs, Generically(..), nsUid, mkUid)
import Language.Drasil.Chunk.Concept.Core (ConceptChunk, sDom)
import Language.Drasil.Document.ShortName (HasShortName(..), ShortName, shortname')
import Language.Drasil.Classes (NamedIdea(term), Idea(getA),
Definition(defn), ConceptDomain(cdom), Concept)
import Language.Drasil.Document.Labels ((+::+), defer, name, raw,
LblType(..), Referable(..), HasRefAddress(..))
import Language.Drasil.Sentence (Sentence (S))
import Language.Drasil.NaturalLanguage.English.NounPhrase (pn)
import Language.Drasil.Chunk.Concept (cncpt')
data ConceptInstance = ConInst { ConceptInstance -> UID
_ciuid :: UID
, ConceptInstance -> ConceptChunk
_cc :: ConceptChunk
, ConceptInstance -> String
ra :: String
, ConceptInstance -> ShortName
shnm :: ShortName}
makeLenses ''ConceptInstance
declareHasChunkRefs ''ConceptInstance
instance Eq ConceptInstance where ConceptInstance
c1 == :: ConceptInstance -> ConceptInstance -> Bool
== ConceptInstance
c2 = (ConceptInstance
c1 ConceptInstance -> Getting UID ConceptInstance UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID ConceptInstance UID
forall c. HasUID c => Getter c UID
Getter ConceptInstance UID
uid) UID -> UID -> Bool
forall a. Eq a => a -> a -> Bool
== (ConceptInstance
c2 ConceptInstance -> Getting UID ConceptInstance UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID ConceptInstance UID
forall c. HasUID c => Getter c UID
Getter ConceptInstance UID
uid)
instance HasUID ConceptInstance where uid :: Getter ConceptInstance UID
uid = (UID -> f UID) -> ConceptInstance -> f ConceptInstance
Lens' ConceptInstance UID
ciuid
instance NamedIdea ConceptInstance where term :: Lens' ConceptInstance NP
term = (ConceptChunk -> f ConceptChunk)
-> ConceptInstance -> f ConceptInstance
Lens' ConceptInstance ConceptChunk
cc ((ConceptChunk -> f ConceptChunk)
-> ConceptInstance -> f ConceptInstance)
-> ((NP -> f NP) -> ConceptChunk -> f ConceptChunk)
-> (NP -> f NP)
-> ConceptInstance
-> f ConceptInstance
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NP -> f NP) -> ConceptChunk -> f ConceptChunk
forall c. NamedIdea c => Lens' c NP
Lens' ConceptChunk NP
term
instance Idea ConceptInstance where getA :: ConceptInstance -> Maybe String
getA = ConceptChunk -> Maybe String
forall c. Idea c => c -> Maybe String
getA (ConceptChunk -> Maybe String)
-> (ConceptInstance -> ConceptChunk)
-> ConceptInstance
-> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting ConceptChunk ConceptInstance ConceptChunk
-> ConceptInstance -> ConceptChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting ConceptChunk ConceptInstance ConceptChunk
Lens' ConceptInstance ConceptChunk
cc
instance Definition ConceptInstance where defn :: Lens' ConceptInstance Sentence
defn = (ConceptChunk -> f ConceptChunk)
-> ConceptInstance -> f ConceptInstance
Lens' ConceptInstance ConceptChunk
cc ((ConceptChunk -> f ConceptChunk)
-> ConceptInstance -> f ConceptInstance)
-> ((Sentence -> f Sentence) -> ConceptChunk -> f ConceptChunk)
-> (Sentence -> f Sentence)
-> ConceptInstance
-> f ConceptInstance
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sentence -> f Sentence) -> ConceptChunk -> f ConceptChunk
forall c. Definition c => Lens' c Sentence
Lens' ConceptChunk Sentence
defn
instance ConceptDomain ConceptInstance where cdom :: ConceptInstance -> [UID]
cdom = ConceptChunk -> [UID]
forall c. ConceptDomain c => c -> [UID]
cdom (ConceptChunk -> [UID])
-> (ConceptInstance -> ConceptChunk) -> ConceptInstance -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting ConceptChunk ConceptInstance ConceptChunk
-> ConceptInstance -> ConceptChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting ConceptChunk ConceptInstance ConceptChunk
Lens' ConceptInstance ConceptChunk
cc
instance HasShortName ConceptInstance where shortname :: ConceptInstance -> ShortName
shortname = ConceptInstance -> ShortName
shnm
instance HasRefAddress ConceptInstance where getRefAdd :: ConceptInstance -> LblType
getRefAdd ConceptInstance
l = IRefProg -> String -> LblType
RP (UID -> IRefProg
defer ([UID] -> UID
sDom ([UID] -> UID) -> [UID] -> UID
forall a b. (a -> b) -> a -> b
$ ConceptInstance -> [UID]
forall c. ConceptDomain c => c -> [UID]
cdom ConceptInstance
l) IRefProg -> IRefProg -> IRefProg
+::+ String -> IRefProg
raw String
":" IRefProg -> IRefProg -> IRefProg
+::+ IRefProg
name) (ConceptInstance -> String
ra ConceptInstance
l)
instance Referable ConceptInstance where
refAdd :: ConceptInstance -> String
refAdd = ConceptInstance -> String
ra
renderRef :: ConceptInstance -> LblType
renderRef = ConceptInstance -> LblType
forall b. HasRefAddress b => b -> LblType
getRefAdd
cic :: Concept c => String -> Sentence -> String -> c -> ConceptInstance
cic :: forall c.
Concept c =>
String -> Sentence -> String -> c -> ConceptInstance
cic String
u Sentence
d String
sn c
dom = UID -> ConceptChunk -> String -> ShortName -> ConceptInstance
ConInst (String -> UID -> UID
nsUid String
"instance" (UID -> UID) -> UID -> UID
forall a b. (a -> b) -> a -> b
$ ConceptChunk
icc ConceptChunk -> Getting UID ConceptChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID ConceptChunk UID
forall c. HasUID c => Getter c UID
Getter ConceptChunk UID
uid) ConceptChunk
icc String
u (ShortName -> ConceptInstance) -> ShortName -> ConceptInstance
forall a b. (a -> b) -> a -> b
$ Sentence -> ShortName
shortname' (String -> Sentence
S String
sn)
where
icc :: ConceptChunk
icc = UID -> NP -> Sentence -> [c] -> ConceptChunk
forall dom.
Concept dom =>
UID -> NP -> Sentence -> [dom] -> ConceptChunk
cncpt' (String -> UID
mkUid String
u) (String -> NP
pn String
sn) Sentence
d [c
dom]