{-# LANGUAGE LambdaCase, Rank2Types #-}
-- | Defines functions to extract certain kinds of information from a document.
-- Mainly used to pull the 'UID's of chunks out of 'Sentence's and 'Expr's.
module Drasil.ExtractDocDesc (getDocDesc, egetDocDesc, sentencePlate) where

import Control.Lens((^.))
import Drasil.DocumentLanguage.Core
import Drasil.Sections.SpecificSystemDescription (inDataConstTbl, outDataConstTbl)
import Language.Drasil hiding (Manual, Verb)
import Theory.Drasil
import Data.List(transpose)

import Data.Functor.Constant (Constant(Constant))
import Data.Generics.Multiplate (appendPlate, foldFor, purePlate, preorderFold)

-- | Creates a section contents plate that contains diferrent system subsections.
secConPlate :: Monoid b => (forall a. HasContents a => [a] -> b) ->
  ([Section] -> b) -> DLPlate (Constant b)
secConPlate :: forall b.
Monoid b =>
(forall a. HasContents a => [a] -> b)
-> ([Section] -> b) -> DLPlate (Constant b)
secConPlate forall a. HasContents a => [a] -> b
mCon [Section] -> b
mSec = forall (p :: (* -> *) -> *) o.
(Multiplate p, Monoid o) =>
p (Constant o) -> p (Constant o)
preorderFold forall a b. (a -> b) -> a -> b
$ forall (p :: (* -> *) -> *) (f :: * -> *).
(Multiplate p, Applicative f) =>
p f
purePlate {
  refSec :: RefSec -> Constant b RefSec
refSec = forall {k} a (b :: k). a -> Constant a b
Constant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \(RefProg Contents
c [RefTab]
_) -> forall a. HasContents a => [a] -> b
mCon [Contents
c],
  introSub :: IntroSub -> Constant b IntroSub
introSub = forall {k} a (b :: k). a -> Constant a b
Constant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \case
    (IOrgSec CI
_ Section
s Sentence
_) -> [Section] -> b
mSec [Section
s]
    IntroSub
_ -> forall a. Monoid a => a
mempty,
  --gsdSec = Constant <$> \case
  --  (GSDProg _) -> mempty,
  gsdSub :: GSDSub -> Constant b GSDSub
gsdSub = forall {k} a (b :: k). a -> Constant a b
Constant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \case
    (SysCntxt [Contents]
c) -> forall a. HasContents a => [a] -> b
mCon [Contents]
c
    (UsrChars [Contents]
c) -> forall a. HasContents a => [a] -> b
mCon [Contents]
c
    (SystCons [Contents]
c [Section]
s) -> forall a. HasContents a => [a] -> b
mCon [Contents]
c forall a. Monoid a => a -> a -> a
`mappend` [Section] -> b
mSec [Section]
s,
  pdSec :: ProblemDescription -> Constant b ProblemDescription
pdSec = forall {k} a (b :: k). a -> Constant a b
Constant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \(PDProg Sentence
_ [Section]
s [PDSub]
_) -> [Section] -> b
mSec [Section]
s,
  pdSub :: PDSub -> Constant b PDSub
pdSub = forall {k} a (b :: k). a -> Constant a b
Constant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \case
    (TermsAndDefs Maybe Sentence
_ [c]
_) -> forall a. Monoid a => a
mempty
    (PhySysDesc a
_ [Sentence]
_ LabelledContent
lc [Contents]
c) -> forall a. HasContents a => [a] -> b
mCon [LabelledContent
lc] forall a. Monoid a => a -> a -> a
`mappend` forall a. HasContents a => [a] -> b
mCon [Contents]
c
    (Goals [Sentence]
_ [ConceptInstance]
_) -> forall a. Monoid a => a
mempty,
  scsSub :: SCSSub -> Constant b SCSSub
scsSub = forall {k} a (b :: k). a -> Constant a b
Constant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \case
    (Constraints Sentence
_ [c]
c) -> forall a. HasContents a => [a] -> b
mCon [forall c.
(HasUncertainty c, Quantity c, Constrained c, HasReasVal c,
 MayHaveUnit c) =>
[c] -> LabelledContent
inDataConstTbl [c]
c]
    (CorrSolnPpties [c]
c [Contents]
cs) -> forall a. HasContents a => [a] -> b
mCon [forall c. (Quantity c, Constrained c) => [c] -> LabelledContent
outDataConstTbl [c]
c] forall a. Monoid a => a -> a -> a
`mappend` forall a. HasContents a => [a] -> b
mCon [Contents]
cs
    SCSSub
_ -> forall a. Monoid a => a
mempty,
  reqSub :: ReqsSub -> Constant b ReqsSub
reqSub = forall {k} a (b :: k). a -> Constant a b
Constant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \case
    (FReqsSub' [ConceptInstance]
_ [LabelledContent]
c) -> forall a. HasContents a => [a] -> b
mCon [LabelledContent]
c
    (FReqsSub [ConceptInstance]
_ [LabelledContent]
c) -> forall a. HasContents a => [a] -> b
mCon [LabelledContent]
c
    (NonFReqsSub [ConceptInstance]
_) -> forall a. Monoid a => a
mempty,
  offShelfSec :: OffShelfSolnsSec -> Constant b OffShelfSolnsSec
offShelfSec = forall {k} a (b :: k). a -> Constant a b
Constant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \(OffShelfSolnsProg [Contents]
c) -> forall a. HasContents a => [a] -> b
mCon [Contents]
c,
  appendSec :: AppndxSec -> Constant b AppndxSec
appendSec = forall {k} a (b :: k). a -> Constant a b
Constant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \(AppndxProg [Contents]
c) -> forall a. HasContents a => [a] -> b
mCon [Contents]
c
}

-- | Creates a section plate for expressions.
exprPlate :: DLPlate (Constant [ModelExpr])
exprPlate :: DLPlate (Constant [ModelExpr])
exprPlate = forall a. Monoid a => ([Sentence] -> a) -> DLPlate (Constant a)
sentencePlate (forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Sentence -> [ModelExpr]
sentToExp) forall (p :: (* -> *) -> *) o.
(Multiplate p, Monoid o) =>
p (Constant o) -> p (Constant o) -> p (Constant o)
`appendPlate` forall b.
Monoid b =>
(forall a. HasContents a => [a] -> b)
-> ([Section] -> b) -> DLPlate (Constant b)
secConPlate (forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall a. HasContents a => a -> [ModelExpr]
egetCon')
  (forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Section -> [ModelExpr]
egetSec) forall (p :: (* -> *) -> *) o.
(Multiplate p, Monoid o) =>
p (Constant o) -> p (Constant o) -> p (Constant o)
`appendPlate` (forall (p :: (* -> *) -> *) o.
(Multiplate p, Monoid o) =>
p (Constant o) -> p (Constant o)
preorderFold forall a b. (a -> b) -> a -> b
$ forall (p :: (* -> *) -> *) (f :: * -> *).
(Multiplate p, Applicative f) =>
p f
purePlate {
  scsSub :: SCSSub -> Constant [ModelExpr] SCSSub
scsSub = forall {k} a (b :: k). a -> Constant a b
Constant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \case
    (TMs [Sentence]
_ Fields
_ [TheoryModel]
t)   -> [TheoryModel] -> [ModelExpr]
goTM [TheoryModel]
t
    (DDs [Sentence]
_ Fields
_ [DataDefinition]
d DerivationDisplay
_) -> forall a. Express a => [a] -> [ModelExpr]
go [DataDefinition]
d
    (GDs [Sentence]
_ Fields
_ [GenDefn]
g DerivationDisplay
_) -> forall a. Express a => [a] -> [ModelExpr]
go [GenDefn]
g
    (IMs [Sentence]
_ Fields
_ [InstanceModel]
i DerivationDisplay
_) -> forall a. Express a => [a] -> [ModelExpr]
go [InstanceModel]
i
    SCSSub
_ -> [],
  auxConsSec :: AuxConstntSec -> Constant [ModelExpr] AuxConstntSec
auxConsSec = forall {k} a (b :: k). a -> Constant a b
Constant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \(AuxConsProg CI
_ [ConstQDef]
qdef) -> forall a. Express a => [a] -> [ModelExpr]
go [ConstQDef]
qdef
  }) where
      go :: Express a => [a] -> [ModelExpr]
      go :: forall a. Express a => [a] -> [ModelExpr]
go = forall a b. (a -> b) -> [a] -> [b]
map forall c. Express c => c -> ModelExpr
express
      goTM :: [TheoryModel] -> [ModelExpr]
      goTM :: [TheoryModel] -> [ModelExpr]
goTM = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\TheoryModel
x -> forall a. Express a => [a] -> [ModelExpr]
go (TheoryModel
x forall s a. s -> Getting a s a -> a
^. forall t. Theory t => Lens' t [ModelQDef]
defined_quant)
                           forall a. [a] -> [a] -> [a]
++ TheoryModel
x forall s a. s -> Getting a s a -> a
^. forall t. Theory t => Lens' t [ModelExpr]
invariants
                           forall a. [a] -> [a] -> [a]
++ forall a. Express a => [a] -> [ModelExpr]
go (forall a b. (a -> b) -> [a] -> [b]
map (forall s a. s -> Getting a s a -> a
^. forall (c :: * -> *) e. DefiningExpr c => Lens' (c e) e
defnExpr) (TheoryModel
x forall s a. s -> Getting a s a -> a
^. forall t. Theory t => Lens' t [ModelQDef]
defined_quant forall a. [a] -> [a] -> [a]
++ TheoryModel
x forall s a. s -> Getting a s a -> a
^. forall t. Theory t => Lens' t [ModelQDef]
defined_fun))
                           forall a. [a] -> [a] -> [a]
++ [TheoryModel] -> [ModelExpr]
goTM (TheoryModel
x forall s a. s -> Getting a s a -> a
^. forall t. Theory t => Lens' t [TheoryModel]
valid_context))

-- | Converts a 'Sentence' into a list of expressions. If the 'Sentence' cant be translated, returns an empty list.
sentToExp :: Sentence -> [ModelExpr]
sentToExp :: Sentence -> [ModelExpr]
sentToExp ((:+:) Sentence
s1 Sentence
s2) = Sentence -> [ModelExpr]
sentToExp Sentence
s1 forall a. [a] -> [a] -> [a]
++ Sentence -> [ModelExpr]
sentToExp Sentence
s2
sentToExp (E ModelExpr
e) = [ModelExpr
e]
sentToExp Sentence
_ = []

-- | Helper that extracts a list of some type from the 'DLPlate' and 'DocDesc'.
fmGetDocDesc :: DLPlate (Constant [a]) -> DocDesc -> [a]
fmGetDocDesc :: forall a. DLPlate (Constant [a]) -> DocDesc -> [a]
fmGetDocDesc DLPlate (Constant [a])
p = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (forall (p :: (* -> *) -> *) a o.
Multiplate p =>
Projector p a -> p (Constant o) -> a -> o
foldFor forall (f :: * -> *). DLPlate f -> DocSection -> f DocSection
docSec DLPlate (Constant [a])
p)

-- | Extracts expressions from the document description ('DocDesc') and default 'DLPlate'.
egetDocDesc :: DocDesc -> [ModelExpr]
egetDocDesc :: DocDesc -> [ModelExpr]
egetDocDesc = forall a. DLPlate (Constant [a]) -> DocDesc -> [a]
fmGetDocDesc DLPlate (Constant [ModelExpr])
exprPlate

-- | Extracts expressions from a 'Section'.
egetSec :: Section -> [ModelExpr]
egetSec :: Section -> [ModelExpr]
egetSec (Section Sentence
_ [SecCons]
sc Reference
_ ) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap SecCons -> [ModelExpr]
egetSecCon [SecCons]
sc

-- | Extracts expressions from section contents.
egetSecCon :: SecCons -> [ModelExpr]
egetSecCon :: SecCons -> [ModelExpr]
egetSecCon (Sub Section
s) = Section -> [ModelExpr]
egetSec Section
s
egetSecCon (Con Contents
c) = forall a. HasContents a => a -> [ModelExpr]
egetCon' Contents
c

-- | Extracts expressions from something that has contents.
egetCon' :: HasContents a => a -> [ModelExpr]
egetCon' :: forall a. HasContents a => a -> [ModelExpr]
egetCon' = RawContent -> [ModelExpr]
egetCon forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall s a. s -> Getting a s a -> a
^. forall c. HasContents c => Lens' c RawContent
accessContents)

-- | Extracts expressions from raw contents.
egetCon :: RawContent -> [ModelExpr]
egetCon :: RawContent -> [ModelExpr]
egetCon (EqnBlock ModelExpr
e) = [ModelExpr
e]
egetCon (Defini DType
_ []) = []
egetCon (Defini DType
dt ((Identifier, [Contents])
hd:[(Identifier, [Contents])]
tl)) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall a. HasContents a => a -> [ModelExpr]
egetCon' (forall a b. (a, b) -> b
snd (Identifier, [Contents])
hd) forall a. [a] -> [a] -> [a]
++ RawContent -> [ModelExpr]
egetCon (DType -> [(Identifier, [Contents])] -> RawContent
Defini DType
dt [(Identifier, [Contents])]
tl)
egetCon RawContent
_ = []

-- | Creates a 'Sentence' plate.
sentencePlate :: Monoid a => ([Sentence] -> a) -> DLPlate (Constant a)
sentencePlate :: forall a. Monoid a => ([Sentence] -> a) -> DLPlate (Constant a)
sentencePlate [Sentence] -> a
f = forall (p :: (* -> *) -> *) o.
(Multiplate p, Monoid o) =>
p (Constant o) -> p (Constant o) -> p (Constant o)
appendPlate (forall b.
Monoid b =>
(forall a. HasContents a => [a] -> b)
-> ([Section] -> b) -> DLPlate (Constant b)
secConPlate ([Sentence] -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall a. HasContents a => a -> [Sentence]
getCon') forall a b. (a -> b) -> a -> b
$ [Sentence] -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Section -> [Sentence]
getSec) forall a b. (a -> b) -> a -> b
$
  forall (p :: (* -> *) -> *) o.
(Multiplate p, Monoid o) =>
p (Constant o) -> p (Constant o)
preorderFold forall a b. (a -> b) -> a -> b
$ forall (p :: (* -> *) -> *) (f :: * -> *).
(Multiplate p, Applicative f) =>
p f
purePlate {
    introSec :: IntroSec -> Constant a IntroSec
introSec = forall {k} a (b :: k). a -> Constant a b
Constant forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Sentence] -> a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \(IntroProg Sentence
s1 Sentence
s2 [IntroSub]
_) -> [Sentence
s1, Sentence
s2],
    introSub :: IntroSub -> Constant a IntroSub
introSub = forall {k} a (b :: k). a -> Constant a b
Constant forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Sentence] -> a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \case
      (IPurpose [Sentence]
s) -> [Sentence]
s
      (IScope Sentence
s) -> [Sentence
s]
      (IChar [Sentence]
s1 [Sentence]
s2 [Sentence]
s3) -> forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Sentence]
s1, [Sentence]
s2, [Sentence]
s3]
      (IOrgSec CI
_ Section
_ Sentence
s1) -> [Sentence
s1],
    stkSub :: StkhldrSub -> Constant a StkhldrSub
stkSub = forall {k} a (b :: k). a -> Constant a b
Constant forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Sentence] -> a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \case
      (Client CI
_ Sentence
s) -> [Sentence
s]
      (Cstmr CI
_) -> [],
    pdSec :: ProblemDescription -> Constant a ProblemDescription
pdSec = forall {k} a (b :: k). a -> Constant a b
Constant forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Sentence] -> a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \(PDProg Sentence
s [Section]
_ [PDSub]
_) -> [Sentence
s],
    pdSub :: PDSub -> Constant a PDSub
pdSub = forall {k} a (b :: k). a -> Constant a b
Constant forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Sentence] -> a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \case
      (TermsAndDefs Maybe Sentence
Nothing [c]
cs) -> forall a. Definition a => [a] -> [Sentence]
def [c]
cs
      (TermsAndDefs (Just Sentence
s) [c]
cs) -> Sentence
s forall a. a -> [a] -> [a]
: forall a. Definition a => [a] -> [Sentence]
def [c]
cs
      (PhySysDesc a
_ [Sentence]
s LabelledContent
_ [Contents]
_) -> [Sentence]
s
      (Goals [Sentence]
s [ConceptInstance]
c) -> [Sentence]
s forall a. [a] -> [a] -> [a]
++ forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c,
    scsSub :: SCSSub -> Constant a SCSSub
scsSub = forall {k} a (b :: k). a -> Constant a b
Constant forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Sentence] -> a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \case
      (Assumptions [ConceptInstance]
c) -> forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c
      (TMs [Sentence]
s Fields
_ [TheoryModel]
t) -> let r :: [TheoryModel] -> [Sentence]
r = forall a. Semigroup a => a -> a -> a
(<>) [Sentence]
s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\TheoryModel
x -> forall a. Definition a => [a] -> [Sentence]
def (TheoryModel
x forall s a. s -> Getting a s a -> a
^. forall t. Theory t => Lens' t [ConceptChunk]
operations) forall a. [a] -> [a] -> [a]
++
                             forall a. Definition a => [a] -> [Sentence]
def (TheoryModel
x forall s a. s -> Getting a s a -> a
^. forall t. Theory t => Lens' t [ModelQDef]
defined_quant) forall a. [a] -> [a] -> [a]
++ forall a. HasAdditionalNotes a => [a] -> [Sentence]
notes [TheoryModel
x] forall a. [a] -> [a] -> [a]
++
                             [TheoryModel] -> [Sentence]
r (TheoryModel
x forall s a. s -> Getting a s a -> a
^. forall t. Theory t => Lens' t [TheoryModel]
valid_context)) in [TheoryModel] -> [Sentence]
r [TheoryModel]
t
      (DDs [Sentence]
s Fields
_ [DataDefinition]
d DerivationDisplay
_) -> [Sentence]
s forall a. [a] -> [a] -> [a]
++ forall a. MayHaveDerivation a => [a] -> [Sentence]
der [DataDefinition]
d forall a. [a] -> [a] -> [a]
++ forall a. HasAdditionalNotes a => [a] -> [Sentence]
notes [DataDefinition]
d
      (GDs [Sentence]
s Fields
_ [GenDefn]
d DerivationDisplay
_) -> forall a. Definition a => [a] -> [Sentence]
def [GenDefn]
d forall a. [a] -> [a] -> [a]
++ [Sentence]
s forall a. [a] -> [a] -> [a]
++ forall a. MayHaveDerivation a => [a] -> [Sentence]
der [GenDefn]
d forall a. [a] -> [a] -> [a]
++ forall a. HasAdditionalNotes a => [a] -> [Sentence]
notes [GenDefn]
d
      (IMs [Sentence]
s Fields
_ [InstanceModel]
d DerivationDisplay
_) -> [Sentence]
s forall a. [a] -> [a] -> [a]
++ forall a. MayHaveDerivation a => [a] -> [Sentence]
der [InstanceModel]
d forall a. [a] -> [a] -> [a]
++ forall a. HasAdditionalNotes a => [a] -> [Sentence]
notes [InstanceModel]
d
      (Constraints Sentence
s [c]
_) -> [Sentence
s]
      (CorrSolnPpties [c]
_ [Contents]
_) -> [],
    reqSub :: ReqsSub -> Constant a ReqsSub
reqSub = forall {k} a (b :: k). a -> Constant a b
Constant forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Sentence] -> a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \case
      (FReqsSub' [ConceptInstance]
c [LabelledContent]
_) -> forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c
      (FReqsSub [ConceptInstance]
c [LabelledContent]
_) -> forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c
      (NonFReqsSub [ConceptInstance]
c) -> forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c,
    lcsSec :: LCsSec -> Constant a LCsSec
lcsSec = forall {k} a (b :: k). a -> Constant a b
Constant forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Sentence] -> a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \(LCsProg [ConceptInstance]
c) -> forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c,
    ucsSec :: UCsSec -> Constant a UCsSec
ucsSec = forall {k} a (b :: k). a -> Constant a b
Constant forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Sentence] -> a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \(UCsProg [ConceptInstance]
c) -> forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c,
    traceSec :: TraceabilitySec -> Constant a TraceabilitySec
traceSec = forall {k} a (b :: k). a -> Constant a b
Constant forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Sentence] -> a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \(TraceabilityProg [TraceConfig]
progs) ->
      forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(TraceConfig UID
_ [Sentence]
ls Sentence
s [TraceViewCat]
_ [TraceViewCat]
_) -> Sentence
s forall a. a -> [a] -> [a]
: [Sentence]
ls) [TraceConfig]
progs,
    auxConsSec :: AuxConstntSec -> Constant a AuxConstntSec
auxConsSec = forall {k} a (b :: k). a -> Constant a b
Constant forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Sentence] -> a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> \(AuxConsProg CI
_ [ConstQDef]
qdef) -> forall a. Definition a => [a] -> [Sentence]
def [ConstQDef]
qdef
  } where
    def :: Definition a => [a] -> [Sentence]
    def :: forall a. Definition a => [a] -> [Sentence]
def = forall a b. (a -> b) -> [a] -> [b]
map (forall s a. s -> Getting a s a -> a
^. forall c. Definition c => Lens' c Sentence
defn)
    der :: MayHaveDerivation a => [a] -> [Sentence]
    der :: forall a. MayHaveDerivation a => [a] -> [Sentence]
der = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Maybe Derivation -> [Sentence]
getDerivSent forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall s a. s -> Getting a s a -> a
^. forall c. MayHaveDerivation c => Lens' c (Maybe Derivation)
derivations))
    getDerivSent :: Maybe Derivation -> [Sentence]
    getDerivSent :: Maybe Derivation -> [Sentence]
getDerivSent Maybe Derivation
Nothing = []
    getDerivSent (Just (Derivation Sentence
h [Sentence]
s)) = Sentence
h forall a. a -> [a] -> [a]
: [Sentence]
s
    notes :: HasAdditionalNotes a => [a] -> [Sentence]
    notes :: forall a. HasAdditionalNotes a => [a] -> [Sentence]
notes = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (forall s a. s -> Getting a s a -> a
^. forall c. HasAdditionalNotes c => Lens' c [Sentence]
getNotes)

-- | Extracts 'Sentence's from a document description.
getDocDesc :: DocDesc -> [Sentence]
getDocDesc :: DocDesc -> [Sentence]
getDocDesc = forall a. DLPlate (Constant [a]) -> DocDesc -> [a]
fmGetDocDesc (forall a. Monoid a => ([Sentence] -> a) -> DLPlate (Constant a)
sentencePlate forall a. a -> a
id)

-- | Extracts 'Sentence's from a 'Section'.
getSec :: Section -> [Sentence]
getSec :: Section -> [Sentence]
getSec (Section Sentence
t [SecCons]
sc Reference
_ ) = Sentence
t forall a. a -> [a] -> [a]
: forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap SecCons -> [Sentence]
getSecCon [SecCons]
sc

-- | Extracts 'Sentence's from section contents.
getSecCon :: SecCons -> [Sentence]
getSecCon :: SecCons -> [Sentence]
getSecCon (Sub Section
s) = Section -> [Sentence]
getSec Section
s
getSecCon (Con Contents
c) = forall a. HasContents a => a -> [Sentence]
getCon' Contents
c

-- | Extracts 'Sentence's from something that has contents.
getCon' :: HasContents a => a -> [Sentence]
getCon' :: forall a. HasContents a => a -> [Sentence]
getCon' = RawContent -> [Sentence]
getCon forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall s a. s -> Getting a s a -> a
^. forall c. HasContents c => Lens' c RawContent
accessContents)

-- | Extracts 'Sentence's from raw content.
getCon :: RawContent -> [Sentence]
getCon :: RawContent -> [Sentence]
getCon (Table [Sentence]
s1 [[Sentence]]
s2 Sentence
t Bool
_) = ([Sentence], [[Sentence]]) -> [Sentence]
isVar ([Sentence]
s1, forall a. [[a]] -> [[a]]
transpose [[Sentence]]
s2) forall a. [a] -> [a] -> [a]
++ [Sentence
t]
getCon (Paragraph Sentence
s)       = [Sentence
s]
getCon EqnBlock{}          = []
getCon CodeBlock{}         = []
getCon (DerivBlock Sentence
h [RawContent]
d)    = Sentence
h forall a. a -> [a] -> [a]
: forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap RawContent -> [Sentence]
getCon [RawContent]
d
getCon (Enumeration ListType
lst)   = ListType -> [Sentence]
getLT ListType
lst
getCon (Figure Sentence
l Identifier
_ MaxWidthPercent
_)    = [Sentence
l]
getCon (Bib BibRef
bref)          = forall c. HasFields c => [c] -> [Sentence]
getBib BibRef
bref
getCon (Graph [(Sentence
s1, Sentence
s2)] Maybe MaxWidthPercent
_ Maybe MaxWidthPercent
_ Sentence
l) = [Sentence
s1, Sentence
s2, Sentence
l]
getCon Graph{}             = []
getCon (Defini DType
_ [])       = []
getCon (Defini DType
dt ((Identifier, [Contents])
hd:[(Identifier, [Contents])]
fs)) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall a. HasContents a => a -> [Sentence]
getCon' (forall a b. (a, b) -> b
snd (Identifier, [Contents])
hd) forall a. [a] -> [a] -> [a]
++ RawContent -> [Sentence]
getCon (DType -> [(Identifier, [Contents])] -> RawContent
Defini DType
dt [(Identifier, [Contents])]
fs)

-- | This function is used in collecting 'Sentence's from a table.
-- Since only the table's first Column titled "Var" should be collected,
-- this function is used to filter out only the first column of 'Sentence's.
isVar :: ([Sentence], [[Sentence]]) -> [Sentence]
isVar :: ([Sentence], [[Sentence]]) -> [Sentence]
isVar (S Identifier
"Var" : [Sentence]
_, [Sentence]
hd1 : [[Sentence]]
_) = [Sentence]
hd1
isVar (Sentence
_ : [Sentence]
tl, [Sentence]
_ : [[Sentence]]
tl1) = ([Sentence], [[Sentence]]) -> [Sentence]
isVar ([Sentence]
tl, [[Sentence]]
tl1)
isVar ([], [[Sentence]]
_) = []
isVar ([Sentence]
_, []) = []

-- | Get the bibliography from something that has a field.
getBib :: (HasFields c) => [c] -> [Sentence]
getBib :: forall c. HasFields c => [c] -> [Sentence]
getBib [c]
a = forall a b. (a -> b) -> [a] -> [b]
map CiteField -> Sentence
getField forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (forall s a. s -> Getting a s a -> a
^. forall c. HasFields c => Lens' c [CiteField]
getFields) [c]
a

-- | Unwraps a 'CiteField' into a 'Sentence'.
getField :: CiteField -> Sentence
getField :: CiteField -> Sentence
getField (Address Identifier
s) = Identifier -> Sentence
S Identifier
s
getField Author{} = Sentence
EmptyS
getField (BookTitle Identifier
s) = Identifier -> Sentence
S Identifier
s
getField Chapter{} = Sentence
EmptyS
getField Edition{} = Sentence
EmptyS
getField Editor{} = Sentence
EmptyS
getField HowPublished{} = Sentence
EmptyS
getField (Institution Identifier
s) = Identifier -> Sentence
S Identifier
s
getField (Journal Identifier
s) = Identifier -> Sentence
S Identifier
s
getField Month{} = Sentence
EmptyS
getField (Note Identifier
s) = Identifier -> Sentence
S Identifier
s
getField Number{} = Sentence
EmptyS
getField (Organization Identifier
s) = Identifier -> Sentence
S Identifier
s
getField Pages{} = Sentence
EmptyS
getField (Publisher Identifier
s) = Identifier -> Sentence
S Identifier
s
getField (School Identifier
s) = Identifier -> Sentence
S Identifier
s
getField (Series Identifier
s) = Identifier -> Sentence
S Identifier
s
getField (Title Identifier
s) = Identifier -> Sentence
S Identifier
s
getField (Type Identifier
s) = Identifier -> Sentence
S Identifier
s
getField Volume{} = Sentence
EmptyS
getField Year{} = Sentence
EmptyS

-- | Translates different types of lists into a 'Sentence' form.
getLT :: ListType -> [Sentence]
getLT :: ListType -> [Sentence]
getLT (Bullet [(ItemType, Maybe Identifier)]
it) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (ItemType -> [Sentence]
getIL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) [(ItemType, Maybe Identifier)]
it
getLT (Numeric [(ItemType, Maybe Identifier)]
it) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (ItemType -> [Sentence]
getIL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) [(ItemType, Maybe Identifier)]
it
getLT (Simple [ListTuple]
lp) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ListTuple -> [Sentence]
getLP [ListTuple]
lp
getLT (Desc [ListTuple]
lp) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ListTuple -> [Sentence]
getLP [ListTuple]
lp
getLT (Definitions [ListTuple]
lp) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ListTuple -> [Sentence]
getLP [ListTuple]
lp

-- | Translates a 'ListTuple' into 'Sentence's.
getLP :: ListTuple -> [Sentence]
getLP :: ListTuple -> [Sentence]
getLP (Sentence
t, ItemType
it, Maybe Identifier
_) = Sentence
t forall a. a -> [a] -> [a]
: ItemType -> [Sentence]
getIL ItemType
it

-- | Flattens out an ItemType into 'Sentence's. Headers for 'Nested' items are prepended to its contents.
getIL :: ItemType -> [Sentence]
getIL :: ItemType -> [Sentence]
getIL (Flat Sentence
s) = [Sentence
s]
getIL (Nested Sentence
h ListType
lt) = Sentence
h forall a. a -> [a] -> [a]
: ListType -> [Sentence]
getLT ListType
lt

-- ciPlate is not currently used. 
-- | A common idea plate.
-- ciPlate :: DLPlate (Constant [CI])
-- ciPlate = preorderFold $ purePlate {
--   introSub = Constant <$> \case
--     (IOrgSec _ ci _ _) -> [ci]
--     _ -> [],
--   stkSub = Constant <$> \case
--    (Client ci _) -> [ci]
--    (Cstmr ci) -> [ci],
--    auxConsSec = Constant <$> \(AuxConsProg ci _) -> [ci]
-- }