Skip to content

Issues with rdflib.Dataset #2021

@NeilGraham

Description

@NeilGraham

At the moment there are a few key issues with the current rdflib.Dataset, particularly in its handling of parsing Default Graph triples. I am very interested in working on a Pull Request to solve these issues since it will improve Named Graph support for all projects making use of rdflib.

Key issues with rdflib.Dataset:

  • Parsed default graph triples are put under a randomized Blank Node named graph.
  • Serializing a rdflib.Dataset to application/n-quads or application/trig will always place default graph triples under a Blank Node named graph.
  • There is no way of accessing only the default graph in a rdflib.Dataset.
  • The default format for Dataset().parse(data=...) is text/turtle when it really should be application/trig.

By adding a new term rdflib.term.DefaultGraph, we can handle the serialization of these triples independent from Named Graph triples. Additionally, we should be able to access the default graph by specifying the following:

from rdflib import Dataset
from rdflib.term import DefaultGraph

ds = Dataset()
trig_string = (
    '<dg:s> <dg:p> <dg:o>. '
    'GRAPH <ng:g> { <ng:s> <ng:p> <ng:o>. }'
)
ds.parse(data=trig_string, format="trig")

default_graph = ds.graph(DefaultGraph)
for triple in default_graph:
    print(triple)
(rdflib.term.URIRef('dg:s'), rdflib.term.URIRef('dg:p'), rdflib.term.URIRef('dg:o'))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingconcept: RDF datasetRelates to the RDF datasets concept.concept: default graphcoreRelates to core functionality of RDFLib, i.e. `rdflib.{graph,store,term}`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions