Strange bug of notation3 serialization that occur with “probability” · Issue #1701 · RDFLib/rdflib (original) (raw)
Version:
rdflib 6.1.1
python 3.8.10
I have a test.py
:
import rdflib
data1='''
@prefix : <http://www.example.com/dev#>.
:a :b :c.
'''
data2='''
@prefix : <http://www.example.com/dev#>.
{:a :b :c}=>{:d :e :f}.
'''
g = rdflib.Graph()
g.parse(data=data1, format = 'n3')
g.parse(data=data2, format = 'n3')
r = g.serialize(format='n3')
print(r)
The output of this test.py
has 2 possibilities.
The first one (which is correct):
@prefix : <http://www.example.com/dev#> .
:a :b :c .
{
:a :b :c .
} => {
:d :e :f .
} .
The second one (missing the triple parsed at the first time):
@prefix : <http://www.example.com/dev#> .
{
:a :b :c .
} => {
:d :e :f .
} .
This strange bug appears in a completely random way. In order to count the "probability" of its occurrence, I wrote a loop like this:
num = 10000
error =0
for i in range(num):
g = rdflib.Graph()
g.parse(data=data1, format = 'n3')
g.parse(data=data2, format = 'n3')
r = g.serialize(format='n3')
#print(g.serialize(format='n3'))
index = (r.find(":a :b :c"))
#print(index)
if index > 43: #second case occur
error +=1
print("error =" ,error)
Each execution gives a different result, like error= 8533, 5693, 437... As the num
increase, the error rate do not converge to a specific value. Can't find any patterns.