module Drasil.GetChunks (
ccss, ccss', combine, vars,
resolveBibliography
) where
import Data.List (nub, sortBy)
import Data.Maybe (mapMaybe)
import qualified Data.Set as Set
import Language.Drasil
import Language.Drasil.Development (sdep)
import Language.Drasil.ModelExpr.Development (meDep)
import Drasil.Database (ChunkDB, findOrErr, find, UID)
import Drasil.Database.SearchTools (defResolve', DomDefn(definition))
vars :: ModelExpr -> ChunkDB -> [DefinedQuantityDict]
vars :: ModelExpr -> ChunkDB -> [DefinedQuantityDict]
vars ModelExpr
e ChunkDB
m = (UID -> DefinedQuantityDict) -> [UID] -> [DefinedQuantityDict]
forall a b. (a -> b) -> [a] -> [b]
map (UID -> ChunkDB -> DefinedQuantityDict
forall a. Typeable a => UID -> ChunkDB -> a
`findOrErr` ChunkDB
m) ([UID] -> [DefinedQuantityDict]) -> [UID] -> [DefinedQuantityDict]
forall a b. (a -> b) -> a -> b
$ ModelExpr -> [UID]
meDep ModelExpr
e
vars' :: Sentence -> ChunkDB -> [DefinedQuantityDict]
vars' :: Sentence -> ChunkDB -> [DefinedQuantityDict]
vars' Sentence
a ChunkDB
m = (UID -> DefinedQuantityDict) -> [UID] -> [DefinedQuantityDict]
forall a b. (a -> b) -> [a] -> [b]
map (UID -> ChunkDB -> DefinedQuantityDict
forall a. Typeable a => UID -> ChunkDB -> a
`findOrErr` ChunkDB
m) ([UID] -> [DefinedQuantityDict]) -> [UID] -> [DefinedQuantityDict]
forall a b. (a -> b) -> a -> b
$ Set UID -> [UID]
forall a. Set a -> [a]
Set.toList (Sentence -> Set UID
sdep Sentence
a)
combine :: Sentence -> ChunkDB -> [DefinedQuantityDict]
combine :: Sentence -> ChunkDB -> [DefinedQuantityDict]
combine Sentence
a ChunkDB
m = (DefinedQuantityDict -> Sentence -> DefinedQuantityDict)
-> [DefinedQuantityDict] -> [Sentence] -> [DefinedQuantityDict]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith DefinedQuantityDict -> Sentence -> DefinedQuantityDict
forall c.
(Quantity c, MayHaveUnit c) =>
c -> Sentence -> DefinedQuantityDict
dqdQd (Sentence -> ChunkDB -> [DefinedQuantityDict]
vars' Sentence
a ChunkDB
m) (Sentence -> ChunkDB -> [Sentence]
concpt Sentence
a ChunkDB
m)
combine' :: ModelExpr -> ChunkDB -> [DefinedQuantityDict]
combine' :: ModelExpr -> ChunkDB -> [DefinedQuantityDict]
combine' ModelExpr
a ChunkDB
m = (DefinedQuantityDict -> Sentence -> DefinedQuantityDict)
-> [DefinedQuantityDict] -> [Sentence] -> [DefinedQuantityDict]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith DefinedQuantityDict -> Sentence -> DefinedQuantityDict
forall c.
(Quantity c, MayHaveUnit c) =>
c -> Sentence -> DefinedQuantityDict
dqdQd (ModelExpr -> ChunkDB -> [DefinedQuantityDict]
vars ModelExpr
a ChunkDB
m) (ModelExpr -> ChunkDB -> [Sentence]
concpt' ModelExpr
a ChunkDB
m)
ccss :: [Sentence] -> [ModelExpr] -> ChunkDB -> [DefinedQuantityDict]
ccss :: [Sentence] -> [ModelExpr] -> ChunkDB -> [DefinedQuantityDict]
ccss [Sentence]
s [ModelExpr]
e ChunkDB
c = [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a. Eq a => [a] -> [a]
nub ([DefinedQuantityDict] -> [DefinedQuantityDict])
-> [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a b. (a -> b) -> a -> b
$ (Sentence -> [DefinedQuantityDict])
-> [Sentence] -> [DefinedQuantityDict]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Sentence -> ChunkDB -> [DefinedQuantityDict]
`combine` ChunkDB
c) [Sentence]
s [DefinedQuantityDict]
-> [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a. [a] -> [a] -> [a]
++ (ModelExpr -> [DefinedQuantityDict])
-> [ModelExpr] -> [DefinedQuantityDict]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (ModelExpr -> ChunkDB -> [DefinedQuantityDict]
`combine'` ChunkDB
c) [ModelExpr]
e
ccss' :: [Sentence] -> [ModelExpr] -> ChunkDB -> [DefinedQuantityDict]
ccss' :: [Sentence] -> [ModelExpr] -> ChunkDB -> [DefinedQuantityDict]
ccss' [Sentence]
s [ModelExpr]
e ChunkDB
c = [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a. Eq a => [a] -> [a]
nub ([DefinedQuantityDict] -> [DefinedQuantityDict])
-> [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a b. (a -> b) -> a -> b
$ (Sentence -> [DefinedQuantityDict])
-> [Sentence] -> [DefinedQuantityDict]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Sentence -> ChunkDB -> [DefinedQuantityDict]
`vars'` ChunkDB
c) [Sentence]
s [DefinedQuantityDict]
-> [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a. [a] -> [a] -> [a]
++ (ModelExpr -> [DefinedQuantityDict])
-> [ModelExpr] -> [DefinedQuantityDict]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (ModelExpr -> ChunkDB -> [DefinedQuantityDict]
`vars` ChunkDB
c) [ModelExpr]
e
concpt :: Sentence -> ChunkDB -> [Sentence]
concpt :: Sentence -> ChunkDB -> [Sentence]
concpt Sentence
a ChunkDB
m = (UID -> Sentence) -> [UID] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map (DomDefn -> Sentence
definition (DomDefn -> Sentence) -> (UID -> DomDefn) -> UID -> Sentence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ChunkDB -> UID -> DomDefn
defResolve' ChunkDB
m) ([UID] -> [Sentence]) -> [UID] -> [Sentence]
forall a b. (a -> b) -> a -> b
$ Set UID -> [UID]
forall a. Set a -> [a]
Set.toList (Sentence -> Set UID
sdep Sentence
a)
concpt' :: ModelExpr -> ChunkDB -> [Sentence]
concpt' :: ModelExpr -> ChunkDB -> [Sentence]
concpt' ModelExpr
a ChunkDB
m = (UID -> Sentence) -> [UID] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map (DomDefn -> Sentence
definition (DomDefn -> Sentence) -> (UID -> DomDefn) -> UID -> Sentence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ChunkDB -> UID -> DomDefn
defResolve' ChunkDB
m) ([UID] -> [Sentence]) -> [UID] -> [Sentence]
forall a b. (a -> b) -> a -> b
$ ModelExpr -> [UID]
meDep ModelExpr
a
resolveBibliography :: ChunkDB -> Set.Set UID -> [Citation]
resolveBibliography :: ChunkDB -> Set UID -> [Citation]
resolveBibliography ChunkDB
db Set UID
uids = (Citation -> Citation -> Ordering) -> [Citation] -> [Citation]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy Citation -> Citation -> Ordering
forall c. HasFields c => c -> c -> Ordering
compareAuthYearTitle [Citation]
cites
where
cites :: [Citation]
cites = (UID -> Maybe Citation) -> [UID] -> [Citation]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (UID -> ChunkDB -> Maybe Citation
forall a. Typeable a => UID -> ChunkDB -> Maybe a
`find` ChunkDB
db) (Set UID -> [UID]
forall a. Set a -> [a]
Set.toList Set UID
uids)