-
Notifications
You must be signed in to change notification settings - Fork 28
Demo: Switch Sentence's SyCh constructor from UID to UIDRefs.
#4716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 ((^.)) | ||
|
|
@@ -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 | ||
|
|
||
| -- | 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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." | ||
|
|
@@ -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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
||
|
|
@@ -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 | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should switch all |
||
| -- 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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' | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
balacij marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| -- | Gets singular form of 'UID'. | ||
| sentenceTerm = Ch TermStyle NoCap | ||
|
|
||
|
|
@@ -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] | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function now becomes tricky. What should the output type be? Previously: It is used as part of |
||
| getUIDs Sy {} = [] | ||
| getUIDs NP {} = [] | ||
| getUIDs S {} = [] | ||
|
|
||
There was a problem hiding this comment.
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
UIDfrom aUIDRefis 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 theChunkDB, so (c) de-referencing will always expect to look up aD-Q-D-. But I think we should be able to avoid exposingraw.