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

N-Triples serializer adds extra newline #1998

Closed
tcmitchell opened this issue Jun 23, 2022 · 0 comments · Fixed by #1999
Closed

N-Triples serializer adds extra newline #1998

tcmitchell opened this issue Jun 23, 2022 · 0 comments · Fixed by #1999

Comments

@tcmitchell
Copy link
Contributor

The N-Triples serializer includes an extra newline at the end. This newline is unnecessary.

This impacts our ability to sort the N-Triples lines in order to produce a sorted N-Triples format that is suitable for diff and version control.

Here is code to demonstrate the issue. Note the pair of \n characters at the end of the output for both "nt" and "nt11" formats.

>>> import rdflib
>>> g = rdflib.Graph()
>>> bob = rdflib.URIRef("http://example.org/people/Bob")
>>> g.add((bob, rdflib.RDF.type, rdflib.FOAF.Person))
<Graph identifier=N9146103a52ed4e7b88e761835d34ec04 (<class 'rdflib.graph.Graph'>)>
>>> g.serialize(format='nt')
'<http://example.org/people/Bob> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .\n\n'
>>> g.serialize(format='nt11')
'<http://example.org/people/Bob> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .\n\n'
>>> 
aucampia pushed a commit that referenced this issue Jun 24, 2022
Remove the extra newline generated by the N-Triples serializer and add
a unit test to verify that N-Triples output does not end in two
consecutive newlines.

Closes #1998
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

Successfully merging a pull request may close this issue.

1 participant