Copyright © 2008 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
The Resource Description Framework (RDF) is a general-purpose language for representing information in the Web.
This document defines a textual syntax for RDF called Turtle that allows RDF graphs to be completely written in a compact and natural text form, with abbreviations for common usage patterns and datatypes. Turtle provides levels of compatibility with the existing N-Triples and Notation 3 formats as well as the triple pattern syntax of the SPARQL W3C Recommendation.
This document specifies a language that is in common usage under the name "Turtle". It is intended to be compatible with, and a subset of, Notation 3.
This is a proposed replacement for the W3C Turtle Submission. It has not been endorsed by any formal W3C process or by the members.
The W3C Turtle Submission is at the head of Dave Beckett's Turtle revision chain, and has been serving as a specification since Jan 2004. While there is apparent interop between Turtle parsers (advice to the contrary welcome), more formality may encourage use in e.g. MPEG formats.
The following proposal is intended to address pfps's call for a parsing semantics. It also aligns the Turtle grammar with the SPARQL Grammar where appropriate. Similar grammars have been tested by DanC in his n3 and ntriples parsers. and ericP in his SWObjects Turtle parser which uses the turtleS Yacker grammar. Note the nonexhaustive differences between SPARQL and Turtle.
A set of named tests have been integrated into the document.
After extensive discussion of a registration request, the media type remains text/turtle
.
This document defines Turtle, the Terse RDF Triple Language, a concrete syntax for RDF as defined in the RDF Concepts and Abstract Syntax ([RDF-CONCEPTS]) W3C Recommendation. Turtle is an extension of N-Triples ([N-TRIPLES]) carefully taking the most useful and appropriate things added from Notation 3 ([NOTATION3]) while staying within the RDF model.
The recommended XML syntax for RDF, RDF/XML ([RDF-XML]) has certain restrictions imposed by XML and the use of XML Namespaces that prevent it encoding all RDF graphs (some predicate URIs are forbidden and XML 1.0 forbids encoding some Unicode codepoints). These restrictions do not apply to Turtle.
Turtle is intended to be compatible with, and a subset of, Notation 3 (see Turtle compared to Notation 3), and is generally usable in systems that support N3.
The Turtle grammar for triples
is a subset of the SPARQL Protocol And RDF Query Language
(SPARQL)
[SPARQLQ] grammar for TriplesBlock
. The two grammars share production and terminal names where possible.
This section is informative. The Turtle Syntax and Turtle Grammar sections formally define the language.
A Turtle document allows writing down an RDF graph in a compact
textual form. It consists of a sequence of directives, triple-generating
statements or blank lines. Comments may be given after a #
and continue to the end of the line.
Simple triples are a sequence of (subject, predicate, object) terms, separated by whitespace and terminated by '.' after each triple. This corresponds to N-Triples ([N-TRIPLES]).
There are three types of RDF Term: RDF URI References (URIs for short), literals and blank nodes.
URIs are written enclosed in '<' and '>' and may be absolute RDF URI References or relative to the current base URI (described below).
# this is not a complete turtle document <http://example.org/path/> <http://example.org/path/#fragment> </path> <#fragment> <>
URIs may also be abbreviated by using Turtle's @prefix
directive that allows declaring a short prefix name for a long prefix
of repeated URIs. This is useful for many RDF vocabularies that are
all defined in nearby namespace URIs, possibly using XML's namespace
mechanism that works in a similar fashion.
Once a prefix such as @prefix foo:
<http://example.org/ns#>
is defined, any mention of a
URI later in the document may use a qualified name that
starts foo:
to stand for the longer URI. So for
example, the qualified name foo:bar
is a shorthand for
the URI http://example.org/ns#bar
.
# this is a complete turtle document @prefix foo: <http://example.org/ns#> . @prefix : <http://other.example.org/ns#> . foo:bar foo: : . :bar : foo:bar .
Literals are written either using double-quotes when they do not
contain linebreaks like "simple literal"
or
"""long literal"""
when they may contain linebreaks.
# this is not a complete turtle document "a string" """a string""" """a string with newlines """
Literals may be given either a language suffix or a datatype URI
but not both. Languages are indicated by appending the simple
literal with @
and the language tag. Datatype URIs
similarly append ^^
followed by any legal URI form (full
or qualified) as described above to give the datatype URI.
# this is not a complete turtle document "chat" "chat"@en "chat"@fr "foo"^^<http://example.org/my/datatype> """10"""^^xsd:decimal
Blank nodes are written as _:
BLANK_NODE_LABEL
to provide a blank node either from the given BLANK_NODE_LABEL.
A generated blank node may also be made with []
which is useful to provide the subject of RDF triples for
each pair from the predicateObjectList
or the root of the collection.
# this is not a complete turtle document _:me _:a1234
Literals and URIs may also contain escapes to encode surrounding syntax, non-printable characters and to encode Unicode characters by codepoint number (although they may also be given directly, encoded as UTF-8). The character escapes are:
\t
(U+0009, tab)\n
(U+000A, linefeed)\r
(U+000D, carriage return)\"
(U+0022, double quote - only allowed inside strings)\>
(U+003E, greater than - only allowed inside IRI_REFs)\\
(U+005C, backslash)\u
HHHH or
\U
HHHHHHHH
for writing Unicode characters by hexadecimal codepoint where
H is a single hexadecimal digit.
See the String escapes section for full details.
The current base URI may be altered in a Turtle document using the
@base
directive. It allows further abbreviation of
URIs but is usually for simplifying the URIs in the data, where
the prefix directives are for vocabularies that describe the data.
Whenever this directive appears, it defines the base URI for which all relative URIs are resolved against. That includes URIs, qualified names, prefix directives as well as later base directives.
# this is a complete turtle document # In-scope base URI is the document URI at this point <a1> <b1> <c1> . @base <http://example.org/ns/> . # In-scope base URI is http://example.org/ns/ at this point <a2> <http://example.org/ns/b2> <c2> . @base <foo/> . # In-scope base URI is http://example.org/ns/foo/ at this point <a3> <b3> <c3> . @prefix : <bar#> . :a4 :b4 :c4 . @prefix : <http://example.org/ns2#> . :a5 :b5 :c5 .
The token a
is equivalent to the URI
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
# this is a complete turtle document @prefix doc: <http://example.org/#ns> . <http://example.org/path> a doc:Document .
Decimal integers may be written directly and correspond to the XML Schema Datatype xsd:integer. in both syntax and datatype URI.
# this is not a complete turtle document -5 0 1 10 +1 # some long form examples "-5"^^xsd:integer "10"^^<http://www.w3.org/2001/XMLSchema#integer>
Decimal floating point double/fixed precision numbers may be written directly and correspond to the XML Schema Datatype xsd:double in both syntax and datatype URI.
# this is not a complete turtle document 1.3e2 10e0 -12.5e10 # some long form examples "1.3e2"^^xsd:double "-12.5e10"^^<http://www.w3.org/2001/XMLSchema#double>
Decimal floating point arbitrary precision numbers may be written directly and correspond to the XML Schema Datatype xsd:decimal. in both syntax and datatype URI.
# this is not a complete turtle document 0.0 1.0 1.234567890123456789 -5.0 # some long form examples "0.0"^^xsd:decimal "-5.0"^^<http://www.w3.org/2001/XMLSchema#decimal>
Boolean may be written directly as true
or
false
and correspond to the
the XML Schema Datatype
xsd:boolean
in both syntax and datatype URI.
# this is not a complete turtle document true false # same in long form "true"^^xsd:boolean "false"^^<http://www.w3.org/2001/XMLSchema#boolean>
The ,
symbol may be used to repeat the subject and
predicate of triples that only differ in the object RDF term.
# this is not a complete turtle document :a :b :c , :d . # the last triple is :a :b :d .
The ;
symbol may be used to repeat the subject of
of triples that vary only in predicate and object RDF terms.
# this is not a complete turtle document :a :b :c ; :d :e . # the last triple is :a :d :e .
An RDF Collection may be abbreviated using a sequence of
RDF Terms enclosed in ( )
brackets. Whitespace may
be used to separate them, as usual. This format provides a
blank node at the start of RDF Collection which may be used
in further abbreviations.
# this is a complete turtle document @prefix : <http://example.org/foo> . # the value of this triple is the RDF collection blank node :subject :predicate ( :a : b : c ) . # an empty collection value - rdf:nil :subject :predicate2 () .
See section Collections for the details on the long form of the generated triples.
Turtle is a language for an RDF graph, a set of RDF triples. An RDF graph is composed of URI references (now interpreted as IRIs), literals and blank nodes.
The Turtle syntax for IRIs is identical to that of SPARQL Query, including the use of prefix
and base
directives, thought these are spelled "@prefix" and "@base" respectively in Turtle. Per RFC3986 section 5.1.1, the parsing begins with a context-defined In-Scope Base URI. Each @base
directive sets a new In-Scope Base URI, relative to the previous one. @prefix
directives map a local name to an IRI, also resolved against the current In-Scope Base URI. Subsequent @prefix
may re-map the same local name.
Turtle IRI syntax, including relative IRI resolution, is defined by SPARQL Query section 4.1.1 (noting the different spellings of the PREFIX
and BASE
keywords).
Example (test-30.ttl) with document base URI http://www.w3.org/2001/sw/DataAccess/df1/tests/
# In-scope base URI is http://www.w3.org/2001/sw/DataAccess/df1/tests/ at this point <test-00.ttl> <test-01.ttl> <test-02.ttl> . @base <http://example.org/ns/> . # In-scope base URI is http://example.org/ns/ at this point <a2> <http://example.org/ns/b2> <c2> . @base <foo/> . # In-scope base URI is http://example.org/ns/foo/ at this point <a3> <b3> <c3> . @prefix : <bar#> . :a4 :b4 :c4 . @prefix : <http://example.org/ns2#> . :a5 :b5 :c5 .
encodes the following N-Triples (test-30.out):
<http://www.w3.org/2001/sw/DataAccess/df1/tests/test-00.ttl> <http://www.w3.org/2001/sw/DataAccess/df1/tests/test-01.ttl> <http://www.w3.org/2001/sw/DataAccess/df1/tests/test-02.ttl> . <http://example.org/ns/a2> <http://example.org/ns/b2> <http://example.org/ns/c2> . <http://example.org/ns/foo/a3> <http://example.org/ns/foo/b3> <http://example.org/ns/foo/c3> . <http://example.org/ns/foo/bar#a4> <http://example.org/ns/foo/bar#b4> <http://example.org/ns/foo/bar#c4> . <http://example.org/ns2#a5> <http://example.org/ns2#b5> <http://example.org/ns2#c5> .
The Turtle syntax for literals and blank nodes are defined by SPARQL Query section 4.1.2 and SPARQL Query section 4.1.4 respectively.
A Turtle document is a Unicode[UNICODE] character string encoded in UTF-8. Unicode codepoints only in the range U+0 to U+10FFFF inclusive are allowed.
White space (production ws) is used to separate two tokens which would otherwise be (mis-)recognized as one token.
White space is significant in tokens IRI_REF and string.
Comments in Turtle take the form of '#', outside an IRI_REF or strings, and continue to the end of line (marked by characters U+000D or U+000A) or end of file if there is no end of line after the comment marker. Comments are treated as white space.
Turtle strings and URIs can use \
-escape sequences to
represent Unicode code points.
The following table describes all the escapes allowed inside a string or IRI_REF:
Escape | Unicode code point |
---|---|
'\u' hex hex hex hex | A Unicode codepoint in the range U+0 to U+FFFF inclusive corresponding to the encoded hexadecimal value. |
'\U' hex hex hex hex hex hex hex hex | A Unicode codepoint in the range U+10000 to U+10FFFF inclusive corresponding to the encoded hexadecimal value. |
'\t' | U+0009 |
'\n' | U+000A |
'\r' | U+000D |
'\"' (inside string) |
U+0022 |
'\>' (inside IRI_REF only) |
U+003E |
'\\' | U+005C |
where HEX is a hexadecimal character
HEX ::= [0-9] | [A-F] | [a-f]
The EBNF used here is defined in XML 1.0 (Third Edition) [NOTATION]. Production labels consisting of a number and a final 's', e.g. [60s], reference to the production with that number in the SPARQL Query Language for RDF grammar [SPARQLQ].
[1] | turtleDoc |
::= | (statement)* |
[2] | statement |
::= | directive "." |
[3] | directive |
::= | prefixID |
[4] | prefixID |
::= | PREFIX PNAME_NS IRI_REF |
[5] | base |
::= | BASE IRI_REF |
[6] | triples |
::= | subject predicateObjectList |
[7] | predicateObjectList |
::= | verb objectList ( ";" verb objectList )* (";")? |
[8] | objectList |
::= | object ( "," object )* |
[9] | verb |
::= | predicate |
[10] | subject |
::= | IRIref |
[11] | predicate |
::= | IRIref |
[12] | object |
::= | IRIref |
[13] | literal |
::= | RDFLiteral |
[14] | blank |
::= | BlankNode |
[15] | blankNodePropertyList |
::= | "[" predicateObjectList "]" |
[16] | collection |
::= | "(" object* ")" |
[60s] | RDFLiteral |
::= | String ( LANGTAG | ( "^^" IRIref ) )? |
[61s] | NumericLiteral |
::= | NumericLiteralUnsigned |
[62s] | NumericLiteralUnsigned |
::= | INTEGER |
[63s] | NumericLiteralPositive |
::= | INTEGER_POSITIVE |
[64s] | NumericLiteralNegative |
::= | INTEGER_NEGATIVE |
[65s] | BooleanLiteral |
::= | "true" |
[66s] | String |
::= | STRING_LITERAL1 |
[67s] | IRIref |
::= | IRI_REF |
[68s] | PrefixedName |
::= | PNAME_LN |
[69s] | BlankNode |
::= | BLANK_NODE_LABEL |
[17] | <BASE > |
::= | "@base" |
[18] | <PREFIX > |
::= | "@prefix" |
[70s] | <IRI_REF > |
::= | "<" ( [^<>\"{}|^`\\] - [#0000- ] )* ">" |
[71s] | <PNAME_NS > |
::= | (PN_PREFIX)? ":" |
[72s] | <PNAME_LN > |
::= | PNAME_NS PN_LOCAL |
[73s] | <BLANK_NODE_LABEL > |
::= | "_:" PN_LOCAL |
[74s] | <VAR1 > |
::= | "?" VARNAME |
[75s] | <VAR2 > |
::= | "$" VARNAME |
[76s] | <LANGTAG > |
::= | BASE |
[77s] | <INTEGER > |
::= | [0-9]+ |
[78s] | <DECIMAL > |
::= | [0-9]+ "." [0-9]* |
[79s] | <DOUBLE > |
::= | [0-9]+ "." [0-9]* EXPONENT |
[80s] | <INTEGER_POSITIVE > |
::= | "+" INTEGER |
[81s] | <DECIMAL_POSITIVE > |
::= | "+" DECIMAL |
[82s] | <DOUBLE_POSITIVE > |
::= | "+" DOUBLE |
[83s] | <INTEGER_NEGATIVE > |
::= | "-" INTEGER |
[84s] | <DECIMAL_NEGATIVE > |
::= | "-" DECIMAL |
[85s] | <DOUBLE_NEGATIVE > |
::= | "-" DOUBLE |
[86s] | <EXPONENT > |
::= | [eE] [+-]? [0-9]+ |
[87s] | <STRING_LITERAL1 > |
::= | "'" ( ( [^'\\\n\r] ) | ECHAR )* "'" |
[88s] | <STRING_LITERAL2 > |
::= | '"' ( ( [^\"\\\n\r] ) | ECHAR )* '"' |
[89s] | <STRING_LITERAL_LONG1 > |
::= | "'''" ( ( "'" | "''" )? ( [^'\\] | ECHAR ) )* "'''" |
[90s] | <STRING_LITERAL_LONG2 > |
::= | '"""' ( ( '"' | '""' )? ( [^\"\\] | ECHAR ) )* '"""' |
[91s] | <ECHAR > |
::= | "\\" [tbnrf\\\"'] |
[92s] | <NIL > |
::= | "(" (WS)* ")" |
[93s] | <WS > |
::= | " " |
[94s] | <ANON > |
::= | "[" (WS)* "]" |
[95s] | <PN_CHARS_BASE > |
::= | [A-Z] |
[96s] | <PN_CHARS_U > |
::= | PN_CHARS_BASE |
[97s] | <VARNAME > |
::= | ( PN_CHARS_U | [0-9] ) ( PN_CHARS_U | [0-9] | #00B7 | [#0300-#036F] | [#203F-#2040] )* |
[98s] | <PN_CHARS > |
::= | PN_CHARS_U |
[99s] | <PN_PREFIX > |
::= | PN_CHARS_BASE ( ( PN_CHARS | "." )* PN_CHARS )? |
[100s] | <PN_LOCAL > |
::= | ( PN_CHARS_U | [0-9] ) ( ( PN_CHARS | "." )* PN_CHARS )? |
[-] | PASSED TOKENS |
::= | [ \t\r\n]+ |
The RDF Concepts and Abstract Syntax ([RDF-CONCEPTS]) specification defines three types of RDF Term:
RDF URI References (here called IRIs),
literals and
blank nodes.
Literals are composed of a lexical form and an optional language tag or datatype IRI.
An extra type, prefix
, is used during parsing to map string identifiers to namespace IRIs.
This section maps a string conforming to the grammar in section 4.4 to a set of triples by mapping this strings matching productions and lexical tokens to these RDF terms or their components (e.g. language tags, lexical forms of literals). Some productions change the parser state (base or prefix declarations).
Parsing Turtle requires a state of four items:
baseURI
— When the base production is reached, the second rule argument, IRI_REF
, is the base URI used for relative IRI resolution (test: base1 base2).namespaces
— The second and third rule arguments (PNAME_NS
and IRI_REF
) in the prefixID production assign a namespace name (IRI_REF
) for the prefix (PNAME_NS
). Outside of a prefixID
production, any PNAME_NS
is substituted with the namespace (test: prefix1 escapedNamespace1). Note that the prefix may be an empty string, per the PNAME_NS,
production: (PN_PREFIX)? ":"
(test: default1).bnodeLabels
— A mapping from string to blank node label.curSubject
— The curSubject
is bound to the subject
production.curPredicate
— The curPredicate
is bound to the verb
production. If token matched was "a
", curPredicate
is bound to the IRI http://www.w3.org/1999/02/22-rdf-syntax-ns#type
(test: type).This table maps productions and lexical tokens to RDF terms
or components of RDF terms
listed in section 5:
production | type | procedure |
---|---|---|
IRI_REF | IRI | The characters between "<" and ">" are unescaped¹ to form the unicode string of the IRI. Relative IRI resolution is performed per SPARQL Query section 4.1.1. |
PNAME_NS | prefix | The potentially empty unicode string matching the first argument of the rule is a key into the namespaces map. |
PNAME_LN | IRI | A prefix is identified by the first argument, PNAME_NS . The namespaces map has a corresponding namespace . The unicode string of the IRI is formed by concatenating this namespace and the second argument, PN_LOCAL . Relative IRI resolution is performed per SPARQL Query section 4.1.1. |
STRING_LITERAL1 | lexical form | The characters between the outermost "'"s are unescaped¹ to form the unicode string of a lexical form. |
STRING_LITERAL2 | lexical form | The characters between the outermost '"'s are unescaped¹ to form the unicode string of a lexical form. |
STRING_LITERAL_LONG1 | lexical form | The characters between the outermost "'''"s are unescaped¹ to form the unicode string of a lexical form. |
STRING_LITERAL_LONG2 | lexical form | The characters between the outermost '"""'s are unescaped¹ to form the unicode string of a lexical form. |
LANGTAG | language tag | The characters following the "@" form the unicode string of the language tag. |
RDFLiteral | literal | The literal has a lexical form of the first rule argument (String ) and either a language tag of LANGTAG or a datatype URI of URIref , depending on which rule matched the input. |
INTEGER | literal | The literal has a lexical form of the input string, and a datatype of xsd:integer. |
DECIMAL | literal | The literal has a lexical form of the input string, and a datatype of xsd:decimal. |
DOUBLE | literal | The literal has a lexical form of the input string, and a datatype of xsd:double. |
BooleanLiteral | literal | The literal has a lexical form of the "true" or "false", depending on which matched the input, and a datatype of xsd:boolean. |
BLANK_NODE_LABEL | blank node | The string matching the second argument, PN_LOCAL , is a key in bnodeLabels. If there is no corresponding blank node in the map, one is allocated. |
ANON | blank node | A blank node is generated. |
blankNodePropertyList | blank node | A blank node is generated. Note the rules for blankNodePropertyList in the next section. |
collection | blank node | A blank node is generated. Note the rules for collection in the next section. |
¹ Section 3.3 defines an mapping from escaped unicode strings
to unicode strings
. The following lexical tokens are unescaped to produce unicode strings
: IRI_REF, STRING_LITERAL1, STRING_LITERAL2, STRING_LITERAL_LONG1 and STRING_LITERAL_LONG2.
A Turtle document defines an RDF graph composed of set of RDF triples.
Each object N
in the document produces an RDF triple: curSubject
curPredicate
N
.
Beginning the blankNodePropertyList
production records the curSubject
and curPredicate
, and sets curSubject
to a novel blank node
B
.
Finishing the blankNodePropertyList
production restores curSubject
and curPredicate
.
The node produced by matching blankNodePropertyList
is the blank node B
.
Beginning the collection
production records the curSubject
and curPredicate
, sets curSubject
to a novel blank node
Bhead
and sets curSubject
and curPredicate
to Bhead
and rdf:first
respectively.
Each object O
in collection
allocates a novel blank node
Bn
, creates an additional triple curSubject rdf:rest Bn
. and sets curSubject
to Bn
.
Finishing the collection
production creates an additional triple curSubject rdf:rest rdf:nil
. and restores curSubject
and curPredicate
The node produced by matching collection
is the blank node Bhead
.
The following informative example shows the semantic actions performed when parsing this Turtle document with an LALR1 parser:
@prefix ericFoaf: <http://www.w3.org/People/Eric/ericP-foaf.rdf#> . @prefix : <http://xmlns.com/foaf/0.1/> . ericFoaf:ericP :givenName "Eric" ; :knows <http://norman.walsh.name/knows/who/dan-brickley> , [ :mbox <mailto:timbl@w3.org> ] , <http://getopenid.com/amyvdh> .
ericFoaf
to the IRI http://www.w3.org/People/Eric/ericP-foaf.rdf#
.http://xmlns.com/foaf/0.1/
.curSubject
the IRI http://www.w3.org/People/Eric/ericP-foaf.rdf#ericP
.curPredicate
the IRI http://xmlns.com/foaf/0.1/givenName
.<...rdf#ericP>
<.../givenName>
"Eric"
.curPredicate
the IRI http://xmlns.com/foaf/0.1/knows
.<...rdf#ericP>
<.../knows>
<...who/dan-brickley>
.<...rdf#ericP>
<.../knows>
<_:1>
.curSubject
and reassign to the blank node <_:1>
.curPredicate
.curPredicate
the IRI http://xmlns.com/foaf/0.1/mbox
._:1
<.../mbox>
<mailto:timbl@w3.org>
.curSubject
and curPredicate
to their saved values (<...rdf#ericP>
, <.../knows>
).<...rdf#ericP>
<.../knows>
<http://getopenid.com/amyvdh>
.This example is a Turtle translation of example 7 in the RDF/XML Syntax specification (example1.ttl):
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix dc: <http://purl.org/dc/elements/1.1/> . @prefix ex: <http://example.org/stuff/1.0/> . <http://www.w3.org/TR/rdf-syntax-grammar> dc:title "RDF/XML Syntax Specification (Revised)" ; ex:editor [ ex:fullname "Dave Beckett"; ex:homePage <http://purl.org/net/dajobe/> ] .
An example of an RDF collection of two literals.
@prefix : <http://example.org/stuff/1.0/> . :a :b ( "apple" "banana" ) .
which is short for (example2.ttl):
@prefix : <http://example.org/stuff/1.0/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . :a :b [ rdf:first "apple"; rdf:rest [ rdf:first "banana"; rdf:rest rdf:nil ] ] .
An example of two identical triples containing literal objects containing newlines, written in plain and long literal forms. Assumes that line feeds in this document are #xA. (example3.ttl):
@prefix : <http://example.org/stuff/1.0/> . :a :b "The first line\nThe second line\n more" . :a :b """The first line The second line more""" .
As indicated by the grammar, a collection can be either a subject or an object. This subject or object will be the novel blank node for the first object, if the collection has one or more objects, or rdf:nil
if the collection is empty.
For example,
(1 2.0 3E1) :p "w" .
is syntactic sugar for (noting that the blank nodes b0
, b1
and b2
do not occur anywhere else in the RDF graph):
_:b0 rdf:first 1 ; rdf:rest _:b1 . _:b1 rdf:first 2.0 ; rdf:rest _:b2 . _:b2 rdf:first 3E1 ; rdf:rest rdf:nil . _:b0 :p "w" .
RDF collections can be nested and can involve other syntactic forms:
(1 [:p :q] ( 2 ) ) .
is syntactic sugar for:
_:b0 rdf:first 1 ; rdf:rest _:b1 . _:b1 rdf:first _:b2 . _:b2 :p :q . _:b1 rdf:rest _:b3 . _:b3 rdf:first _:b4 . _:b4 rdf:first 2 ; rdf:rest rdf:nil . _:b3 rdf:rest rdf:nil .
The URI that identifies the Turtle language is:
http://www.w3.org/2008/turtle#turtle
The XML (Namespace name, Local name) pair that identifies
the Turtle language is:
Namespace: http://www.w3.org/2008/turtle#
Local name: turtle
The suggested namespace prefix is ttl
(informative)
which would make this ttl:turtle
as an XML QName.
Systems conforming to Turtle MUST pass all the following test cases:
Passing these tests means:
test-n.ttl
tests MUST generate equivalent RDF
triples to those given in the corresponding test-n.out
N-Triples file.bad-n.ttl
tests MUST NOT generate RDF triples.The media type of Turtle is text/turtle
.
The content encoding of Turtle content is always UTF-8.
Charset parameters on the mime type are required until such time as the text/ media type tree permits UTF-8 to be sent without a charset parameter.
See B. Internet Media Type, File Extension and Macintosh File Type for the media type registration form.
Turtle adds the following syntax to N-Triples:
@base
directive for setting a base IRI@prefix
directive for assigning namespace prefixes,
;
[]
rdf:type
shorthand a
()
sxsd:integer
xsd:double
xsd:decimal
xsd:boolean
Notation 3 (N3) triples are a superset of RDF triples.
In particular, N3 formulae (graphs) may be the subject or object of N3 triples.
For example here, the formula with _:Bob a foaf:Person
is the object of another arc:
_:Bob ex:said { _:Bob a foaf:Person } .
Following is a partial list of syntactic features in N3 which are not in Turtle:
{
... }
is
of
:a.:b.:c
and :a^:b^:c
@keywords
=>
implies=
equivalence@forAll
@forSome
The SPARQL Query Language for RDF (SPARQL) [SPARQLQ] uses a Turtle/N3 style syntax for its TriplesBlock production. This production differs from the Turtle langage in that:
?
name or $
name) in any part of the triple of the formFor further information see the Syntax for IRIs and SPARQL Grammar sections of the SPARQL query document [SPARQLQ].
The Internet Media Type / MIME Type for Turtle is "text/turtle".
It is recommended that Turtle files have the extension ".ttl" (all lowercase) on all platforms.
It is recommended that Turtle files stored on Macintosh HFS file systems be given a file type of "TEXT".
This information that follows has been submitted to the IESG for review, approval, and registration with IANA.
This work was described in the paper New Syntaxes for RDF which discusses other RDF syntaxes and the background to the Turtle (Submitted to WWW2004, referred to as N-Triples Plus there).
This work was started during the Semantic Web Advanced Development Europe (SWAD-Europe) project funded by the EU IST-7 programme IST-2001-34732 (2002-2004) and further development supported by the Institute for Learning and Research Technology at the University of Bristol, UK (2002-Sep 2005).
Changes since the last publication of this document W3C Turtle Submission 2008-01-14 . See the Previous changelog for further information
true
and false
.ex:first.name
.ex:7tm
.