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

Graphs don't serialize new content correctly #228

Closed
jeroenh opened this issue Sep 6, 2012 · 4 comments
Closed

Graphs don't serialize new content correctly #228

jeroenh opened this issue Sep 6, 2012 · 4 comments

Comments

@jeroenh
Copy link
Contributor

jeroenh commented Sep 6, 2012

Consider the following:

>>> g = rdflib.Graph()
>>> g.add((u"#foo",u"#bar",u"#foobar"))
>>> g.serialize()
'<?xml version="1.0" encoding="UTF-8"?>\n<rdf:RDF\n   xmlns:ns1="#"\n   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n>\n</rdf:RDF>\n'

My new triplet is not there.

Ah you say, but you should commit your graph! But that also does not work:

>>> g = rdflib.Graph()
>>> g.add((u"#foo",u"#bar",u"#foobar"))
>>> g.commit()
>>> g.serialize()
'<?xml version="1.0" encoding="UTF-8"?>\n<rdf:RDF\n   xmlns:ns1="#"\n   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n>\n</rdf:RDF>\n'

What is going on here? Note that in both cases the Namespace does get added to the graph, so clearly something is happening.

@wikier
Copy link
Member

wikier commented Sep 7, 2012

Wrong usage of the API, subjects can not be plain text variables.

Therefore you would need to use something like:

>>> g = rdflib.Graph()
>>> g.add((rdflib.URIRef(u"#foo"), u"#bar", u"#foobar")) 
>>> g.serialize(base="http://example.org")

Maybe we would need to improve both the documentation and the feedback provided to the user on such situations...

@jeroenh
Copy link
Contributor Author

jeroenh commented Sep 7, 2012

Okay, it makes sense to combine this with #227 also and add some more sensible valuechecking in the add method. Not only should it reject plain strings, it should also reject triplets which have the subject and predicate as unicode objects.

@gromgull
Copy link
Member

gromgull commented Sep 7, 2012

This is the same underlying issue as #200 again.

@wikier - actually no part of the triple (or quad, see #167) should be a string, it may work sometimes, but will come back and bit you sooner or later. "unicode object has no .n3()" method for instance...

We could "auto-box" non rdflib.term.Node objects though - but only in rdflib4, where a literal/python mapping overhaul is planned anyway.

@gromgull gromgull closed this as completed Sep 7, 2012
@gromgull
Copy link
Member

gromgull commented Sep 7, 2012

I made #230 for the possibility of auto-boxing objects.

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

3 participants