Sleepycat store

172 views
Skip to first unread message

Jeroen van der Ham

unread,
Feb 15, 2012, 8:17:47 AM2/15/12
to rdfli...@googlegroups.com
Hi,

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.

signature.asc

Gunnar Aastrand Grimnes

unread,
Feb 15, 2012, 8:25:22 AM2/15/12
to rdfli...@googlegroups.com
A random stab in the dark - you forgot to close the store?

Try a g.close() in between the two opens.

- Gunnar

--
http://gromgull.net

Jeroen van der Ham

unread,
Feb 15, 2012, 8:29:49 AM2/15/12
to rdfli...@googlegroups.com
Hi,

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()

signature.asc

Gunnar Aastrand Grimnes

unread,
Feb 15, 2012, 8:34:26 AM2/15/12
to rdfli...@googlegroups.com
You may have to pass create=True to open the first time?

I have several services running based on persistent sleepycat stores,
so it DOES work somehow :)

- Gunnar

--
http://gromgull.net

Graham Higgins

unread,
Feb 15, 2012, 10:07:33 AM2/15/12
to rdfli...@googlegroups.com
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:


loadfile is /path/to/n3/file - if you want a quick file of n3 data, grab one of the files in


HTH

Graham

Graham Higgins

unread,
Feb 15, 2012, 10:22:20 AM2/15/12
to rdfli...@googlegroups.com
Yer 'tis, as they say round here ...

>>> from rdflib import Graph, term, namespace, URIRef
>>> graph = Graph('Sleepycat', URIRef("http://example.com"))
>>> configString = "/tmp/sleepyDB"
>>> graph.open(configString, create=True)
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')))
>>> print(len(graph))
2
>>> graph.commit()
>>> graph = None
>>> graph = Graph('Sleepycat', URIRef("http://example.com"))
>>> graph.open(configString, create=False)
1
>>> print(len(graph))
2
>>> 

Jeroen van der Ham

unread,
Feb 15, 2012, 10:31:57 AM2/15/12
to rdfli...@googlegroups.com

On 15 Feb 2012, at 16:07, Graham Higgins wrote:

> 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.

signature.asc

Jeroen van der Ham

unread,
Feb 16, 2012, 5:15:24 AM2/16/12
to rdfli...@googlegroups.com
Hi,

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.

signature.asc
Reply all
Reply to author
Forward
0 new messages