Skip to content

RDF Turtle 🐢 Model Language Format Syntax

Turtle 🐢 is the “Terse Resource Description Framework (RDF) Triple Language” (TTL).

It’s a textual syntax format to write down models of linked things.

This page serves as a brief “cheat sheet” about its syntax.

The tutorial elaborates further, incl. alt. formats.

Short

The following “full” 3 Subject - Predicate - Object statements:

<http://example.org/thing1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Example>.
<http://example.org/thing1> <http://example.org/name> "First Thing".
<http://example.org/thing1> <http://example.org/next> <http://example.org/thing2>.

are typically written in this completely equivalent shorter form, with predicate lists:

<http://example.org/thing1> a <http://example.org/Example>;
  <http://example.org/name> "First Thing";
  <http://example.org/next> <http://example.org/thing2>.

Prefix

The initial example above is typically written even shorter, but semantically equivalently, by declaring prefixes, and using CURIEs instead:

@prefix ex: <http://example.org/>.

ex:thing1 a ex:Example;
  ex:name "First Thing";
  ex:next ex:thing2.

There can be several different such prefixes, of course. We can also define (a single one) default prefix:

@prefix : <http://example.org/>.

:thing1 a :Example;
  :name "First Thing";
  :next :thing2.

Base

Relative instead of absolute IRIs are allowed. By default, they are interpreted as based on “where the TTL is” (e.g. file:/...). What you typically want however is to declare an explicit absolute @base; e.g. we could also write our example from above like this if we wanted:

@base <http://example.org/>.

<thing1> a <Example>;
  <name> "First Thing";
  <next> <thing2>.

This variant is valid, and again semantically equivalently to above, but much less commonly used.

Object Lists

Here is our thing with 2 more names, note the , (comma) in the :name line:

@prefix : <http://example.org/>.

:thing1 a :Example;
  :name "Thing Name", "Another Name";
  :next :thing2.

It’s important to understand that with this syntax the names are unordered.

Collection

The (...) instead of , syntax preserves order (and it is represented differently internally):

@prefix : <http://example.org/>.

:thing1 a :Example;
  :names ("First Name", "Middle Name", "Last Name");
  :next :thing2.

Nest

The [...] syntax make this Thing contain another nested Thing (which is “anonymous”, and internally represented using a “blank node”):

@prefix : <http://example.org/>.

:thing1 a :Example;
  :nest [
    :name "Another Thing";
    :next :thing2
  ].

References