gpt4 book ai didi

python - RDFlib:将三元组批量添加到图形

转载 作者:行者123 更新时间:2023-11-28 19:05:47 26 4
gpt4 key购买 nike

我正在解析三元组文件并将三元组添加到我的本地三元组存储中。
代码片段:

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 个值才能解包

最佳答案

添加图形应该可以解决问题:

graph += g

关于python - RDFlib:将三元组批量添加到图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47058642/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com