4

I am parsing triple files and adding the triples into my local triplestore.
Code Snippet:

graph = ConjunctiveGraph('Sleepycat')
graph.open("mytriplestore", create=False)
g = Graph()
g.parse("filename.ttl", format="ttl") 
for t in g:
    graph.add(t)

Instead of iterating over every triple, is it possible to add the parsed content to the triplestore in bulk?

What I have tried so far:
Attempt 1:

graph.add(g)

Error:

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

Attempt 2:

graph.addN(g)        

Error:

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: need more than 3 values to unpack

RDangol
  • 179
  • 9

1 Answers1

3

Addition of graph should do the trick :

graph += g
Swann_bm
  • 76
  • 7