我正在解析三重文件并将三元组添加到我的本地三元组中。
代码段:
graph = ConjunctiveGraph('Sleepycat')
graph.open("mytriplestore", create=False)
g = Graph()
g.parse("filename.ttl", format="ttl")
for t in g:
graph.add(t)
是否可以将解析后的内容批量添加到三元组中,而不是遍历每个三元组?
到目前为止我尝试了什么:
尝试1:
graph.add(g)
错误:
File "/usr/local/lib/python2.7/dist-packages/rdflib/graph.py", line 1345, in add
s,p,o,c = self._spoc(triple_or_quad, default=True)
File "/usr/local/lib/python2.7/dist-packages/rdflib/graph.py", line 1326, in _spoc
return s,p,o,c
UnboundLocalError: local variable 's' referenced before assignment
尝试2:
graph.addN(g)
错误:
File "/usr/local/lib/python2.7/dist-packages/rdflib/graph.py", line 1363, in addN
(s, p, o, self._graph(c)) for s, p, o, c in quads if
File "/usr/local/lib/python2.7/dist-packages/rdflib/store.py", line 221, in addN
for s, p, o, c in quads:
File "/usr/local/lib/python2.7/dist-packages/rdflib/graph.py", line 1363, in <genexpr>
(s, p, o, self._graph(c)) for s, p, o, c in quads if
ValueError:解包需要3个以上的值
答案 0 :(得分:0)
图的添加应该可以解决问题:
graph += g