Skip to content
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

Improved list Implementation #958

Merged
merged 29 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4e8d164
Added enumitem to package list in TeX - log.log not empty
samm82 Jun 28, 2018
4457bfc
Merge branch 'master' into sentenceConstructors
samm82 Jun 28, 2018
fdf22a8
Merge branch 'master' into sentenceConstructors
samm82 Jun 29, 2018
b964e8c
Merge branch 'master' into sentenceConstructors
samm82 Jul 4, 2018
6c78aae
Manual merge of master
samm82 Jul 5, 2018
5d741eb
Merge branch 'master' into sentenceConstructors
samm82 Jul 6, 2018
4f12466
Merge branch 'master' into sentenceConstructors
samm82 Jul 12, 2018
b854d3c
Merge branch 'master' into sentenceConstructors
samm82 Jul 19, 2018
9e2f409
Merge branch 'master' into sentenceConstructors
samm82 Jul 20, 2018
e906266
Merge branch 'master' into sentenceConstructors
samm82 Jul 20, 2018
ae99e07
Fixed grammar errors in A1
samm82 Jul 20, 2018
83f4a54
Updated stable and added colon to A1
samm82 Jul 20, 2018
d13efb4
Added preliminary (hardcoded) version for enumerated inline lists
samm82 Jul 20, 2018
6028765
Merge branch 'master' into sentenceConstructors
samm82 Jul 20, 2018
8996819
Updated stable
samm82 Jul 20, 2018
086536e
Implemented EnumType
samm82 Jul 20, 2018
85ac81f
Merge branch 'master' into sentenceConstructors
samm82 Jul 23, 2018
85b420a
Pulled out commonalities in foldInlineList and via numList
samm82 Jul 23, 2018
c057b92
Added WrapType and expanded wrap function
samm82 Jul 23, 2018
0bc8c9c
Manual merge of master - version numbers
samm82 Jul 24, 2018
2496e14
Implemented FoldType to facilitate merge of functions - glassBR examp…
samm82 Jul 24, 2018
85edb4e
Added SepType and getSep
samm82 Jul 24, 2018
843aee6
Removed Paren from wrap and enumitem from TeX Preamble
samm82 Jul 24, 2018
42aee45
Removed foldlList; renamed makeList to foldlList
samm82 Jul 24, 2018
073dc16
Renamed foldlInlineList to foldlEnumList to better represent its func…
samm82 Jul 24, 2018
b93c181
Removed foldlOptions
samm82 Jul 24, 2018
0fb6b05
Merge branch 'master' into sentenceConstructors
samm82 Jul 25, 2018
5d3295e
Replaced guards with pattern matching in foldlList
samm82 Jul 25, 2018
0b8887e
Manual merge of master
samm82 Jul 26, 2018
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
49 changes: 34 additions & 15 deletions code/drasil-data/Data/Drasil/SentenceStructures.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Data.Drasil.SentenceStructures
( foldlSent, foldlSent_, foldlSentCol, foldlsC, foldlList
( foldlSent, foldlSent_, foldlSentCol, foldlsC, foldlList, foldlEnumList
, sAnd, andIts, andThe, sAre, sIn, sVersus
, sIs, isThe, sOf, sOr, ofThe, ofThe'
, ofGiv, ofGiv'
, toThe, tableShows, figureLabel
, isExpctdToHv, underConsidertn, showingCxnBw, refineChain
, foldlSP, foldlSP_, foldlSPCol,foldlOptions
, foldlSP, foldlSP_, foldlSPCol
, maybeChanged, maybeExpanded, maybeWOVerb
, tAndDWAcc, tAndDWSym, tAndDOnly
, followA
Expand All @@ -15,6 +15,7 @@ module Data.Drasil.SentenceStructures
, fmtPhys, fmtSfwr, typUncr
, mkTableFromColumns
, acroA, acroGD, acroGS, acroIM, acroLC, acroPS, acroR, acroT
, EnumType(..), WrapType(..), SepType(..), FoldType(..)
) where

import Language.Drasil
Expand Down Expand Up @@ -49,21 +50,39 @@ foldlSP_ = Paragraph . foldlSent_
foldlSPCol :: [Sentence] -> Contents
foldlSPCol = Paragraph . foldlSentCol

-- | creates a list of elements seperated by commas, including the last element
-- | creates a list of elements separated by commas, including the last element
foldlsC :: [Sentence] -> Sentence
foldlsC = mconcat . intersperse (S ", ")

-- | creates a list of elements seperated by commas, ending in a "_, and _"
foldlList :: [Sentence] -> Sentence
foldlList [] = EmptyS
foldlList [a,b] = a `sAnd` b
foldlList lst = foldle1 sC (\a b -> a `sC` S "and" +:+ b) lst
data EnumType = Numb | Upper | Lower
data WrapType = Parens | Period
data SepType = Comma | SemiCol
data FoldType = List | Options

-- | creates a list of elements seperated by commas, ending in a "_, or _"
foldlOptions :: [Sentence] -> Sentence
foldlOptions [] = EmptyS
foldlOptions [a,b] = a `sOr` b
foldlOptions lst = foldle1 sC (\a b -> a `sC` S "or" +:+ b) lst
-- | creates an list of elements with "enumerators" in "wrappers" using foldlList
foldlEnumList :: EnumType -> WrapType -> SepType -> FoldType -> [Sentence] -> Sentence
foldlEnumList e w s l lst = foldlList s l $ map (\(a, b) -> a +:+ b) $ zip (numList e w $ length lst) lst
where
numList :: EnumType -> WrapType -> Int -> [Sentence]
numList Numb wt len = map (\x -> wrap wt $ S $ show x) [1..len]
numList Upper wt len = map (\x -> wrap wt $ S $ [x]) (take len ['A'..'Z'])
numList Lower wt len = map (\x -> wrap wt $ S $ [x]) (take len ['a'..'z'])
wrap :: WrapType -> Sentence -> Sentence
wrap Parens x = sParen x
wrap Period x = x :+: S "."

-- | creates a list of elements separated by a "separator", ending with "and" or "or"
foldlList :: SepType -> FoldType -> [Sentence] -> Sentence
foldlList _ _ [] = EmptyS
foldlList _ List [a, b] = a `sAnd` b
foldlList _ Options [a, b] = a `sOr` b
foldlList s List lst = foldle1 (getSep s) (\a b -> (getSep s) a (S "and" +:+ b)) lst
foldlList s Options lst = foldle1 (getSep s) (\a b -> (getSep s) a (S "or" +:+ b)) lst

--Helper function to foldlList - not exported
getSep :: SepType -> (Sentence -> Sentence -> Sentence)
getSep Comma = sC
getSep SemiCol = semiCol

{--** Combinators **--}
sAnd, andIts :: Sentence -> Sentence -> Sentence
Expand Down Expand Up @@ -222,10 +241,10 @@ constraintToExpr c (EnumeratedStr _ l) = isin (sy c) (DiscreteS l)

--Formatters for the constraints
fmtPhys :: (Constrained c, Quantity c) => c -> Sentence
fmtPhys c = foldlList $ map (E . constraintToExpr c) $ filter isPhysC (c ^. constraints)
fmtPhys c = foldlList Comma List $ map (E . constraintToExpr c) $ filter isPhysC (c ^. constraints)

fmtSfwr :: (Constrained c, Quantity c) => c -> Sentence
fmtSfwr c = foldlList $ map (E . constraintToExpr c) $ filter isSfwrC (c ^. constraints)
fmtSfwr c = foldlList Comma List $ map (E . constraintToExpr c) $ filter isSfwrC (c ^. constraints)

replaceEmptyS :: Sentence -> Sentence
replaceEmptyS EmptyS = none
Expand Down
2 changes: 1 addition & 1 deletion code/drasil-data/drasil-data.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: drasil-data
Version: 0.1.3
Version: 0.1.4
Cabal-Version: >= 1.18
Author: Dan Szymczak, Steven Palmer, Jacques Carette, Spencer Smith
build-type: Simple
Expand Down
4 changes: 2 additions & 2 deletions code/drasil-docLang/Drasil/Sections/Introduction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Drasil.Sections.Introduction
import Language.Drasil
import qualified Drasil.DocLang.SRS as SRS (intro, prpsOfDoc, scpOfReq, charOfIR, orgOfDoc)
import Data.Drasil.SentenceStructures (ofThe, ofThe',
foldlList, foldlsC, refineChain, foldlSP)
foldlList, SepType(Comma), FoldType(List), foldlsC, refineChain, foldlSP)
import Data.Drasil.Concepts.Documentation as Doc (goal, organization, thModel, inModel, goalStmt,
documentation, user, theory, definition, scope, requirement, section_, document, purpose,
system, model, design, intReader, srs, characteristic, designDoc, decision, environment,
Expand Down Expand Up @@ -44,7 +44,7 @@ developmentProcessParagraph refdb = foldlSP [S "This", phrase document,

-- | Sentence containing the subsections of the introduction
introductionSubsections :: Sentence
introductionSubsections = foldlList (map (\(x,y) -> x `ofThe` y)
introductionSubsections = foldlList Comma List (map (\(x,y) -> x `ofThe` y)
[(phrase scope, phrase system),
(phrase Doc.organization, phrase document),
(plural characteristic, phrase intReader)])
Expand Down
10 changes: 5 additions & 5 deletions code/drasil-docLang/Drasil/Sections/Requirements.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Language.Drasil
import Data.Drasil.Concepts.Documentation (priority, software, requirement, nonfunctionalRequirement,
functionalRequirement, section_)
import Data.Drasil.Concepts.Software (program)
import Data.Drasil.SentenceStructures (foldlSP, foldlList, foldlSent)
import Data.Drasil.SentenceStructures (foldlSP, foldlList, foldlSent, SepType(Comma), FoldType(List))

import qualified Drasil.DocLang.SRS as SRS

Expand Down Expand Up @@ -51,10 +51,10 @@ nonFuncReq noPriority priority_ reason_ explanation_ = Paragraph $ reason_ `sC`
listO :: Sentence -> [Sentence] -> [Sentence] -> Sentence
listO explanation_ [] [] = S "so there are no" +:+ (plural priority) +:+ explanation_
listO explanation_ [] priority_ = S "so" +:+ head priority_ +:+ S "is a high" +:+. (phrase priority) +:+ explanation_ +:+ S "The other" +:+. listT (tail priority_)
listO explanation_ [s] priority_ = S "so" +:+ s +:+ S "is not a" +:+. (phrase priority) +:+ explanation_ +:+ S "Rather than" +:+ s `sC` S "the" +:+. listT priority_
listO explanation_ s priority_ = S "so" +:+ foldlList s +:+ S "are not" +:+. (plural priority) +:+ explanation_ +:+ S "Rather, the" +:+. listT priority_
listO explanation_ [s] priority_ = S "so" +:+ s +:+ S "is not a" +:+. phrase priority +:+ explanation_ +:+ S "Rather than" +:+ s `sC` S "the" +:+. listT priority_
listO explanation_ s priority_ = S "so" +:+ foldlList Comma List s +:+ S "are not" +:+. (plural priority) +:+ explanation_ +:+ S "Rather, the" +:+. listT priority_

listT :: [Sentence] -> Sentence
listT [] = (phrase program) +:+ S "does not possess a" +:+ (phrase priority) +:+ (phrase $ nonfunctionalRequirement)
listT [] = (phrase program) +:+ S "does not possess a" +:+ (phrase priority) +:+ (phrase nonfunctionalRequirement)
listT [s] = (phrase nonfunctionalRequirement) +:+ (phrase priority) +:+ S "is" +:+ s
listT s = (phrase nonfunctionalRequirement) +:+ (plural priority) +:+ S "are" +:+ foldlList s
listT s = (phrase nonfunctionalRequirement) +:+ (plural priority) +:+ S "are" +:+ foldlList Comma List s
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import Data.Drasil.Concepts.Math (equation, law)
import Data.Drasil.Concepts.Computation (computer)
import Data.Drasil.Concepts.Software (program)
import Data.Drasil.Utils (foldle)
import Data.Drasil.SentenceStructures (ofThe, foldlSP, foldlSent, foldlList, sAnd)
import Data.Drasil.SentenceStructures (ofThe, foldlSP, foldlSent, foldlList,
SepType(Comma), FoldType(List), sAnd)
import qualified Data.Drasil.Concepts.Documentation as Doc
import Data.List (find)
import Control.Lens ((^.))
Expand Down Expand Up @@ -406,7 +407,7 @@ goalStatementIntro :: [Sentence] -> Contents
goalStatementIntro inputs = Paragraph $ foldl (+:+) EmptyS [S "Given",
(inputToSystem inputs), plural Doc.goalStmt +: S "are"]
where inputToSystem [] = S "the inputs" `sC` S "the" --FIXME add ref input variables if none are given?
inputToSystem listInputs = (foldlList listInputs) `sC` S "the"
inputToSystem listInputs = (foldlList Comma List listInputs) `sC` S "the"


-------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Data.Drasil.Concepts.Math (equation)
import Data.Drasil.Concepts.Software (program)
import Data.Drasil.Utils (foldle, fmtU, getRVal)
import Data.Drasil.SentenceStructures (fmtPhys, fmtSfwr, mkTableFromColumns, foldlSent,
foldlSP, typUncr, ofThe, foldlList)
foldlSP, typUncr, ofThe, foldlList, SepType(Comma), FoldType(List))
import Data.List (sortBy)

import qualified Drasil.DocLang.SRS as SRS
Expand All @@ -42,7 +42,7 @@ intro_ :: Contents
intro_ = Paragraph $ foldlSent [S "This", phrase section_, S "first presents the",
phrase problemDescription `sC` S "which gives a high-level view of the", phrase problem,
S "to be solved. This is followed by the", plural solutionCharacteristic, phrase specification `sC`
S "which presents the", foldlList (map S ["assumptions", "theories", "definitions"]), S "that are used"]
S "which presents the", foldlList Comma List (map S ["assumptions", "theories", "definitions"]), S "that are used"]

--Up to change, decide on what ending sentence structure we would like to employ
--Using Verbatim for now.
Expand Down Expand Up @@ -79,7 +79,7 @@ physSystDesc progName fg otherContents = SRS.physSyst ((intro):otherContents) []
--List all the given inputs. Might be possible to use ofThe combinator from utils.hs
goalStmtF :: [Sentence] -> [Contents] -> Section
goalStmtF givenInputs otherContents = SRS.goalStmt (intro:otherContents) []
where intro = Paragraph $ S "Given" +:+ foldlList givenInputs `sC` S "the" +:+
where intro = Paragraph $ S "Given" +:+ foldlList Comma List givenInputs `sC` S "the" +:+
plural goalStmt +: S "are"


Expand Down
2 changes: 1 addition & 1 deletion code/drasil-docLang/drasil-docLang.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ library
parsec >= 3.1.9,
data-fix (>= 0.0.4 && <= 1.0),
drasil-lang >= 0.1.6,
drasil-data >= 0.1.1
drasil-data >= 0.1.4
default-language: Haskell2010
ghc-options: -Wall

Expand Down
19 changes: 10 additions & 9 deletions code/drasil-example/Drasil/GamePhysics/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ import qualified Data.Drasil.Quantities.Math as QM (orientation)
import qualified Data.Drasil.Quantities.PhysicalProperties as QPP (mass)
import qualified Data.Drasil.Quantities.Physics as QP (time,
position, force, velocity, angularVelocity, linearVelocity)
import Data.Drasil.SentenceStructures (foldlSent, foldlSent_, foldlList, sOf,
sAnd, sOr, foldlSentCol, foldlSP, foldlSPCol, showingCxnBw)
import Data.Drasil.SentenceStructures (foldlSent, foldlSent_, foldlList,
SepType(Comma), FoldType(List), sOf,sAnd, sOr, foldlSentCol, foldlSP,
foldlSPCol, showingCxnBw)
import Data.Drasil.Software.Products (videoGame, openSource, sciCompS)
import Data.Drasil.Utils (makeTMatrix, itemRefToSent, refFromType,
makeListRef, bulletFlat, bulletNested, enumSimple, enumBullet)
Expand Down Expand Up @@ -205,7 +206,7 @@ para1_purpose_of_document_param :: (Idea a, NamedIdea b) => a -> b -> Sentence -
para1_purpose_of_document_param progName typeOf progDescrip appOf listOf = foldlSent
[S "This", (phrase typeOf), S "descibes the modeling of an",
progDescrip, S "used for" +:+. appOf, S "The",
foldlList listOf, S "used in", (short progName),
foldlList Comma List listOf, S "used in", (short progName),
S "are provided. This", (phrase typeOf),
S "is intended to be used as a", (phrase reference),
S "to provide all necessary", (phrase information),
Expand Down Expand Up @@ -404,9 +405,9 @@ goalStatementStruct state inputs wrt adjective outputs objct condition1 conditio
S "over a period of", (phrase QP.time), condition2]
where initial EmptyS = S "initial"
initial p = p `sC` (S "initial")
listOfInputs EmptyS = (foldlList $ map plural inputs)
listOfInputs i = (foldlList $ map plural inputs) `sC` S "and" +:+ i
listOfOutputs = (foldlList $ map plural outputs)
listOfInputs EmptyS = (foldlList Comma List $ map plural inputs)
listOfInputs i = (foldlList Comma List $ map plural inputs) `sC` S "and" +:+ i
listOfOutputs = (foldlList Comma List $ map plural outputs)

goal_statements_G_linear = goalStatementStruct (plural physicalProperty)
(take 2 inputSymbols) (plural QP.force) (S "applied on")
Expand Down Expand Up @@ -479,7 +480,7 @@ allObject thing = [S "All objects are", thing]
thereNo :: [Sentence] -> [Sentence]
thereNo [x] = [S "There is no", x, S "involved throughout the",
(phrase simulation)]
thereNo l = [S "There are no", foldlList l, S "involved throughout the",
thereNo l = [S "There are no", foldlList Comma List l, S "involved throughout the",
(phrase simulation)]

assumptions_assum1 = allObject (plural CP.rigidBody)
Expand Down Expand Up @@ -643,7 +644,7 @@ nonfunctional_requirements_intro = foldlSP
[(titleize' game), S "are resource intensive, so", phrase performance,
S "is a high" +:+. phrase priority, S "Other", plural nonfunctionalRequirement,
S "that are a", phrase priority +: S "are",
foldlList (map phrase chpmnkPriorityNFReqs)]
foldlList Comma List (map phrase chpmnkPriorityNFReqs)]

--------------------------------
-- SECTION 6 : LIKELY CHANGES --
Expand Down Expand Up @@ -686,7 +687,7 @@ traceability_matrices_and_graph = traceMGF [traceMatTabReqGoalOther, traceMatTab
[traceMatTabReqGoalOther, traceMatTabAssump, traceMatTabDefnModel] []

traceability_matrices_and_graph_traces, traceability_matrices_and_graph_trace1, traceability_matrices_and_graph_trace2, traceability_matrices_and_graph_trace3 :: [Sentence]
traceability_matrices_and_graph_traces = map (foldlList) [traceability_matrices_and_graph_trace1, traceability_matrices_and_graph_trace2, traceability_matrices_and_graph_trace3]
traceability_matrices_and_graph_traces = map (foldlList Comma List) [traceability_matrices_and_graph_trace1, traceability_matrices_and_graph_trace2, traceability_matrices_and_graph_trace3]

traceability_matrices_and_graph_trace1 = [(plural goalStmt), (plural requirement), (plural inModel),
(plural datumConstraint) +:+. S "with each other"]
Expand Down
22 changes: 11 additions & 11 deletions code/drasil-example/Drasil/GlassBR/Assumptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import Drasil.DocLang (cite, refA)
import Data.Drasil.Concepts.Documentation as Doc (condition, constant, practice, reference, scenario,
system, value)
import Data.Drasil.Concepts.Math (calculation, surface, shape)
import Data.Drasil.SentenceStructures (sAnd, foldlSent, foldlOptions, foldlList, sOf, sIn)
import Data.Drasil.SentenceStructures (EnumType(Numb), WrapType(Parens), SepType(..),
FoldType(..), foldlSent, foldlSent_, foldlList, foldlEnumList, sAnd, sIn, sOf)
import Data.Drasil.Concepts.PhysicalProperties (materialProprty)

import Drasil.GlassBR.Unitals ( lite, explosion, lateral, load_dur, explosion,
Expand Down Expand Up @@ -42,21 +43,20 @@ assumptionDescs = [a1Desc, a2Desc, a3Desc, a4Desc load_dur, a5Desc, a6Desc, a7De

a1Desc :: Sentence
a1Desc = foldlSent [S "The standard E1300-09a for",
phrase calculation, S "applies only to", foldlOptions $ map S ["monolithic",
phrase calculation, S "applies only to", foldlList Comma Options $ map S ["monolithic",
"laminated", "insulating"], S "glass constructions" `sOf` S "rectangular",
phrase shape, S "with continuous", phrase lateral +:+. S "support along",
foldlOptions $ map S ["one", "two", "three", "four"], plural edge, S "This",
phrase practice, S "assumes that", sParenNum 1, S "the supported glass",
plural edge, S "for two, three" `sAnd` S "four-sided support",
phrase shape, S "with continuous", phrase lateral, S "support along",
(foldlList Comma Options $ map S ["one", "two", "three", "four"]) +:+. plural edge, S "This",
phrase practice +: S "assumes that", (foldlEnumList Numb Parens SemiCol List $ map foldlSent_
[[S "the supported glass", plural edge, S "for two, three" `sAnd` S "four-sided support",
plural condition, S "are simply supported" `sAnd` S "free to slip in",
phrase plane `semiCol` (sParenNum 2), S "glass supported on two sides acts",
S "as a simply supported", phrase beam `sAnd` (sParenNum 3), S "glass",
S "supported on one side acts as a", phrase cantilever]
phrase plane], [S "glass supported on two sides acts as a simply supported", phrase beam],
[S "glass supported on one side acts as a", phrase cantilever]])]

a2Desc :: Sentence
a2Desc = foldlSent [S "Following", cite gbRefDB astm2009 +:+ sParen
(S "pg. 1") `sC` S "this", phrase practice,
S "does not apply to any form of", foldlOptions $ map S ["wired",
S "does not apply to any form of", foldlList Comma Options $ map S ["wired",
"patterned", "etched", "sandblasted", "drilled", "notched", "grooved glass"],
S "with", phrase surface `sAnd`
S "edge treatments that alter the glass strength"]
Expand All @@ -70,7 +70,7 @@ a4Desc :: UnitaryChunk -> Sentence
a4Desc mainIdea = foldlSent [S "The", plural value, S "provided in",
makeRef (SRS.valsOfAuxCons SRS.missingP []), S "are assumed for the",
phrase mainIdea, sParen (ch mainIdea) `sC` S "and the",
plural materialProprty `sOf` foldlList (map ch
plural materialProprty `sOf` foldlList Comma List (map ch
(take 3 assumptionConstants))] +:+ S "[IM1, DD3, DD5, DD7, DD9]"

a5Desc :: Sentence
Expand Down
Loading