Skip to content

Formats that don't support named graphs serialize Datasets and ConjunctiveGraphs with non-default graphs without raising any errors #2393

Open
@aucampia

Description

@aucampia

If RDFLib is used to serialize a Dataset or ConjunctiveGraph that contains non-default graphs [ref] as a format that does not support named graphs (i.e. N-Triples or Turtle) no error is raised, and the output is wrong.

Given this data in test/data/variants/diverse_quads.nq (equivalent to this trig document):

<http://example.com/subject> <http://example.com/predicate> "日本語の表記体系"@jpx <example:graph> .
<urn:example:subject> <example:predicate> <example:subject> <example:graph> .
<example:subject> <example:predicate> <example:object> <example:graph> .
<example:subject> <example:predicate> "12"^^<http://www.w3.org/2001/XMLSchema#integer> <example:graph> .
<example:subject> <example:predicate> <example:object> <urn:example:graph> .
<example:subject> <http://example.com/predicate> <http://example.com/object> <urn:example:graph> .
<example:subject> <http://example.com/predicate> "XSD string" <urn:example:graph> .
<example:subject> <example:predicate> <example:object> .
<http://example.com/subject> <http://example.com/predicate> "typeless" .
<urn:example:subject> <urn:example:predicate> <urn:example:object> .

Using rdfpipe to convert it to turtle gives:

$ pipx run --spec git+https://github.com/RDFLib/rdflib.git@main rdfpipe -o turtle test/data/variants/diverse_quads.nq; echo status=$?
⚠️  rdfpipe is already on your PATH and installed at /home/iwana/.local/bin/rdfpipe. Downloading and running anyway.
@prefix ns1: <http://example.com/> .
@prefix ns2: <urn:example:> .
@prefix ns3: <example:> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ns1:subject ns1:predicate "typeless",
        "日本語の表記体系"@jpx .

ns2:subject ns3:predicate ns3:subject ;
    ns2:predicate ns2:object .

ns3:subject ns3:predicate ns3:object,
        12 ;
    ns1:predicate ns1:object,
        "XSD string" .

status=0

And using rdfpipe to convert it to ntriples gives:

$ pipx run --spec git+https://github.com/RDFLib/rdflib.git@main rdfpipe -o ntriples test/data/variants/diverse_quads.nq; echo status=$?
⚠️  rdfpipe is already on your PATH and installed at /home/iwana/.local/bin/rdfpipe. Downloading and running anyway.
/home/iwana/.local/pipx/.cache/bf79805433c3d94/lib64/python3.11/site-packages/rdflib/plugins/serializers/nt.py:40: UserWarning: NTSerializer always uses UTF-8 encoding. Given encoding was: None
  warnings.warn(
<http://example.com/subject> <http://example.com/predicate> "typeless" .
<example:subject> <http://example.com/predicate> <http://example.com/object> .
<urn:example:subject> <example:predicate> <example:subject> .
<example:subject> <example:predicate> "12"^^<http://www.w3.org/2001/XMLSchema#integer> .
<example:subject> <example:predicate> <example:object> .
<http://example.com/subject> <http://example.com/predicate> "日本語の表記体系"@jpx .
<urn:example:subject> <urn:example:predicate> <urn:example:object> .
<example:subject> <http://example.com/predicate> "XSD string" .
status=0

In both cases, the output is wrong, not just incomplete.

I would say the right behaviour is that an error is raised when a ConjunctiveGraph or Dataset with non-default graphs are serialized using a format that does not support named graphs.

I'm making this issue to get some feedback, but I will make a PR to fix it shortly.

There is a similar issue with riot from Jena [ref], but riots behaviour is not quite as bad

Metadata

Metadata

Assignees

Labels

breaking changeThis involves or proposes breaking RDFLib's public API.bugSomething isn't workingconcept: RDF datasetRelates to the RDF datasets concept.interface bugAn issue with our public interfaceserializationRelated to serialization.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions