Commits

Doug Burke committed 9be451e

Formatter: more minor refactoring

  • Participants
  • Parent commits 0593863

Comments (0)

Files changed (2)

File src/Swish/RDF/Formatter/N3.hs

   case maybeExtractList osubjs oprops lctxt ln of
     Just (ls, osubjs', oprops') -> do
       setSubjs osubjs'
-      setProps oprops' -- TODO: this used to be optional; is this valid?
+      setProps oprops'
       return (Just ls)
 
     _ -> return Nothing
   fp <- if dopref
         then formatPrefixes (getNamespaces gr)
         else return mempty
-  more <- moreSubjects
+  more <- hasMore subjs
   if more
     then do
       fr <- formatSubjects
   sb    <- nextSubject
   sbstr <- formatLabel SubjContext sb
   
-  flagP <- moreProperties
+  flagP <- hasMore props
   if flagP
     then do
       prstr <- formatProperties sb sbstr
-      flagS <- moreSubjects
+      flagS <- hasMore subjs
       if flagS
         then do
           fr <- formatSubjects
     else do
       txt <- nextLine sbstr
     
-      flagS <- moreSubjects
+      flagS <- hasMore subjs
       if flagS
         then do
           fr <- formatSubjects
   pr <- nextProperty sb
   prstr <- formatLabel PredContext pr
   obstr <- formatObjects sb pr $ mconcat [sbstr, " ", prstr]
-  more  <- moreProperties
+  more  <- hasMore props
   let sbindent = hackIndent -- mkIndent sbstr
   if more
     then do
 formatObjects sb pr prstr = do
   ob    <- nextObject sb pr
   obstr <- formatLabel ObjContext ob
-  more  <- moreObjects
+  more  <- hasMore objs
   if more
     then do
       let prindent = hackIndent -- mkIndent prstr
 
 insertBnode :: LabelContext -> RDFLabel -> Formatter B.Builder
 insertBnode SubjContext lbl = do
-  flag <- moreProperties
+  flag <- hasMore props
   txt <- if flag
          then (`mappend` "\n") `liftM` formatProperties lbl ""
          else return ""
                 }
 
   put nst
-  flag <- moreProperties
+  flag <- hasMore props
   txt <- if flag
          then (`mappend` "\n") `liftM` formatProperties lbl ""
          else return ""
 setGraph :: RDFGraph -> Formatter ()
 setGraph = modify . newState
 
-moreSubjects :: Formatter Bool
-moreSubjects = hasMore subjs
-
-moreProperties :: Formatter Bool
-moreProperties = hasMore props
-
-moreObjects :: Formatter Bool
-moreObjects = hasMore objs
-
 nextSubject :: Formatter RDFLabel
 nextSubject = 
     changeState $ \st -> 

File src/Swish/RDF/Formatter/Turtle.hs

     , subjs     = []
     , props     = []
     , objs      = []
-    -- , formAvail = emptyFormulaMap
-    -- , formQueue = []
     , prefixes  = emptyNamespaceMap
     , nodeGenSt = ngs
     , bNodesCheck   = []
 setProps ps = modify $ \st -> st { props = ps }
 
 {-
-getObjs :: Formatter ([RDFLabel])
-getObjs = objs `liftM` get
-
-setObjs :: [RDFLabel] -> Formatter ()
-setObjs os = do
-  st <- get
-  put $ st { objs = os }
--}
-
-{-
-addTrace :: String -> Formatter ()
-addTrace tr = do
-  st <- get
-  put $ st { traceBuf = tr : traceBuf st }
--}
-  
-{-
 TODO:
 
 Should we change the preds/objs entries as well?
   case maybeExtractList osubjs oprops lctxt ln of
     Just (ls, osubjs', oprops') -> do
       setSubjs osubjs'
-      setProps oprops' -- TODO: this used to be optional; is this valid?
+      setProps oprops'
       return (Just ls)
 
     _ -> return Nothing
   fp <- if dopref
         then formatPrefixes (getNamespaces gr)
         else return mempty
-  more <- moreSubjects
+  more <- hasMore subjs
   if more
     then do
       fr <- formatSubjects
   sb    <- nextSubject
   sbstr <- formatLabel SubjContext sb
   
-  flagP <- moreProperties
+  flagP <- hasMore props
   if flagP
     then do
       prstr <- formatProperties sb sbstr
-      flagS <- moreSubjects
+      flagS <- hasMore subjs
       if flagS
         then do
           fr <- formatSubjects
     else do
       txt <- nextLine sbstr
     
-      flagS <- moreSubjects
+      flagS <- hasMore subjs
       if flagS
         then do
           fr <- formatSubjects
   pr <- nextProperty sb
   prstr <- formatLabel PredContext pr
   obstr <- formatObjects sb pr $ mconcat [sbstr, " ", prstr]
-  more  <- moreProperties
+  more  <- hasMore props
   let sbindent = hackIndent -- mkIndent sbstr
   if more
     then do
 formatObjects sb pr prstr = do
   ob    <- nextObject sb pr
   obstr <- formatLabel ObjContext ob
-  more  <- moreObjects
+  more  <- hasMore objs
   if more
     then do
       let prindent = hackIndent -- mkIndent prstr
 insertBnode :: LabelContext -> RDFLabel -> Formatter B.Builder
 insertBnode SubjContext lbl = do
   -- a safety check
-  flag <- moreProperties
+  flag <- hasMore props
   if flag
     then do
       txt <- (`mappend` "\n") `liftM` formatProperties lbl ""
                 }
 
   put nst
-  flag <- moreProperties
+  flag <- hasMore props
   txt <- if flag
          then (`mappend` "\n") `liftM` formatProperties lbl ""
          else return ""
 
-  -- TODO: how do we restore the original set up?
-  --       I can't believe the following is sufficient
-  --
+  -- restore the original data (where appropriate)
   nst' <- get
   let slist  = map fst $ subjs nst'
       nsubjs = filter (\(l,_) -> l `elem` slist) osubjs
 setGraph :: RDFGraph -> Formatter ()
 setGraph = modify . newState
 
-moreSubjects :: Formatter Bool
-moreSubjects = hasMore subjs
-
-moreProperties :: Formatter Bool
-moreProperties = hasMore props
-
-moreObjects :: Formatter Bool
-moreObjects = hasMore objs
-
 nextSubject :: Formatter RDFLabel
 nextSubject = 
     changeState $ \st ->