Authoring RDF data with SPARQL
Yesterday Yves Raimond and I presented a tutorial at WOD-PD where we created some turtle data and used my online semantic converter tool to convert the data to RDF/XML and POST it to the platform store we set up for the tutorial (wod-pd-sandbox).
In fact though, every SPARQL endpoint that supports CONSTRUCT is already a turtle -> rdf/xml converter. You can write Turtle with no variables in the CONSTRUCT graph, leave the WHERE graph pattern empty, and you will get back RDF/XML.
eg:
PREFIX ex: <http://example.org/>
CONSTRUCT {
ex:Jimmy ex:eat ex:World .
}
WHERE {}
returns
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ex="http://example.org/" >
<rdf:Description rdf:about="http://example.org/Jimmy">
<ex:eat rdf:resource="http://example.org/World"/>
</rdf:Description>
</rdf:RDF>
You can also use CONSTRUCT to create new data inferred from existing data. For instance, I wanted to add some triples about the conference, and I knew that everyone in the store with a URI in the store’s own namespace had been following the tutorial, and so was also attending the conference. So I made this query, and then POSTed the results into the store:
PREFIX schema: <http://api.talis.com/stores/wod-pd-sandbox/items/Schema/>
PREFIX sandbox: <http://api.talis.com/stores/wod-pd-sandbox/items/Things/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
CONSTRUCT {
schema:Conference a rdfs:Class ;
rdfs:isDefinedBy schema: ;
rdfs:label "Conference" .
schema:startDate a rdf:Property ;
rdfs:isDefinedBy schema: ;
rdfs:label "start date" .
schema:endDate a rdf:Property ;
rdfs:isDefinedBy schema: ;
rdfs:label "end date" .
schema:attendee a rdf:Property ;
rdfs:isDefinedBy schema: ;
rdfs:label "attendee" ; owl:inverseOf schema:attended .
schema:attended a rdf:Property ;
rdfs:isDefinedBy schema: ;
rdfs:label "attended"; owl:inverseOf schema:attendee .
sandbox:WOD-PD a schema:Conference ;
rdfs:label "Web of Data" ;
schema:startDate "2008-10-22" ;
schema:endDate "2008-10-23" ;
schema:attendee ?person .
?person schema:attended sandbox:WOD-PD .
} WHERE
{
?person a <http://xmlns.com/foaf/0.1/Person> .
FILTER(REGEX(STR(?person), "sandbox/items/People/"))
}
I used PREFIX to declare a prefix for a couple of namespaces with the store’s contentbox URIs – this meant that these URIs would dereference and work as Linked Data – 303ing to their RDF descriptions. This is a really nice feature of the platform, and makes it easy to mint new URIs that will play nice on the semantic web.
You might also have noticed that there are some new properties and classes defined there in the CONSTRUCT. This isn’t absolutely ideal – there is no documentation, and the terms are unlikely to be used again – but on the other hand, the descriptions are dereferencable according to the principles of linked data, and just as persistent as the data they describe. Moreover, as Richard Cyganiak said today – if you worry about doing RDF ‘right’ to the extent that it stops you doing RDF, you’re not doing it right
.

