Python RDF example of a MySQL triple store thanks to redland/librdf

In a way similar to my previous post about persisting graphs in PostGreSQL in PHP, here’s similar examples for Python and MySQL.

Note that you may need to adjust the MySQL table creation templates if you’re running librdf version 1.0.16 (see this bug for details).

The first example will load data from a file, and store the parsed model to the RDBMS, while the second example, will reload the model and issue queries on it.watch A Cure for Wellness 2017 movie now

These examples don’t do much, but hopefully, they’ll help you get started if you’re interested in using redland/librdf.

One potential benefit can be interoperability with other languages like PHP, for instance if you’re running harvesters in Python that will save facts in a triple store, which is then accessed by a PHP application that will publish a Web interface.

RDF development in PHP with a PostGreSQL triple store thanks to the LibRDF OO wrapper for redland/librdf

Redland/librdf offers powerful features like being able to persist an RDF model to a relational database (only PostGreSQL seems to work on my setup with 1.0.16, but I may have misconfigured it). You can then do SPARQL queries over the model, and lots of other nice things.

Unfortunately, the default PHP bindings are not really object-oriented, so the code isn’t looking so good.

But thanks to a gentleman named David Shea, there is an object-oriented library named LibRDF (case is sensitive), that helps write nice looking PHP.

I discovered it via the blog post of Felix Ostrowski, who took over the maintenance of the LibRDF library (still the docs live on the original author’s site).

In his post, Felix illustrates how you may use it to parse Richard Cyganiak’s FOAF profile.

But the examples he gives don’t illustrate the full potential of persistence of the RDF graph into the DB.

Here’s my contribution in 2 examples that will hopefully help : first, one that load Richard’s FOAF to the DB, and one, that later retrieve the saved model and perform the same query (both pushed to my github clone of the library).

There may be some problems with the use of librdf, including its availability, as it is not full PHP of course… and I’ve heard of memory management problems, but, depening on your needs, this may be quite handy for writing Linked Data applications.