Lacking an example of how to setup postgreSQL store

160 views
Skip to first unread message

Dominique Guardiola Falco

unread,
Feb 14, 2012, 4:52:38 AM2/14/12
to rdfli...@googlegroups.com
Can you help me please giving me an example of setting up a rdflib store with PostGreSQL ?

The differents docs explore many things, but lacks sortof basic examples for guys like me
The only example I found was at the very bottom of this page :
http://readthedocs.org/docs/rdfextras/en/latest/store/mysqlpg.html

But it doesn't work for me
I'm using rdflib 3.2.0 , rdfextras 0.2dev (cloned on the google code repository) and the rdflib_postgresql plugin on github (is it necessary as rdfextras also has PG store?)
My code looks like this :

from rdflib import plugin
from rdflib.store import Store
plugin.register(
        'PostgreSQL', Store,
        'rdflib_postgresql.PostgreSQL', 'PostgreSQL')

config = "user=dom,password=xxxxx,host=localhost,db=rdf_test"
store = plugin.get('PostgreSQL', Store)(identifier = 'rdfstore',
                                        configuration = config)

store.open(create=True)

And this brings me this error :

  File "rdf_store.py", line 15, in <module>
    configuration = config)
TypeError: __init__() got an unexpected keyword argument 'configuration'

Thank you for your help

Dominique Guardiola Falco

unread,
Feb 14, 2012, 5:41:32 AM2/14/12
to rdfli...@googlegroups.com
Well, Im' sorry in fact there is a good example here :
http://readthedocs.org/docs/rdfextras/en/latest/intro_mysql_as_triplestore.html

It introduces another syntax, but it throws an error too :

  File "rdf_store.py", line 17, in <module>
store = plugin.get('PostgreSQL', Store)('rdfstore')
TypeError: __init__() takes exactly 1 argument (2 given)


Gunnar Aastrand Grimnes

unread,
Feb 14, 2012, 5:44:16 AM2/14/12
to rdfli...@googlegroups.com
I never used the psql store, but try removing the 'rdfstore' param here.

- Gunnar

On 14 February 2012 11:41, Dominique Guardiola Falco

> --
> You received this message because you are subscribed to the Google Groups
> "rdflib-dev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rdflib-dev/-/-juRgQGLm3MJ.
>
> To post to this group, send email to rdfli...@googlegroups.com.
> To unsubscribe from this group, send email to
> rdflib-dev+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rdflib-dev?hl=en.

--
http://gromgull.net

Dominique Guardiola Falco

unread,
Feb 14, 2012, 6:35:40 AM2/14/12
to rdfli...@googlegroups.com

Le 14 févr. 2012 à 11:44, Gunnar Aastrand Grimnes a écrit :

> I never used the psql store, but try removing the 'rdfstore' param here.


it passes without error, but then store.open() complains :

store.open(create=True)
TypeError: unbound method open() must be called with PostgreSQL instance as first argument (got nothing instead)

I don't get what can be a PosteGreSQL instance in this context
Trying to pass the previously created store instance won't work :

store.open(store,create=True)
TypeError: unbound method open() must be called with PostgreSQL instance as first argument (got type instance instead)


Graham Higgins

unread,
Feb 14, 2012, 10:34:56 AM2/14/12
to rdfli...@googlegroups.com
On Tuesday, 14 February 2012 09:52:38 UTC, Dominique Guardiola Falco wrote:
Can you help me please giving me an example of setting up a rdflib store with PostGreSQL ?

The differents docs explore many things, but lacks sortof basic examples for guys like me
The only example I found was at the very bottom of this page :
http://readthedocs.org/docs/rdfextras/en/latest/store/mysqlpg.html

Sorry for the lack of explicit basic examples, I'm in the process of sorting 
out the SQL-based RDFLib stores and once that exercise is complete, I'll produce an 
analysis along the lines of the one I created for the key-value-based stores [1]:

In the meantime, there are some caveats to consider.

1. you should apprise yourself of the test failures:


2. Looking at the code, I can't see that any of the AbstractSQLStore-based back-ends could ever have handled Statements - which is what 
produces the "not all arguments converted during string formatting" exception - the code is written to handle a string, not a tuple.

3. There's something very screwy about context-handling in the AbstractSQLStore/FOPLRelationalModel which I'm currently trying to isolate.

4. The REGEXStore test is also broken until I can work out how to add the regexp function to PostgreSQL.

I've just pushed the results of my latest work on this store up to the github rdflib-postgresql repos. I strongly recommend that you run the tests locally before spending any serious time using this store ("nosetests" should just work, let me know if it doesn't).

I'm using rdflib 3.2.0 , rdfextras 0.2dev (cloned on the google code repository) and the rdflib_postgresql plugin on github (is it necessary as rdfextras also has PG store?)

Apologies also for the somewhat confusing state of rdfextras at the moment, we're between horses, so to speak. You might prefer to use Thomas' py3-compatible port of rdfextras that is currently residing on github:


This (pre-release) version on github has the plugin stores, parsers and serializers stripped out, partly to reduce the amount of py3compat work required down to an acceptable level and partly to enable rdfextras to be added to the shiningpanda CI build: 


Until we're properly sorted with a release of py3compat rdfextras, you'll need to add the split-off plugins back in by grabbing the repository code for the desired plugin and installing that - just as you have done.

The PostgreSQL store in the extant rdfextras-0.1 release should also be basically functional (it fails the same tests as does the split-off plugin). Look in rdfextras-01's tests/test_store/test_postgresql for another usage example (or rdflib-postgresql's test/test_postgresql or test/test_store_performance)

It's not clear to me yet whether the AbstractSQLStore-based backends have a real future as rdfextras plugins - Gunnar was right on the button in describing my pickup of the stores as "brave". The code is complex and it has been extremely difficult task to try and reconstruct the modelling intentions behind the code.

HTH,

Cheers,

Graham




Dominique Guardiola Falco

unread,
Feb 14, 2012, 12:39:24 PM2/14/12
to rdfli...@googlegroups.com
Graham,
thanks for your extensive answer on the state of things about rdf-postgresql

with the example in the test files, I found my error, works better now :

from rdflib import plugin
from rdflib.graph import ConjunctiveGraph as Graph


from rdflib.store import Store
plugin.register(
'PostgreSQL', Store,
'rdflib_postgresql.PostgreSQL', 'PostgreSQL')

config = "host=localhost,user=dom,password=q4s5d6,db=rdflib"
default_graph_uri = "http://example.com/mygraph"


store = plugin.get('PostgreSQL', Store)

graph = Graph(store="PostgreSQL",
identifier = URIRef(default_graph_uri))
graph.open(config, create=True) # I was previously doing .open() on the store

it just outputs a strange error at the creation of the store:
"table kb_bec6803d52_asserted_statements Doesn't exist"
(but the table was created, along with the other tables)
and I can add triples so work can start now.

I want to use the PGSQL backend because of its full-text-search features (stemming among other filters), so this could be a lighter alternative to Lucene, only available with a few java-based stores. And mutualize the PG instance every django site already has.


Could you tell me, in your opinion, which backend has these features :

- lightweight (I'll need 100-200K triples in a store)
- fast query
- easy to install
- good support right now in rdflib

So I could switch if I really have problems with PG...

> --
> You received this message because you are subscribed to the Google Groups "rdflib-dev" group.

> To view this discussion on the web visit https://groups.google.com/d/msg/rdflib-dev/-/AtQbyaSquyoJ.

Graham Higgins

unread,
Feb 14, 2012, 2:58:59 PM2/14/12
to rdfli...@googlegroups.com
On Tuesday, 14 February 2012 15:34:56 UTC, Graham Higgins wrote:
4. The REGEXStore test is also broken until I can work out how to add the regexp function to PostgreSQL.

Fortunately, that's complete nonsense. The REGEXMatching Store is only relevant when the back-end doesn't offer text search. PostgreSQL does, so that failing test is irrelevant and can simply be expunged from the rdflib-postgresql test suite. 

More later.

Cheers,

Graham.
Reply all
Reply to author
Forward
0 new messages