rdflib icon indicating copy to clipboard operation
rdflib copied to clipboard

The default graph should have no name.

Open aucampia opened this issue 1 year ago • 4 comments

According to https://www.w3.org/TR/rdf11-concepts/#section-dataset

An RDF dataset is a collection of RDF graphs, and comprises:

  • Exactly one default graph, being an RDF graph. The default graph does not have a name and may be empty.
  • Zero or more named graphs. Each named graph is a pair consisting of an IRI or a blank node (the graph name), and an RDF graph. Graph names are unique within an RDF dataset.

In RDFLib however:

  • The default context in ConjunctiveGraph has a BNode as name.
  • The default context in Dataset has a IRI as a name.

Related issues:

  • https://github.com/RDFLib/rdflib/issues/2021

aucampia avatar Jun 13 '23 18:06 aucampia

According to https://www.w3.org/TR/rdf11-concepts/#section-dataset

The default graph does not have a name and may be empty.

I encountered this in my explorations of a solution ...

In RDFLib however:

* The default context in ConjunctiveGraph has a BNode as name.

If the entire class is to be deprecated, issue can be ignored

* The default context in Dataset has a IRI as a name.

Doesn't seem to present an issue for the API: exclude the URI from list(Dataset.contexts()) but include the Graph object in list(Dataset.graphs()) and I've found the Dataset.default_graph reference to be convenient.

OTOH, the Store API could be changed. AIUI RDFLib now has only context-aware Stores and I believe that uncontextualized statements are just quads with NULL as the fourth element (ISTR it's implemented with "" as a key).

ghost avatar Jun 13 '23 22:06 ghost

FWIW, I have a static-rebuild motivation for requesting this change too. I think.

I include built graph files as part of unit test output, and version-control those files to show result evolution. One of those generated formats is JSON-LD. If I try to write the least code possible and use rdfpipe to handle joining or format-converting graph files, I end up with an artifact that's a bit of a nuisance for independent results reproduction. The path to the input file is embedded in the output as what I thought would be the "default" graph's IRI. For instance, one workflow I just tried took a single Turtle file as input, converted it with rdfpipe --output-format json-ld in.ttl > out.json, and I got this form of output (excerpted):

[
  {
    "@graph": [
      {
        "@id": "http://example.org/kb/[snip]",
        "@type": [
          "http://example.org/ontology/[snip]"
        ]
      }
    ]
    "@id": "file:///private/tmp/[snip]/result.ttl"
  }
]

Is this rdfpipe behavior in scope of this issue about the name of the default graph, or should I re-file this as a separate request for new flags to tune rdfpipe's JSON-LD output? I'm guessing this could also be a quads issue.

ajnelson-nist avatar Jun 21 '23 15:06 ajnelson-nist

For instance, one workflow I just tried took a single Turtle file as input, converted it with rdfpipe --output-format json-ld in.ttl > out.json, and I got this form of output (excerpted):

[
  {
    "@graph": [
      {
        "@id": "http://example.org/kb/[snip]",
        "@type": [
          "http://example.org/ontology/[snip]"
        ]
      }
    ]
    "@id": "file:///private/tmp/[snip]/result.ttl"
  }
]

Is this rdfpipe behavior in scope of this issue about the name of the default graph, or should I re-file this as a separate request for new flags to tune rdfpipe's JSON-LD output? I'm guessing this could also be a quads issue.

I think this was fixed in this PR:

  • https://github.com/RDFLib/rdflib/pull/2406

It would be worth checking the behaviour with the master branch, I think you can use pipx to run it without installing.

aucampia avatar Jun 21 '23 22:06 aucampia

I think this was fixed in this PR:

It would be worth checking the behaviour with the master branch, I think you can use pipx to run it without installing.

@aucampia - You are correct, my issue is addressed in the current main branch. Thank you for informing me!

ajnelson-nist avatar Jun 22 '23 12:06 ajnelson-nist