Template system for RDF?

Most of the time I find myself writing a sort of well-known RDF graph structure, and I have to build it triple by triple. In the more general case, this well known graph structure is of course not guaranteed to be complete nor fixed (e.g. something else can be added). However, if a more or less invariant backbone exists, it would be nice to describe this backbone with placeholders and then pass a context to produce the fully deployed RDF graph.

Does something like this exist in Python?

You could use an ORM for Python (surf or RDFAlchemy).

For instance, an RDFAlchemy-model is an Python class. It could have default values, thus providing your "backbone". You could instantiate this class, update the relevant attributes and serialize this graph to RDFXML, Trutle, ntriples, ...

Along the lines of:

p = Person("Name")
o = Organisation("Name")
p.memberOf = o

If your input is in an XML format, you could use XSLT for this.

But your favorite programming language could help too. This is a piece of Groovy code I wrote yesterday to convert a JSON format in N3:


You could utilise mustache for this task.

Mustache is a logic-less templating system for HTML, config files, anything.

(quoted from the mustache manual)