如何在 rdflib 中使用图形添加添加图像 url
How do I add image url with graph add in rdflib
我正在使用 rdflib==4.1.2。
这是我的代码
>>> 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"))
我得到了这个回溯。
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
我该如何解决这个问题?
谢谢!
函数Graph.add
expects a tuple with three nodes as can be seen in the graph.py code:
assert isinstance(o, Node)
你可以使用 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")))
我正在使用 rdflib==4.1.2。 这是我的代码
>>> 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"))
我得到了这个回溯。
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
我该如何解决这个问题?
谢谢!
函数Graph.add
expects a tuple with three nodes as can be seen in the graph.py code:
assert isinstance(o, Node)
你可以使用 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")))