RDFLib itself still contains support for one persistent store, in the form of the Sleepycat database format. Or at least I hoped it was persistent, because I can't seem to get it to work.
Can someone help me with making this persistent?
>>> from rdflib import Graph, term, namespace
>>> graph=Graph(store='Sleepycat')
>>> graph.open("sleepyDB")
1
>>> graph.add((term.URIRef('http://www.google.com/'),namespace.RDFS.label, term.Literal('Google home page')))
>>> graph.add((term.URIRef('http://wikipedia.org/'), namespace.RDFS.label, term.Literal('Wikipedia home page')))
>>> len(graph)
2
>>> graph=Graph(store='Sleepycat')
>>> graph.open("sleepyDB")
1
>>> len(graph)
0
Jeroen.
Try a g.close() in between the two opens.
- Gunnar
On 15 Feb 2012, at 14:25, Gunnar Aastrand Grimnes wrote:
> A random stab in the dark - you forgot to close the store?
>
> Try a g.close() in between the two opens.
Nope, that's not it. And for good measure I threw in a graph.commit() as well:
>>> len(graph)
2
>>> graph.commit()
>>> graph.close()
I have several services running based on persistent sleepycat stores,
so it DOES work somehow :)
- Gunnar
Can someone help me with making this persistent?
> On Wednesday, 15 February 2012 13:17:47 UTC, Jeroen wrote:
>>
>> Can someone help me with making this persistent?
>>
> I'll try and reflect your code back to you, working. In the
> interim, perhaps, this example might help:
>
> http://www.pastie.org/3388033
Ah, that helped to track down the issue!
I didn't realize that a Graph object came with a generated identifier, which was then tied to the store.
>>> from rdflib import Graph, term, namespace
>>> graph=Graph(store='Sleepycat',identifier='test')
>>> graph.open("sleepyDB")
1
>>> graph.add((term.URIRef('http://www.google.com/'),namespace.RDFS.label, term.Literal('Google home page')))
>>> graph.add((term.URIRef('http://wikipedia.org/'), namespace.RDFS.label, term.Literal('Wikipedia home page')))
>>> len(graph)
2
>>> graph=Graph(store='Sleepycat',identifier='test')
>>> graph.open("sleepyDB")
1
>>> len(graph)
2
Problem solved!
I'll update the wiki to reflect this.
Jeroen.
On 15 Feb 2012, at 14:34, Gunnar Aastrand Grimnes wrote:
> You may have to pass create=True to open the first time?
>
That doesn't seem necessary. The only condition is that the directory in which you want to create the Sleepycat store exists.
The code I listed in my original email was exactly what I ran, with an empty directory, so it does indeed all work.
Jeroen.