rdflib issue wirh nested references



I am looking at this code:



from rdflib import URIRef, BNode, Literal
import rdflib

bob = URIRef("http://ift.tt/1uyaLu3")
linda = BNode()

name = Literal('Bob') # passing a string
age = Literal(24) # passing a python int
height = Literal(76.5) # passing a python float
from rdflib import Namespace

n = Namespace("http://ift.tt/1uyaLKj")
from rdflib.namespace import RDF, FOAF

from rdflib import Graph
g = Graph()

g.add( (bob, RDF.type, FOAF.Person) )
g.add( (bob, FOAF.name, name) )
g.add( (bob, FOAF.knows, linda) )
g.add( (linda, RDF.type, FOAF.Person) )
g.add( (linda, FOAF.name, Literal('Linda') ) )

g.serialize("prova.rdf",format="pretty-xml")


When I open the file i have this output:



<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF
xmlns:ns1="http://ift.tt/PpfGLc"
xmlns:rdf="http://ift.tt/oZyhLL"
>
<ns1:Person rdf:about="http://ift.tt/1uyaLu3">
<ns1:name>Bob</ns1:name>
<ns1:knows>
<ns1:Person rdf:nodeID="N85c01d2d7fd54f8395c75906f5bdc93f">
<ns1:name>Linda</ns1:name>
</ns1:Person>
</ns1:knows>
</ns1:Person>
</rdf:RDF>


As you can see, in the "knows" sector, i see the details of the linked node (Linda). I would expect something like this:



<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF
xmlns:ns1="http://ift.tt/PpfGLc"
xmlns:rdf="http://ift.tt/oZyhLL">

<ns1:Person rdf:about="http://ift.tt/1uyaLu3">
<ns1:name>Bob</ns1:name>
<ns1:knows rdf:nodeID="N85c01d2d7fd54f8395c75906f5bdc93f"/>
</ns1:Person>
<ns1:Person rdf:nodeID="N85c01d2d7fd54f8395c75906f5bdc93f">
<ns1:name>Linda</ns1:name>
</ns1:Person>
</rdf:RDF>


How can I get this kind of output? In particular I would like to see only the reference of Linda in the Bob ns1:knows list. Any suggestion? Where am I wrong?


No comments:

Post a Comment