[Fencommits] fenfire-hs: deal slightly better with bnodes

Benja Fallenstein benja.fallenstein at gmail.com
Wed Feb 28 22:42:38 EET 2007


Wed Feb 28 22:42:11 EET 2007  Benja Fallenstein <benja.fallenstein at gmail.com>
  * deal slightly better with bnodes
diff -rN -u old-fenfire-hs/Fenfire.fhs new-fenfire-hs/Fenfire.fhs
--- old-fenfire-hs/Fenfire.fhs	2007-02-28 22:42:38.000000000 +0200
+++ new-fenfire-hs/Fenfire.fhs	2007-02-28 22:42:38.000000000 +0200
@@ -223,7 +223,7 @@
     let convert (s,p,o) = (f s, f p, f o)
         f (Raptor.Uri s) = URI s
         f (Raptor.Literal s) = PlainLiteral s
-        f (Raptor.Blank s) = URI $ "blank:" ++ s
+        f (Raptor.Blank s) = BNode fileName s
     (raptorTriples, namespaces) <- if List.isPrefixOf "http:" fileName
         then Raptor.uriToTriples fileName Nothing
         else Raptor.filenameToTriples fileName Nothing
@@ -240,6 +240,8 @@
                         u <- Network.URI.parseURI s
                         return $ show $ Network.URI.relativeFrom u uri
         f (PlainLiteral s) = Raptor.Literal s
+        f (BNode g s) = if g == fileName then Raptor.Blank s
+                        else error "XXX Cannot save bnode from different graph"
         triples = graphToList graph
         namespaces = Map.toAscList $ graphNamespaces graph
     Raptor.triplesToFilename (map convert triples) namespaces fileName
diff -rN -u old-fenfire-hs/RDF.hs new-fenfire-hs/RDF.hs
--- old-fenfire-hs/RDF.hs	2007-02-28 22:42:38.000000000 +0200
+++ new-fenfire-hs/RDF.hs	2007-02-28 22:42:38.000000000 +0200
@@ -27,8 +27,9 @@
 import Data.Set (Set)
 import qualified Data.Set as Set
 
-data Node = URI String | PlainLiteral String    deriving (Eq, Ord)
-data Dir  = Pos | Neg                           deriving (Eq, Ord, Show)
+data Node = URI String | BNode String String | PlainLiteral String
+                          deriving (Eq, Ord)
+data Dir  = Pos | Neg     deriving (Eq, Ord, Show)
 
 instance Show Node where
     show = showNode defaultNamespaces
@@ -90,6 +91,7 @@
 instance Hashable Node where
     hash (URI s) = hash s
     hash (PlainLiteral s) = hash s
+    hash (BNode g s) = hash (g,s)
     
 instance Hashable Dir where
     hash Pos = 0
@@ -108,6 +110,7 @@
                          | otherwise = f xs
     f [] = "<" ++ uri ++ ">"
 showNode _  (PlainLiteral lit) = show lit
+showNode _  (BNode graph id') = "bnode[" ++ id' ++ " @ " ++ graph ++ "]"
 
 subject :: Triple -> Node
 subject (s,_,_) = s
@@ -182,10 +185,6 @@
 triple Pos (s,p,o) = (s,p,o)
 triple Neg (o,p,s) = (s,p,o)
 
-fromNode :: Node -> String
-fromNode (URI uri)        = uri
-fromNode (PlainLiteral s) = s
-
 mul :: Num a => Dir -> a -> a
 mul Pos = id
 mul Neg = negate




More information about the Fencommits mailing list