Skip to content

Commit

Permalink
Changed type of RefName from Sentence to String (#553)
Browse files Browse the repository at this point in the history
* started update of RefName type; stuck on Title as a Sentence mismatch

* Added noSpaces as requested in 73d16d3 comments

* added another field specifically for shortname for the section datatype (as discussed in issue #551); Example files broken

* Re-added ShortName.hs (oops)

* make runs fine; removed some warnings wrt redundant imports; logs no longer empty

* hack closes #551

* Added RefAff to Language.Drasil to specify type signature of section'

* Formatting and removing Rationale in this branch
  • Loading branch information
niazim3 authored and samm82 committed May 31, 2018
1 parent e781b49 commit 985bb42
Show file tree
Hide file tree
Showing 38 changed files with 243 additions and 225 deletions.
6 changes: 3 additions & 3 deletions code/Example/Drasil/DocumentLanguage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ mkSections si l = map doit l
mkRefSec :: SystemInformation -> RefSec -> Section
mkRefSec _ (RefVerb s) = s
mkRefSec si (RefProg c l) = section (titleize refmat) [c]
(map (mkSubRef si) l) "RefMat"
(map (mkSubRef si) l) "RefMat" "RefMat"
where
mkSubRef :: SystemInformation -> RefTab -> Section
mkSubRef (SI {_sysinfodb = db}) TUnits =
Expand Down Expand Up @@ -509,9 +509,9 @@ siSys (SI {_sys = sys}) = nw sys
-- mkAssump :: String -> Sentence -> Contents
-- mkAssump i desc = Assumption $ ac' i desc

mkRequirement :: String -> Sentence -> Sentence -> Contents
mkRequirement :: String -> Sentence -> String -> Contents
mkRequirement i desc shrtn = Requirement $ frc i desc (shrtn) [shortname shrtn] --FIXME: HACK - Should have explicit refname

mkLklyChnk :: String -> Sentence -> Sentence -> Contents
mkLklyChnk :: String -> Sentence -> String -> Contents
mkLklyChnk i desc shrtn = Change $ lc i desc (shrtn) [shortname shrtn] -- FIXME: HACK -- See above

33 changes: 16 additions & 17 deletions code/Example/Drasil/DocumentLanguage/RefHelpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module Drasil.DocumentLanguage.RefHelpers

import Language.Drasil

import Data.Drasil.Concepts.Documentation (assumption)

import Control.Lens ((^.), Simple, Lens)
import Data.List (sortBy)
import Data.Function (on)
Expand All @@ -35,19 +33,26 @@ mdb tms gds dds ims = MDB

-- | Automatically reference TMs by number.
refTM :: RefMap TheoryModel -> TheoryModel -> Sentence
refTM db c = customRef c (S $ "T" ++ (show $ snd $ modelLookup c db))
refTM db c = customRef c ("T" ++ (show $ snd $ modelLookup c db))

-- | Automatically reference GDs by number.
refGD :: RefMap GenDefn -> GenDefn -> Sentence
refGD db c = customRef c (S $ "GD" ++ (show $ snd $ modelLookup c db))
refGD db c = customRef c ("GD" ++ (show $ snd $ modelLookup c db))

-- | Automatically reference DDs by number.
refDD :: RefMap QDefinition -> QDefinition -> Sentence
refDD db c = customRef c (S $ "DD" ++ (show $ snd $ modelLookup c db))
refDD db c = customRef c ("DD" ++ (show $ snd $ modelLookup c db))

-- | Automatically reference IMs by number.
refIM :: RefMap InstanceModel -> InstanceModel -> Sentence
refIM db c = customRef c (S $ "IM" ++ (show $ snd $ modelLookup c db))
refIM db c = customRef c ("IM" ++ (show $ snd $ modelLookup c db))

-- | Reference Assumptions by Name or by Number where applicable
refACustom :: ReferenceDB -> RefBy -> AssumpChunk -> Sentence
refACustom rfdb ByNum a = customRef a ("A" ++
numLookup rfdb assumpRefTable assumpLookup a)
refACustom rfdb ByName a =
makeRef (chunkLookup rfdb assumpRefTable assumpLookup a)

modelLookup :: HasUID a => a -> RefMap a -> (a, Int)
modelLookup c db = getS $ Map.lookup (c ^. uid) db
Expand All @@ -63,9 +68,9 @@ modelLookup c db = getS $ Map.lookup (c ^. uid) db
-- a reference database, the assumpRefTable lens, the assumpLookup function, and
-- the assumption chunk being looked up.
numLookup :: HasUID c => ReferenceDB -> Simple Lens ReferenceDB t ->
(c -> t -> (ct, Int)) -> c -> Sentence
(c -> t -> (ct, Int)) -> c -> String
numLookup db tableLens lookupFun chunk =
S $ show $ snd $ lookupFun chunk (db ^. tableLens)
show $ snd $ lookupFun chunk (db ^. tableLens)

-- | Verifies that a chunk exists within our referencing database before we
-- attempt to make a reference to it.
Expand All @@ -79,12 +84,6 @@ refA, refAByNum :: ReferenceDB -> AssumpChunk -> Sentence
refA rfdb = refACustom rfdb ByName
refAByNum rfdb = refACustom rfdb ByNum

-- | Reference Assumptions by Name or by Number where applicable
refACustom :: ReferenceDB -> RefBy -> AssumpChunk -> Sentence
refACustom rfdb ByNum a = customRef a (short assumption :+:
numLookup rfdb assumpRefTable assumpLookup a)
refACustom rfdb ByName a =
makeRef (chunkLookup rfdb assumpRefTable assumpLookup a)

-- | Smart constructors for requirement referencing by name or by number.
refR, refRByNum :: ReferenceDB -> ReqChunk -> Sentence
Expand All @@ -93,7 +92,7 @@ refRByNum rfdb = refRCustom rfdb ByNum

-- | Reference Requirements by Name or by Number where applicable
refRCustom :: ReferenceDB -> RefBy -> ReqChunk -> Sentence
refRCustom rfdb ByNum r = customRef r (S (show (reqType r)) :+:
refRCustom rfdb ByNum r = customRef r (show (reqType r) ++
numLookup rfdb reqRefTable reqLookup r)
refRCustom rfdb ByName r = makeRef (chunkLookup rfdb reqRefTable reqLookup r)

Expand All @@ -104,7 +103,7 @@ refChngByNum rfdb = refChngCustom rfdb ByNum

-- | Reference Changes by Name or by Number where applicable
refChngCustom :: ReferenceDB -> RefBy -> Change -> Sentence
refChngCustom chdb ByNum c = customRef c (S (show (chngType c)) :+:
refChngCustom chdb ByNum c = customRef c (show (chngType c) ++
numLookup chdb changeRefTable changeLookup c)
refChngCustom chdb ByName c =
makeRef (chunkLookup chdb changeRefTable changeLookup c)
Expand All @@ -117,6 +116,6 @@ citeByNum rfdb = citeCustom rfdb ByNum
-- | Reference Changes by Name or by Number where applicable
citeCustom :: ReferenceDB -> RefBy -> Citation -> Sentence
citeCustom rfdb ByNum c = customRef c
(S "[" :+: numLookup rfdb citationRefTable citeLookup c :+: S "]")
("[" ++ numLookup rfdb citationRefTable citeLookup c ++ "]")
citeCustom rfdb ByName c =
makeRef (chunkLookup rfdb citationRefTable citeLookup c)
16 changes: 8 additions & 8 deletions code/Example/Drasil/GlassBR/Assumptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ newAssumptions :: [AssumpChunk] -- For testing
newAssumptions = [newA1, newA2, newA3, newA4, newA5, newA6, newA7, newA8]

newA1, newA2, newA3, newA4, newA5, newA6, newA7, newA8 :: AssumpChunk
newA1 = assump "glassTyA" a1Desc (S "glassTy") []
newA2 = assump "glassConditionA" a2Desc (S "glassCondition") []
newA3 = assump "explsnScenarioA"a3Desc (S "explainScenario") []
newA4 = assump "standardValuesA" (a4Desc load_dur) (S "StandardValues") []
newA5 = assump "glassLiteA" a5Desc (S "glassLite") []
newA6 = assump "bndryConditionsA" a6Desc (S "boundaryConditions") []
newA7 = assump "responseTyA" a7Desc (S "responseType") []
newA8 = assump "ldfConstantA" (a8Desc constant_LoadDF) (S "ldfConstant") []
newA1 = assump "glassTyA" a1Desc "glassTy" []
newA2 = assump "glassConditionA" a2Desc "glassCondition" []
newA3 = assump "explsnScenarioA"a3Desc "explainScenario" []
newA4 = assump "standardValuesA" (a4Desc load_dur) "StandardValues" []
newA5 = assump "glassLiteA" a5Desc "glassLite" []
newA6 = assump "bndryConditionsA" a6Desc "boundaryConditions" []
newA7 = assump "responseTyA" a7Desc "responseType" []
newA8 = assump "ldfConstantA" (a8Desc constant_LoadDF) "ldfConstant" []

assumptionDescs :: [Sentence]
assumptionDescs = [a1Desc, a2Desc, a3Desc, a4Desc load_dur, a5Desc, a6Desc, a7Desc, a8Desc constant_LoadDF]
Expand Down
24 changes: 12 additions & 12 deletions code/Example/Drasil/GlassBR/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ assumpList :: [AssumpChunk] -> [Contents]
assumpList = map Assumption

assumptions :: [Contents] -- FIXME: Remove this entirely and use new refs + docLang.
assumptions = fst (foldr (\s (ls, n) -> ((Assumption $ assump ("A" ++ show n) s (S $ "A" ++ show n) []) : ls, n-1))
assumptions = fst (foldr (\s (ls, n) -> ((Assumption $ assump ("A" ++ show n) s ("A" ++ show n) []) : ls, n-1))
([], (length assumptionDescs)::Int) assumptionDescs)
-- These correspond to glassTyAssumps, glassCondition, explsnScenario,
-- standardValues, glassLiteAssmp, bndryConditions, responseTyAssump, ldfConstant
Expand Down Expand Up @@ -484,17 +484,17 @@ s7_1_req6 :: [Contents] --FIXME: Issue #327
s7_1_listOfReqs :: [Contents]
s7_1_listOfReqs = [s7_1_req1, s7_1_req2, s7_1_req3, s7_1_req4, s7_1_req5]

s7_1_req1 = mkRequirement "s7_1_req1" req1Desc (S "Input-Glass-Props")
s7_1_req2 = mkRequirement "s7_1_req2" req2Desc (S "System-Set-Values-Following-Assumptions")
s7_1_req3 = mkRequirement "s7_1_req3" req3Desc (S "Check-Input-with-Data_Constraints")
s7_1_req4 = mkRequirement "s7_1_req4" req4Desc (S "Output-Values-and-Known-Quantities")
s7_1_req5 = mkRequirement "s7_1_req5" (req5Desc (output_)) (S "Check-Glass-Safety")
s7_1_req1 = mkRequirement "s7_1_req1" req1Desc "Input-Glass-Props"
s7_1_req2 = mkRequirement "s7_1_req2" req2Desc "System-Set-Values-Following-Assumptions"
s7_1_req3 = mkRequirement "s7_1_req3" req3Desc "Check-Input-with-Data_Constraints"
s7_1_req4 = mkRequirement "s7_1_req4" req4Desc "Output-Values-and-Known-Quantities"
s7_1_req5 = mkRequirement "s7_1_req5" (req5Desc (output_)) "Check-Glass-Safety"

-- newReqs is ONLY for testing until I get refs working. Then the old reqs should
-- be converted to reqChunk format with meaningful refnames and this should be
-- removed.
newReqs :: [ReqChunk]
newReqs = map (\(x,y) -> frc x y (S x) []) --FIXME: FRC Hack for referencing
newReqs = map (\(x,y) -> frc x y x []) --FIXME: FRC Hack for referencing --FIXME: x used twice?
[ ("r1",req1Desc)
, ("r2",req2Desc)
, ("r3",req3Desc)
Expand Down Expand Up @@ -585,11 +585,11 @@ likelyChanges_SRS = [s8_likelychg1, s8_likelychg2, s8_likelychg3,
s8_likelychg1, s8_likelychg2, s8_likelychg3, s8_likelychg4,
s8_likelychg5 :: Contents

s8_likelychg1 = mkLklyChnk "s8_likelychg1" (lc1Desc (blastRisk)) (S "Calculate-Internal-Blask-Risk")
s8_likelychg2 = mkLklyChnk "s8_likelychg2" (lc2Desc) (S "Variable-Values-of-m,k,E")
s8_likelychg3 = mkLklyChnk "s8_likelychg3" (lc3Desc) (S "Accomodate-More-than-Single-Lite")
s8_likelychg4 = mkLklyChnk "s8_likelychg4" (lc4Desc) (S "Accomodate-More-Boundary-Conditions")
s8_likelychg5 = mkLklyChnk "s8_likelychg5" (lc5Desc) (S "Consider-More-than-Flexure-Glass")
s8_likelychg1 = mkLklyChnk "s8_likelychg1" (lc1Desc (blastRisk)) "Calculate-Internal-Blask-Risk"
s8_likelychg2 = mkLklyChnk "s8_likelychg2" (lc2Desc) "Variable-Values-of-m,k,E"
s8_likelychg3 = mkLklyChnk "s8_likelychg3" (lc3Desc) "Accomodate-More-than-Single-Lite"
s8_likelychg4 = mkLklyChnk "s8_likelychg4" (lc4Desc) "Accomodate-More-Boundary-Conditions"
s8_likelychg5 = mkLklyChnk "s8_likelychg5" (lc5Desc) "Consider-More-than-Flexure-Glass"

lc1Desc :: NamedChunk -> Sentence
lc2Desc, lc3Desc, lc4Desc, lc5Desc :: Sentence
Expand Down
2 changes: 1 addition & 1 deletion code/Example/Drasil/GlassBR/IMods.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Drasil.DocumentLanguage.RefHelpers
import Data.Drasil.SentenceStructures (foldlSent, isThe, sAnd, sOr)
import Data.Drasil.Utils (getES)
import Data.Drasil.Concepts.Math (parameter)
import Data.Drasil.Concepts.Documentation (coordinate, assumption)
import Data.Drasil.Concepts.Documentation (coordinate)

import Prelude hiding (exp)
import Control.Lens ((^.))
Expand Down
30 changes: 15 additions & 15 deletions code/Example/Drasil/NoPCM/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import Data.Drasil.Concepts.Documentation as Doc (datumConstraint, inModel,
requirement, section_, traceyGraph, item, assumption, dataDefn,
likelyChg, genDefn, thModel, traceyMatrix, model,
output_, quantity, input_, physicalConstraint, condition,
property, variable, description, symbol_, uncertainty,
information, uncertCol, value, column, softwareConstraint, goalStmt,
property, variable, description, symbol_,
information, value, column, softwareConstraint, goalStmt,
physSyst, problem, definition, srs, content, reference, document,
goal, purpose, typUnc)

Expand Down Expand Up @@ -414,40 +414,40 @@ assumpS3 =
(foldlSent [S "The", phrase water, S "in the", phrase tank,
S "is fully mixed, so the", phrase temp_W `isThe`
S "same throughout the entire", phrase tank, sSqBr (acroGD 2)])
assump3 = let a3 = "assump3" in Assumption $ assump a3 assumpS3 (S a3) []
assump3 = let a3 = "assump3" in Assumption $ assump a3 assumpS3 a3 []

assumpS4 =
(foldlSent [S "The", phrase w_density, S "has no spatial variation; that is"
`sC` S "it is constant over their entire", phrase vol, sSqBr ((acroGD 2)`sC`
(makeRef (find' likeChg2 s6_list) ))])
assump4 = let a4 = "assump4" in Assumption $ assump a4 assumpS4 (S a4) []
assump4 = let a4 = "assump4" in Assumption $ assump a4 assumpS4 a4 []

assumpS5 =
(foldlSent [S "The", phrase htCap_W, S "has no spatial variation; that",
S "is, it is constant over its entire", phrase vol, sSqBr (acroGD 2)])
assump5 = let a5 = "assump5" in Assumption $ assump a5 assumpS5 (S a5) []
assump5 = let a5 = "assump5" in Assumption $ assump a5 assumpS5 a5 []

assumpS9_npcm =
(foldlSent [S "The", phrase model, S "only accounts for charging",
S "of the tank" `sC` S "not discharging. The", phrase temp_W, S "can only",
S "increase, or remain constant; it cannot decrease. This implies that the",
phrase temp_init, S "is less than (or equal to) the", phrase temp_C,
sSqBr ((acroIM 1) `sC` (makeRef (find' likeChg3_npcm s6_list)))])
assump9_npcm = let a9 = "assump9_npcm" in Assumption $ assump a9 assumpS9_npcm (S a9) []
assump9_npcm = let a9 = "assump9_npcm" in Assumption $ assump a9 assumpS9_npcm a9 []

assumpS12 =
(S "No internal" +:+ phrase heat +:+ S "is generated by the" +:+ phrase water
`semiCol` S "therefore, the" +:+ phrase vol_ht_gen +:+ S "is zero" +:+.
sSqBr (acroIM 1))
assump12 = let a12 = "assump12" in Assumption $ assump a12 assumpS12 (S a12) []
assump12 = let a12 = "assump12" in Assumption $ assump a12 assumpS12 a12 []

assumpS13 =
(S "The pressure in the" +:+ phrase tank +:+ S "is atmospheric, so the" +:+
phrase melt_pt `sAnd` phrase boil_pt +:+ S "are" +:+ S (show (0 :: Integer))
:+: Sy (unit_symb QT.temp) `sAnd` S (show (100 :: Integer)) :+:
Sy (unit_symb QT.temp) `sC` S "respectively" +:+.
sSqBr ((acroIM 1) `sC` (acroIM 2)))
assump13 = let a13 = "assump13" in Assumption $ assump a13 assumpS13 (S a13) []
assump13 = let a13 = "assump13" in Assumption $ assump a13 assumpS13 a13 []


s4_2_3_paragraph :: ConceptChunk -> ConceptChunk -> [Contents]
Expand Down Expand Up @@ -679,30 +679,30 @@ req1, req2, req3, req4, req5, req6 :: Contents
req1 = mkRequirement "req1" (
titleize input_ +:+ S "the following" +:+ plural quantity `sC`
S "which define the" +:+ plural tank_para `sC` S "material" +:+
plural property +:+ S "and initial" +: plural condition) (S "Input-Inital-Values")
plural property +:+ S "and initial" +: plural condition) "Input-Inital-Values"
req2 = mkRequirement "req2" (
S "Use the" +:+ plural input_ +:+ S "in" +:+
(makeRef (find' req1 s5_1_list_words_num)) +:+ S "to find the" +:+ phrase mass +:+
S "needed for" +:+ acroIM 1 +:+ S "to" +:+ acroIM 2 `sC`
S "as follows, where" +:+ getES w_vol `isThe` phrase w_vol +:+
S "and" +: (getES tank_vol `isThe` phrase tank_vol) ) (S "Use-Above-Find-Mass-IM1-IM2")
S "and" +: (getES tank_vol `isThe` phrase tank_vol) ) "Use-Above-Find-Mass-IM1-IM2"
req3 = mkRequirement "req3" (
S "Verify that the" +:+ plural input_ +:+ S "satisfy the required"
+:+ phrase physicalConstraint +:+ S "shown in" +:+. makeRef s4_2_6_table1 ) (S "Check-Inputs-Satisfy-Physical-Constraints")
+:+ phrase physicalConstraint +:+ S "shown in" +:+. makeRef s4_2_6_table1 ) "Check-Inputs-Satisfy-Physical-Constraints"
req4 = mkRequirement "req4" (
titleize' output_ `sAnd` plural input_ +:+ plural quantity
+:+ S "and derived" +:+ plural quantity +:+ S "in the following list: the" +:+
plural quantity +:+ S "from" +:+ (makeRef (find' req1 s5_1_list_words_num)) `sC`
S "the" +:+ phrase mass +:+ S "from" +:+ (makeRef (find' req2 s5_1_list_words_num))
`sAnd` getES tau_W +:+. sParen(S "from" +:+ acroIM 1) ) (S "Output-Input-Derivied-Quantities")
`sAnd` getES tau_W +:+. sParen(S "from" +:+ acroIM 1) ) "Output-Input-Derivied-Quantities"
req5 = mkRequirement "req5" (
S "Calculate and output the" +:+ phrase temp_W +:+
sParen (getES temp_W :+: sParen (getES time)) +:+ S "over the" +:+
phrase sim_time ) (S "Calculate-Temperature-Water-Over-Time")
phrase sim_time ) "Calculate-Temperature-Water-Over-Time"
req6 = mkRequirement "req6" (
S "Calculate and" +:+ phrase output_ +:+ S "the" +:+ phrase w_E
+:+ sParen (getES w_E :+: sParen (getES time)) +:+ S "over the" +:+
phrase sim_time +:+. sParen (S "from" +:+ acroIM 3) ) (S "Calculate-Change-Heat_Energy-Water-Time")
phrase sim_time +:+. sParen (S "from" +:+ acroIM 3) ) "Calculate-Change-Heat_Energy-Water-Time"

-------------------------------------------
--Section 5.2 : NON-FUNCTIONAL REQUIREMENTS
Expand Down Expand Up @@ -741,7 +741,7 @@ likeChg3_npcm :: Contents
likeChg3_npcm = mkLklyChnk "likeChg3" (
(makeRef (find' assump9_npcm npcmAssumptions)) :+: S "- The" +:+ phrase model +:+
S "currently only accounts for charging of the tank. A more complete"
+:+ phrase model +:+. S "would also account for discharging of the tank") (S "Discharging-Tank")
+:+ phrase model +:+. S "would also account for discharging of the tank") "Discharging-Tank"
-- likeChg4 = LikelyChange (LCChunk (nw $ npnc "likeChg4" $
-- nounPhraseSent (makeRef assump11 :+: S "- Any real" +:+ phrase tank +:+
-- S "cannot be perfectly insulated and will lose" +:+. phrase heat))
Expand Down
2 changes: 1 addition & 1 deletion code/Example/Drasil/NoPCM/IMods.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ balWtrDesc = foldlSent [(E $ sy temp_W) `isThe` phrase temp_W +:+.

-- FIXME
a10 :: Contents
a10 = Assumption $ assump "assump10" EmptyS (S "assump10") []
a10 = Assumption $ assump "assump10" EmptyS "assump10" []
Loading

0 comments on commit 985bb42

Please sign in to comment.