trishnag
trishnag

Reputation: 322

How do I add image url with graph add in rdflib

I am using rdflib==4.1.2. This is my code

>>> g=rdflib.Graph()
>>> s=rdflib.BNode()
>>> FOAF = rdflib.Namespace("http://xmlns.com/foaf/0.1/")
>>> g.bind('foaf', FOAF)
>>> g.add((s, FOAF['img'],"https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcToZGEWvIBFgCiona6d74FtVthl4lkdJg3d61SGy-UCf4qFuDLD"))

I am getting this traceback.

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/rdflib/graph.py", line 394, in add
    "Object %s must be an rdflib term" % (o,)
AssertionError: Object https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcToZGEWvIBFgCiona6d74FtVthl4lkdJg3d61SGy-UCf4qFuDLD must be an rdflib term

How do I fix this?

Thanks!

Upvotes: 0

Views: 202

Answers (1)

agold
agold

Reputation: 6276

The function Graph.add expects a tuple with three nodes as can be seen in the graph.py code:

assert isinstance(o, Node)

you can use URIRef to convert your last parameter into one (see also the examples of the documentation):

g.add((s, FOAF['img'],rdflib.URIRef("https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcToZGEWvIBFgCiona6d74FtVthl4lkdJg3d61SGy-UCf4qFuDLD")))

Upvotes: 1

Related Questions