I am trying to understand the logic of Set Operations (Union, Addition, Intersection, Difference,Xor) in RDFlib, and have done some tests with identical files for which the results didn't match my naive expectations. Therefore, I have tested the "in" operator two ways:
I looped over all items in graph A and checking if they exist in graph B, after initializing A from a tiny RDF/Turtle test file, and initializing B either :
- by setting B=A
A = Graph()
A.parse("A.ttl", format='turtle')
B=A
for t in A.triples((None, None, None)):
if t in B:
print(f"found {t} in B")
else:
print(f"didn't find {t} in B")
- by loading it from the same file
A = Graph()
A.parse("A.ttl", format='turtle')
B = Graph()
B.parse("A.ttl", format='turtle')
for t in A.triples((None, None, None)):
if t in B:
print(f"found {t} in B")
else:
print(f"didn't find {t} in B")
In case 1), all triples in A were also found in B -- as expected In case 2),only part of the triples in A were also found in B. (those without BNodes)
Is there any way to avoid the behavious of case 2).. or did I misunderstand something very basic? (i'm an RDF newbie, but otherwise not afraid of graphs)
cheers Joel