Relatively low activity since last update, but some interesting stuff nevertheless. There hasn’t been a release for a while, but, hey, you can install right from svn with
pip install http://surfrdf.googlecode.com/svn/trunk#egg=SuRF pip install http://surfrdf.googlecode.com/svn/trunk/plugins/surf.sparql_protocol#egg=surf.sparql_protocol
So, the updates:
- Python 2.4 compatibility based on patch by Saša Vinčić. This had mostly to do with replacing
a = b if c else dconstructs with and-or trick.
- Good Relations namespace added to default namespaces in
added dictionary-style attribute access. This comes handy in two situations:
- When properties contain special characters that are not allowed in Python attribute names
- When iterating over a set of attributes, or attribute names are determined dynamically. You can always use Pythons’ built-in
getattr(), but this looks nicer.
>>> for attr in ["name", "surname"]: print john["foaf_%s" % attr].first John Smith # URIRefs are also accepted as dictionary keys: >>> for attr in ["name", "surname"]: print john[surf.ns.FOAF[attr]].first John Smith
SomeClass.get_by(ns_predicate = ....)now accepts lists and other iterable objects as values. So, for example,
johns_and_joes = FoafPerson.get_by(foaf_name = ["John", "Joe"])
You can even use SuRF queries as arguments since they are iterable:
persons_that_know_any_john_or_joe = \ FoafPerson.get_by(foaf_knows = johns_and_joes)
In this case, SuRF will first evaluate the inner query, and then use its values to form a bunch of UNION clauses in outer query. So beware, you can easily get a long and inefficient query. SURF could of course be made super-clever to combine both queries into a more sophisticated one.
- … bugfixes, optimizations
Inference Rules & Reasoning with Virtuoso
OpenLink Virtuoso supports some inferencing, but requires you to prefix SPARQL queries with some special syntax to enable it. So how do you prefix SPARQL queries generated by SuRF with some vendor-specific stuff? One way to do this, is to create a new reader/writer plugin which subclasses and extends sparql_protocol plugin. An example of this is in SuRF mailing list. There is a link to experimental
surf.sparql_protocol_virtuoso plugin, which adds inferencing support.