Commits

Doug Burke committed be189e5

N3Formatter: fix loss of blank nodes as subjects (scripts/SwishTest.ss now works)

Comments (0)

Files changed (2)

Swish/RDF/N3Formatter.hs

 
 import Data.Char (ord, isDigit)
 
-import Data.List (foldl', delete, groupBy, intercalate, partition, sort)
+import Data.List (foldl', delete, groupBy, partition, sort)
 
 import Text.Printf (printf)
 
     , bNodesCheck   :: [RDFLabel]      -- these bNodes are not to be converted to '[..]' format
     , traceBuf  :: [String]
     }
-
+             
 type Formatter a = State N3FormatterState a
 
 emptyN3FS :: NodeGenState -> N3FormatterState
   put $ st { objs = os }
 -}
 
-getBnodesCheck :: Formatter ([RDFLabel])
+getBnodesCheck :: Formatter [RDFLabel]
 getBnodesCheck = bNodesCheck `liftM` get
 
 {-
   setIndent ind
   setLineBreak dobreak
   setGraph gr
+  
   fp <- if dopref
         then formatPrefixes (getNamespaces gr)
         else return $ puts ""
   more <- moreSubjects
-  res  <- if more
-          then do
-            fr <- formatSubjects
-            return $ fp . fr . puts end
-          else return fp
-
-  return res
+  if more
+    then do
+      fr <- formatSubjects
+      return $ fp . fr . puts end
+    else return fp
 
 formatPrefixes :: NamespaceMap -> Formatter ShowS
 formatPrefixes pmap = do
           fr <- formatSubjects
           return $ puts (prstr ++ " .") . fr
           -- return $ puts (prstr ++ fmstr ++ " .") . fr
-        else return $ puts $ prstr
+        else return $ puts prstr
         -- else return $ puts $ prstr ++ fmstr
            
     else do
-         txt <- nextLine sbstr
-         return $ puts txt
+      txt <- nextLine sbstr
     
+      flagS <- moreSubjects
+      if flagS
+        then do
+          fr <- formatSubjects
+          return $ puts (txt ++ " .") . fr
+        else return $ puts txt
+
 formatProperties :: RDFLabel -> String -> Formatter String
 formatProperties sb sbstr = do
   pr <- nextProperty sb
 by ().
 -}
 insertList :: [RDFLabel] -> Formatter String
-insertList [] = return $ "()" -- not convinced this can happen
+insertList [] = return "()" -- not convinced this can happen
 insertList xs = do
   ls <- mapM (formatLabel ObjContext) xs
-  return $ "( " ++ intercalate " " ls ++ " )"
+  return $ "( " ++ unwords ls ++ " )"
   
   
 {-

tests/N3FormatterTest.hs

 
 -- bnode graphs
 
-graph_b1, graph_b1rev, graph_b2, graph_b2rev, graph_b3 :: RDFGraph
+graph_b1, graph_b1rev, graph_b2, graph_b2rev, graph_b3, 
+  graph_b4, graph_b5 :: RDFGraph
 graph_b1    = toGraph [arc s1 p1 b1]
 graph_b1rev = toGraph [arc b1 p1 o1]
 graph_b2    = toGraph [arc s1 p1 b1,
                        arc b1 o2 o3,
                        arc s1 p2 b2,
                        arc s2 p2 o2]
+graph_b4    = toGraph [arc b1 res_rdf_type o1,
+                       arc b2 res_rdf_type o2]
+graph_b5    = toGraph [arc b1 res_rdf_type o1,
+                       arc b2 p2 o2,
+                       arc b3 res_rdf_type o3]
 
 ------------------------------------------------------------
 --  Trivial formatter tests
     "         base2:p2 [] .\n" ++
     "base2:s2 base2:p2 base2:o2 .\n"
 
+simpleN3Graph_b4 :: String
+simpleN3Graph_b4 =
+  commonPrefixes ++
+  "[\n a base1:o1\n] .\n" ++ 
+  "[\n a base2:o2\n] .\n"
+
+simpleN3Graph_b5 :: String
+simpleN3Graph_b5 =
+  commonPrefixes ++
+  "[\n a base1:o1\n] .\n" ++ 
+  "[\n base2:p2 base2:o2\n] .\n" ++
+  "[\n a base3:o3\n] .\n"
+
 -- diag13 = diagTest "trivialTest13" x13a simpleN3Graph_x13a
 
 trivialTestSuite :: Test
  , formatTest "trivialTestb1" graph_b1 simpleN3Graph_b1
  , formatTest "trivialTestb2" graph_b2 simpleN3Graph_b2
  , formatTest "trivialTestb3" graph_b3 simpleN3Graph_b3
+ , formatTest "trivialTestb4" graph_b4 simpleN3Graph_b4
+ , formatTest "trivialTestb5" graph_b5 simpleN3Graph_b5
  , formatTest "trivialTestb1rev" graph_b1rev simpleN3Graph_b1rev
  , formatTest "trivialTestb2rev" graph_b2rev simpleN3Graph_b2rev