You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The longturtle serializer fails to emit a whitespace separator between a predicate and a list of objects if one of these objects is a blank node (and the blank node cannot be 'inlined', i.e. is used more than once). The problem can be reproduced using this Python code:
fromrdflibimportGraphinput='''\@prefix ex: <https://example.org/> .ex:1 a ex:Thing ; ex:relatedTo ex:3, _:bnode0 .ex:2 a ex:Thing ; ex:relatedTo _:bnode0 ._:bnode0 a ex:Thing .'''graph=Graph().parse(data=input, format='turtle')
output=graph.serialize(format='longturtle')
print(output)
assertoutput.find('relatedTo_:') ==-1, \
'Missing whitespace separation between predicate' \
' and the first blank node of a list of objects.'
The resulting Turtle with the bug looks like below. Note the missing space between the predicate ex:relatedTo and blank node _:n40fef3a41a034be9a7116df126afd613b1 for the ex:1 case. The ex:2 case does correctly use a space separator when serializing because it's a single object and not a list.
PREFIX ex: <https://example.org/>
ex:1
a ex:Thing ;
ex:relatedTo_:n40fef3a41a034be9a7116df126afd613b1 ,
ex:3 ;
.
ex:2
a ex:Thing ;
ex:relatedTo _:n40fef3a41a034be9a7116df126afd613b1 ;
.
_:n40fef3a41a034be9a7116df126afd613b1
a ex:Thing ;
.
I believe the issue might be solved by adding an additional indent in the longturtle.py source code on this line, as shown in the code below.
defobjectList(self, objects):
count=len(objects)
ifcount==0:
returndepthmod= (count==1) and0or1self.depth+=depthmodfirst_nl=Falseifcount>1:
ifnotisinstance(objects[0], BNode):
self.write("\n"+self.indent(1))
# BUG: Gave below line an extra indent.first_nl=Trueself.path(objects[0], OBJECT, newline=first_nl)
forobjinobjects[1:]:
self.write(" ,")
ifnotisinstance(obj, BNode):
self.write("\n"+self.indent(1))
self.path(obj, OBJECT, newline=True)
self.depth-=depthmod
The text was updated successfully, but these errors were encountered:
I think this issue has been addressed by PR #2700 but that fix is currently only in the HEAD of this repo, not an RDFlib release yet. It should appear in 7.0.1 or 7.1.0 in the next few weeks when we make that release which will fix a bunch of small things.
I think this issue has been addressed by PR #2700 but that fix is currently only in the HEAD of this repo, not an RDFlib release yet. It should appear in 7.0.1 or 7.1.0 in the next few weeks when we make that release which will fix a bunch of small things.
Excellent, thank you! I can confirm this addresses the issue. Looking forward to the next rdflib release then 👍
The
longturtle
serializer fails to emit a whitespace separator between a predicate and a list of objects if one of these objects is a blank node (and the blank node cannot be 'inlined', i.e. is used more than once). The problem can be reproduced using this Python code:The resulting Turtle with the bug looks like below. Note the missing space between the predicate
ex:relatedTo
and blank node_:n40fef3a41a034be9a7116df126afd613b1
for theex:1
case. Theex:2
case does correctly use a space separator when serializing because it's a single object and not a list.I believe the issue might be solved by adding an additional indent in the
longturtle.py
source code on this line, as shown in the code below.The text was updated successfully, but these errors were encountered: