on master help sign in
fix dumb error in relation terminal display involving empty string atoms
6b69c62AgentM
RelationTerm.hs+17−4
@@ -1,6 +1,7 @@
1--writes Relation to a String suitable for terminal output
1--writes Relation to a String suitable for terminal output
2module RelationTerm where
2module RelationTerm where
3import RelationType
3import RelationType
4+import RelationTuple
4import Relation
5import Relation
5import qualified Data.Set as S
6import qualified Data.Set as S
6import qualified Data.Map as M
7import qualified Data.Map as M
@@ -48,10 +49,15 @@ cellLocations tab@(header, body) = (maxWidths, maxHeights)
48 maxHeights = map (L.maximumBy compare) rowHeights
49 maxHeights = map (L.maximumBy compare) rowHeights
49 mergeMax a b = map (\(a,b) -> max a b) (zip a b)
50 mergeMax a b = map (\(a,b) -> max a b) (zip a b)
50
51
52+--the normal "lines" function returns an empty list for an empty string which is not what we want
53+breakLines :: String -> [String]
54+breakLines "" = [""]
55+breakLines x = lines x
56+
51cellSizes :: Table -> [([Int], [Int])]
57cellSizes :: Table -> [([Int], [Int])]
52−cellSizes (header, body) = map (\row -> (map maxRowWidth row, map (length . lines) row)) allRows
58+cellSizes (header, body) = map (\row -> (map maxRowWidth row, map (length . breakLines) row)) allRows
53 where
59 where
54− maxRowWidth row = L.maximumBy compare (map length (lines row))
60+ maxRowWidth row = L.maximumBy compare (map length (breakLines row))
55 allRows = [header] ++ body
61 allRows = [header] ++ body
56
62
57relationAsTable :: Relation -> Table
63relationAsTable :: Relation -> Table
@@ -87,7 +93,7 @@ renderHBar left middle end columnLocations = left ++ concat (L.intersperse middl
87leftPaddedString :: Int -> Int -> String -> String
93leftPaddedString :: Int -> Int -> String -> String
88leftPaddedString lineNum size str = paddedLines !! lineNum
94leftPaddedString lineNum size str = paddedLines !! lineNum
89 where
95 where
90− paddedLines = map (\s -> s ++ repeatString (size - length s) " ") (lines str ++ repeat "")
96+ paddedLines = map (\s -> s ++ repeatString (size - length s) " ") (breakLines str ++ repeat "")
91
97
92renderRow :: [Cell] -> [Int] -> Int -> String -> String
98renderRow :: [Cell] -> [Int] -> Int -> String -> String
93renderRow cells columnLocations rowHeight interspersed = unlines $ map renderOneLine [0..rowHeight-1]
99renderRow cells columnLocations rowHeight interspersed = unlines $ map renderOneLine [0..rowHeight-1]
@@ -118,4 +124,11 @@ showRelation rel
118
124
119simpleExample = s
125simpleExample = s
120groupedExample = case group (S.fromList ["CITY"]) "CITYREL" s of {Right rel -> rel}
126groupedExample = case group (S.fromList ["CITY"]) "CITYREL" s of {Right rel -> rel}
121−
127+
128+emptyStringExample = case mkRelation attributes tupleSet of
129+ Right x -> x
130+ _ -> undefined
131+ where
132+ attributes = M.fromList [("x", Attribute "x" StringAtomType)]
133+ tupleSet = HS.singleton $ mkRelationTuple (S.fromList ["x"]) (M.singleton "x" $ StringAtom "")
134+