On RDF Turtle and file encodings

authored by Frank Lynam at 13/11/2012 13:08:59

I’ve been reading a primer on the practicalities of LOD called Linked Data: Evolving the Web into a Global Data Space. It is available online here and is written by two of the gurus on the subject, Tom Heath of Talis and Christian Bizer of the Freie Universität Berlin. It was recommended by the people behind the Pleiades project and is pretty good. Its goal is to get you to start writing RDF code in one form or another and as with most types of computer work, there is nothing like a bit of practice to infuse a concept into one’s grey matter.

The examples that appear in the book are all written in Turtle which is another type of RDF encoding. Up to this point I had been writing everything in RDF/XML but the authors point out, and are correct I think in saying, that Turtle is a much more intuitive and straightforward way of encoding RDF, especially when you are dealing with writing ontologies which is what I am trying to do.

I wrote the following ontology to describe my first archaeological forms (to use the language of Plato).

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

@prefix owl: <http://www.w3.org/2002/07/owl#> .

@prefix dcterms: <http://purl.org/dc/terms/> .

@prefix foaf: <http://xmlns.com/foaf/0.1/> .

@prefix cc: <http://creativecommons.org/ns#> .

@prefix arch: <http://dighousedata.net/vocab/archaeology#> .



       rdf:type owl:Ontology ;

       rdfs:label "DigHouseData Archaeology Vocabulary" ;

       dcterms:creator <http://dighousedata.net/people/frank-lynam> ;

       dcterms:publisher <http://dighousedata.net/company.rdf#company> ;

       cc:license <http://creativecommons.org/licenses/by-sa/3.0/> .



       rdf:type rdfs:Class;

       rdfs:label "Excavation";

       rdfs:comment "the class of all excavations".



       rdf:type rdfs:Class;

       rdfs:label "Excavator";

       rdfs:comment "the class of all excavators";

       rdfs:subClassOf foaf:Person.



       rdf:type owl:ObjectProperty;

       rdfs:label "excavator";

       rdfs:comment "an excavator for the excavation";

       rdfs:domain arch:Excavation;

       rdfs:range arch:Excavator;

       owl:inverseOf arch:excavated.



       rdf:type owl:ObjectProperty;

       rdfs:label "excavated";

       rdfs:comment "the excavation that was excavated";

       rdfs:domain arch:Excavator;

       rdfs:range arch:Excavation;

       rdfs:subPropertyOf foaf:made.                  

Now I won’t get into the ins and outs of Turtle formatting but suffice to say, my goal is to get this encoding into my RDF triple store, 4store (see this previous post for a discussion on my RDF triple store configuration). As I’m using the dotNetRDF SDK to interface with 4store, I thought that I would use the following code to send in the new Turtle data.

SparqlParameterizedString update = new SparqlParameterizedString();

update.CommandText = ("LOAD <http://mydomain.net/sample.ttl>");

SparqlRemoteUpdateEndpoint endpoint = new SparqlRemoteUpdateEndpoint("");


Unfortunately, it didn’t work.

My first guess was that there might be something wrong with the formatting of the Turtle encoding and I found by using a helpful tool offered by the ‘rdf : about’ website that indeed there was. Upon making the necessary changes, however, I was still unable to get any Turtle RDF data into the 4store server.

I then switched over to my Mac and tried to use the curl command line tool (http://curl.haxx.se/) to try to upload my Turtle RDF file to the 4store server as is described here but again with no success. The response of the server did however indicate that there might be something wrong with the parsing of the file. It appears that 4store uses the Raptor RDF Syntax library (http://librdf.org/raptor/) to handle its RDF encoding parsing and so I downloaded this and after the usual trauma that comes with installing something on Unix, I finally managed to run the rapper utility which allows you to see if your RDF is encoded correctly. It claims to support most of the major encoding types.

It told me that there was an error on the first line which is always a bit suspicious. On a hunch, I copied the text from the file and created a new file in OS X using the TextMate app. I choose to save as ‘Latin 1’ character encoding instead of the default Unicode UTF-8 and found that on running rapper a second time, no errors were encountered with the file. I was then able to return to my Windows machine and using dotNetRDF I was able to successfully upload the Turtle file to the 4store server. So the problem must have come from the fact that I had saved the original file in Windows and not on a Unix-based OS and some change of encoding must have caused a problem for my Ubuntu-powered 4store server.

Anyway, now I am able to write RDF ontologies using the fairly simple Turtle formatting and am able to get these ontologies into my public 4store SPARQL-enabled server using my web service that is utilises the dotNetRDF framework.

We’re getting there…