rdflib: Dataset.parse broken

Using Dataset.parse to parse a graph just doesn’t work.

from rdflib import Dataset, URIRef
d = Dataset()
g = d.parse(data='<a:a> <b:b> <c:c> .', format='turtle', publicID=URIRef('g:g'))
print("After parse:")
for h in d.graphs(): print(h)
if g.identifier not in d.graphs():
    print("g has not been added to Dataset")

This gives:

After parse:
DEFAULT
g has not been added to Dataset

It turns out that no triple has been added at all.

On the other hand, the same works with ConjunctiveGraph:

from rdflib import ConjunctiveGraph, URIRef
d = ConjunctiveGraph()
g = d.parse(data='<a:a> <b:b> <c:c> .', format='turtle')
print("After parse:")
for h in d.contexts(): print(h)
if g not in d.contexts():
    print("g has not been added to Dataset")

which yields

After parse:
[a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']].

About this issue

  • Original URL
  • State: open
  • Created 11 years ago
  • Reactions: 1
  • Comments: 27 (25 by maintainers)

Most upvoted comments

Am I right in assuming that the only bit missing of this is that if you parse some context-aware rdf format into a dataset, and your input file contains several graphs, they may not all appear? If so, we should close and make a new issue for that. With less comments 😃

@iherman : you contributed the dataset class - could you have a look at this?