index.html 54.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Turtle - Terse RDF Triple Language</title>
<style type="text/css">
/*<![CDATA[*/
.grammar
                { /* border: thin solid #888888; */ font-size: 88% ;
 /*                 padding: 1ex 2ex 1ex 2ex ; *//* top, right, bottom, left */
 /*                 margin: 1em 6em 1em 2em ;  */
                  page-break-inside: avoid ;
                  background-color: #F8F8F8 ; }
/*]]>*/
</style>
    <link rel="stylesheet" type="text/css" href="style.css" />
    <link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-Team-SUBM" />
</head>
<body>

<div class="head">
  <p><a href="http://www.w3.org/"><img height="48" width="72" alt="W3C" src="http://www.w3.org/Icons/w3c_home"/></a> 
     <a href="http://www.w3.org/TeamSubmission/"><img height="48" width="211" alt="W3C Team Submission" src="http://www.w3.org/Icons/team_subm"/></a></p>

<h1 id="main">Turtle - Terse RDF Triple Language</h1>
<h2>W3C Team Submission 28 March 2011</h2>

<dl>
<dt>This version:</dt>
<dd><a href="http://www.w3.org/TeamSubmission/2011/SUBM-turtle-20110328/">http://www.w3.org/TeamSubmission/2011/SUBM-turtle-20110328/</a></dd>
<dt>Latest version:</dt>
<dd><a href="http://www.w3.org/TeamSubmission/turtle/">http://www.w3.org/TeamSubmission/turtle/</a></dd>
<dt>Previous version:</dt>
<dd><a href="http://www.w3.org/TeamSubmission/2008/SUBM-turtle-20080114/">http://www.w3.org/TeamSubmission/2008/SUBM-turtle-20080114/</a></dd>
<dt>Authors:</dt>
<dd><a href="http://purl.org/net/dajobe/">David Beckett</a><br /><a href="http://www.w3.org/People/Berners-Lee/">Tim Berners-Lee</a> W3C</dd>
</dl>

<p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> &copy; 2008 <a href="http://www.w3.org/"><acronym title="World Wide Web Consortium">W3C</acronym></a><sup>&reg;</sup> (<a href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute of Technology">MIT</acronym></a>, <a href="http://www.ercim.org/"><acronym title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>, <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply.</p>
</div>


<hr title="Separator for header" />
<div>
  <h2 class="notoc" id="abstract">Abstract</h2>

  <p>The Resource Description Framework
  (<abbr title="Resource Description Framework">RDF</abbr>) is a 
  general-purpose language for representing information in the Web.</p>

  <p>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
  <a href="http://www.w3.org/TR/rdf-testcases/#ntriples">N-Triples</a>
  and
  <a href="http://www.w3.org/DesignIssues/Notation3">Notation 3</a> 
  formats as well as the triple pattern syntax of the
  <a href="http://www.w3.org/TR/2007/PR-rdf-sparql-query-20071112/">SPARQL</a>
  W3C Proposed Recommendation.
  </p>

      <p>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, <a href="">Notation 3</a>.</p>

</div>


<div>
<h2 class="status" id="status">Status of this Document</h2>

<p><em>This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications can be found in the <a href="http://www.w3.org/TR/">W3C technical reports index</a>  at http://www.w3.org/TR/.</em></p>

      <p>This 14 January 2008 <a href="http://www.w3.org/TeamSubmission/">W3C Team Submission</a> documents the currently deployed <em>Turtle</em> language, an alternative syntax to RDF/XML.</p>

<p>By publishing this document, David Beckett and Tim Berners-Lee have made a formal submission to W3C for discussion. Publication of this document by W3C indicates no endorsement of its content by W3C, nor that W3C has, is, or will be allocating any resources to the issues addressed by it. This document is not the product of a chartered W3C group, but is published as potential input to the W3C Process. Please consult the <a href="/view=Medium/www.w3.org/TeamSubmission">complete list of acknowledged W3C Team Submissions</a>.</p>

</div>

<hr />

<div class="toc">
  <h2 id="contents">Table of Contents</h2>

  <ul class="toc">
    <li class="tocline1">1. <a href="#sec-intro">Introduction</a></li>
    <li class="tocline1">2. <a href="#sec-tutorial">Turtle Syntax</a></li>
    <li class="tocline1">3. <a href="#sec-grammar">Turtle Grammar</a></li>
    <li class="tocline2">3.1 <a href="#sec-grammar-ws">White Space</a></li>
    <li class="tocline2">3.2 <a href="#sec-grammar-comments">Comments</a></li>
    <li class="tocline2">3.3 <a href="#sec-strings">String Escapes</a></li>
    <li class="tocline2">3.4 <a href="#sec-uris">URI References</a></li>
    <li class="tocline2">3.5 <a href="#sec-collections">Collections</a></li>
    <li class="tocline2">3.6 <a href="#sec-grammar-grammar">Grammar</a></li>
    <li class="tocline1">4. <a href="#sec-examples">Examples</a></li>
    <li class="tocline1">5. <a href="#sec-identifiers">Identifiers for the Turtle Language</a></li>
    <li class="tocline1">6. <a href="#sec-conformance">Conformance</a></li>
    <li class="tocline1">7. <a href="#sec-mime">Media Type and Content Encoding</a></li>
    <li class="tocline1">8. <a href="#sec-diff-ntriples">Turtle compared to N-Triples</a></li>
    <li class="tocline1">9. <a href="#sec-diff-n3">Turtle compared to Notation3</a></li>
    <li class="tocline1">10. <a href="#sec-diff-sparql">Turtle compared to SPARQL</a></li>
    <li class="tocline1">A. <a href="#sec-refs">References</a></li>
    <li class="tocline2">A.1 <a href="#sec-refs-normative">Normative</a></li>
    <li class="tocline2">A.2 <a href="#sec-refs-informative">Informative</a></li>
    <li class="tocline1">B. <a href="#sec-mediaReg">Internet Media Type, File Extension and Macintosh File Type</a></li>
    <li class="tocline1">C. <a href="#sec-acks">Acknowledgements</a></li>
    <li class="tocline1">D. <a href="#sec-changelog">Changes</a></li>
  </ul>

</div>

<hr />

<h2 id="sec-intro">1. Introduction</h2>


<p>This document defines Turtle, the Terse RDF Triple Language,
a concrete syntax for RDF as defined in the
<a href="http://www.w3.org/TR/rdf-concepts/">RDF Concepts and Abstract Syntax</a>
(<a href="#ref-rdf-concepts">[RDF-CONCEPTS]</a>) W3C Recommendation.
Turtle is an extension of 
<a href="http://www.w3.org/TR/rdf-testcases/#ntriples">N-Triples</a>
(<a href="#ref-ntriples">[N-TRIPLES]</a>)
carefully taking the most useful and appropriate things added from
<a href="http://www.w3.org/DesignIssues/Notation3">Notation 3</a>
(<a href="#ref-n3">[NOTATION3]</a>)
while keeping it in the RDF model.</p>

<p>The recommended XML syntax for RDF,
<a href="http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/">RDF/XML</a>
(<a href="#ref-rdfxml">[RDF-XML]</a>)
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.</p>

    <p>Turtle is intended to be compatible with, and a subset of, <a href="">Notation 3</a> (see 
<a href="#sec-diff-n3">Turtle compared to Notation 3</a>), and is generally usable in systems that support N3.</p>

<p>All RDF written in Turtle should be usable inside the query
language part of the
<a href="http://www.w3.org/TR/2007/PR-rdf-sparql-query-20071112/">SPARQL Protocol And RDF Query Language</a>
(<acronym title="SPARQL Protocol And RDF Query Language">SPARQL</acronym>)
<a href="#ref-sparqlq">[SPARQLQ]</a>
which uses a Turtle/N3 style syntax for the Triple patterns and
for RDF triples in the <code>CONSTRUCT</code> clause.  This allows
using RDF written in Turtle to allow forming "queries by example",
using the data to make an initial query which can then be edited to
use variables where bindings are wanted.
</p>


<h2 id="sec-tutorial">2. Turtle Syntax (Informative)</h2>

<p>This section is informative.  In case of disagreement, the
<a href="#sec-grammar">Turtle Grammar</a> section is definitive.
</p>

<p>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 <code>#</code>
and continue to the end of the line.</p>

<p>Simple triples are a sequence of (subject, predicate, object)
terms, separated by whitespace and terminated by '.' after each
triple.  This corresponds to
<a href="http://www.w3.org/TR/rdf-testcases/#ntriples">N-Triples</a>
(<a href="#ref-ntriples">[N-TRIPLES]</a>).
</p>

<p>There are three types of <em>RDF Term</em>:
<a href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-URI-reference">RDF URI References</a> (URIs for short),
<a href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-literal">literals</a> and
<a href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-blank-node">blank nodes</a>.</p>

<h3 id="terms">2.1. RDF Terms</h3>

<p>URIs are written enclosed in '&lt;' and '&gt;' and may be
absolute RDF URI References or relative to the current base URI
(described below).
</p>

<pre class="example">
# this is not a complete turtle document
&lt;http://example.org/path/&gt;
&lt;http://example.org/path/#fragment&gt;
&lt;/path&gt;
&lt;#fragment&gt;
&lt;&gt;
</pre>

<p>URIs may also be abbreviated by using Turtle's <code>@prefix</code>
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.</p>

<p>Once a prefix such as <code>@prefix foo:
&lt;http://example.org/ns#&gt;</code> is defined, any mention of a
URI later in the document may use a <em>qualified name</em> that
starts <code>foo:</code> to stand for the longer URI.  So for
example, the qualified name <code>foo:bar</code> is a shorthand for
the URI <code>http://example.org/ns#bar</code>.</p>

<pre class="example">
# this is a complete turtle document
@prefix foo: &lt;http://example.org/ns#&gt; .
@prefix : &lt;http://other.example.org/ns#&gt; .
foo:bar foo: : .
:bar : foo:bar .
</pre>

<p>Literals are written either using double-quotes when they do not
contain linebreaks like <code>"simple literal"</code> or
<code>"""long literal"""</code> when they may contain linebreaks.
</p>

<pre class="example">
# this is not a complete turtle document
"a string"
"""a string"""
"""a string
with newlines
"""
</pre>

<p>Literals may be given either a language suffix or a datatype URI
but not both.  Languages are indicated by appending the simple
literal with <code>@</code> and the language tag.  Datatype URIs
similarly append <code>^^</code> followed by any legal URI form (full
or qualified) as described above to give the datatype URI.
</p>

<pre class="example">
# this is not a complete turtle document
"chat"
"chat"@en
"chat"@fr
"foo"^^&lt;http://example.org/my/datatype&gt;
"""10"""^^xsd:decimal
</pre>

<p>Blank nodes are written as <code>_:</code><em>nodeID</em>
to provide a blank node either from the given <a href="#nodeID">nodeID</a>.
A generated blank node may also be made with <code>[]</code>
which is useful to provide the subject of RDF triples for
each pair from the <a href="#predicateObjectList">predicateObjectList</a>
or the root of the <a href="#collection">collection</a>.
</p>

<pre class="example">
# this is not a complete turtle document
_:me
_:a1234
</pre>


<p>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:</p>
<ul>
<li><code>\t</code> (U+0009, tab)</li>
<li><code>\n</code> (U+000A, linefeed)</li>
<li><code>\r</code> (U+000D, carriage return)</li>
<li><code>\"</code> (U+0022, double quote - only allowed inside <a href="#quotedString">strings</a>)</li>
<li><code>\></code> (U+003E, greater than - only allowed inside <a href="#relativeURI">URIs</a>)</li>
<li><code>\\</code> (U+005C, backslash)</li>
<li>
<code>\u</code><em>HHHH</em> or
<code>\U</code><em>HHHHHHHH</em>
for writing Unicode characters by hexadecimal codepoint where
<em>H</em> is a single hexadecimal digit.
</li>
</ul>
<p>See the <a href="#sec-strings">String escapes</a> section for full details.</p>


<h3 id="uris">2.2. Abbreviating URIs</h3>

<p>The current base URI may be altered in a Turtle document using the
<code>@base</code> 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.</p>

<p>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.
</p>

<pre class="example">
# this is a complete turtle document
# In-scope base URI is the document URI at this point
&lt;a1&gt; &lt;b1&gt; &lt;c1&gt; .
@base &lt;http://example.org/ns/&gt; .
# In-scope base URI is http://example.org/ns/ at this point
&lt;a2&gt; &lt;http://example.org/ns/b2&gt; &lt;c2&gt; .
@base &lt;foo/&gt; .
# In-scope base URI is http://example.org/ns/foo/ at this point
&lt;a3&gt; &lt;b3&gt; &lt;c3&gt; .
@prefix : &lt;bar#&gt; .
:a4 :b4 :c4 .
@prefix : &lt;http://example.org/ns2#&gt; .
:a5 :b5 :c5 .
</pre>


<p>The token <code>a</code> is equivalent to the URI
<code>&lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&gt;</code>
</p>

<pre class="example">
# this is a complete turtle document
@prefix doc: &lt;http://example.org/#ns&gt; .
&lt;http://example.org/path&gt; a doc:Document .
</pre>


<h3 id="groups">2.3. Abbreviating groups of triples</h3>

<p>The <code>,</code> symbol may be used to repeat the subject and
predicate of triples that only differ in the object RDF term.</p>

<pre class="example">
# this is not a complete turtle document
:a :b :c ,
      :d .
# the last triple is :a :b :d .
</pre>

<p>The <code>;</code> symbol may be used to repeat the subject of
of triples that vary only in predicate and object RDF terms.</p>

<pre class="example">
# this is not a complete turtle document
:a :b :c ;
   :d :e .
# the last triple is :a :d :e .
</pre>


<h3 id="abbrev">2.4. Abbreviating common datatypes</h3>

<p>Decimal integers may be written directly and correspond to
the XML Schema Datatype
<a href="http://www.w3.org/TR/xmlschema-2/#integer">xsd:integer</a>.
in both syntax and datatype URI.</p>

<pre class="example">
# this is not a complete turtle document
-5
0
1
10
+1
# some long form examples
"-5"^^xsd:integer
"10"^^&lt;http://www.w3.org/2001/XMLSchema#integer&gt;
</pre>

<p>Decimal floating point double/fixed precision numbers may be written
directly and correspond to the XML Schema Datatype
<a href="http://www.w3.org/TR/xmlschema-2/#integer">xsd:double</a>
in both syntax and datatype URI.
</p>

<pre class="example">
# this is not a complete turtle document
1.3e2
10e0
-12.5e10
# some long form examples
"1.3e2"^^xsd:double
"-12.5e10"^^&lt;http://www.w3.org/2001/XMLSchema#double&gt;
</pre>

<p>Decimal floating point arbitrary precision numbers may be written
directly and correspond to the XML Schema Datatype
<a href="http://www.w3.org/TR/xmlschema-2/#integer">xsd:decimal</a>.
in both syntax and datatype URI.
</p>

<pre class="example">
# 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"^^&lt;http://www.w3.org/2001/XMLSchema#decimal&gt;
</pre>

<p>Boolean may be written directly as <code>true</code> or
<code>false</code> and correspond to the
the XML Schema Datatype
<a href="http://www.w3.org/TR/xmlschema-2/#boolean">xsd:boolean</a>
in both syntax and datatype URI.
</p>

<pre class="example">
# this is not a complete turtle document
true
false
# same in long form
"true"^^xsd:boolean
"false"^^&lt;http://www.w3.org/2001/XMLSchema#boolean&gt;
</pre>

<h3 id="collections">2.5. Abbreviating RDF Collections</h3>

<p>An RDF Collection may be abbreviated using a sequence of
RDF Terms enclosed in <code>( )</code> 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.
</p>

<pre class="example">
# this is a complete turtle document
@prefix : &lt;http://example.org/foo&gt; .
# the value of this triple is the RDF collection blank node
:subject :predicate ( :a : b : c ) .

# an empty collection value - rdf:nil
:subject :predicate2 () .
</pre>

<p>See section <a href="#sec-collections">Collections</a> for
the details on the long form of the generated triples.
</p>

<h2 id="sec-grammar">3. Turtle Grammar</h2>

<p>A Turtle document is a
Unicode<cite><a href="#Unicode">[UNICODE]</a></cite>
character string encoded in UTF-8.
Unicode codepoints only in the range U+0 to U+10FFFF inclusive are
allowed.
</p>


<h3 id="sec-grammar-ws">3.1 White Space</h3>

<p>White space (production <a href="#ws">ws</a>) is used to separate
two tokens which would otherwise be (mis-)recognized as one token.
</p>

<p>White space is significant in tokens
<a href="#relativeURI">relativeURI</a>, <a href="#string">string</a>
and <a href="#longString">longString</a>.
</p>


<h3 id="sec-grammar-comments">3.2 Comments</h3>

<p>Comments in Turtle take the form of '#', outside an
<a href="#relativeURI">relativeURI</a> 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 and defined by token
<a href="#comment">comment</a>.
</p>

<h3 id="sec-strings">3.3. String Escapes</h3>

<p>Turtle strings and URIs can use <code>\</code>-escape sequences to
represent Unicode code points.</p>


<p>The following table describes all the escapes
allowed inside a <a href="#string">string</a>, 
<a href="#longString">longString</a>
or <a href="#relativeURI">relativeURI</a>:</p>

  <table border="1" summary="Turtle string escapes">
    <tbody>
      <tr>
        <th>Escape</th>

        <th>Unicode code point</th>

      </tr>

      <tr>
        <td>'\u' <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a></td>
        <td>A Unicode codepoint in the range U+0 to U+FFFF inclusive
	corresponding to the encoded hexadecimal value.</td>
      </tr>
		      		       		       		       
      <tr>
        <td>'\U' <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a></td>
        <td>A Unicode codepoint in the range U+10000 to U+10FFFF inclusive
	corresponding to the encoded hexadecimal value.</td>
      </tr>

      <tr>
        <td>'\t'</td>
        <td>U+0009</td>
      </tr>
		      		       		       		       
      <tr>
        <td>'\n'</td>
        <td>U+000A</td>
      </tr>
		      		       		       		       
      <tr>
        <td>'\r'</td>
        <td>U+000D</td>
      </tr>
		      		       		       		       
      <tr>
        <td>'\"'<br />
 (inside <a href="#string">string</a> and
<a href="#longString">longString</a>)</td>
      <td>U+0022</td>
      </tr>
		      		       		       		       
      <tr>
        <td>'\>'<br />
 (inside <a href="#relativeURI">relativeURI</a> only)</td>
        <td>U+003E</td>
      </tr>
		      		       		       		       
      <tr>
        <td>'\\'</td>
        <td>U+005C</td>
      </tr>
		      		       		       		       
    </tbody>
  </table>


<h3 id="sec-uris">3.4. URI References</h3>

<p>URIs are resolved relative to the <em>In-scope base URI</em>.
</p>

<p>The starting <em>In-Scope Base URI</em> is defined using
the Base URI mechanism defined in the URI RFC - dependent
on the protocol or other context outside the document.
During turtle parsing, the in-scope base URI at any point in
the document is determined by the 
<a href="#base"><code>@base</code></a> directive
which sets a new base URI relative to the current in-scope base URI.
This directive may be repeated.
</p>

<p>Example (<a href="tests/test-30.ttl">test-30.ttl</a>) with document base URI 
http://www.w3.org/2001/sw/DataAccess/df1/tests/</p>
<pre class="example">
# In-scope base URI is http://www.w3.org/2001/sw/DataAccess/df1/tests/ at this point
&lt;test-00.ttl&gt; &lt;test-01.ttl&gt; &lt;test-02.ttl&gt; .
@base &lt;http://example.org/ns/&gt; .
# In-scope base URI is http://example.org/ns/ at this point
&lt;a2&gt; &lt;http://example.org/ns/b2&gt; &lt;c2&gt; .
@base &lt;foo/&gt; .
# In-scope base URI is http://example.org/ns/foo/ at this point
&lt;a3&gt; &lt;b3&gt; &lt;c3&gt; .
@prefix : &lt;bar#&gt; .
:a4 :b4 :c4 .
@prefix : &lt;http://example.org/ns2#&gt; .
:a5 :b5 :c5 .
</pre>
<p>encodes the following N-Triples
(<a href="tests/test-30.out">test-30.out</a>):
</p>
<pre class="example">
&lt;http://www.w3.org/2001/sw/DataAccess/df1/tests/test-00.ttl&gt; &lt;http://www.w3.org/2001/sw/DataAccess/df1/tests/test-01.ttl&gt; &lt;http://www.w3.org/2001/sw/DataAccess/df1/tests/test-02.ttl&gt; .
&lt;http://example.org/ns/a2&gt; &lt;http://example.org/ns/b2&gt; &lt;http://example.org/ns/c2&gt; .
&lt;http://example.org/ns/foo/a3&gt; &lt;http://example.org/ns/foo/b3&gt; &lt;http://example.org/ns/foo/c3&gt; .
&lt;http://example.org/ns/foo/bar#a4&gt; &lt;http://example.org/ns/foo/bar#b4&gt; &lt;http://example.org/ns/foo/bar#c4&gt; .
&lt;http://example.org/ns2#a5&gt; &lt;http://example.org/ns2#b5&gt; &lt;http://example.org/ns2#c5&gt; .
</pre>


<h3 id="sec-collections">3.5. Collections</h3>

<p>The triples that are generated by the <a href="#collection">collection</a>
term is given by these expansions to the longer triples form:</p>

<p>( <em>object1</em> <em>object2</em> ) is short for:<br />
[ <code>rdf:first</code> <em>object1</em>;
<code>rdf:rest</code> [ <code>rdf:first</code> <em>object2</em>;
<code>rdf:rest</code> <code>rdf:nil</code> ] ]</p>

<p><code>( )</code> is short for the resource:<br />
<code>rdf:nil</code><br />
</p>



<h3 id="sec-grammar-grammar">3.6 Grammar</h3>

<p>The EBNF used here is defined in XML 1.0 (Third Edition)
<a href="#ref-notation">[NOTATION]</a>
</p>

<table class="grammar" summary="Turtle - Terse RDF Triple Language EBNF">
   <caption>Turtle - Terse RDF Triple Language EBNF</caption>
   <tbody>
<tr align="left">
          <td class="cell">[1]</td><td class="topcell"><a name="ntriplesPlusDoc"></a><a name="turtleDoc">turtleDoc</a></td> <td class="topcell">::=</td> <td class="topcell"><a href="#statement">statement</a>*</td>
</tr>

<tr align="left">
          <td class="cell">[2]</td><td class="cell"><a name="statement">statement</a></td> <td class="cell">::=</td> <td class="cell"><a href="#directive">directive</a>  '.'  | <a href="#triples">triples</a>  '.'  | <a href="#ws">ws</a>+</td>
</tr>

<tr align="left">
          <td class="cell">[3]</td><td class="cell"><a name="directive">directive</a></td> <td class="cell">::=</td> <td class="cell"><a href="#prefixID">prefixID</a> | <a href="#base">base</a></td>
</tr>

<tr align="left">
          <td class="cell">[4]</td><td class="cell"><a name="prefixID">prefixID</a></td> <td class="cell">::=</td> <td class="cell">'@prefix' <a href="#ws">ws</a>+ <a href="#prefixName">prefixName</a>? ':' <a href="#uriref">uriref</a></td>
</tr>

<tr align="left">
          <td class="cell">[5]</td><td class="cell"><a name="base">base</a></td> <td class="cell">::=</td> <td class="cell">'@base' <a href="#ws">ws</a>+ <a href="#uriref">uriref</a></td>
</tr>

<tr align="left">
          <td class="cell">[6]</td><td class="cell"><a name="triples" id="triples">triples</a></td> <td class="cell">::=</td> <td class="cell"><a href="#subject">subject</a> <a href="#predicateObjectList">predicateObjectList</a></td>
</tr>

<tr align="left">
          <td class="cell">[7]</td><td class="cell"><a name="predicateObjectList">predicateObjectList</a></td> <td class="cell">::=</td> <td class="cell"><a href="#verb">verb</a> <a href="#objectList">objectList</a> (  ';'  <a href="#verb">verb</a> <a href="#objectList">objectList</a> )* ( ';')?</td>
</tr>

<tr align="left">
          <td class="cell">[8]</td><td class="cell"><a name="objectList">objectList</a></td> <td class="cell">::=</td> <td class="cell"><a href="#object">object</a> ( ','  <a href="#object">object</a>)*</td>
</tr>

<tr align="left">
          <td class="cell">[9]</td><td class="cell"><a name="verb">verb</a></td> <td class="cell">::=</td> <td class="cell"><a href="#predicate">predicate</a> | 'a'</td>
</tr>

<tr align="left">
          <td class="cell">[10]</td><td class="cell"><a name="comment">comment</a></td> <td class="cell">::=</td> <td class="cell">'#' ( [^#xA#xD] )*</td>
</tr>

<tr align="left">
          <td class="cell">[11]</td><td class="cell"><a name="subject">subject</a></td> <td class="cell">::=</td> <td class="cell"><a href="#resource">resource</a> | <a href="#blank">blank</a></td>
</tr>

<tr align="left">
          <td class="cell">[12]</td><td class="cell"><a name="predicate">predicate</a></td> <td class="cell">::=</td> <td class="cell"><a href="#uriref">resource</a></td>
</tr>

<tr align="left">
          <td class="cell">[13]</td><td class="cell"><a name="object">object</a></td> <td class="cell">::=</td> <td class="cell"><a href="#resource">resource</a> | <a href="#blank">blank</a> | <a href="#literal">literal</a></td>
</tr>

<tr align="left">
          <td class="cell">[14]</td><td class="cell"><a name="literal">literal</a></td> <td class="cell">::=</td> <td class="cell"><a href="#quotedString">quotedString</a> ( '@' <a href="#language">language</a> )? | <a href="#datatypeString">datatypeString</a> | <a href="#integer">integer</a> | <a href="#double">double</a> | <a href="#decimal">decimal</a> | <a href="#boolean">boolean</a></td>
</tr>

<tr align="left">
          <td class="cell">[15]</td><td class="cell"><a name="datatypeString">datatypeString</a></td> <td class="cell">::=</td> <td class="cell"><a href="#quotedString">quotedString</a> '^^' <a href="#resource">resource</a></td>
</tr>

<tr align="left">
          <td class="cell">[16]</td><td class="cell"><a name="integer">integer</a></td> <td class="cell">::=</td> <td class="cell">('-' | '+') ? [0-9]+</td>
</tr>

<tr align="left">
          <td class="cell">[17]</td><td class="cell"><a name="double">double</a></td> <td class="cell">::=</td> <td class="cell">('-' | '+') ? ( [0-9]+ '.' [0-9]* <a href="#exponent">exponent</a> | '.' ([0-9])+ <a href="#exponent">exponent</a> | ([0-9])+ <a href="#exponent">exponent</a> )</td>
</tr>

<tr align="left">
          <td class="cell">[18]</td><td class="cell"><a name="decimal">decimal</a></td> <td class="cell">::=</td> <td class="cell">('-' | '+')? ( [0-9]+ '.' [0-9]* | '.' ([0-9])+ | ([0-9])+ )</td>
</tr>

<tr align="left">
          <td class="cell">[19]</td><td class="cell"><a name="exponent">exponent</a></td> <td class="cell">::=</td> <td class="cell">[eE] ('-' | '+')? [0-9]+</td>
</tr>

<tr align="left">
          <td class="cell">[20]</td><td class="cell"><a name="boolean">boolean</a></td> <td class="cell">::=</td> <td class="cell">'true' | 'false'</td>
</tr>

<tr align="left">
          <td class="cell">[21]</td><td class="cell"><a name="blank">blank</a></td> <td class="cell">::=</td> <td class="cell"><a href="#nodeID">nodeID</a> | '[]' | '['  <a href="#predicateObjectList">predicateObjectList</a>  ']' | <a href="#collection">collection</a></td>
</tr>

<tr align="left">
          <td class="cell">[22]</td><td class="cell"><a name="itemList">itemList</a></td> <td class="cell">::=</td> <td class="cell"><a href="#object">object</a>+</td>
</tr>

<tr align="left">
          <td class="cell">[23]</td><td class="cell"><a name="collection">collection</a></td> <td class="cell">::=</td> <td class="cell">'('  <a href="#itemList">itemList</a>?  ')'</td>
</tr>

<tr align="left">
          <td class="cell">[24]</td><td class="cell"><a name="ws">ws</a></td> <td class="cell">::=</td> <td class="cell">#x9 | #xA | #xD | #x20 | <a href="#comment">comment</a> </td>
</tr>

<tr align="left">
          <td class="cell">[25]</td><td class="cell"><a name="resource">resource</a></td> <td class="cell">::=</td> <td class="cell"><a href="#uriref">uriref</a> | <a href="#qname">qname</a></td>
</tr>

<tr align="left">
          <td class="cell">[26]</td><td class="cell"><a name="nodeID">nodeID</a></td> <td class="cell">::=</td> <td class="cell">'_:' <a href="#name">name</a></td>
</tr>

<tr align="left">
          <td class="cell">[27]</td><td class="cell"><a name="qname">qname</a></td> <td class="cell">::=</td> <td class="cell"><a href="#prefixName">prefixName</a>? ':' <a href="#name">name</a>?</td>
</tr>

<tr align="left">
          <td class="cell">[28]</td><td class="cell"><a name="uriref">uriref</a></td> <td class="cell">::=</td> <td class="cell">'&lt;' <a href="#relativeURI">relativeURI</a> '&gt;'
</td>
</tr>

<tr align="left">
          <td class="cell">[29]</td><td class="cell"><a name="language">language</a></td> <td class="cell">::=</td> <td class="cell">[a-z]+ ('-' [a-z0-9]+ )*
</td>
</tr>

<tr align="left">
          <td class="cell">[30]</td><td class="cell"><a name="nameStartChar">nameStartChar</a></td> <td class="cell">::=</td> <td class="cell">[A-Z] | "_" | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]</td>
</tr>

<tr align="left">
          <td class="cell">[31]</td><td class="cell"><a name="nameChar">nameChar</a></td> <td class="cell">::=</td> <td class="cell"><a href="#nameStartChar">nameStartChar</a> | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]</td>
</tr>

<tr align="left">
          <td class="cell">[32]</td><td class="cell"><a name="name">name</a></td> <td class="cell">::=</td> <td class="cell"><a href="#nameStartChar">nameStartChar</a> <a href="#nameChar">nameChar</a>*</td>
</tr>

<tr align="left">
          <td class="cell">[33]</td><td class="cell"><a name="prefixName">prefixName</a></td> <td class="cell">::=</td> <td class="cell">( <a href="#nameStartChar">nameStartChar</a> - '_' ) <a href="#nameChar">nameChar</a>*</td>
</tr>

<tr align="left">
          <td class="cell">[34]</td><td class="cell"><a name="relativeURI">relativeURI</a></td> <td class="cell">::=</td> <td class="cell">
<a href="#ucharacter">ucharacter</a>*</td>
</tr>

<tr align="left">
          <td class="cell">[35]</td><td class="cell"><a name="quotedString">quotedString</a></td> <td class="cell">::=</td> <td class="cell"><a href="#string">string</a> | <a href="#longString">longString</a></td>
</tr>

<tr align="left">
          <td class="cell">[36]</td><td class="cell"><a name="string">string</a></td> <td class="cell">::=</td> <td class="cell">#x22 <a href="#scharacter">scharacter</a>* #x22</td>
</tr>

<tr align="left">
          <td class="cell">[37]</td><td class="cell"><a name="longString">longString</a></td> <td class="cell">::=</td> <td class="cell">#x22 #x22 #x22 <a href="#lcharacter">lcharacter</a>* #x22 #x22 #x22</td>
</tr>

<tr align="left">
          <td class="cell">[38]</td><td class="cell"><a name="character">character</a></td> <td class="cell">::=</td> <td class="cell">
'\u' <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> |<br />
'\U' <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> <a href="#hex">hex</a> |<br />
'\\' |<br />
[#x20-#x5B] | [#x5D-#x10FFFF]
</td>
</tr>

<tr align="left">
          <td class="cell">[39]</td><td class="cell"><a name="echaracter">echaracter</a></td> <td class="cell">::=</td> <td class="cell"><a href="#character">character</a> |
'\t' | '\n' | '\r'
</td>
</tr>

<tr align="left">
          <td class="cell">[40]</td><td class="cell"><a name="hex">hex</a></td> <td class="cell">::=</td> <td class="cell">[#x30-#x39] | [#x41-#x46]</td>
</tr>

<tr align="left">
          <td class="cell">[41]</td><td class="cell"><a name="ucharacter">ucharacter</a></td> <td class="cell">::=</td> <td class="cell">
( <a href="#character">character</a> - #x3E ) | '\>'
</td>
</tr>

<tr align="left">
          <td class="cell">[42]</td><td class="cell"><a name="scharacter">scharacter</a></td> <td class="cell">::=</td> <td class="cell">
( <a href="#echaracter">echaracter</a> - #x22 ) | '\"'
</td>
</tr>

<tr align="left">
          <td class="cell">[43]</td><td class="cell"><a name="lcharacter">lcharacter</a></td> <td class="cell">::=</td> <td class="cell">
<a href="#echaracter">echaracter</a> | '\"' | #x9 | #xA | #xD
</td>
</tr>

      </tbody>
    </table>


<h2 id="sec-examples">4. Examples</h2>

<p>This example is a Turtle translation of 
<a href="http://www.w3.org/TR/rdf-syntax-grammar/#example7">example 7</a>
in the
<a href="http://www.w3.org/TR/rdf-syntax-grammar/">RDF/XML Syntax specification</a>
(<a href="example1.ttl">example1.ttl</a>):
</p>

<pre class="example">
@prefix rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
@prefix dc: &lt;http://purl.org/dc/elements/1.1/&gt; .
@prefix ex: &lt;http://example.org/stuff/1.0/&gt; .

&lt;http://www.w3.org/TR/rdf-syntax-grammar&gt;
  dc:title "RDF/XML Syntax Specification (Revised)" ;
  ex:editor [
    ex:fullname "Dave Beckett";
    ex:homePage &lt;http://purl.org/net/dajobe/&gt;
  ] .
</pre>


<p>An example of an RDF collection of two literals.</p>
<pre class="example">
@prefix : &lt;http://example.org/stuff/1.0/&gt; .
:a :b ( "apple" "banana" ) .
</pre>
<p>which is short for (<a href="example2.ttl">example2.ttl</a>):</p>
<pre class="example">
@prefix : &lt;http://example.org/stuff/1.0/&gt; .
@prefix rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
:a :b
  [ rdf:first "apple";
    rdf:rest [ rdf:first "banana";
               rdf:rest rdf:nil ]
  ] .
</pre>

<p>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.
(<a href="example3.ttl">example3.ttl</a>):</p>

<pre class="example">
@prefix : &lt;http://example.org/stuff/1.0/&gt; .

:a :b "The first line\nThe second line\n  more" .

:a :b """The first line
The second line
  more""" .
</pre>



<h2 id="sec-identifiers">5. Identifiers for the Turtle Language</h2>

<p>The URI that identifies the Turtle language is:<br />
<code>http://www.w3.org/2008/turtle#turtle</code>
</p>

<p>The XML (Namespace name, Local name) pair that identifies
the Turtle language is:<br />
Namespace: <code>http://www.w3.org/2008/turtle#</code><br />
Local name: <code>turtle</code><br />
The suggested namespace prefix is <code>ttl</code> (informative)
which would make this <code>ttl:turtle</code> as an XML QName.
</p>


<h2 id="sec-conformance">6. Conformance</h2>

<p>Systems conforming to Turtle MUST pass all the following test cases:</p>

<ol>
<li>The <a href="http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/#ntrip_tests">N-Triples tests</a> in the
<a href="http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/">RDF Test Cases</a> W3C Recommendation.</li>
<li>The <a href="tests/">Turtle Test Suite</a>
(<a href="tests.zip">tests.zip</a> md5sum 361f0b8b5e3a36d0ecd60be7965009df )
<br />
<p>Passing these tests means:</p>
<ol>
<li>All the <code>test-n.ttl</code> tests MUST generate equivalent RDF
triples to those given in the corresponding <code>test-n.out</code>
N-Triples file.</li>
<li>All the <code>bad-n.ttl</code> tests MUST NOT generate RDF triples.</li>
</ol>
</li>
</ol>



<h2 id="sec-mime">7. Media Type and Content Encoding</h2>

<p>The media type of Turtle is
<code>text/turtle</code> (pre-registration media type
<code>application/x-turtle</code> should be accepted).
The content encoding of Turtle content is always
UTF-8.
      Charset parameters on the mime type are required until such time as the <tt>text/</tt> media type tree permits UTF-8 to be sent without a charset parameter.
      See <a href="#sec-mediaReg">B. Internet Media Type, File Extension and Macintosh File Type</a> for the media type registration form.
</p>


<h2 id="sec-diff-ntriples">8. Turtle compared to N-Triples (Informative)</h2>

<p>Turtle adds the following syntax to N-Triples:</p>

<ol>
<li>Whitespace restrictions removed</li>
<li>Text content-encoding changed from ASCII to UTF-8</li>
<li><code>@prefix</code></li>
<li>QNames</li>
<li><code>,</code></li>
<li><code>;</code></li>
<li><code>[]</code></li>
<li><code>a</code></li>
<li><code>()</code></li>
<li>Decimal integer literals (<code>xsd:integer</code>)</li>
<li>Decimal double literals (<code>xsd:double</code>)</li>
<li>Decimal arbitrary length literals (<code>xsd:decimal</code>)</li>
<li>Boolean literals</li>
<li><code>@base</code></li>
</ol>


<h2 id="sec-diff-n3">9. Turtle compared to Notation 3 (Informative)</h2>

<p>Notation 3 includes at least the following syntax that is not in Turtle
(not a complete list):</p>

<ol>
<li><code>{</code> ... <code>}</code></li>
<li><code>is</code> <code>of</code></li>
<li>paths like <code>:a.:b.:c</code> and <code>:a^:b^:c</code></li>
<li><code>@keywords</code></li>
<li><code>=&gt;</code> implies</li>
<li><code>=</code>  equivalence</li>
<li><code>@forAll</code></li>
<li><code>@forSome</code></li>
<li>&lt;=</li>
</ol>


<h2 id="sec-diff-sparql">10. Turtle compared to SPARQL (Informative)</h2>

<p>the
<a href="http://www.w3.org/TR/2007/PR-rdf-sparql-query-20071112/">SPARQL Query Language for RDF</a>
(<acronym title="SPARQL Protocol And RDF Query Language">SPARQL</acronym>)
<a href="#ref-sparqlq">[SPARQLQ]</a>
uses a Turtle/N3 style syntax for the Triple patterns including
the same forms of abbreviated forms given here.</p>

<p>SPARQL includes at least the following syntax that is not in Turtle
(not a complete list):
</p>

<ol>
<!-- li>Blank nodes are allowed in triple predicates either given explicitly
with a blank node identifier using
<code>_:</code><em>name</em> or with no name using <code>[]</code>
or <code>[</code> ... <code>]</code>.
</li -->
<li>RDF Literals are allowed in triple subjects</li>
<li>Variables are allowed in any part of the triple of the form
<code>?</code><em>name</em> or <code>$</code><em>name</em>
</li>
<li>Long literals can use use single quote (<code>'</code>) characters:
<code>'''</code> ... <code>'''</code>
</li>
<li>The constants allowed for XSD booleans: <code>true</code> and
<code>false</code> are case independent.  In Turtle they are not,
only lowercase forms are allowed.
</li>
<li>SPARQL allows '.'s in names in all positions apart from the first or last.  These would correspond to rules:<br />
<span class="grammar">name ::= nameStartChar ( ( nameChar | '.' )* nameChar )?</span><br />
<span class="grammar">prefixName ::= ( nameStartChar - '_' ) ( ( nameChar | ' .' )* nameChar )?</span>
</li>
      <li>SPARQL allows digits in the first character of the <a href="http://www.w3.org/TR/rdf-sparql-query/#rPN_LOCAL">PN_LOCAL</a> lexical token. In Turtle, the only ascii characters allowed in a <a href="#nameStartChar">nameStartChar</a> are <span class="grammar">[A-Z]&nbsp;|&nbsp;"_"&nbsp;|&nbsp;[a-z]</span>.</li>
      <li>Turtle allows <a href="#nameStartChar">prefix and base declarations</a> anywhere outside of a triple. In SPARQL, they are only allowed in the <a href="http://www.w3.org/TR/rdf-sparql-query/#rPrologue">Prologue</a> (at the start of the SPARQL query).</li>
</ol>

<p>For further information see the
<a href="http://www.w3.org/TR/2007/PR-rdf-sparql-query-20071112/#QSynIRI">Syntax for IRIs</a>
and <a href="http://www.w3.org/TR/2007/PR-rdf-sparql-query-20071112/#grammar">SPARQL Grammar</a>
sections of the SPARQL query document <a href="#ref-sparqlq">[SPARQLQ]</a>.
</p>


<h2 id="sec-refs">A. References</h2>

<h3 id="sec-refs-normative">A.1 Normative</h3>

<dl>


<dt><a name="ref-notation">[NOTATION]</a></dt>
<dd><cite><a href="http://www.w3.org/TR/2004/REC-xml-20040204/#sec-notation">Notation</a></cite> section in <cite><a href="http://www.w3.org/TR/2004/REC-xml-20040204/">Extensible Markup Language (XML) 1.0 (Third Edition)</a></cite>, T. Bray, J. Paoli, C.m. Sperberg-McQueen, E. Maler, F. Yergeau editors, W3C Recommendation, 04 February 2004. This version of XML 1.0 is http://www.w3.org/TR/2004/REC-xml-20040204/.  The <a href="http://www.w3.org/TR/REC-xml/">latest version of the Extensible Markup Language (XML) 1.0</a> is at http://www.w3.org/TR/REC-xml/.
</dd>

<dt><a name="ref-ntriples">[N-TRIPLES]</a></dt>
<dd><cite><a href="http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/">N-Triples</a></cite> section in <a href="http://www.w3.org/TR/rdf-testcases/">RDF Test Cases</a>, J. Grant and D. Beckett, Editors, W3C Recommendation, 10 February 2004.  This version of the RDF Test Cases is http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/.  The <a href="http://www.w3.org/TR/rdf-testcases/">latest version of the RDF Test Cases</a> is at http://www.w3.org/TR/rdf-testcases/.
</dd>

<dt><a name="Unicode">[UNICODE]</a></dt>
<dd><cite><a href="http://www.unicode.org/unicode/standard/standard.html">The Unicode Standard Version 3.0</a></cite>, Addison Wesley, Reading MA, 2000, ISBN: 0-201-61633-5. This document is http://www.unicode.org/unicode/standard/standard.html.</dd>

<dt><a name="charmod">[CHARMOD]</a></dt>
<dd><cite><a href="http://www.w3.org/TR/2005/REC-charmod-20050215/">Character Model for the World Wide Web 1.0: Fundamentals</a></cite>, M. J. Dürst, F. Yergeau, R. Ishida, M. Wolf, T. Texin editors, W3C Recommendation, 15 February 2005. This version of Character Model for the WWW 1.0: Fundamentals is http://www.w3.org/TR/2005/REC-charmod-20050215/ The <a href="http://www.w3.org/TR/charmod/">latest version</a> of Character Model for the WWW: Fundamentals 1.0 is at http://www.w3.org/TR/charmod/.</dd>

<dt><a name="ref-rdf-concepts">[RDF-CONCEPTS]</a></dt>
<dd><cite><a href="http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/">Resource Description Framework (RDF): Concepts and Abstract Syntax</a></cite>, G. Klyne, J.J. Carroll editors, W3C Recommendation, 10 February 2004.  This version of RDF Concepts and Abstract Syntax is http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/.  The <a href="http://www.w3.org/TR/rdf-concepts/">latest version</a> of RDF Concepts and Abstract Syntax is http://www.w3.org/TR/rdf-concepts/.</dd>

<dt><a name="ref-rdfxml">[RDF-XML]</a></dt>
<dd><cite><a href="http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/">RDF/XML Syntax Specification (Revised)</a></cite>, D. Beckett editor, W3C Recommendation, 10 February 2004.  This version of RDF/XML is http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/.  The <a href="http://www.w3.org/TR/rdf-syntax-grammar/">latest version</a> of RDF/XML is http://www.w3.org/TR/rdf-syntax-grammar/.</dd>

<dt><a name="rfc3629" id="rfc3629">[RFC3629]</a></dt>
<dd>RFC 3629 <cite><a href="http://www.ietf.org/rfc/rfc3629.txt">UTF-8, a transformation format of ISO 10646</a></cite>, F. Yergeau November 2003</dd>

<dt><a name="rfc3986" id="rfc3986">[RFC3986]</a></dt>
<dd>RFC 3986 <cite><a href="http://www.ietf.org/rfc/rfc3986.txt">Uniform Resource Identifier (URI): Generic Syntax</a></cite>, T. Berners-Lee, R. Fielding, L. Masinter January 2005</dd>

<dt><a name="rfc3987" id="rfc3987">[RFC3987]</a></dt>
<dd><a href="http://www.ietf.org/rfc/rfc3987.txt">RFC 3987</a>, "Internationalized Resource Identifiers (IRIs)", M. D&uuml;rst , M. Suignard</dd>

<dt><a name="UNISEC" id="UNISEC">[UNISEC]</a></dt>
<dd><cite><a href="http://www.unicode.org/reports/tr36/">Unicode Security Considerations</a></cite>, Mark Davis, Michel Suignard</dd>

<dt><a name="UNICODE" id="UNICODE">[UNICODE]</a></dt>
<dd><cite>The Unicode Standard, Version 4</cite>. ISBN 0-321-18578-1, as updated from time to time by the publication of new versions. The latest version of Unicode and additional information on versions of the standard and of the Unicode Character Database is available at <a href="http://www.unicode.org/unicode/standard/versions/">http://www.unicode.org/unicode/standard/versions/</a>.</dd>

</dl>

<h3 id="sec-refs-informative">A.2 Informative</h3>

<dl>
      <dt>Previous version</dt>
<dd><a href="http://www.dajobe.org/2004/01/turtle/2007-09-11/">http://www.dajobe.org/2004/01/turtle/2007-09-11/</a></dd>

<dt><a name="ref-n3">[NOTATION3]</a></dt>
<dd><cite><a href="http://www.w3.org/DesignIssues/Notation3">Notation 3</a></cite>, Tim Berners-Lee, World Wide Web Consortium</dd>

<dt><a name="mswm">[MSWM]</a></dt>
<dd><cite><a href="http://www.idealliance.org/papers/dx_xmle04/papers/03-08-03/03-08-03.html">Modernising Semantic Web Markup</a></cite>, Dave Beckett and <a href="http://www.dajobe.org/talks/xmleurope2004/">presentation</a> given at  <a href="http://www.xmleurope.com/">XML Europe 2004</a>, Amsterdam, 20 April 2004</dd>

<dt><a name="ref-sparqlq">[SPARQLQ]</a></dt>
<dd><cite><a href="http://www.w3.org/TR/2007/PR-rdf-sparql-query-20071112/">SPARQL Query Language for RDF</a></cite>, E. Prud'hommeaux, A. Seaborne, Editors. World Wide Web Consortium.  W3C Proposed Recommendation, 12 November 2007. This version is http://www.w3.org/TR/2007/PR-rdf-sparql-query-20071112/.  The <a href="http://www.w3.org/TR/rdf-sparql-query/">latest version of SPARQL Query Language for RDF</a> is available at http://www.w3.org/TR/rdf-sparql-query/.</dd>

</dl>


<h2 id="sec-mediaReg">B. Internet Media Type, File Extension and Macintosh File Type (Normative)</h2>

    <dl>
      <dt>Contact:</dt>
      <dd>Eric Prud'hommeaux</dd>
      <dt>See also:</dt>
      <dd><a href="http://www.w3.org/2002/06/registering-mediatype">How to Register a Media Type for a W3C Specification</a></dd>
      <dd><a href="http://www.w3.org/2001/tag/2002/0129-mime">Internet Media Type registration, consistency of use</a><br />TAG Finding 3 June 2002 (Revised 4 September 2002)</dd>
    </dl>
    <p>The Internet Media Type / MIME Type for Turtle is &quot;text/turtle&quot;.</p>
    <p>It is recommended that Turtle files have the extension &quot;.ttl&quot; (all lowercase) on all platforms.</p>
    <p>It is recommended that Turtle files stored on Macintosh HFS file systems be given a file type of &quot;TEXT&quot;.</p>
    <p>This information that follows has been <a href="http://www.w3.org/mid/20071218114549.GQ8244@w3.org">submitted to the IESG</a> for review, approval, and registration with IANA.</p>
    <dl>
      <dt>Type name:</dt>
      <dd>text</dd>
      <dt>Subtype name:</dt>
      <dd>turtle</dd>
      <dt>Required parameters:</dt>
      <dd>None</dd>
      <dt>Optional parameters:</dt>
      <dd><tt>charset</tt> — this parameter is required when transferring non-ASCII data. If present, the value of <tt>charset</tt> is always <tt>UTF-8</tt>.</dd>
      <dt>Encoding considerations:</dt>
      <dd>The syntax of Turtle is expressed over code points in Unicode [<a href="#UNICODE">UNICODE</a>]. The encoding is always UTF-8 [<a href="#rfc3629">RFC3629</a>].</dd>
      <dd>Unicode code points may also be expressed using an \uXXXX (U+0 to U+FFFF) or \UXXXXXXXX syntax (for U+10000 onwards) where X is a hexadecimal digit [0-9A-F]</dd>
      <dt>Security considerations:</dt>
      <dd>Turtle is a general-purpose assertion language; applications may evaluate given data to infer more assertions or to dereference URIs, invoking the security considerations of the scheme for that URI. Note in particular, the privacy issues in [<a href="#rfc3023">RFC3023</a>] section 10 for HTTP URIs. Data obtained from an inaccurate or malicious data source may lead to inaccurate or misleading conclusions, as well as the dereferencing of unintended URIs. Care must be taken to align the trust in consulted resources with the sensitivity of the intended use of the data; inferences of potential medical treatments would likely require different trust than inferences for trip planning.</dd>
      <dd>Turtle is used to express arbitrary application data; security considerations will vary by domain of use. Security tools and protocols applicable to text (e.g. PGP encryption, MD5 sum validation, password-protected compression) may also be used on Turtle documents. Security/privacy protocols must be imposed which reflect the sensitivity of the embedded information.</dd>
      <dd>Turtle can express data which is presented to the user, for example, RDF Schema labels. Application rendering strings retrieved from untrusted Turtle documents must ensure that malignant strings may not be used to mislead the reader. The security considerations in the media type registration for XML ([RFC3023] section 10) provide additional guidance around the expression of arbitrary data and markup.</dd>
      <dd>Turtle uses IRIs as term identifiers. Applications interpreting data expressed in Turtle should address the security issues of
  <a class="norm" href="http://www.ietf.org/rfc/rfc3987.txt">Internationalized Resource Identifiers (IRIs)</a> [<a href="#rfc3987">RFC3987</a>] Section 8, as well as
  <a class="norm" href="http://www.ietf.org/rfc/rfc3986.txt">Uniform Resource Identifier (URI): Generic Syntax</a> [<a href="#rfc3986">RFC3986</a>] Section 7.</dd>
      <dd>Multiple IRIs may have the same appearance. Characters in different scripts may 
look similar (a Cyrillic &quot;&#1086;&quot; may appear similar to a Latin &quot;o&quot;). A character followed 
by combining characters may have the same visual representation as another character 
(LATIN SMALL LETTER E followed by COMBINING ACUTE ACCENT has the same visual representation 
as LATIN SMALL LETTER E WITH ACUTE).
<!-- (<code>foo:resum&#40751;code> and <code>f&#1086;&#1086;:resume&#769;</code>)-->
Any person or application that is writing or interpreting data in Turtle must take care to use the IRI that matches the intended semantics, and avoid IRIs that make look similar.
Further information about matching of similar characters can be found 
in <a class="inform" href="http://www.unicode.org/reports/tr36/">Unicode Security 
Considerations</a> [<a href="#UNISEC">UNISEC</a>] and
<a class="norm" href="http://www.ietf.org/rfc/rfc3987.txt">Internationalized Resource 
Identifiers (IRIs)</a> [<a href="#rfc3987">RFC3987</a>] Section 8.
<!--@@ no security considerations section at this time. @@
See Turtle - Terse RDF Triple Language appendix X, <a href="#security">Security Considerations</a> 
	as well as <a class="norm" href="http://www.ietf.org/rfc/rfc3629.txt">RFC 3629</a> 
	[<a href="#rfc3629">RFC3629</a>] section 7, Security Considerations. --></dd>

      <dt>Interoperability considerations:</dt>
      <dd>There are no known interoperability issues.</dd>
      <dt>Published specification:</dt>
      <dd>This specification.</dd>
      <dt>Applications which use this media type:</dt>
      <dd>No widely deployed applications are known to use this media type. It may be used by some web services and clients consuming their data.</dd>
      <dt>Additional information:</dt>
      <dt>Magic number(s):</dt>
      <dd>Turtle documents may have the strings '@prefix' or '@base' (case dependent) near the beginning of the document.</dd>
      <dt>File extension(s):</dt>
      <dd>".ttl"</dd>
      <dt>Base URI:</dt>
      <dd>The Turtle '@base &lt;IRIref&gt;' term can change the current base URI for relative IRIrefs in the query language that are used sequentially later in the document.</dd>
      <dt>Macintosh file type code(s):</dt>
      <dd>&quot;TEXT&quot;</dd>
      <dt>Person &amp; email address to contact for further information:</dt>
      <dd>Eric Prud'hommeaux &lt;eric@w3.org&gt;</dd>
      <dt>Intended usage:</dt>
      <dd>COMMON</dd>
      <dt>Restrictions on usage:</dt>
      <dd>None</dd>
      <dt>Author/Change controller:</dt>
      <dd>The Turtle specification is the product of David Beckett and Tim Berners-Lee. A W3C Working Group may assume maintenance of this document; W3C reserves change control over this specifications.</dd>
    </dl>


<h2 id="sec-acks">C. Acknowledgements (Informative)</h2>

<p>This work was described in the paper
<a href="http://www.dajobe.org/2003/11/new-syntaxes-rdf/">New Syntaxes for RDF</a>
which discusses other RDF syntaxes and the background
to the Turtle (Submitted to WWW2004, referred to as <em>N-Triples
Plus</em> there).
</p>


<p>This work was started during the
<a href="http://www.w3.org/2001/sw/Europe/">Semantic Web Advanced Development Europe (SWAD-Europe)</a>
project funded by the EU IST-7 programme IST-2001-34732 (2002-2004)
and further development supported by the
<a href="http://www.ilrt.bris.ac.uk/">Institute for Learning and Research Technology</a> at the  <a href="http://www.bristol.ac.uk/">University of Bristol</a>, UK (2002-Sep 2005).
</p>



<h2 id="sec-changelog">D. Changes (Informative)</h2>

<p>Changes since the last publication of this document
<a href="http://www.dajobe.org/2004/01/turtle/2007-09-11/">Turtle 2007-09-11</a>
.  See the
<a href="http://www.dajobe.org/2004/01/turtle/2007-09-11/#sec-changelog">Previous changelog for further information</a>
</p>


<ul>

<li>
Renamed section 2 to Turtle Syntax and completed it with examples.<br />
Tidied mime type section<br />
Added acknowledgements appendix C<br />
Added normative and informative references appendices<br />
Added RDF Concepts reference and link to it for RDF terms<br />
Renumbered collections section to 3.5<br />
Renumbered sections 4 onwards<br />
Removed <!-- a href="#sec-implementations" -->implementations section<!-- /a -->
2007-11-20
</li>

<li>
Added <a href="#sec-tutorial">Tutorial Section</a><br />
Removed canonicalisation of lexical forms <a href="#integer">integer</a> and <a href="#boolean">boolean</a> literals<br />
Renumbered section 6 as <a href="#sec-uris">3.4. URI References</a><br />
Renumbered section 3 as <a href="#sec-strings">3.3. String Escapes</a><br />
Deleted empty section <a id="sec-future" name="sec-future">11. Possible Extensions</a><br />
Deleted section <a id="sec-qnames" name="sec-qnames">10. XML QNames</a>
as differences with SPARQL are noted elsewhere<br />
Added grammar sub-sections
<a href="#sec-grammar-ws">3.1 White Space</a> and
<a href="#sec-grammar-comments">3.2 Comments</a> and
<a href="#sec-grammar-grammar">3.5 Grammar</a>
<br />
Removed use of <a href="#ws">ws</a> production except where required<br />
2007-11-19
</li>

</ul>

</body>
</html>