rdf4h icon indicating copy to clipboard operation
rdf4h copied to clipboard

Cannot use parseFile with RDF that does not have a base URI and URI without "http:"

Open koslambrou opened this issue 4 years ago • 0 comments

Problem: Cannot parse RDF file which contains absolute or relative URIs (ex. /void/Dataset) without specifying a base URI. It works when I use mkRdf, but not when I use parseFile.

Sample code:

{-# LANGUAGE OverloadedStrings          #-}

import Data.RDF
import           Text.RDF.RDF4H.TurtleParser
import           Text.RDF.RDF4H.TurtleSerializer
import System.Exit
import qualified Data.Map as Map

main = do
  -- mkRdf works for URIs without domain name
  let t1 = Triple (unode "/void/Dataset") (unode "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") (unode "http://rdfs.org/ns/void#DatasetDescription")
  let triples = [t1]
  let voidGraph = mkRdf triples Nothing (PrefixMappings Map.empty) :: RDF TList
  putStrLn $ showGraph voidGraph

  -- parseFile doesn't work for URIs without domain name
  -- test.ttl contains a single RDF triple:
  -- </void/Dataset> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/ns/void#DatasetDescription> .
  let rdfFile = "test.ttl"
  voidGraphE <- parseFile (TurtleParser Nothing Nothing) rdfFile :: IO (Either ParseFailure (RDF TList))
  case voidGraphE of
    Left err -> do
      print err
    Right graph -> do
      putStrLn $ showGraph graph

Actual output:

Triple (UNode "/void/Dataset") (UNode "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") (UNode "http://rdfs.org/ns/void#DatasetDescription")

ParseFailure "Parse failure: \n(line 1, column 15):\nunexpected Cannot resolve IRI: Scheme head: not enough input (Nothing,Nothing,\"/void/Dataset\")\nexpecting subject
resource"

Expected output:

Triple (UNode "/void/Dataset") (UNode "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") (UNode "http://rdfs.org/ns/void#DatasetDescription")

Triple (UNode "/void/Dataset") (UNode "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") (UNode "http://rdfs.org/ns/void#DatasetDescription")

koslambrou avatar Dec 29 '20 15:12 koslambrou