Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions code/drasil-database/lib/Drasil/Database/UIDRef.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Drasil.Database.UIDRef (
-- * 'UID' References
UIDRef, hide, unhide, unhideOrErr,
UnitypedUIDRef, hideUni, unhideUni, unhideUniOrErr
UIDRef, hide, unhide, unhideOrErr, raw,
UnitypedUIDRef, hideUni, unhideUni, unhideUniOrErr, rawUni
) where

import Control.Lens ((^.))
Expand Down Expand Up @@ -30,9 +30,13 @@ hide = UIDRef . (^. uid)
unhide :: IsChunk t => UIDRef t -> ChunkDB -> Maybe t
unhide (UIDRef u) = find u

-- | Get the raw 'UID' from a 'UIDRef'.
raw :: UIDRef t -> UID
raw (UIDRef u) = u
Comment on lines +33 to +35
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being able to dump the UID from a UIDRef is helpful, in particular in the case of quantities in Drasil because: (a) we have many 'quantity' types, but (b) only insert a single variant of them (DefinedQuantityDicts) in the ChunkDB, so (c) de-referencing will always expect to look up a D-Q-D-. But I think we should be able to avoid exposing raw.


-- | Find a chunk by a 'UIDRef', erroring if not found.
unhideOrErr :: IsChunk t => UIDRef t -> ChunkDB -> t
unhideOrErr tu cdb = fromMaybe (error "Typed UID dereference failed.") (unhide tu cdb)
unhideOrErr tu cdb = fromMaybe (error $ "Typed UID dereference failed for UID: " ++ show (raw tu)) (unhide tu cdb)
Comment on lines 33 to +39
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These messages just need to be upgraded a bit.


-- | A variant of 'UIDRef' without type information about the chunk being
-- referred to, effectively treating chunks as being "unityped."
Expand All @@ -54,3 +58,7 @@ unhideUni (UnitypedUIDRef u) = find u
-- | Find a chunk by its 'UnitypedUIDRef', erroring if not found.
unhideUniOrErr :: IsChunk t => UnitypedUIDRef -> ChunkDB -> t
unhideUniOrErr tu cdb = fromMaybe (error "Untyped UID dereference failed.") (unhideUni tu cdb)

-- | Get the raw 'UID' from a 'UnitypedUIDRef'.
rawUni :: UnitypedUIDRef -> UID
rawUni (UnitypedUIDRef u) = u
6 changes: 3 additions & 3 deletions code/drasil-docLang/lib/Drasil/DocDecl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import qualified Drasil.DocumentLanguage.Core as DL (DocSection(..), RefSec(..),
ReqsSub(..), LCsSec(..), UCsSec(..), TraceabilitySec(..), AuxConstntSec(..),
AppndxSec(..), OffShelfSolnsSec(..), DerivationDisplay)

import Drasil.Database (HasUID(..), findAll)
import Drasil.Database (HasUID(..), findAll, IsChunk)
import Drasil.System
import Language.Drasil hiding (sec)

Expand Down Expand Up @@ -85,9 +85,9 @@ data SCSSub where
-- | Instance models.
IMs :: [Sentence] -> Fields -> DL.DerivationDisplay -> SCSSub
-- | Constraints.
Constraints :: (HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => Sentence -> [c] -> SCSSub
Constraints :: (IsChunk c, HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => Sentence -> [c] -> SCSSub
-- | Properties of a correct solution.
CorrSolnPpties :: (Quantity c, Constrained c) => [c] -> [Contents] -> SCSSub
CorrSolnPpties :: (IsChunk c, Quantity c, Constrained c) => [c] -> [Contents] -> SCSSub

-- | Requirements section (wraps 'ReqsSub' subsections).
newtype ReqrmntSec = ReqsProg [ReqsSub]
Expand Down
6 changes: 3 additions & 3 deletions code/drasil-docLang/lib/Drasil/DocumentLanguage/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Drasil.DocumentLanguage.Core where

import Data.Generics.Multiplate (Multiplate(multiplate, mkPlate))

import Drasil.Database (UID)
import Drasil.Database (UID, IsChunk)
import Language.Drasil hiding (Manual, Verb) -- Manual - Citation name conflict. FIXME: Move to different namespace
import Theory.Drasil (DataDefinition, GenDefn, InstanceModel, TheoryModel)

Expand Down Expand Up @@ -184,11 +184,11 @@ data SCSSub where
-- | Instance Models.
IMs :: [Sentence] -> Fields -> [InstanceModel] -> DerivationDisplay -> SCSSub
-- | Constraints.
Constraints :: (HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => Sentence -> [c] -> SCSSub
Constraints :: (IsChunk c, HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => Sentence -> [c] -> SCSSub
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should switch all HasUID usage in drasil-lang to IsChunk.

-- Sentence -> [LabelledContent] Fields -> [UncertainWrapper] -> [ConstrainedChunk] -> SCSSub --FIXME: temporary definition?
--FIXME: Work in Progress ^
-- | Properties of a correct solution.
CorrSolnPpties :: (Quantity c, Constrained c) => [c] -> [Contents] -> SCSSub
CorrSolnPpties :: (IsChunk c, Quantity c, Constrained c) => [c] -> [Contents] -> SCSSub

-- | Choose whether to show or hide the derivation of an expression.
data DerivationDisplay = ShowDerivation
Expand Down
12 changes: 6 additions & 6 deletions code/drasil-docLang/lib/Drasil/Sections/Requirements.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Utils.Drasil (stringList, mkTable)
import Control.Lens ((^.))
import Data.Bifunctor (bimap)

import Drasil.Database (HasUID(..))
import Drasil.Database (HasUID(..), IsChunk)
import Language.Drasil
import Language.Drasil.Chunk.Concept.NamedCombinators
import qualified Language.Drasil.Sentence.Combinators as S
Expand Down Expand Up @@ -47,7 +47,7 @@ reqF = SRS.require [reqIntro]
-- The resulting requirement sentence is of the form: "Inputs the values from
-- @table_ref@, which define @description@". If the description is 'Nothing',
-- the sentence is: "Inputs the values from @table_ref@".
inReqWTab :: (Quantity q, MayHaveUnit q) => Maybe Sentence -> [q] -> (ConceptInstance, LabelledContent)
inReqWTab :: (IsChunk q, Quantity q, MayHaveUnit q) => Maybe Sentence -> [q] -> (ConceptInstance, LabelledContent)
inReqWTab mdesc qs = (ci, tbl)
where
tbl = mkInputPropsTable qs
Expand Down Expand Up @@ -143,7 +143,7 @@ mkSecurityNFR refAddress lbl = cic refAddress (foldlSent [
]) lbl nonFuncReqDom

-- | Creates an Input Data Table for use in the Functional Requirments section. Takes a list of wrapped variables and something that is 'Referable'.
mkInputPropsTable :: (Quantity i, MayHaveUnit i) =>
mkInputPropsTable :: (IsChunk i, Quantity i, MayHaveUnit i) =>
[i] -> LabelledContent
mkInputPropsTable [] = mkRawLC (Paragraph EmptyS) reqInputsRef
mkInputPropsTable reqInputs = mkRawLC (Table [atStart symbol_, atStart description, atStart' unit_]
Expand All @@ -155,14 +155,14 @@ reqInputsRef :: Reference
reqInputsRef = makeTabRef' (reqInput ^. uid)

-- | Creates a table for use in the Functional Requirments section. Takes a list of tuples containing variables and sources, a label, and a caption.
mkValsSourceTable :: (Quantity i, MayHaveUnit i, Concept i) =>
mkValsSourceTable :: (IsChunk i, Quantity i, MayHaveUnit i, Concept i) =>
[(i, Sentence)] -> String -> Sentence -> LabelledContent
mkValsSourceTable vals labl cap = llccTab labl $
Table [atStart symbol_, atStart description, S "Source", atStart' unit_]
(mkTable [ch . fst, atStart . fst, snd, toSentence . fst] $ sortBySymbolTuple vals) cap True

mkQRTuple :: (HasOutput i, HasShortName i, Referable i) => [i] -> [(DefinedQuantityDict, Sentence)]
mkQRTuple :: (IsChunk i, HasOutput i, HasShortName i, Referable i) => [i] -> [(DefinedQuantityDict, Sentence)]
mkQRTuple = map (\c -> (c ^. output, refS c))

mkQRTupleRef :: (Quantity i, MayHaveUnit i, Concept i, HasShortName r, Referable r) => [i] -> [r] -> [(DefinedQuantityDict, Sentence)]
mkQRTupleRef :: (Quantity i, MayHaveUnit i, Concept i, HasShortName r, Referable r) =>[i] -> [r] -> [(DefinedQuantityDict, Sentence)]
mkQRTupleRef = zipWith (curry (bimap dqdWr refS))
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Control.Lens ((^.), over)
import Data.Maybe

-- rest of Drasil
import Drasil.Database (UID, HasUID(..), showUID)
import Drasil.Database (UID, HasUID(..), showUID, IsChunk)
import Data.Drasil.Concepts.Documentation (assumption, column, constraint,
datum, datumConstraint, inDatumConstraint, outDatumConstraint, definition,
element, general, goalStmt, information, input_, limitation, model, output_,
Expand Down Expand Up @@ -200,7 +200,7 @@ inModelIntro r1 r2 r3 r4 = foldlSP [S "This", phrase section_,
namedRef r4 (plural genDefn)]

-- | Constructor for Data Constraints section. Takes a trailing 'Sentence' (use 'EmptyS' if none) and data constraints.
datConF :: (HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) =>
datConF :: (IsChunk c, HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) =>
Sentence -> [c] -> Section
datConF _ [] = SRS.datCon [mkParagraph $ emptySectSentPlu [datumConstraint]] []
datConF t c = SRS.datCon [dataConstraintParagraph t, LlC $ inDataConstTbl c] []
Expand Down Expand Up @@ -253,7 +253,7 @@ mkDataConstraintTable col rf lab = llccTab' rf $ uncurry Table
(mkTableFromColumns col) lab True

-- | Creates the input Data Constraints Table.
inDataConstTbl :: (HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) =>
inDataConstTbl :: (IsChunk c, HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) =>
[c] -> LabelledContent
inDataConstTbl qlst = mkDataConstraintTable [(S "Var", map ch $ sortBySymbol qlst),
(titleize' physicalConstraint, map fmtPhys $ sortBySymbol qlst),
Expand All @@ -265,7 +265,7 @@ inDataConstTbl qlst = mkDataConstraintTable [(S "Var", map ch $ sortBySymbol qls
getRVal c = fromMaybe (error $ "getRVal found no Expr for " ++ showUID c) (c ^. reasVal)

-- | Creates the output Data Constraints Table.
outDataConstTbl :: (Quantity c, Constrained c) => [c] -> LabelledContent
outDataConstTbl :: (IsChunk c, Quantity c, Constrained c) => [c] -> LabelledContent
outDataConstTbl qlst = mkDataConstraintTable [(S "Var", map ch qlst),
(titleize' physicalConstraint, map fmtPhys qlst),
(titleize' softwareConstraint, map fmtSfwr qlst)] (outDatumConstraint ^. uid) $
Expand All @@ -286,7 +286,7 @@ fmtSfwr :: (Constrained c, Quantity c) => c -> Sentence
fmtSfwr c = foldConstraints c $ filter isSfwrC (c ^. constraints)

-- | Creates the Properties of a Correct Solution section.
propCorSolF :: (Quantity c, Constrained c) => [c] -> [Contents] -> Section
propCorSolF :: (IsChunk c, Quantity c, Constrained c) => [c] -> [Contents] -> Section
propCorSolF [] [] = SRS.propCorSol [mkParagraph $ emptySectSentPlu [propOfCorSol]] []
propCorSolF [] con = SRS.propCorSol con []
propCorSolF c con = SRS.propCorSol ([propsIntro, LlC $ outDataConstTbl c] ++ con) []
Expand Down
7 changes: 3 additions & 4 deletions code/drasil-docLang/lib/Drasil/Sentence/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ import Control.Lens ((^.))
import Data.Decimal (DecimalRaw, realFracToDecimal)
import Data.List (transpose)

import Drasil.Database (HasUID)
import Drasil.Database (IsChunk)

import Language.Drasil (ConceptChunk, DefinesQuantity(defLhs) , UnitDefn, MayHaveUnit(..)
, UnitalChunk , HasUnitSymbol(usymb), Quantity, Concept, Definition(defn), NamedIdea(..)
, HasSymbol
, HasShortName(..) , short, atStart, titleize, phrase, plural , Section , ItemType(..), ListType(Bullet)
, ModelExpr , refS, namedRef
, Sentence(S, Percent, (:+:), Sy, EmptyS), eS
Expand Down Expand Up @@ -67,7 +66,7 @@ definedIn'' :: (Referable r, HasShortName r) => r -> Sentence
definedIn'' q = S "defined" `S.in_` refS q

-- | Takes a 'Symbol' and its 'Reference' (does not append a period at the end!). Outputs as "@symbol@ is defined in @source@".
definedIn''' :: (HasSymbol q, HasUID q, Referable r, HasShortName r) => q -> r -> Sentence
definedIn''' :: (IsChunk q, Quantity q, Referable r, HasShortName r) => q -> r -> Sentence
definedIn''' q src = ch q `S.is` S "defined in" +:+ refS src

-- | Zip helper function enumerates abbreviations and zips it with list of 'ItemType':
Expand Down Expand Up @@ -192,7 +191,7 @@ tAndDWAcc temp = Flat $ atStart temp +:+. (sParen (short temp) `sDash` capSent (

-- | Helpful combinators for making 'Sentence's into Terminologies with Definitions.
-- Returns of the form: "@term (symbol) - termDefinition@".
tAndDWSym :: (Concept s, Quantity a) => s -> a -> ItemType
tAndDWSym :: (IsChunk a, Concept s, Quantity a) => s -> a -> ItemType
tAndDWSym tD sym = Flat $ atStart tD +:+. (sParen (ch sym) `sDash` capSent (tD ^. defn))

-- | Helpful combinators for making 'Sentence's into Terminologies with Definitions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Drasil.GlassBR.Assumptions (assumpGT, assumpGC, assumpES, assumpSV,
assumpGL, assumpBC, assumpRT, assumpLDFC, assumptionConstants,
assumptions) where

import Drasil.Database (IsChunk)
import Language.Drasil hiding (organization)
import qualified Language.Drasil.Development as D
import qualified Drasil.DocLang.SRS as SRS (valsOfAuxCons)
Expand Down Expand Up @@ -84,7 +85,7 @@ responseTypeDesc :: Sentence
responseTypeDesc = foldlSent [D.toSent $ atStartNP (the responseTy), S "considered in",
short progName, S "is flexural"]

ldfConstantDesc :: (HasSymbol c, NamedIdea c) => c -> Sentence
ldfConstantDesc :: (IsChunk c, Quantity c) => c -> Sentence
ldfConstantDesc mainConcept = foldlSent [S "With", phrase reference, S "to",
refS assumpSV `sC` D.toSent (phraseNP (NP.the (value `of_`
mainConcept))), sParen (ch mainConcept) `S.is` D.toSent (phraseNP (a_ constant))
Expand Down
4 changes: 2 additions & 2 deletions code/drasil-example/glassbr/lib/Drasil/GlassBR/DataDefs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Drasil.GlassBR.DataDefs (dataDefs, aspRat, glaTyFac, glaTyFacQD, gtfRef,
import Control.Lens ((^.))
import Prelude hiding (log, exp, sqrt)

import Drasil.Database (HasUID)
import Drasil.Database (IsChunk)
import Language.Drasil
import Theory.Drasil (DataDefinition, ddE)
import qualified Language.Drasil.Sentence.Combinators as S
Expand Down Expand Up @@ -150,7 +150,7 @@ gtfRef = definedIn glaTyFac
hRef = definedIn' hFromt (S "and is based on the nominal thicknesses")

--- Helper
stdVals :: (HasSymbol s, HasUID s) => [s] -> Sentence
stdVals :: (IsChunk s, Quantity s) => [s] -> Sentence
stdVals s = foldlList Comma List (map ch s) +:+ sent +:+. refS assumpSV
where sent = case s of [ ] -> error "stdVals needs quantities"
[_] -> S "comes from"
Expand Down
4 changes: 2 additions & 2 deletions code/drasil-example/glassbr/lib/Drasil/GlassBR/IMods.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Drasil.GlassBR.IMods (symb, iMods, pbIsSafe, lrIsSafe, instModIntro) wher
import Control.Lens ((^.))
import Prelude hiding (exp)

import Drasil.Database (HasUID)
import Drasil.Database (IsChunk)
import Drasil.Sentence.Combinators (definedIn', definedIn)
import Language.Drasil
import qualified Language.Drasil.Development as D
Expand Down Expand Up @@ -215,6 +215,6 @@ qHtTlTolRef = definedIn tolPre
riskRef = definedIn risk

-- Helper --
interpolating :: (HasUID s, HasSymbol s, Referable f, HasShortName f) => s -> f -> Sentence
interpolating :: (IsChunk s, Quantity s, Referable f, HasShortName f) => s -> f -> Sentence
interpolating s f = foldlSent [ch s `S.is` S "obtained by interpolating from",
plural datum, S "shown" `S.in_` refS f]
5 changes: 4 additions & 1 deletion code/drasil-lang/lib/Language/Drasil/Chunk/Constrained.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Language.Drasil.Chunk.Constrained (

import Control.Lens ((^.), makeLenses, view)

import Drasil.Database (HasUID(..))
import Drasil.Database (HasUID(..), HasChunkRefs(..))

import Language.Drasil.Chunk.Concept (cw, dcc, dccWDS)
import Language.Drasil.Chunk.DefinedQuantity (DefinedQuantityDict, dqd, dqd', dqdWr, dqdNoUnit)
Expand Down Expand Up @@ -38,6 +38,9 @@ data ConstrConcept = ConstrConcept { _defq :: DefinedQuantityDict
}
makeLenses ''ConstrConcept

instance HasChunkRefs ConstrConcept where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.

-- | Finds 'UID' of the 'DefinedQuantityDict' used to make the 'ConstrConcept'.
instance HasUID ConstrConcept where uid = defq . uid
-- | Finds term ('NP') of the 'DefinedQuantityDict' used to make the 'ConstrConcept'.
Expand Down
5 changes: 4 additions & 1 deletion code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Language.Drasil.Chunk.Eq (
) where

import Control.Lens ((^.), view, lens, Lens', to)
import Drasil.Database (UID, HasUID(..))
import Drasil.Database (UID, HasUID(..), HasChunkRefs(..))

import Language.Drasil.Chunk.UnitDefn (unitWrapper, MayHaveUnit(getUnit), UnitDefn)
import Language.Drasil.Symbol (HasSymbol(symbol), Symbol)
Expand All @@ -40,6 +40,9 @@ import Language.Drasil.WellTyped (RequiresChecking(..))
data QDefinition e where
QD :: DefinedQuantityDict -> [UID] -> e -> QDefinition e

instance HasChunkRefs (QDefinition e) where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.

qdQua :: Lens' (QDefinition e) DefinedQuantityDict
qdQua = lens (\(QD qua _ _) -> qua) (\(QD _ ins e) qua' -> QD qua' ins e)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Language.Drasil.Chunk.UncertainQuantity (

import Control.Lens ((^.), makeLenses, view)

import Drasil.Database (HasUID(..))
import Drasil.Database (HasUID(..), HasChunkRefs(..))

import Language.Drasil.Chunk.DefinedQuantity (dqdWr)
import Language.Drasil.Chunk.Constrained (ConstrConcept(..), cuc')
Expand All @@ -32,6 +32,9 @@ import Language.Drasil.Uncertainty
data UncertQ = UQ { _coco :: ConstrConcept , _unc'' :: Uncertainty }
makeLenses ''UncertQ

instance HasChunkRefs UncertQ where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.

-- | Equal if 'UID's are equal.
instance Eq UncertQ where a == b = (a ^. uid) == (b ^. uid)
-- | Finds 'UID' of the 'ConstrConcept' used to make the 'UncertQ'.
Expand Down
5 changes: 4 additions & 1 deletion code/drasil-lang/lib/Language/Drasil/Chunk/Unital.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Language.Drasil.Chunk.Unital (

import Control.Lens (makeLenses, view, (^.))

import Drasil.Database (HasUID(..))
import Drasil.Database (HasUID(..), HasChunkRefs(..))

import Language.Drasil.Chunk.Concept (dccWDS,cw)
import Language.Drasil.Chunk.DefinedQuantity (DefinedQuantityDict, dqd, dqd', dqdWr)
Expand All @@ -33,6 +33,9 @@ data UnitalChunk = UC { _defq' :: DefinedQuantityDict
}
makeLenses ''UnitalChunk

instance HasChunkRefs UnitalChunk where
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.

-- | Finds 'UID' of the 'DefinedQuantityDict' used to make the 'UnitalChunk'.
instance HasUID UnitalChunk where uid = defq' . uid
-- | Finds term ('NP') of the 'DefinedQuantityDict' used to make the 'UnitalChunk'.
Expand Down
22 changes: 10 additions & 12 deletions code/drasil-lang/lib/Language/Drasil/Sentence.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ module Language.Drasil.Sentence (
-- * Functions
(+:+), (+:+.), (+:), (!.), capSent, headSent, ch, eS, eS', sC, sDash, sParen,
sentencePlural, sentenceShort,
sentenceSymb, sentenceTerm,
sentenceTerm,
sdep, shortdep, lnames, lnames', sentenceRefs
) where

import Control.Lens ((^.))
import Data.Char (toUpper)
import qualified Data.Set as Set

import Drasil.Database (HasChunkRefs(..), HasUID(..), UID)
import Drasil.Database (IsChunk, HasChunkRefs(..), UID, UIDRef, hide, raw)

import Language.Drasil.Chunk.NamedIdea (Idea)
import Language.Drasil.ExprClasses (Express(express))
import Language.Drasil.ModelExpr.Lang (ModelExpr)
import Language.Drasil.ModelExpr.Extract (meNames)
import Language.Drasil.NounPhrase.Types (NP)
import Language.Drasil.UnitLang (USymb)
import Language.Drasil.Space (HasSpace)
import Language.Drasil.Symbol (HasSymbol, Symbol)

import qualified Data.Set as Set

-- | Used in 'Ch' constructor to determine the state of a term
-- (can record whether something is in plural form, a singular term, or in short form).
data SentenceStyle = PluralTerm
Expand Down Expand Up @@ -60,7 +60,7 @@ data Sentence where
-- This allows Sentences to hold plural forms of 'NamedIdea's.
Ch :: SentenceStyle -> TermCapitalization -> UID -> Sentence
-- | A branch of Ch dedicated to SymbolStyle only.
SyCh :: UID -> Sentence
SyCh :: (IsChunk t, Idea t, HasSpace t, HasSymbol t) => UIDRef t -> Sentence
-- | Converts a unit symbol into a usable Sentence form.
Sy :: USymb -> Sentence
-- | Directly embeds a 'NP'
Expand Down Expand Up @@ -90,8 +90,8 @@ eS' = E . express

-- The HasSymbol is redundant, but on purpose
-- | Gets a symbol and places it in a 'Sentence'.
ch :: (HasUID c, HasSymbol c) => c -> Sentence
ch x = SyCh (x ^. uid)
ch :: (IsChunk t, Idea t, HasSpace t, HasSymbol t) => t -> Sentence
ch s = SyCh $ hide s

-- | Sentences can be concatenated.
instance Semigroup Sentence where
Expand All @@ -102,13 +102,11 @@ instance Monoid Sentence where
mempty = EmptyS

-- | Smart constructors for turning a 'UID' into a 'Sentence'.
sentencePlural, sentenceShort, sentenceSymb, sentenceTerm :: UID -> Sentence
sentencePlural, sentenceShort, sentenceTerm :: UID -> Sentence
-- | Gets plural term of 'UID'.
sentencePlural = Ch PluralTerm NoCap
-- | Gets short form of 'UID'.
sentenceShort = Ch ShortStyle NoCap
-- | Gets symbol form of 'UID'.
sentenceSymb = SyCh
-- | Gets singular form of 'UID'.
sentenceTerm = Ch TermStyle NoCap

Expand Down Expand Up @@ -161,7 +159,7 @@ getUIDs :: Sentence -> [UID]
getUIDs (Ch ShortStyle _ _) = []
getUIDs (Ch TermStyle _ _) = []
getUIDs (Ch PluralTerm _ _) = []
getUIDs (SyCh a) = [a]
getUIDs (SyCh a) = [raw a]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function now becomes tricky. What should the output type be? Previously: getUIDs :: Sentence -> [UID].

It is used as part of chunkRefs. Does this mean we need to re-design chunkRefs a bit? Should HasChunkRefs give us UnitypedUIDRefs instead of raw UIDs?

getUIDs Sy {} = []
getUIDs NP {} = []
getUIDs S {} = []
Expand Down
Loading