{-# Language TemplateHaskell #-}
module Language.Drasil.Chunk.CommonIdea (
CI,
commonIdea, commonIdeaWithDict,
getAcc, prependAbrv) where
import Language.Drasil.Chunk.NamedIdea (IdeaDict, nc)
import Language.Drasil.Classes (NamedIdea(term), Idea(getA),
CommonIdea(abrv), ConceptDomain(cdom))
import Language.Drasil.Misc (repUnd)
import Language.Drasil.NounPhrase.Core (NP)
import Language.Drasil.Sentence (Sentence(S))
import Language.Drasil.UID (UID, HasUID(uid))
import Control.Lens (makeLenses, (^.), view)
data CI = CI { CI -> IdeaDict
_nc' :: IdeaDict, CI -> String
_ab :: String, CI -> [UID]
cdom' :: [UID]}
makeLenses ''CI
instance HasUID CI where uid :: Getter CI UID
uid = (IdeaDict -> f IdeaDict) -> CI -> f CI
Lens' CI IdeaDict
nc' ((IdeaDict -> f IdeaDict) -> CI -> f CI)
-> ((UID -> f UID) -> IdeaDict -> f IdeaDict)
-> (UID -> f UID)
-> CI
-> f CI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID -> f UID) -> IdeaDict -> f IdeaDict
forall c. HasUID c => Getter c UID
Getter IdeaDict UID
uid
instance NamedIdea CI where term :: Lens' CI NP
term = (IdeaDict -> f IdeaDict) -> CI -> f CI
Lens' CI IdeaDict
nc' ((IdeaDict -> f IdeaDict) -> CI -> f CI)
-> ((NP -> f NP) -> IdeaDict -> f IdeaDict)
-> (NP -> f NP)
-> CI
-> f CI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NP -> f NP) -> IdeaDict -> f IdeaDict
forall c. NamedIdea c => Lens' c NP
Lens' IdeaDict NP
term
instance Idea CI where getA :: CI -> Maybe String
getA = String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String) -> (CI -> String) -> CI -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting String CI String -> CI -> String
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting String CI String
Lens' CI String
ab
instance CommonIdea CI where abrv :: CI -> String
abrv = Getting String CI String -> CI -> String
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting String CI String
Lens' CI String
ab
instance ConceptDomain CI where cdom :: CI -> [UID]
cdom = CI -> [UID]
cdom'
commonIdea :: String -> NP -> String -> [UID] -> CI
commonIdea :: String -> NP -> String -> [UID] -> CI
commonIdea String
s NP
np = IdeaDict -> String -> [UID] -> CI
CI (String -> NP -> IdeaDict
nc String
s NP
np)
commonIdeaWithDict :: String -> NP -> String -> [IdeaDict] -> CI
commonIdeaWithDict :: String -> NP -> String -> [IdeaDict] -> CI
commonIdeaWithDict String
x NP
y String
z = String -> NP -> String -> [UID] -> CI
commonIdea String
x NP
y String
z ([UID] -> CI) -> ([IdeaDict] -> [UID]) -> [IdeaDict] -> CI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (IdeaDict -> UID) -> [IdeaDict] -> [UID]
forall a b. (a -> b) -> [a] -> [b]
map (IdeaDict -> Getting UID IdeaDict UID -> UID
forall s a. s -> Getting a s a -> a
^.Getting UID IdeaDict UID
forall c. HasUID c => Getter c UID
Getter IdeaDict UID
uid)
getAcc :: CI -> Sentence
getAcc :: CI -> Sentence
getAcc = String -> Sentence
S (String -> Sentence) -> (CI -> String) -> CI -> Sentence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CI -> String
forall c. CommonIdea c => c -> String
abrv
prependAbrv :: CommonIdea c => c -> String -> String
prependAbrv :: forall c. CommonIdea c => c -> String -> String
prependAbrv c
c String
s = c -> String
forall c. CommonIdea c => c -> String
abrv c
c String -> String -> String
forall a. [a] -> [a] -> [a]
++ (Char
':' Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
repUnd String
s)