[Fencommits] fenfire-hs: give a known base URI to the parser so that we will be able to save the graph back to disk without changing relative to absolute URIs

Benja Fallenstein benja.fallenstein at gmail.com
Thu Feb 15 11:28:37 EET 2007


Thu Feb 15 11:28:22 EET 2007  Benja Fallenstein <benja.fallenstein at gmail.com>
  * give a known base URI to the parser so that we will be able to save the graph back to disk without changing relative to absolute URIs
diff -rN -u old-fenfire-hs/Fenfire.fhs new-fenfire-hs/Fenfire.fhs
--- old-fenfire-hs/Fenfire.fhs	2007-02-15 11:28:37.000000000 +0200
+++ new-fenfire-hs/Fenfire.fhs	2007-02-15 11:28:37.000000000 +0200
@@ -328,7 +328,8 @@
         f (Raptor.Uri s) = URI s
         f (Raptor.Literal s) = PlainLiteral s
         f (Raptor.Blank s) = URI $ "blank:" ++ s
-    triples <- Raptor.filenameToTriples fileName >>= return . map convert
+    raptorTriples <- Raptor.filenameToTriples fileName (Just "fakebase:/")
+    triples <- return $ map convert raptorTriples
     return $ listToGraph triples
 
 saveGraph :: Graph -> FilePath -> IO ()
diff -rN -u old-fenfire-hs/Raptor.chs new-fenfire-hs/Raptor.chs
--- old-fenfire-hs/Raptor.chs	2007-02-15 11:28:37.000000000 +0200
+++ new-fenfire-hs/Raptor.chs	2007-02-15 11:28:37.000000000 +0200
@@ -170,14 +170,17 @@
 
 -- | Parse a file with the given filename into triples
 --
-filenameToTriples :: String -> IO [Triple]
-filenameToTriples filename = do 
+filenameToTriples :: String -> Maybe String -> IO [Triple]
+filenameToTriples filename baseURI = do 
   result <- newIORef []
 
   initRaptor
   let suffix = reverse $ takeWhile (/= '.') $ reverse filename
       parsertype = case suffix of "turtle" -> "turtle"
-                                  _        -> "guess"
+                                  "ttl"    -> "turtle"
+                                  "rdf"    -> "rdfxml"
+                                  "nt"     -> "ntriples"
+                                  _        -> "ntriples"
   rdf_parser <- withCString parsertype new_parser 
   when (rdf_parser == nullPtr) $ fail "parser is null"
   handler <- mkHandler $ \_user_data triple -> do
@@ -189,7 +192,7 @@
   set_statement_handler rdf_parser nullPtr handler
   uri_str <- withCString filename uri_filename_to_uri_string
   uri <- new_uri uri_str
-  base_uri <- uri_copy uri
+  base_uri <- maybe (uri_copy uri) (\s -> withCString s new_uri) baseURI
   parse_file rdf_parser uri base_uri
 
   {# call free_parser #} (Parser rdf_parser)




More information about the Fencommits mailing list