walidazizi / rdflib

Automatically exported from code.google.com/p/rdflib
Other
0 stars 0 forks source link

Graph().parse() and relative URIs and blank nodes #173

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Parse xml from string and print results:

g1=rdflib.graph.ConjunctiveGraph()
    g1.parse(data="""<?xml version='1.0'?>
<rdf:RDF
      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
      xmlns:foaf="http://xmlns.com/foaf/0.1/"
      xmlns:owl="http://www.w3.org/2002/07/owl#"
      xmlns:pim="http://www.w3.org/2000/10/swap/pim/contact#"
      xmlns:org="http://www.w3.org/2001/04/roadmap/org#"
      xmlns:doap="http://usefulinc.com/ns/doap#"
      xmlns:sioc="http://rdfs.org/sioc/ns#"
      xmlns:dp="http://sw.deri.ie/2004/08/pubs/swpubs#"
      xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
      xmlns:dc="http://purl.org/dc/elements/1.1/">
<foaf:Person rdf:about="#John">
 <foaf:knows>
  <foaf:Person rdf:nodeID="b1"/>
 </foaf:knows>
</foaf:Person>
<foaf:Person rdf:about="#Mary">
 <foaf:knows>
  <foaf:Person rdf:nodeID="b1"/>
 </foaf:knows>
</foaf:Person>
</rdf:RDF>""")

    for s,p,o in g1:
        print s,p,o

2. Parse the same xml from url:    

    g2=rdflib.graph.ConjunctiveGraph()
    g2.parse("http://127.0.0.1:5000/test")

    for s,p,o in g2:
        print s,p,o

What is the expected output? What do you see instead?

I expect the output to be the same but the xml string does not contain a URI to 
attach the relative URIs to.

Result of the string parsing:

#John http://xmlns.com/foaf/0.1/knows owiEBRcs5
#John http://www.w3.org/1999/02/22-rdf-syntax-ns#type 
http://xmlns.com/foaf/0.1/Person
#Mary http://xmlns.com/foaf/0.1/knows owiEBRcs5
#Mary http://www.w3.org/1999/02/22-rdf-syntax-ns#type 
http://xmlns.com/foaf/0.1/Person
owiEBRcs5 http://www.w3.org/1999/02/22-rdf-syntax-ns#type 
http://xmlns.com/foaf/0.1/Person

Result of the uri parsing:

http://127.0.0.1:5000/test#John http://xmlns.com/foaf/0.1/knows owiEBRcs5
http://127.0.0.1:5000/test#John http://www.w3.org/1999/02/22-rdf-syntax-ns#type 
http://xmlns.com/foaf/0.1/Person
http://127.0.0.1:5000/test#Mary http://xmlns.com/foaf/0.1/knows owiEBRcs5
http://127.0.0.1:5000/test#Mary http://www.w3.org/1999/02/22-rdf-syntax-ns#type 
http://xmlns.com/foaf/0.1/Person
owiEBRcs5 http://www.w3.org/1999/02/22-rdf-syntax-ns#type 
http://xmlns.com/foaf/0.1/Person

What version of the product are you using? On what operating system?
rdflib trunk with python 2.6

I would like to add an option to g.parse() that allows to define a URI to add 
as a prefix for relative URIs.
Also it would be helpful to have a possibility to add a real URI to blank 
nodes, too.
What else does parse() need?

Original issue reported on code.google.com by danielmr...@gmail.com on 16 May 2011 at 9:41

GoogleCodeExporter commented 8 years ago
Issue #137 also addresses parse() API

Original comment by danielmr...@gmail.com on 16 May 2011 at 9:42

GoogleCodeExporter commented 8 years ago
Addition to the initial post here: one could pass the "publicID" -->
g.parse(data=data, publicID="http://127.0.0.1:5000/test")
gives the same result.

I just think that the documentation on that part could be better and would like 
to get feedback on what exactly is not well documented/the best interface

Original comment by danielmr...@gmail.com on 17 May 2011 at 5:52