SuRF with OpenLink Virtuoso on Windows

I happened to have fresh Windows system handy and decided to try out how hard or easy it is to set up and use SuRF together with OpenLink Virtuoso on Windows. The overall experience was pretty smooth except for the rdflib dependency. Here are the notes I took along the way.

OpenLink Virtuoso

I went with version 5.0.11 because it has prebuilt Windows binaries available.

  • Download
  • Extract it to c:\virtuoso
  • Add c:\virtuoso\bin to system PATH
  • (optional) Adjust c:\virtuoso\database\virtuoso.ini as needed. You can change port number for Virtuoso’s web interface, how much memory it uses, which plugins it loads and so forth, documentation here.
  • Execute from shell:
    cd c:\virtuoso\database
    virtuoso-t -f virtuoso.ini

    “-f” flag tells virtuoso process to run in foreground.

  • Go explore web frontend at http://localhost:8890. Default username/password for administrator is dba/dba.
  • To communicate with Virtuoso, SuRF will use it’s SPARQL endpoint at http://localhost:8890/sparql. By default this endpoint has no write rights. To grant these rights, launch “isql” utility from shell and execute this line in it:
    grant SPARQL_UPDATE to "SPARQL";

    Such setup is fine for development and testing, but having public writable SPARQL endpoint on production system is probably not a good idea.

Python, setuptools, rdflib

Because of rdflib I went with Python 2.5 not 2.6, couldn’t get it to compile on 2.6

  • Download and install Python 2.5.4
  • Add c:\Python25 and c:\Python25\Scripts to system PATH
  • Download and install setuptools 0.6c11 for python 2.5. This package includes the easy_install program which will be used for installing rdflib and SuRF
  • Install rdflib 2.4.2 following their instructions. This is the most painful step as it involves installing cygwin and editing distutils.cfg file. Once that is done, however, I was able to install rdflib with just easy_install rdflib.


With all the dependencies in place, installing SuRF is really very easy. Execute these two lines from shell:

easy_install SuRF
easy_install surf.sparql_protocol

If these succeed you can launch python interactive console (or better yet, do easy_install ipython and launch ipython) and try out SuRF. A transcript from “demo session” in ipython console follows:

>>> import surf
>>> # Specifying default_context is important for Virtuoso as 
>>> # every triple has to be in *some* graph.
>>> store = surf.Store(reader = "sparql_protocol", 
              writer = "sparql_protocol", 
              default_context = "http://localhost:8890/demo")

WARNING:ReaderPlugin:cjson not available, falling back on slower simplejson
endpoint: http://localhost:8890/sparql

>>> session = surf.Session(store)

>>> # Create and save two foaf:Person resources.
>>> Person = session.get_class(surf.ns.FOAF["Person"])
>>> john = session.get_resource("", Person)
>>> john.foaf_name = "John"
>>> jane = session.get_resource("", Person)
>>> jane.foaf_name = "Jane"
>>> john.foaf_knows = jane

>>> # Getting all resources of foaf:Person class
>>> Person.all()
[<surf.session.FoafPerson object at 0x021658B0>,
 <surf.session.FoafPerson object at 0x02165B90>]

>>> for person in Person.all():
>>>   print "Name:", person.foaf_name.first
>>>   print "Knows:"
>>>   for friend in person.foaf_knows:
>>>     print "  ", friend.foaf_name.first

Name: John
Name: Jane

>>> # Filtering resources by foaf:knows
>>> for person in Person.get_by(foaf_knows = jane.subject): 
>>>   print person.subject