Using ShorthandRDF to develop domain-specific language for RDF

ShorthandRDF <http://www.w3.org/wiki/ShorthandRDF> is a language which
provides some fairly trivial extensions to Notation 3, allowing N3's
syntax to be extended.

As a simple example, in N3 and Turtle, the keyword "a" is expanded to
rdf:type. ShorthandRDF allows you to define other keywords which expand
to full URIs (or indeed to literals) - e.g.

	@term called <http://xmlns.com/foaf/0.1/name> .
	
	<#me> called "Toby Inkster".

A key feature of ShorthandRDF is that it allows you to place
prefix declarations, term declarations and so forth into an external
file and include it by reference:

	@profile <http://www.example.com/definitions.n3x>.
	<#me> a Person; called "Toby Inkster".

This makes it suitable as a foundation for building domain-specific RDF
serialisations. (GRDDL is another candidate for RDF DSLs, but in
practice is restricted to operating on HTML/XML.)

Pretdsl is my first experiment at using ShorthandRDF to develop a
domain-specific RDF serialisation. It is indented to be a DSL for
describing software - in particular, Perl modules. It makes writing
DOAP data easy, and is especially optimised to make writing change logs
simple (as that's the most frequently updated data).

For example, here's some metadata for one of my projects in Pretdsl:
https://metacpan.org/source/TOBYINK/IO-Detect-0.004/meta/doap.pret
https://metacpan.org/source/TOBYINK/IO-Detect-0.004/meta/makefile.pret
https://metacpan.org/source/TOBYINK/IO-Detect-0.004/meta/changes.pret

The ShorthandRDF profile for Pretdsl is here:
http://buzzword.org.uk/2012/pretdsl/profile-1

My Pretdsl parser is implemented on top of my ShorthandRDF parser. It
performs the following additional tasks on top of generic ShorthandRDF
parsing:

1. automatically assumes that input documents are Pretdsl, so loads
the profile implicitly, rather than requiring an "@profile" line; and

2. intercepts literals of particular Pretdsl-specific datatypes,
replacing them with various URIs and blank nodes. Thus a single triple:

    "Example-Distribution 0.001 cpan:TOBYINK"^^pretdsl-dt:Release
        dc:issued "2012-06-18"^^xsd:date .

Can actually be expanded to something like:

    <http://purl.org/NET/cpan-uri/dist/Example-Distribution/v_0-001>
        a doap:Version ;
        doap:revision "0.001"^^xsd:string ;
        doap:file-release
            </authors/id/T/TO/TOBYINK/Example-Distribution-0.001.tar.gz> ;
        dcs:released-by cpan:tobyink ;
        dc:identifier "Example-Distribution-0.001"^^xsd:string ;
        dc:issued "2012-06-18"^^xsd:date .
    <http://purl.org/NET/cpan-uri/dist/Example-Distribution/project>
        doap:release
            <http://purl.org/NET/cpan-uri/dist/Example-Distribution/v_0-001> .

I've now been using Pretdsl for about a month to drive my project
release system (the Pretdsl metadata is used to generate
human-reaadable change logs, generate dependency lists used by
CPAN, etc) and it seems to have been working quite nicely.

If you have a task where you seem to be writing a lot of boilerplate
RDF, take a look at ShorthandRDF and see if it could make your life
easier. (And then beg whoever develops your RDF tools to support
ShorthandRDF as an input format.)

-- 
Toby A Inkster
<mailto:mail@tobyinkster.co.uk>
<http://tobyinkster.co.uk>

Received on Thursday, 9 August 2012 14:08:57 UTC