reconstruct raw query to Surf objects

4 views
Skip to first unread message

Ming

unread,
Nov 13, 2011, 8:30:51 PM11/13/11
to surfrdf

As documented in http://packages.python.org/SuRF/query.html
When using raw query, Surf will make no attempt to represent returned
data as resource objects
But if we want to, is there an easy for user to write code to take
the raw results and reconstruct to Surf objects?

Christoph Burgmer

unread,
Nov 14, 2011, 5:41:35 AM11/14/11
to surfrdf
Hi Ming

Sadly there is no integrated & simple way of doing so, as far as I
remember. I think this is a valid question and I had a similar request
some time ago.

I believe SuRF could be extended by adding raw SPARQL capabilities to
the ResultProxy.

Practically, to fix your problem, you could just gather the subject of
all objects you require, and pass each and every one to a Resource
object:

>>> result = select("?s").where(...)
>>> for entry in ['results']['bindings']:
... resources.append(MusicAlbum(entry['?s']))

However you'll add some load overhead, as attribute access to the
resources will trigger additional queries to load the respective data.
If speed is not an issue for you, this should be fine though.

HTH
-Christoph

Ming

unread,
Nov 15, 2011, 9:52:08 PM11/15/11
to surfrdf
Christoph - Thanks - will give a try
Reply all
Reply to author
Forward
0 new messages