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.
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.
Turtle supports shorthand for defining classes with the verb a
:
<profile.ttl#me> a <http://xmlns.com/foaf/0.1/Person> .
To simplify URIs, Turtle allows prefixes. For instance:
@prefix foaf: <http://xmlns.com/foaf/0.1/> . <profile.ttl#me> a foaf:Person .
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> .
Turtle supports different data types:
"Alice"
for strings20
for integers20.0
for decimals2.0e1
for floating-point numbersOrganize data with blank nodes using square brackets [ ... ]
:
:Alice :home [ :address [ :street "Acacia Ave"; :number 123; :city "Anytown" ]; :phone <tel:+1-781-555-1212> ] .
Represent ordered lists with round brackets:
<#alice> foaf:children ( <#bob> <#charlie> <#dave> ) .
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.
For specific test data and quick scripts, RDFLib.js offers extensions, including shortcuts for dates and inverse relationships.