{-# 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.SRS.ExtractDocDesc (
  getDocDesc, egetDocDesc,
  sentencePlate
) where

import Control.Lens((^.))
import Data.Functor.Constant (Constant(Constant))
import Data.Generics.Multiplate (appendPlate, foldFor, purePlate, preorderFold)
import Data.Maybe (maybeToList)

import Language.Drasil (Sentence, Definition(..), ModelExpr,
  HasAdditionalNotes(..), Express(express))
import Language.Drasil.Document (HasContents, Section(Section), SecCons(..),
  sentToExp, extractSents, extractSents', extractMExprs, getSec)
import Theory.Drasil (Derivation(..), MayHaveDerivation(..))

import Drasil.SRS.DocumentLanguage.Core
import Drasil.SRS.Sections.SpecificSystemDescription (inDataConstTbl, outDataConstTbl)

-- | 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 = DLPlate (Constant b) -> DLPlate (Constant b)
forall (p :: (* -> *) -> *) o.
(Multiplate p, Monoid o) =>
p (Constant o) -> p (Constant o)
preorderFold (DLPlate (Constant b) -> DLPlate (Constant b))
-> DLPlate (Constant b) -> DLPlate (Constant b)
forall a b. (a -> b) -> a -> b
$ DLPlate (Constant b)
forall (p :: (* -> *) -> *) (f :: * -> *).
(Multiplate p, Applicative f) =>
p f
purePlate {
  refSec = Constant <$> \(RefProg Contents
c [RefTab]
_) -> [Contents] -> b
forall a. HasContents a => [a] -> b
mCon [Contents
c],
  introSub = Constant <$> \case
    (IOrgSec CI
_ Section
s Maybe Sentence
_) -> [Section] -> b
mSec [Section
s]
    IntroSub
_ -> b
forall a. Monoid a => a
mempty,
  gsdSub = Constant <$> \case
    (SysCntxt [Contents]
c) -> [Contents] -> b
forall a. HasContents a => [a] -> b
mCon [Contents]
c
    (UsrChars [Contents]
c) -> [Contents] -> b
forall a. HasContents a => [a] -> b
mCon [Contents]
c
    (SystCons [Contents]
c [Section]
s) -> [Contents] -> b
forall a. HasContents a => [a] -> b
mCon [Contents]
c b -> b -> b
forall a. Monoid a => a -> a -> a
`mappend` [Section] -> b
mSec [Section]
s,
  pdSec = Constant <$> \(PDProg Sentence
_ [Section]
s [PDSub]
_) -> [Section] -> b
mSec [Section]
s,
  pdSub = Constant <$> \case
    (TermsAndDefs Maybe Sentence
_ [c]
_) -> b
forall a. Monoid a => a
mempty
    (PhySysDesc a
_ [Sentence]
_ LabelledContent
lc [Contents]
c) -> [LabelledContent] -> b
forall a. HasContents a => [a] -> b
mCon [LabelledContent
lc] b -> b -> b
forall a. Monoid a => a -> a -> a
`mappend` [Contents] -> b
forall a. HasContents a => [a] -> b
mCon [Contents]
c
    (Goals [Sentence]
_ [ConceptInstance]
_) -> b
forall a. Monoid a => a
mempty,
  scsSub = Constant <$> \case
    (Constraints Sentence
_ [c]
c) -> [LabelledContent] -> b
forall a. HasContents a => [a] -> b
mCon [[c] -> LabelledContent
forall c.
(HasUncertainty c, Quantity c, Constrained c, HasReasVal c,
 MayHaveUnit c) =>
[c] -> LabelledContent
inDataConstTbl [c]
c]
    (CorrSolnPpties [c]
c [Contents]
cs) -> [LabelledContent] -> b
forall a. HasContents a => [a] -> b
mCon [[c] -> LabelledContent
forall c. (Quantity c, Constrained c) => [c] -> LabelledContent
outDataConstTbl [c]
c] b -> b -> b
forall a. Monoid a => a -> a -> a
`mappend` [Contents] -> b
forall a. HasContents a => [a] -> b
mCon [Contents]
cs
    SCSSub
_ -> b
forall a. Monoid a => a
mempty,
  reqSub = Constant <$> \case
    (FReqsSub [ConceptInstance]
_ [LabelledContent]
c) -> [LabelledContent] -> b
forall a. HasContents a => [a] -> b
mCon [LabelledContent]
c
    (NonFReqsSub [ConceptInstance]
_) -> b
forall a. Monoid a => a
mempty,
  offShelfSec = Constant <$> \(OffShelfSolnsProg [Contents]
c) -> [Contents] -> b
forall a. HasContents a => [a] -> b
mCon [Contents]
c,
  appendSec = Constant <$> \(AppndxProg [Contents]
c) -> [Contents] -> b
forall a. HasContents a => [a] -> b
mCon [Contents]
c
}

-- | Creates a section plate for expressions.
exprPlate :: DLPlate (Constant [ModelExpr])
exprPlate :: DLPlate (Constant [ModelExpr])
exprPlate = ([Sentence] -> [ModelExpr]) -> DLPlate (Constant [ModelExpr])
forall a. Monoid a => ([Sentence] -> a) -> DLPlate (Constant a)
sentencePlate ((Sentence -> [ModelExpr]) -> [Sentence] -> [ModelExpr]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Sentence -> [ModelExpr]
sentToExp) DLPlate (Constant [ModelExpr])
-> DLPlate (Constant [ModelExpr]) -> DLPlate (Constant [ModelExpr])
forall (p :: (* -> *) -> *) o.
(Multiplate p, Monoid o) =>
p (Constant o) -> p (Constant o) -> p (Constant o)
`appendPlate` (forall a. HasContents a => [a] -> [ModelExpr])
-> ([Section] -> [ModelExpr]) -> DLPlate (Constant [ModelExpr])
forall b.
Monoid b =>
(forall a. HasContents a => [a] -> b)
-> ([Section] -> b) -> DLPlate (Constant b)
secConPlate ((a -> [ModelExpr]) -> [a] -> [ModelExpr]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap a -> [ModelExpr]
forall a. HasContents a => a -> [ModelExpr]
extractMExprs)
  ((Section -> [ModelExpr]) -> [Section] -> [ModelExpr]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Section -> [ModelExpr]
egetSec) DLPlate (Constant [ModelExpr])
-> DLPlate (Constant [ModelExpr]) -> DLPlate (Constant [ModelExpr])
forall (p :: (* -> *) -> *) o.
(Multiplate p, Monoid o) =>
p (Constant o) -> p (Constant o) -> p (Constant o)
`appendPlate` (DLPlate (Constant [ModelExpr]) -> DLPlate (Constant [ModelExpr])
forall (p :: (* -> *) -> *) o.
(Multiplate p, Monoid o) =>
p (Constant o) -> p (Constant o)
preorderFold (DLPlate (Constant [ModelExpr]) -> DLPlate (Constant [ModelExpr]))
-> DLPlate (Constant [ModelExpr]) -> DLPlate (Constant [ModelExpr])
forall a b. (a -> b) -> a -> b
$ DLPlate (Constant [ModelExpr])
forall (p :: (* -> *) -> *) (f :: * -> *).
(Multiplate p, Applicative f) =>
p f
purePlate {
  scsSub = Constant <$> \case
    (TMs [Sentence]
_ Fields
_ [TheoryModel]
t)   -> [TheoryModel] -> [ModelExpr]
forall a. Express a => [a] -> [ModelExpr]
go [TheoryModel]
t
    (DDs [Sentence]
_ Fields
_ [DataDefinition]
d DerivationDisplay
_) -> [DataDefinition] -> [ModelExpr]
forall a. Express a => [a] -> [ModelExpr]
go [DataDefinition]
d
    (GDs [Sentence]
_ Fields
_ [GenDefn]
g DerivationDisplay
_) -> [GenDefn] -> [ModelExpr]
forall a. Express a => [a] -> [ModelExpr]
go [GenDefn]
g
    (IMs [Sentence]
_ Fields
_ [InstanceModel]
i DerivationDisplay
_) -> [InstanceModel] -> [ModelExpr]
forall a. Express a => [a] -> [ModelExpr]
go [InstanceModel]
i
    SCSSub
_ -> [],
  auxConsSec = Constant <$> \(AuxConsProg CI
_ [ConstQDef]
qdef) -> [ConstQDef] -> [ModelExpr]
forall a. Express a => [a] -> [ModelExpr]
go [ConstQDef]
qdef
  }) where
      go :: Express a => [a] -> [ModelExpr]
      go :: forall a. Express a => [a] -> [ModelExpr]
go = (a -> ModelExpr) -> [a] -> [ModelExpr]
forall a b. (a -> b) -> [a] -> [b]
map a -> ModelExpr
forall c. Express c => c -> ModelExpr
express

-- | 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 = (DocSection -> [a]) -> DocDesc -> [a]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Projector DLPlate DocSection
-> DLPlate (Constant [a]) -> DocSection -> [a]
forall (p :: (* -> *) -> *) a o.
Multiplate p =>
Projector p a -> p (Constant o) -> a -> o
foldFor DLPlate f -> DocSection -> f DocSection
Projector DLPlate DocSection
docSec DLPlate (Constant [a])
p)

-- | Extracts expressions from the document description ('DocDesc') and default 'DLPlate'.
egetDocDesc :: DocDesc -> [ModelExpr]
egetDocDesc :: DocDesc -> [ModelExpr]
egetDocDesc = DLPlate (Constant [ModelExpr]) -> DocDesc -> [ModelExpr]
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
_ ) = (SecCons -> [ModelExpr]) -> [SecCons] -> [ModelExpr]
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) = Contents -> [ModelExpr]
forall a. HasContents a => a -> [ModelExpr]
extractMExprs Contents
c

-- | 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 = DLPlate (Constant a)
-> DLPlate (Constant a) -> DLPlate (Constant a)
forall (p :: (* -> *) -> *) o.
(Multiplate p, Monoid o) =>
p (Constant o) -> p (Constant o) -> p (Constant o)
appendPlate ((forall a. HasContents a => [a] -> a)
-> ([Section] -> a) -> DLPlate (Constant a)
forall b.
Monoid b =>
(forall a. HasContents a => [a] -> b)
-> ([Section] -> b) -> DLPlate (Constant b)
secConPlate ([Sentence] -> a
f ([Sentence] -> a) -> ([a] -> [Sentence]) -> [a] -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [Sentence]
forall a. HasContents a => [a] -> [Sentence]
extractSents') (([Section] -> a) -> DLPlate (Constant a))
-> ([Section] -> a) -> DLPlate (Constant a)
forall a b. (a -> b) -> a -> b
$ [Sentence] -> a
f ([Sentence] -> a) -> ([Section] -> [Sentence]) -> [Section] -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Section -> [Sentence]) -> [Section] -> [Sentence]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Section -> [Sentence]
getSec) (DLPlate (Constant a) -> DLPlate (Constant a))
-> DLPlate (Constant a) -> DLPlate (Constant a)
forall a b. (a -> b) -> a -> b
$
  DLPlate (Constant a) -> DLPlate (Constant a)
forall (p :: (* -> *) -> *) o.
(Multiplate p, Monoid o) =>
p (Constant o) -> p (Constant o)
preorderFold (DLPlate (Constant a) -> DLPlate (Constant a))
-> DLPlate (Constant a) -> DLPlate (Constant a)
forall a b. (a -> b) -> a -> b
$ DLPlate (Constant a)
forall (p :: (* -> *) -> *) (f :: * -> *).
(Multiplate p, Applicative f) =>
p f
purePlate {
    introSec = Constant . f <$> \(IntroProg Sentence
s1 Sentence
s2 [IntroSub]
s3) -> [Sentence
s1, Sentence
s2] [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ (IntroSub -> [Sentence]) -> [IntroSub] -> [Sentence]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap IntroSub -> [Sentence]
getIntroSub [IntroSub]
s3,
    introSub = Constant . f <$> \case
      (IPurpose [Sentence]
s) -> [Sentence]
s
      (IScope Sentence
s) -> [Sentence
s]
      (IChar [Sentence]
s1 [Sentence]
s2 [Sentence]
s3) -> [[Sentence]] -> [Sentence]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Sentence]
s1, [Sentence]
s2, [Sentence]
s3]
      (IOrgSec CI
_ Section
s1 Maybe Sentence
s2) -> Maybe Sentence -> [Sentence]
forall a. Maybe a -> [a]
maybeToList Maybe Sentence
s2 [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ Section -> [Sentence]
getSec Section
s1,
    stkSub = Constant . f <$> \case
      (Client CI
_ Sentence
s) -> [Sentence
s]
      (Cstmr CI
_) -> [],
    pdSec = Constant . f <$> \(PDProg Sentence
s [Section]
secs [PDSub]
pds) -> Sentence
s Sentence -> [Sentence] -> [Sentence]
forall a. a -> [a] -> [a]
: (Section -> [Sentence]) -> [Section] -> [Sentence]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Section -> [Sentence]
getSec [Section]
secs [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ (PDSub -> [Sentence]) -> [PDSub] -> [Sentence]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDSub -> [Sentence]
getPDSub [PDSub]
pds,
    pdSub = Constant . f <$> \case
      (TermsAndDefs Maybe Sentence
Nothing [c]
cs) -> [c] -> [Sentence]
forall a. Definition a => [a] -> [Sentence]
def [c]
cs
      (TermsAndDefs (Just Sentence
s) [c]
cs) -> Sentence
s Sentence -> [Sentence] -> [Sentence]
forall a. a -> [a] -> [a]
: [c] -> [Sentence]
forall a. Definition a => [a] -> [Sentence]
def [c]
cs
      (PhySysDesc a
_ [Sentence]
s LabelledContent
lc [Contents]
cs) -> [Sentence]
s [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ LabelledContent -> [Sentence]
forall a. HasContents a => a -> [Sentence]
extractSents LabelledContent
lc [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [Contents] -> [Sentence]
forall a. HasContents a => [a] -> [Sentence]
extractSents' [Contents]
cs
      (Goals [Sentence]
s [ConceptInstance]
c) -> [Sentence]
s [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [ConceptInstance] -> [Sentence]
forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c,
    scsSub = Constant . f <$> \case
      (Assumptions [ConceptInstance]
c) -> [ConceptInstance] -> [Sentence]
forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c
      (TMs [Sentence]
s Fields
_ [TheoryModel]
t)   -> [Sentence]
s [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [TheoryModel] -> [Sentence]
forall a. Definition a => [a] -> [Sentence]
def [TheoryModel]
t [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [TheoryModel] -> [Sentence]
forall a. HasAdditionalNotes a => [a] -> [Sentence]
notes [TheoryModel]
t
      (DDs [Sentence]
s Fields
_ [DataDefinition]
d DerivationDisplay
_) -> [Sentence]
s [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [DataDefinition] -> [Sentence]
forall a. MayHaveDerivation a => [a] -> [Sentence]
der [DataDefinition]
d [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [DataDefinition] -> [Sentence]
forall a. HasAdditionalNotes a => [a] -> [Sentence]
notes [DataDefinition]
d
      (GDs [Sentence]
s Fields
_ [GenDefn]
d DerivationDisplay
_) -> [Sentence]
s [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [GenDefn] -> [Sentence]
forall a. Definition a => [a] -> [Sentence]
def [GenDefn]
d [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [GenDefn] -> [Sentence]
forall a. MayHaveDerivation a => [a] -> [Sentence]
der [GenDefn]
d [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [GenDefn] -> [Sentence]
forall a. HasAdditionalNotes a => [a] -> [Sentence]
notes [GenDefn]
d
      (IMs [Sentence]
s Fields
_ [InstanceModel]
d DerivationDisplay
_) -> [Sentence]
s [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [InstanceModel] -> [Sentence]
forall a. MayHaveDerivation a => [a] -> [Sentence]
der [InstanceModel]
d [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [InstanceModel] -> [Sentence]
forall a. HasAdditionalNotes a => [a] -> [Sentence]
notes [InstanceModel]
d
      (Constraints Sentence
s [c]
_) -> [Sentence
s]
      (CorrSolnPpties [c]
_ [Contents]
cs) -> [Contents] -> [Sentence]
forall a. HasContents a => [a] -> [Sentence]
extractSents' [Contents]
cs,
    reqSub = Constant . f <$> \case
      (FReqsSub [ConceptInstance]
c [LabelledContent]
lcs) -> [ConceptInstance] -> [Sentence]
forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [LabelledContent] -> [Sentence]
forall a. HasContents a => [a] -> [Sentence]
extractSents' [LabelledContent]
lcs
      (NonFReqsSub [ConceptInstance]
c) -> [ConceptInstance] -> [Sentence]
forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c,
    lcsSec = Constant . f <$> \(LCsProg [ConceptInstance]
c) -> [ConceptInstance] -> [Sentence]
forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c,
    ucsSec = Constant . f <$> \(UCsProg [ConceptInstance]
c) -> [ConceptInstance] -> [Sentence]
forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c,
    traceSec = Constant . f <$> \(TraceabilityProg [TraceConfig]
progs) ->
      (TraceConfig -> [Sentence]) -> [TraceConfig] -> [Sentence]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(TraceConfig UID
_ [Sentence]
ls Sentence
s [TraceViewCat]
_ [TraceViewCat]
_) -> Sentence
s Sentence -> [Sentence] -> [Sentence]
forall a. a -> [a] -> [a]
: [Sentence]
ls) [TraceConfig]
progs,
    auxConsSec = Constant . f <$> \(AuxConsProg CI
_ [ConstQDef]
qdef) -> [ConstQDef] -> [Sentence]
forall a. Definition a => [a] -> [Sentence]
def [ConstQDef]
qdef
  } where
    def :: Definition a => [a] -> [Sentence]
    def :: forall a. Definition a => [a] -> [Sentence]
def = (a -> Sentence) -> [a] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map (a -> Getting Sentence a Sentence -> Sentence
forall s a. s -> Getting a s a -> a
^. Getting Sentence a Sentence
forall c. Definition c => Lens' c Sentence
Lens' a Sentence
defn)

    getIntroSub :: IntroSub -> [Sentence]
    getIntroSub :: IntroSub -> [Sentence]
getIntroSub (IPurpose [Sentence]
ss) = [Sentence]
ss
    getIntroSub (IScope Sentence
s) = [Sentence
s]
    getIntroSub (IChar [Sentence]
s1 [Sentence]
s2 [Sentence]
s3) = [Sentence]
s1 [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [Sentence]
s2 [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [Sentence]
s3
    getIntroSub (IOrgSec CI
_ Section
s1 Maybe Sentence
s2) = Maybe Sentence -> [Sentence]
forall a. Maybe a -> [a]
maybeToList Maybe Sentence
s2 [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ Section -> [Sentence]
getSec Section
s1

    der :: MayHaveDerivation a => [a] -> [Sentence]
    der :: forall a. MayHaveDerivation a => [a] -> [Sentence]
der = (a -> [Sentence]) -> [a] -> [Sentence]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Maybe Derivation -> [Sentence]
getDerivSent (Maybe Derivation -> [Sentence])
-> (a -> Maybe Derivation) -> a -> [Sentence]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
-> Getting (Maybe Derivation) a (Maybe Derivation)
-> Maybe Derivation
forall s a. s -> Getting a s a -> a
^. Getting (Maybe Derivation) a (Maybe Derivation)
forall c. MayHaveDerivation c => Lens' c (Maybe Derivation)
Lens' a (Maybe Derivation)
derivations))

    getDerivSent :: Maybe Derivation -> [Sentence]
    getDerivSent :: Maybe Derivation -> [Sentence]
getDerivSent Maybe Derivation
Nothing = []
    getDerivSent (Just (Derivation Sentence
h [Sentence]
s)) = Sentence
h Sentence -> [Sentence] -> [Sentence]
forall a. a -> [a] -> [a]
: [Sentence]
s

    notes :: HasAdditionalNotes a => [a] -> [Sentence]
    notes :: forall a. HasAdditionalNotes a => [a] -> [Sentence]
notes = (a -> [Sentence]) -> [a] -> [Sentence]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (a -> Getting [Sentence] a [Sentence] -> [Sentence]
forall s a. s -> Getting a s a -> a
^. Getting [Sentence] a [Sentence]
forall c. HasAdditionalNotes c => Lens' c [Sentence]
Lens' a [Sentence]
getNotes)

    getPDSub :: PDSub -> [Sentence]
    getPDSub :: PDSub -> [Sentence]
getPDSub (TermsAndDefs Maybe Sentence
ms [c]
c) = [c] -> [Sentence]
forall a. Definition a => [a] -> [Sentence]
def [c]
c [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [Sentence]
-> (Sentence -> [Sentence]) -> Maybe Sentence -> [Sentence]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] Sentence -> [Sentence]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Sentence
ms
    getPDSub (PhySysDesc a
_ [Sentence]
s LabelledContent
lc [Contents]
cs) = [Sentence]
s [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ LabelledContent -> [Sentence]
forall a. HasContents a => a -> [Sentence]
extractSents LabelledContent
lc [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [Contents] -> [Sentence]
forall a. HasContents a => [a] -> [Sentence]
extractSents' [Contents]
cs
    getPDSub (Goals [Sentence]
s [ConceptInstance]
c) = [Sentence]
s [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
++ [ConceptInstance] -> [Sentence]
forall a. Definition a => [a] -> [Sentence]
def [ConceptInstance]
c

-- | Extracts 'Sentence's from a document description.
getDocDesc :: DocDesc -> [Sentence]
getDocDesc :: DocDesc -> [Sentence]
getDocDesc = DLPlate (Constant [Sentence]) -> DocDesc -> [Sentence]
forall a. DLPlate (Constant [a]) -> DocDesc -> [a]
fmGetDocDesc (([Sentence] -> [Sentence]) -> DLPlate (Constant [Sentence])
forall a. Monoid a => ([Sentence] -> a) -> DLPlate (Constant a)
sentencePlate [Sentence] -> [Sentence]
forall a. a -> a
id)
-- ^ FIXME: We want all Sentences from a document (not necessarily a document
-- description), so we use this function. But 'sentencePlate' does not include
-- all 'Sentence's! Some only appear when rendering (at least, after
-- `mkSections` is used on a `DocDesc` to create `[Section]`).