Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
koslambrou opened this issue Dec 29, 2020 · 0 comments

Comments

@koslambrou
Copy link
Contributor

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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant