Reputation: 189
I have lists of literals that I would like to add as rdf:lists to a graph. I can read rdf:lists without issue using rdflib.collection.Collection, but I haven't been able to add those lists to other graphs, or iteratively generate an rdf:list from a python list.
Does rdflib have any functionality like this?
Update: I went back through the docs and found a solution using Collection.
from rdflib.graph import Graph, BNode, Collection, Literal, RDF, Namespace
listName = BNode()
EX = Namespace('http://www.example.org/')
g.bind('ex', EX)
g = Graph()
listo = [1,2,356,4]
c = Collection(g,EX.name,[Literal(x) for x in listo])
Upvotes: 2
Views: 820
Reputation: 189
This did the trick:
c = Collection(g,EX.name,[Literal(x) for x in listo])
Upvotes: 0
Reputation: 1251
if c = Collection(g,EX.name,[Literal(x) for x in listo])
solves the question, please mark it solved so people know to visit it for an answer if they have the same question, thanks!
Upvotes: 2