Using Turtle

Turtle is a language designed for expressing linked data on the web. While HTML is used for linked text, Turtle is used for linked data, describing information about various things—whether abstract, real, or conceptual.

Understanding Turtle Basics

Turtle's data model, RDF (Resource Description Framework), is very straightforward. The core of Turtle is a simple structure of triples—each containing a subject, predicate, and object:

<profile.ttl#me> <http://xmlns.com/foaf/0.1/knows> <students.ttl#bob> .

In this example, profile.ttl#me "knows" students.ttl#bob. Each triple ends with a period.

Shorthand Notations

Turtle supports shorthand for defining classes with the verb a:

<profile.ttl#me> a <http://xmlns.com/foaf/0.1/Person> .

Prefixes

To simplify URIs, Turtle allows prefixes. For instance:

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<profile.ttl#me> a foaf:Person .
        

Property Trees

To describe multiple facts about a single subject, use semicolons ; to separate properties:

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

<profile.ttl#me> a foaf:Person ;
              foaf:name "Alice" ;
              foaf:knows <students.ttl#bob> .
        

Data Values

Turtle supports different data types:

Using Structure

Organize data with blank nodes using square brackets [ ... ]:

:Alice :home [
    :address [
        :street "Acacia Ave";
        :number 123;
        :city "Anytown"
    ];
    :phone <tel:+1-781-555-1212>
] .
        

Lists

Represent ordered lists with round brackets:

<#alice> foaf:children ( <#bob> <#charlie> <#dave> ) .
        

Conclusion

That’s all there is to Turtle! Practice reading and writing Turtle triples like sentences, and you’ll soon be comfortable using it to represent linked data in various contexts.

Additional Notes on RDFLib Extensions

For specific test data and quick scripts, RDFLib.js offers extensions, including shortcuts for dates and inverse relationships.