--- a/rdf-turtle/N-Turples.html Mon Mar 26 12:11:36 2012 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1372 +0,0 @@
-<!DOCTYPE html>
-<html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Turtle</title>
- <meta http-equiv='Content-Type' content='text/html;charset=utf-8'/>
- <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js' class='remove'></script>
- <script src='../ReSpec.js/js/respec.js' class='remove'></script>
- <script class='remove'>
- $.fn.renameElement = function (name) {
- return this.each(function () {
- var $newElement = $(this.ownerDocument.createElement(name));
- for (var i = 0, n = this.attributes.length; i < n; i++) {
- var attribute = this.attributes[i];
- $newElement[0].setAttributeNS(attribute.namespaceURI, attribute.name, attribute.value);
- }
- $(this).contents().appendTo($newElement);
- $(this).replaceWith($newElement);
- });
- };
- preprocessTurtle = { apply: function (ignore) {
- $("script[type='text/turtle']").removeAttr('type').renameElement('span');
- $("script[type='text/plain']").removeAttr('type').renameElement('span');
- }
- };
- var respecConfig = {
- // specification status (e.g. WD, LCWD, NOTE, etc.). If in doubt use ED.
- specStatus: "ED",
-
- // the specification's short name, as in http://www.w3.org/TR/short-name/
- shortName: "Turtle",
-
- // if your specification has a subtitle that goes below the main
- // formal title, define it here
- subtitle : "Terse RDF Triple Language",
-
- // if you wish the publication date to be other than today, set this
- // publishDate: "2011-08-09",
-
- // if the specification's copyright date is a range of years, specify
- // the start date here:
- copyrightStart: "2008",
-
- // if there is a previously published draft, uncomment this and set its YYYY-MM-DD date
- // and its maturity status
- previousPublishDate: "2011-08-09",
- previousMaturity: "FPWD",
- previousURI: "http://www.w3.org/TR/2011/WD-turtle-20110809/",
-
- // if there a publicly available Editor's Draft, this is the link
- edDraftURI: "http://dvcs.w3.org/hg/rdf/raw-file/default/rdf-turtle/index.html",
-
- // if this is a LCWD, uncomment and set the end of its review period
- // lcEnd: "2009-08-05",
-
- // if you want to have extra CSS, append them to this list
- // it is recommended that the respec.css stylesheet be kept
- extraCSS: ["http://dev.w3.org/2009/dap/ReSpec.js/css/respec.css"],
-
- // editors, add as many as you like
- // only "name" is required
- editors: [
- { name: "Eric Prud'hommeaux", url: "http://www.w3.org/People/Eric/",
- company: "W3C", companyURL: "http://www.w3.org/" },
- { name: "Gavin Carothers", url: "http://gavin.carothers.name/",
- company: "TopQuadrant, Inc", companyURL: "http://topquadrant.com/" },
- ],
-
- // authors, add as many as you like.
- // This is optional, uncomment if you have authors as well as editors.
- // only "name" is required. Same format as editors.
-
- authors: [
- { name: "David Beckett", url: "http://purl.org/net/dajobe/" },
- { name: "Tim Berners-Lee", url: "http://www.w3.org/People/Berners-Lee/",
- company: "W3C", companyURL: "http://www.w3.org/" },
- { name: "Eric Prud'hommeaux", url: "http://www.w3.org/People/Eric/",
- company: "W3C", companyURL: "http://www.w3.org/" },
- { name: "Gavin Carothers", url: "http://gavin.carothers.name/",
- company: "TopQuadrant, Inc", companyURL: "http://topquadrant.com/" },
- ],
-
- // name of the WG
- wg: "RDF Working Group",
-
- // URI of the public WG page
- wgURI: "http://www.w3.org/2011/rdf-wg/",
-
- // name (with the @w3c.org) of the public mailing to which comments are due
- wgPublicList: "public-rdf-comments",
-
- // URI of the patent status for this WG, for Rec-track documents
- // !!!! IMPORTANT !!!!
- // This is important for Rec-track documents, do not copy a patent URI from a random
- // document unless you know what you're doing. If in doubt ask your friendly neighbourhood
- // Team Contact.
- wgPatentURI: "http://www.w3.org/2004/01/pp-impl/46168/status",
- doRDFa: true,
- preProcess: [ preprocessTurtle ]
- };
- </script>
- <script class="remove">
- function updateExample(doc, content) {
- // perform transformations to make it render and prettier
- return '<pre class="example">' + doc._esc(content) + '</pre>';
- }
- function esc(doc, content) {
- return doc._esc(content);
- }
- </script>
- <style type="text/css">
- /* Style Turtle script blocks to be visable */
- pre.example script {
- display:block;
- }
- .separated thead tr th { border:1px solid black; padding: .2em; }
- .separated tbody tr td { border:1px solid black; text-align: center; }
- .separated tbody tr td.r { text-align: right; padding: .5em; }
- </style>
-
- </head>
-
- <body>
- <section id='abstract'>
- <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 an RDF graph 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> -->
- format as well as the triple pattern syntax of the
- <a href="http://www.w3.org/TR/sparql11-query/">SPARQL</a>
- W3C Recommendation.
- </p>
- </section>
-
- <section id='sotd'>
- <p>
- Turtle is already a reasonably settled serialization of RDF. Many
- implementations of Turtle already exist. We are hoping for feedback from those
- existing implementers and other people deciding that now would be a good time
- to support Turtle. There are still a few rough edges that need polishing, and
- better alignment is needed with the SPARQL triple patterns. The working group
- does not expect to make any large changes to the existing syntax.
- </p>
- </section>
-
- <section id="sec-intro">
- <h2>Introduction</h2>
-
- <p>
- This document defines two syntaxes for <a href="../rdf-concepts/index.html">RDF</a> ([[!RDF-CONCEPTS]]), Turtle, the Terse RDF Triple Language, and N-Triples.
- N-Triples is a sublanguage of Turtle, which in turn borrows much of its syntax from <a href="http://www.w3.org/DesignIssues/Notation3">Notation 3</a> ([[N3]]).
- </p>
-
- <p>
- Turtle and N-Triples documents are textual representation of a RDF graphs.
- A Turtle document consists parsing directives and triples.
- An N-Triples document contains no parsing directives.
- Comments in either language may be given after a <code>#</code> that is not part of another lexical token and continue to the end of the line.
- </p>
-
- <p>
- N-Triples triples are a sequence of RDF terms representing the subject, predicate and object of an RDF Triple. This sequence is terminated by a '.' and a new line (optional at the end of a document).
- </p>
-
- <pre class="example"><script type="text/plain">
-_:subject1 <http://an.example/predicate1> "object1" .
-_:subject2 <http://an.example/predicate2> "object2" .
-</script></pre>
-
- <p>
- N-Triples triples are also Turtle triples, but Turtle includes other <a href="#terms">representations of RDF Terms</a> and <a href="#groups">abbreviations of RDF Triples</a>.
- </p>
-
- <p>
- The Turtle grammar for <a href="#prod-turtle2-triples"><code>triples</code></a> is a subset of the <a href="http://www.w3.org/TR/2008/REC-rdf-sparql-query-20080115/">SPARQL Query Language for RDF</a> [[RDF-SPARQL-QUERY]] grammar for <a href="http://www.w3.org/TR/sparql11-query/#rTriplesBlock"><code>TriplesBlock</code></a>.
- The two grammars share production and terminal names where possible.
- Likewise, the N-Triples grammar re-uses some productions and terminals from Turtle.
- </p>
-
- <p>
- The <a href="#sec-grammar">Turtle Grammar</a> and <a href="#sec-parsing">Parsing</a> sections define the construction of an RDF graph from a Turtle document.
- The RDF graph represented by an N-Triples document contains exactly each triple matching <a href="#prod-ntriples-triple">N-Triples <code>triple</code> production</a>.
- </p>
- </section>
- <section id="terms">
- <h2>RDF Terms in Turtle and N-Triples</h2>
-
- <p>
- There are three types of <em>RDF Term</em>:
- <a href="../rdf-concepts/index.html#dfn-iri">IRIs</a> (Internationalized Resource Identifiers),
- <a href="../rdf-concepts/index.html#dfn-literal">literals</a> and
- <a href="../rdf-concepts/index.html#dfn-blank-node">blank nodes</a>.
- </p>
-
- <section id="IRIs">
- <h3>RDF IRIs</h3>
-
- <p>
- Turtle's grammar production <a href="#prod-turtle2-IRIref">IRIref</a> designates <a href="../rdf-concepts/index.html#dfn-iri">RDF IRIs</a>.
- These may be written as relative or absolute IRIs or prefixed names.
- Relative and absolute IRIs are enclosed in '<' and '>' and may contain <a href="#numeric">numeric escape sequences</a> (described below).
- The N-Triples language includes absolute IRIs but no relative IRIs or prefixed names.
- </p>
-
- <section id="turtleIRIs">
- <h3>Relative IRIs and Prefixed Names in Turtle</h3>
-
- <p>
- The <code>@prefix</code> directive associates a prefix label with an IRI.
- Subsequent <code>@prefix</code> directives may re-map the same local name.
- A prefixed name is a prefix label and a local part, separated by a colon ":".
- A prefixed name is mapped to an IRI by concatenating the IRI associated with the prefix and the local part.
- The local part of a prefixed name may have <a href="#reserved">reserved character escape sequences</a> (described below).
- </p>
-
- <div class="note">
- <p>
- Prefixed names are a superset of XML namespaces.
- They differ in that the local part of prefixed names may include:
- </p>
- <ul>
- <li>leading digits, e.g. <code>leg:3032571</code> or <code>isbn13:9780136019701</code></li>
- <li>reserved character escape sequences, e.g. <code>og:video\:height</code> or <code>wgs:lat\-long</code></li>
- </ul>
- </div>
-
- <p>
- Relative IRIs are combined with base IRIs as per <a href="http://www.ietf.org/rfc/rfc3986.txt" class="norm">Uniform Resource Identifier (URI): Generic Syntax</a> [<a href="#rfc3986">RFC3986</a>] using only the basic algorithm in section 5.2.
- Neither Syntax-Based Normalization nor Scheme-Based Normalization (described in sections 6.2.2 and 6.2.3 of RFC3986) are performed.
- Characters additionally allowed in IRI references are treated in the same way that unreserved characters are treated in URI references, per section 6.5 of <a href="http://www.ietf.org/rfc/rfc3987.txt" class="norm">Internationalized Resource Identifiers (IRIs)</a> [<a href="#rfc3987">RFC3987</a>].
- </p>
- <p>
- The <code>@base</code> directive defines the Base IRI used to resolve relative IRIs per RFC3986 section 5.1.1, "Base URI Embedded in Content".
- Section 5.1.2, "Base URI from the Encapsulating Entity" defines how the In-Scope Base IRI may come from an encapsulating document, such as a SOAP envelope with an xml:base directive or a mime multipart document with a Content-Location header.
- The "Retrieval URI" identified in 5.1.3, Base "URI from the Retrieval URI", is the URL from which a particular SPARQL query was retrieved.
- If none of the above specifies the Base URI, the default Base URI (section 5.1.4, "Default Base URI") is used.
- Each <code>@base</code> directive sets a new In-Scope Base URI, relative to the previous one.
- </p>
-
- <p>
- The token <code>a</code> in the predicate position of a Turtle triple represents the IRI <code>rdf:type</code> .
- </p>
-
- <pre class="example"><script type="text/plain">
-# A triple with all absolute IRIs (which is also a valid N-Triples triple):
-<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> .
-
-@base <http://one.example/>
-<subject2> <predicate2> <object2> . # relative IRIs, e.g. http://one.example/subject2
-
-@prefix p: <http://two.example/>
-p:subject3 p:predicate3 p:object3 . # prefixed IRIs, e.g. http://two.example/subject3
-
-@prefix p: <path/> # prefix p: now stands for http://one.example/path/
-p:subject4 p:predicate4 p:object4 . # prefixed IRIs, e.g. http://one.example/path/subject4
-
-@prefix : <http://another.example/> # empty prefix
-:subject5 :predicate5 :object5 . # prefixed IRIs, e.g. http://another.example/subject5
-
-:subject6 a :subject7 . # same as :subject6 rdf:type :subject7 .
-</script></pre>
-
- </section>
- <section id="iri-summary">
- <h3>Summary of IRI Representations in N-Triples and Turtle</h3>
-
- <table id="term2escape" class="separated" style="border-collapse:collapse;margin: 2em;">
- <thead>
- <tr>
- <th></th>
- <th>Turtle</th>
- <th>N-Triples</th>
- <th>example</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td class="r">absolute IRI</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td><code><http://a.example/some/path/></code></td>
- </tr>
- <tr>
- <td class="r">relative IRI</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td>no</td>
- <td><code></some/path/></code></td>
- </tr>
- <tr>
- <td class="r">prefixed name</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td>no</td>
- <td><code>foo:bar\=baz</code></td>
- </tr>
- <tr>
- <td class="r"><code>a</code> for the predicate <code>rdf:type</code></td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td>no</td>
- <td><code>a</code></td>
- </tr>
- </tbody>
- </table>
- </section>
- </section>
-
- <section id="literals">
- <h3>RDF Literals</h3>
-
- <p>
- Literals in N-Triples have a lexical form followed by a bare langugae tag, a datatype IRI, or neither.
- The representation of the lexical form consists of a delimiting <code>"</code>, a sequence of characters matching the regular expression <code>[^\"\\\n\r]</code> or <a href="#numeric">numeric escape sequence</a> or <a href="#string">string escape sequence</a>, and a final delimiting <code>"</code>.
- The corresponding <a href="../rdf-concepts/index.html#dfn-lexical-form">RDF lexical form</a> is the characters between the <code>""</code>s, after processing the escape sequences.
- If present, the <a href="../rdf-concepts/index.html#dfn-language-tagged-string">language tag</a> is preceded by a <code>@</code>.
- The datatype of literals with a language tag is <code>rdf:langString</code>, though this datatype is not written in N-Triples or Turtle.
- The datatype IRI in Turtle may be written in any valid IRI representation.
- If there is no language tag, there may be a <a href="../rdf-concepts/index.html#dfn-datatype-URI">datatype IRI</a>, preceeded by <code>^^</code>.
- If there is no datatype IRI and no language tag, the datatype is <code>xsd:string</code>.
- </p>
-
- <section id="turtle-literals">
- <h3>Alternative Lexical Representations in Turtle</h3>
- <p>
- Turtle literals include N-Triples literals, as well as three other representations of the lexical form:
- </p>
- <ul>
- <li>Literals delimited by <code>'</code>, which contain escape characters and characters matching the pattern <code>[^'\\\n\r]</code>.</li>
- <li>Literals delimited by <code>"""</code>, which permit up to two <code>"</code>s, as well as <code>\r</code> and <code>\n</code>.</li>
- <li>Literals delimited by <code>'''</code>, which permit up to two <code>'</code>s, as well as <code>\r</code> and <code>\n</code>.</li>
- </ul>
-
- <p>
- Turtle datatype IRIs may be represented by <a href="#iri-summary">any valid IRI form</a>.
- </p>
-
- <pre class="example"><script type="text/plain">
-show:218 rdfs:label "That Seventies Show"^^xsd:string . # literal with XML Schema string datatype
-show:218 rdfs:label "That Seventies Show"^^<http://www.w3.org/2001/XMLSchema#string> . # same as above
-show:218 rdfs:label "That Seventies Show" . # same again
-show:218 show:localName "That Seventies Show"@en . # literal with a language tag
-show:218 show:localName 'Cette Série des Années Soixante-dix'@fr . # literal delimited by single quote
-show:218 show:localName "Cette Série des Années Septante"@fr-be . # literal with a region subtag
-show:218 show:blurb '''This is a
-multi-line, single-quoted literal.''' . # literal with embedded new line
-</script></pre>
- </section>
- <section id="abbrev">
- <h3 >Abbreviating Common Datatypes in Turtle</h3>
- <p>Integer values, arbitrary precision decimal values, double precision floating point values and boolean values may be written without quotes or datatypes as follows:</p>
- <ul>
- <li>
- Integer values may be written as an optional sign and a series of digits. Integers match the regular expression "<code>[+-]?[0-9]+</code>".
- </li>
-
- <li style="padding-top: 1ex;">
- Arbitrary-precision decimals may be written as an optional sign, zero or more digits, a decimal point and one or more digits. Decimals match the regular expression "<code>[+-]?[0-9]*\.[0-9]+</code>".
- </li>
-
- <li style="padding-top: 1ex;">
- Double-precision floating point values may be written as an optionally signed mantissa with an optional decimal point, the letter "e" or "E", and an optionally signed integer exponent.
- The exponent matches the regular expression "<code>[+-]?[0-9]+</code>" and the mantissa one of these regular expressions: "<code>[+-]?[0-9]+\.[0-9]+</code>", "<code>[+-]?\.[0-9]+</code>" or "<code>[+-]?[0-9]</code>".
- </li>
-
- <li style="padding-top: 1ex;">
- Boolean values may be written as either <code>true</code> or <code>false</code> (case-sensitive) and represent RDF literals with the datatype <a href="http://www.w3.org/TR/xmlschema-2/#boolean">xsd:boolean</a>.
- </li>
- </ul>
-
- <table class="separated">
- <caption style="font-weight: bold;">Example numeric representations:</caption>
- <tbody>
- <tr><th><a href="http://www.w3.org/TR/xmlschema-2/#integer">xsd:integer</a></th>
- <td><code>-5</code></td> <td><code>0</code></td> <td><code>1</code></td> <td><code>010</code></td> <td><code>+10</code></td></tr>
- <tr><th><a href="http://www.w3.org/TR/xmlschema-2/#decimal">xsd:decimal</a></th>
- <td><code>-5.0</code></td> <td><code>.0</code></td> <td><code>1.234567890</code></td> <td><code>010.0</code></td> <td><code>+10.0</code></td></tr>
- <tr><th><a href="http://www.w3.org/TR/xmlschema-2/#double">xsd:double</a></th>
- <td><code>-.5e1</code></td> <td><code>0E0</code></td> <td><code>1.234567890E0</code></td> <td><code>01e1</code></td> <td><code>+10e0</code></td></tr>
- </tbody>
- </table>
-
- <pre class="example"><script type="text/turtle">
-@prefix : <http://example.org/stats> .
-<http://somecountry.example/census2007>
- :censusYear 2007 ; # xsd:integer
- :birthsPerPerson .0135 ; # xsd:decimal
- :gdpDollars 14074.2E9 ; # xsd:double
- :isLandlocked false . # xsd:boolean
- :series "IV"^^my:romanNumeral . # no abbreviation available
- </script></pre>
- </section>
- <section id="literal-summary">
- <h3>Summary of Literal Representations in N-Triples and Turtle</h3>
-
- <table id="term2escape" class="separated" style="border-collapse:collapse;margin: 2em;">
- <thead>
- <tr>
- <th></th>
- <th>Turtle</th>
- <th>N-Triples</th>
- <th>example</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td class="r">single-quoted single-line lexical representation</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td>no</td>
- <td><code>'some literal'</code></td>
- </tr>
- <tr>
- <td class="r">double-quoted single-line lexical representation</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td><code>"some literal"</code></td>
- </tr>
- <tr>
- <td class="r">single-quoted multi-line lexical representation</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td>no</td>
- <td><code>'''some<br/>literal'''</code></td>
- </tr>
- <tr>
- <td class="r">double-quoted multi-line lexical representation</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td>no</td>
- <td><code>"""some<br/>literal"""</code></td>
- </tr>
- <tr>
- <td class="r">abbreviated numeric</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td>no</td>
- <td><code>13</code></td>
- </tr>
- <tr>
- <td class="r">abbreviated boolean</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td>no</td>
- <td><code>true</code></td>
- </tr>
- </tbody>
- </table>
- </section>
- </section>
-
- <section id="BNodes">
- <h3>RDF Blank Nodes</h3>
-
- <div class="issue">
- <p>
- documented presuming we remove %XX and \C escapes from blank node labels:
- </p>
- <pre>
--[73s] BLANK_NODE_LABEL ::= "_:" PN_LOCAL
-+[73s] BLANK_NODE_LABEL ::= "_:" ( PN_CHARS_U | [0-9] ) ( ( PN_CHARS | '.' )* PN_CHARS ) ? # no PLX
- [100s] PN_LOCAL ::= ( PN_CHARS_U | [0-9] | PLX ) ( ( PN_CHARS | '.' | PLX )* ( PN_CHARS | PLX ) ) ?
- [160s] PLX ::= PERCENT | PN_LOCAL_ESC
- [161s] PERCENT ::= '%' HEX HEX
- [163s] PN_LOCAL_ESC ::= '\\' ( '_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | ':' | '/' | '?' | '#' | '@' | '%' )
- </pre>
- </div>
-
- <p>
- <a href="../rdf-concepts/index.html#dfn-blank-node">RDF blank nodes</a> in N-Triples are expressed as <code>_:</code> followed by a blank node label which is a series of name characters.
- The characters in the label are built upon <a href="#term-turtle2-PN_CHARS_BASE">PN_CHARS_BASE</a>, liberalized to allow:
- </p>
- <ul>
- <li>The characters <code>_</code> and digits may appear anywhere in a blank node label.</li>
- <li>The character <code>.</code> may appear anywhere except the first or last character.</li>
- <li>The characters <code>-</code>, <code>\uB7</code>, <code>\u300</code> to <code>\u36F</code> and <code>\u203F</code> to <code>2040</code> are permitted anywhere except the first character.</li>
- </ul>
- <p>
- A fresh RDF blank node is allocated for each unique blank node label in a Turtle or N-Triples document.
- Repeated use of the same blank node label identifies the same RDF blank node.
- </p>
- <pre class="example"><script type="text/plain">
-_:alice foaf:knows _:bob .
-_:bob foaf:knows _:alice .
-</script></pre>
-
- <section id="abbrev">
- <h3>Nesting Unlabeled Blank Nodes in Turtle</h3>
- <p>
- In Turtle, fresh RDF blank nodes are also allocated when matching the production <a href="#prod-turtle2-blankNodePropertyList">blankNodePropertyList</a> and the terminal <a href="#term-turtle2-ANON">ANON</a>.
- Both of these may appear in the subject or object position of a triple.
- That subject or object is a fresh RDF blank node.
- This blank node also serves as the subject of the triples produced by matching the <a href="#prod-turtle2-predicateObjectList">predicateObjectList</a> production embedded in a blankNodePropertyList.
- The generation of these triples is described below in <a href="#groups">Predicate Object Lists in Turtle</a>.
- Blank nodes are also allocated for <a href="#collections">Turtle Collections</a> (below).
- </p>
- <pre class="example"><script type="text/plain">
-# Someone knows someone else, who has the name "Bob".
-[] foaf:knows [ foaf:name "Bob" ] .
-</script></pre>
- </section>
- <section id="bnode-summary">
- <h3>Summary of Blank Node Representations in N-Triples and Turtle</h3>
-
- <table id="term2escape" class="separated" style="border-collapse:collapse;margin: 2em;">
- <thead>
- <tr>
- <th></th>
- <th>Turtle</th>
- <th>N-Triples</th>
- <th>example</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td class="r">labeled blank node</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td><code><http://a.example/who#Alice> foaf:knows _:bob .</code></td>
- </tr>
- <tr>
- <td class="r">anonymous node</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td>no</td>
- <td><code><http://a.example/who#Alice> foaf:knows [] .</code></td>
- </tr>
- <tr>
- <td class="r">blank node property list</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td>no</td>
- <td><code><http://a.example/who#Alice> foaf:knows [ foaf:name "Bob" ] .</code></td>
- </tr>
- </tbody>
- </table>
- </section>
- </section>
- </section>
- <section id="groups">
- <h3>Predicate Object Lists in Turtle</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"><script type="text/plain">
-# this is not a complete turtle document
-:subject :predicate :object1 ,
- :object2 .
-# creates two triples, the last triple is :subject :predicate :object2 .
- </script></pre>
-
- <p>The <code>;</code> symbol may be used to repeat the subject of
- triples that vary only in predicate and object RDF terms.</p>
- <pre class="example"><script type="text/plain">
-# this is not a complete turtle document
-:subject :predicate1 :obj1 ;
-:predicate2 :obj2 .
-# creates two triples, the last triple is :subject :predicate2 :obj2 .
- </script></pre>
-
- </section>
- <section id="collections">
- <h3>Turtle 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"><script type="text/turtle">
-# this is a complete turtle document
-@prefix : <http://example.org/foo> .
-# the object of this triple is the RDF collection blank node
-:subject :predicate ( :a :b :c ) .
-
-# an empty collection value - rdf:nil
-:subject :predicate2 () .
- </script></pre>
- </section>
- </section>
- <!-- section id="sec-syntax">
- <h3>Syntax for IRIs, Literals and Blank Nodes</h3>
- <p>Turtle is a language for an <a href="../rdf-concepts/index.html#dfn-rdf-graph">RDF graph</a>,
- a set of <a href="../rdf-concepts/index.html#dfn-rdf-triple">RDF triple</a>s. An RDF graph is
- composed of <a href="../rdf-concepts/index.html#dfn-iri">URI reference</a>s (now interpreted as IRIs),
- <a href="../rdf-concepts/index.html#dfn-literal">literal</a>s and
- <a href="../rdf-concepts/index.html#dfn-blank-node">blank node</a>s.</p>
- <p>The Turtle syntax for IRIs is identical to that of SPARQL Query, including the use of
- <code>prefix</code> and <code>base</code> directives, though these are spelled
- <code>@prefix</code> and <code>@base</code> respectively in Turtle.
- Per <a href="http://tools.ietf.org/html/rfc3986#section-5.1.1">RFC3986 section 5.1.1</a> [[!RFC3986]],
- the parsing begins with a context-defined In-Scope Base URI. Each <code>@base</code> directive
- sets a new In-Scope Base URI, relative to the previous one. <code>@prefix</code> directives
- map a local name to an IRI, also resolved against the current In-Scope Base URI.
- Subsequent <code>@prefix</code> directives may re-map the same local name.</p>
-
- <p>Turtle IRI syntax, including relative IRI resolution, is defined by <a href="http://www.w3.org/TR/rdf-sparql-query/#QSynIRI">SPARQL Query section 4.1.1</a> (noting the different spellings of the <code>PREFIX</code> and <code>BASE</code> keywords).</p>
-
- <p>Example (<a href="tests/test-30.ttl">test-30.ttl</a>) with document base IRI
- http://www.w3.org/2001/sw/DataAccess/df1/tests/</p>
-
- <div data-include="tests/test-30.ttl" data-oninclude="updateExample">
- </div>
- <p>encodes the following N-Triples
- (<a href="tests/test-30.out">test-30.out</a>):
-
- </p>
- <div data-include="tests/test-30.out" data-oninclude="updateExample">
- </div>
-
- <p>The Turtle syntax for literals and blank nodes are defined by <a href="http://www.w3.org/TR/rdf-sparql-query/#QSynLiterals">SPARQL Query section 4.1.2</a> and <a href="http://www.w3.org/TR/rdf-sparql-query/#QSynBlankNodes">SPARQL Query section 4.1.4</a> respectively.</p>
- </section -->
- <section id="sec-grammar">
- <h2>Turtle Grammar</h2>
-
- <p>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.
- </p>
- <section id="sec-grammar-ws">
- <h3>White Space</h3>
-
- <p>White space (production <a href="#prod-turtle2-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="#prod-turtle2-IRI_REF">IRI_REF</a> and <a href="#prod-turtle2-String">string</a>.
- </p>
- </section>
- <section id="sec-grammar-comments">
- <h3>Comments</h3>
-
- <p>Comments in Turtle take the form of '#', outside an
- <a href="#prod-turtle2-IRI_REF">IRI_REF</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.
-
- </p>
- </section>
- <section id="sec-escapes">
- <h3>Escape Sequences</h3>
-
- <p>
- There are three forms of escapes used in turtle documents:
- </p>
-
- <ul>
- <li>
- <p>
- <em id="numeric">numeric escape sequences</em> represent Unicode code points:
- </p>
-
- <table>
- <thead>
- <tr>
- <th>Escape sequence</th>
-
- <th>Unicode code point</th>
-
- </tr>
- </thead>
- <tbody>
-
- <tr>
- <td>'\u' <a href="#rHEX">hex</a> <a href="#rHEX">hex</a> <a href="#rHEX">hex</a> <a href="#rHEX">hex</a></td>
- <td>A Unicode codepoint in the range U+0 to U+FFFF inclusive
- corresponding to the value encoded by the four hexadecimal digits interpreted from most significant to least significant digit.</td>
- </tr>
-
-
- <tr>
- <td>'\U' <a href="#rHEX">hex</a> <a href="#rHEX">hex</a> <a href="#rHEX">hex</a> <a href="#rHEX">hex</a> <a href="#rHEX">hex</a> <a href="#rHEX">hex</a> <a href="#rHEX">hex</a> <a href="#rHEX">hex</a></td>
-
- <td>A Unicode codepoint in the range U+10000 to U+10FFFF inclusive
- corresponding to the value encoded by the eight hexadecimal digits interpreted from most significant to least significant digit.</td>
- </tr>
-
- </tbody>
- </table>
-
- <p>where <a href="#rHEX">HEX</a> is a hexadecimal character</p>
- <blockquote>
- <p><span style="font-family: monospace; font-size: 85%;"><a id="rHEX">HEX</a>
- ::= [0-9] | [A-F] | [a-f]</span></p>
-
- </blockquote>
- </li>
-
- <li>
- <p>
- <em id="string">string escape sequences</em> represent the characters traditionally escaped in string literals:
- </p>
-
- <table>
- <thead>
- <tr>
- <th>Escape sequence</th>
-
- <th>Unicode code point</th>
-
- </tr>
- </thead>
- <tbody>
-
- <tr>
- <td>'\t'</td>
- <td>U+0009</td>
- </tr>
-
- <tr>
- <td>'\b'</td>
- <td>U+0008</td>
- </tr>
-
- <tr>
-
- <td>'\n'</td>
- <td>U+000A</td>
- </tr>
-
- <tr>
- <td>'\r'</td>
- <td>U+000D</td>
- </tr>
-
- <tr>
- <td>'\f'</td>
- <td>U+000C</td>
- </tr>
-
- <tr>
- <td>'\"'</td>
- <td>U+0022</td>
- </tr>
-
- <tr>
- <td>'\''</td>
- <td>U+0027</td>
- </tr>
-
- <tr>
- <td>'\\'</td>
-
- <td>U+005C</td>
- </tr>
-
- </tbody>
- </table>
- </li>
-
- <li>
- <p>
- <em id="reserved">reserved character escape sequences</em> consist of a '\' followed by one of <code>~.-!$&'()*+,;=:/?#@%_</code> and represent the character to the right of the '\'.
- </p>
- </li>
-
- </ul>
-
- <table id="term2escape" class="separated" style="border-collapse:collapse;">
- <thead>
- <tr>
- <th></th>
- <th><a href="#numeric">numeric<br/>escapes</a></th>
- <th><a href="#string">string<br/>escapes</a></th>
- <th><a href="#reserved">reserved character<br/>escapes</a></th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td class="r"><span style="font-weight:bold;">IRI</span>s, used as <a href="#prod-turtle2-IRIref">RDF terms</a> or as in <a href="#prod-turtle2-prefixID">@prefix</a> or <a href="#prod-turtle2-base">@base</a> declarations</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td>no</td>
- <td>no</td>
- </tr>
- <tr>
- <td class="r"><del><a href="#term-turtle2-BLANK_NODE_LABEL"><span style="font-weight:bold;">Blank node label</span>s</a> and </del><a href="#term-turtle2-PN_LOCAL"><span style="font-weight:bold;">local name</span>s</a></td>
- <td>no</td>
- <td>no</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- </tr>
- <tr>
- <td class="r"><span style="font-weight:bold;">String</span>s</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td style="background-color: green; border:1px solid black;">yes</td>
- <td>no</td>
- </tr>
- </tbody>
- </table>
- <p class="note">%-encoded sequences are in the <a href="#term-turtle2-IRI_REF">character range for IRIs</a> and are <a href="#term-turtle2-PERCENT">explicitly allowed</a> in <del>blank node labels and </del>local names. These appear as a '%' followed by two hex characters and represent that same sequence of three characters. These sequences are <em>not</em> decoded during processing. A term written as <code><http://a.example/%66oo-bar></code> in Turtle designates the RDF IRI <code>http://a.example/%66oo-bar</code> and not RDF IRI <code>http://a.example/foo-bar</code>. A term written as <code>ex:%66oo-bar</code> with a prefix <code>@prefix ex: <http://a.example/></code> also designates the RDF IRI <code>http://a.example/%66oo-bar</code>.</p>
-
- </section>
- <section id="sec-grammar-grammar">
- <h3>Grammar</h3>
- <p>The <abbr title="Extended Backus–Naur Form">EBNF</abbr> used here is defined in XML 1.0 (Third Edition)
- [[!EBNF-NOTATION]]. Production labels consisting of a number and a final 's', e.g. [<a href="http://www.w3.org/TR/2008/REC-rdf-sparql-query-20080115/#rRDFLiteral"><span class="prodNo">60s</span></a>], reference the production with that number in the <a href="http://www.w3.org/TR/2008/REC-rdf-sparql-query-20080115/#sparqlGrammar">SPARQL Query Language for RDF grammar</a> [[RDF-SPARQL-QUERY]].
- </p>
- <p class="note">There are known formating issues with the table form of the grammar. Please see <a href="turtle.bnf">turtle.bnf</a> for exact grammar.</p>
- <div data-include="turtle-bnf.html">
- </div>
- </section>
- </section>
- <section id="sec-parsing">
- <h2>Parsing</h2>
-
- <p>The <a href="../rdf-concepts/index.html">RDF Concepts and Abstract Syntax</a> ([[!RDF-CONCEPTS]]) specification defines three types of <em>RDF Term</em>:
-
- <a href="../rdf-concepts/index.html#dfn-iri">RDF URI References</a> (here called IRIs),
- <a href="../rdf-concepts/index.html#dfn-literal">literals</a> and
- <a href="../rdf-concepts/index.html#dfn-blank-node">blank nodes</a>.
- Literals are composed of a <a href="../rdf-concepts/index.html#dfn-lexical-form">lexical form</a> and an optional <a href="../rdf-concepts/index.html#dfn-language-identifier">language tag</a> or datatype IRI.
- An extra type, <code id="prefix" class="dfn">prefix</code>, is used during parsing to map string identifiers to namespace IRIs.
-
- <!-- The Turtle grammar uses the same productions and terminals to create these terms as does <a href="http://www.w3.org/TR/rdf-sparql-query/#grammar">SPARQL</a>. --><!-- This set is listed in <a href="http://www.w3.org/TR/rdf-sparql-query/#docTerminology">SPARQL §1.2.4</a>. -->
-
- This section maps a string conforming to the grammar in <a href="#sec-grammar-grammar">section 4.4</a> to a set of triples by mapping strings matching productions and lexical tokens to RDF terms or their components (e.g. language tags, lexical forms of literals). Some productions change the parser state (base or prefix declarations).</p>
- <section id="sec-parsing-state">
- <h3>Parser State</h3>
-
- <p>Parsing Turtle requires a state of four items:</p>
-
- <ul>
- <li id="baseURI">IRI <code class="dfn">baseURI</code> — When the <a href="#prod-turtle2-base">base production</a> is reached, the second rule argument, <code>IRI_REF</code>, is the base URI used for relative IRI resolution <span class="testrefs">(test: <a href="tests/#base1">base1</a> <a href="tests/#base2">base2</a>)</span>.</li>
-
- <li id="namespaces">Map[<a class="type prefix" href="#prefix">prefix</a> -> IRI] <code class="dfn">namespaces</code> — The second and third rule arguments (<code>PNAME_NS</code> and <code>IRI_REF</code>) in the <a href="#prod-turtle2-prefixID">prefixID production</a> assign a namespace name (<code>IRI_REF</code>) for the prefix (<code>PNAME_NS</code>). Outside of a <code>prefixID</code> production, any <code>PNAME_NS</code> is substituted with the namespace <span class="testrefs">(test: <a href="tests/#prefix1">prefix1</a> <!-- a href="tests/#escapedPrefix1">escapedPrefix1</a --> <a href="tests/#escapedNamespace1">escapedNamespace1</a>)</span>. Note that the prefix may be an empty string, per the <code>PNAME_NS,</code> production: <code>(PN_PREFIX)? ":"</code> <span class="testrefs">(test: <a href="tests/#default1">default1</a>)</span>.</li>
-
- <li id="bnodeLabels">Map[<a class="type string">string</a> -> <a href="../rdf-concepts/index.html#dfn-blank-node">blank node</a>] <code class="dfn">bnodeLabels</code> — A mapping from string to blank node label.</li>
- <li id="curSubject">RDF_Term <code class="dfn">curSubject</code> — The <code class="curSubject">curSubject</code> is bound to the <code><a href="#prod-turtle2-subject">subject</a></code> production.</li>
-
- <li id="curPredicate">RDF_Term <code class="dfn">curPredicate</code> — The <code class="curPredicate">curPredicate</code> is bound to the <code><a href="#prod-turtle2-verb">verb</a></code> production. If token matched was "<code>a</code>", <code class="curPredicate">curPredicate</code> is bound to the IRI <code>http://www.w3.org/1999/02/22-rdf-syntax-ns#type</code> <span class="testrefs">(test: <a href="tests/#type">type</a>)</span>.</li>
-
- </ul>
- </section>
- <section id="sec-parsing-terms">
- <h3>RDF Term Constructors</h3>
-
- <p>This table maps productions and lexical tokens to <code>RDF terms</code> or components of <code>RDF terms</code> listed in <a href="#sec-parsing">section 5</a>:</p>
-
- <table>
- <thead>
- <tr> <th> production </th><th> type </th><th>procedure</th></tr>
- </thead>
- <tbody>
- <tr id="handle-IRI_REF" ><td><a class="type IRI" href="#term-turtle2-IRI_REF" >IRI_REF </a></td><td><a href="../rdf-concepts/index.html#dfn-iri"> IRI </a></td><td>The characters between "<" and ">" are <a href="#unescape">unescaped¹</a> to form the unicode string of the IRI. Relative IRI resolution is performed per <a href="http://www.w3.org/TR/rdf-sparql-query/#QSynIRI">SPARQL Query section 4.1.1</a>.</td></tr>
- <tr id="handle-PNAME_NS" ><td><a class="type string" href="#term-turtle2-PNAME_NS" >PNAME_NS </a></td><td><a href="#prefix"> prefix </a></td><td>The potentially empty unicode string matching the first argument of the rule is a key into the <a href="#namespaces">namespaces map</a>.</td></tr>
- <tr id="handle-PNAME_LN" ><td><a class="type IRI" href="#term-turtle2-PNAME_LN" >PNAME_LN </a></td><td><a href="../rdf-concepts/index.html#dfn-iri"> IRI </a></td><td>A <a href="#prefix">prefix</a> is identified by the first argument, <code>PNAME_NS</code>. The <a href="#namespaces">namespaces map</a> has a corresponding <code>namespace</code>. The unicode string of the IRI is formed by concatenating this <code>namespace</code> and the second argument, <code>PN_LOCAL</code>. Relative IRI resolution is performed per <a href="http://www.w3.org/TR/rdf-sparql-query/#QSynIRI">SPARQL Query section 4.1.1</a>.</td></tr>
- <tr id="handle-STRING_LITERAL1" ><td><a class="type lexicalForm" href="#term-turtle2-STRING_LITERAL1" >STRING_LITERAL1 </a></td><td><a href="../rdf-concepts/index.html#dfn-lexical-form"> lexical form</a></td><td>The characters between the outermost "'"s are <a href="#unescape">unescaped¹</a> to form the unicode string of a lexical form.</td></tr>
- <tr id="handle-STRING_LITERAL2" ><td><a class="type lexicalForm" href="#term-turtle2-STRING_LITERAL2" >STRING_LITERAL2 </a></td><td><a href="../rdf-concepts/index.html#dfn-lexical-form"> lexical form</a></td><td>The characters between the outermost '"'s are <a href="#unescape">unescaped¹</a> to form the unicode string of a lexical form.</td></tr>
- <tr id="handle-STRING_LITERAL_LONG1" ><td><a class="type lexicalForm" href="#term-turtle2-STRING_LITERAL_LONG1" >STRING_LITERAL_LONG1 </a></td><td><a href="../rdf-concepts/index.html#dfn-lexical-form"> lexical form</a></td><td>The characters between the outermost "'''"s are <a href="#unescape">unescaped¹</a> to form the unicode string of a lexical form.</td></tr>
- <tr id="handle-STRING_LITERAL_LONG2" ><td><a class="type lexicalForm" href="#term-turtle2-STRING_LITERAL_LONG2" >STRING_LITERAL_LONG2 </a></td><td><a href="../rdf-concepts/index.html#dfn-lexical-form"> lexical form</a></td><td>The characters between the outermost '"""'s are <a href="#unescape">unescaped¹</a> to form the unicode string of a lexical form.</td></tr>
- <tr id="handle-LANGTAG" ><td><a class="type langTag" href="#term-turtle2-LANGTAG" >LANGTAG </a></td><td><a href="../rdf-concepts/index.html#dfn-language-identifier">language tag</a></td><td>The characters following the "@" form the unicode string of the language tag.</td></tr>
- <tr id="handle-RDFLiteral" ><td><a class="type literal" href="#term-turtle2-RDFLiteral" >RDFLiteral </a></td><td><a href="../rdf-concepts/index.html#dfn-literal"> literal </a></td><td>The literal has a lexical form of the first rule argument (<code>String</code>) and either a language tag of <code>LANGTAG</code> or a datatype IRI of <code>IRIref</code>, depending on which rule matched the input.</td></tr>
- <tr id="handle-INTEGER" ><td><a class="type integer" href="#term-turtle2-INTEGER" >INTEGER </a></td><td><a href="../rdf-concepts/index.html#dfn-literal"> literal </a></td><td>The literal has a lexical form of the input string, and a datatype of xsd:integer.</td></tr>
- <tr id="handle-DECIMAL" ><td><a class="type decimal" href="#term-turtle2-DECIMAL" >DECIMAL </a></td><td><a href="../rdf-concepts/index.html#dfn-literal"> literal </a></td><td>The literal has a lexical form of the input string, and a datatype of xsd:decimal.</td></tr>
- <tr id="handle-DOUBLE" ><td><a class="type double" href="#term-turtle2-DOUBLE" >DOUBLE </a></td><td><a href="../rdf-concepts/index.html#dfn-literal"> literal </a></td><td>The literal has a lexical form of the input string, and a datatype of xsd:double.</td></tr>
- <tr id="handle-BooleanLiteral" ><td><a class="type boolean" href="#prod-turtle2-BooleanLiteral" >BooleanLiteral </a></td><td><a href="../rdf-concepts/index.html#dfn-literal"> literal </a></td><td>The literal has a lexical form of the "true" or "false", depending on which matched the input, and a datatype of xsd:boolean.</td></tr>
- <tr id="handle-BLANK_NODE_LABEL" ><td><a class="type bNode" href="#term-turtle2-BLANK_NODE_LABEL" >BLANK_NODE_LABEL </a></td><td><a href="../rdf-concepts/index.html#dfn-blank-node"> blank node </a></td><td>The string matching the second argument, <code>PN_LOCAL</code>, is a key in <a href="#bnodeLabels">bnodeLabels</a>. If there is no corresponding blank node in the map, one is allocated.</td></tr>
- <tr id="handle-ANON" ><td><a class="type bNode" href="#term-turtle2-ANON" >ANON </a></td><td><a href="../rdf-concepts/index.html#dfn-blank-node"> blank node </a></td><td>A blank node is generated.</td></tr>
- <tr id="handle-blankNodePropertyList"><td><a class="type bNode" href="#prod-turtle2-blankNodePropertyList">blankNodePropertyList</a></td><td><a href="../rdf-concepts/index.html#dfn-blank-node"> blank node </a></td><td>A blank node is generated. Note the rules for <code>blankNodePropertyList</code> in the next section.</td></tr>
- <tr id="handle-collection" ><td><a class="type bNode" href="#prod-turtle2-collection" >collection </a></td><td><a href="../rdf-concepts/index.html#dfn-blank-node"> blank node </a></td><td>A blank node is generated. Note the rules for <code>collection</code> in the next section.</td></tr>
- </tbody>
- </table>
-
- <p><a id="unescape">¹</a> <a href="http://www.w3.org/TeamSubmission/turtle/#sec-strings">Section 3.3</a> defines a mapping from <code>escaped unicode strings</code> to <code>unicode strings</code>. The following lexical tokens are unescaped to produce <code>unicode strings</code>: <a class="type IRI" href="#term-turtle2-IRI_REF">IRI_REF</a>, <!-- <a class="type PNAME_NS" href="#term-turtle2-PNAME_NS">PNAME_NS</a>, --><!-- <a class="type IRI" href="#term-turtle2-PNAME_LN">PNAME_LN</a>, --><a class="type lexicalForm" href="#term-turtle2-STRING_LITERAL1">STRING_LITERAL1</a>, <a class="type lexicalForm" href="#term-turtle2-STRING_LITERAL2">STRING_LITERAL2</a>, <a class="type lexicalForm" href="#term-turtle2-STRING_LITERAL_LONG1">STRING_LITERAL_LONG1</a> and <a class="type lexicalForm" href="#term-turtle2-STRING_LITERAL_LONG2">STRING_LITERAL_LONG2</a><!-- and <a class="type langTag" href="#term-turtle2-LANGTAG">LANGTAG</a> --><!-- and <a class="type bNode" href="#term-turtle2-BLANK_NODE_LABEL">BLANK_NODE_LABEL</a> -->.</p>
- </section>
- <section id="sec-parsing-triples">
- <h3>RDF Triples Constructors</h3>
- <p>A Turtle document defines an <a href="../rdf-concepts/index.html#dfn-rdf-graph">RDF graph</a> composed of set of <a href="../rdf-concepts/index.html#dfn-rdf-triple">RDF triple</a>s.
- Each <a tabindex="30" class="grammarRef" href="#prod-turtle2-object">object</a> <code>N</code> in the document produces an RDF triple: <span class="ntriple"><code class="curSubject">curSubject</code> <code class="curPredicate">curPredicate</code> <code>N</code> .</span>
-
- </p>
-
- <p>
- Beginning the <code><a href="#prod-turtle2-blankNodePropertyList">blankNodePropertyList</a></code> production records the <code class="curSubject">curSubject</code> and <code class="curPredicate">curPredicate</code>, and sets <code class="curSubject">curSubject</code> to a novel <code>blank node</code> <code>B</code>.
- Finishing the <code><a href="#prod-turtle2-blankNodePropertyList">blankNodePropertyList</a></code> production restores <code class="curSubject">curSubject</code> and <code class="curPredicate">curPredicate</code>.
- The node produced by matching <code><a href="#prod-turtle2-blankNodePropertyList">blankNodePropertyList</a></code> is the blank node <code>B</code>.
-
- </p>
-
- <p>
- Beginning the <code><a href="#prod-turtle2-collection">collection</a></code> production records the <code class="curSubject">curSubject</code> and <code class="curPredicate">curPredicate</code>, sets <code class="curSubject">curSubject</code> to a novel <code>blank node</code> <code>B<sub>head</sub></code> and sets <code class="curSubject">curSubject</code> and <code class="curPredicate">curPredicate</code> to <code>B<sub>head</sub></code> and <code>rdf:first</code> respectively.
- Each object <code>O</code> in <code><a href="#prod-turtle2-collection">collection</a></code> allocates a novel <code>blank node</code> <code>B<sub>n</sub></code>, creates an additional triple <span class="ntriple"><code>curSubject rdf:rest B<sub>n</sub></code> .</span> and sets <code>curSubject</code> to <code>B<sub>n</sub></code>.
- Finishing the <code><a href="#prod-turtle2-collection">collection</a></code> production creates an additional triple <span class="ntriple"><code>curSubject rdf:rest rdf:nil</code> .</span> and restores <code class="curSubject">curSubject</code> and <code class="curPredicate">curPredicate</code>
-
- The node produced by matching <code><a href="#prod-turtle2-collection">collection</a></code> is the blank node <code>B<sub>head</sub></code>.
- </p>
- </section>
- <section id="sec-parsing-example" class="informative">
- <h3>Parsing Example (Informative)</h3>
-
- <p>The following informative example shows the semantic actions performed when parsing this Turtle document with an LALR(1) parser:</p>
- <pre class="example"><script type="text/turtle">
-@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> .
- </script></pre>
-
- <ul>
- <li>Map the prefix <code>ericFoaf</code> to the IRI <code>http://www.w3.org/People/Eric/ericP-foaf.rdf#</code>.</li>
- <li>Map the empty prefix to the IRI <code>http://xmlns.com/foaf/0.1/</code>.</li>
- <li>Assign <code class="curSubject">curSubject</code> the IRI <code>http://www.w3.org/People/Eric/ericP-foaf.rdf#ericP</code>.</li>
-
- <li>Assign <code class="curPredicate">curPredicate</code> the IRI <code>http://xmlns.com/foaf/0.1/givenName</code>.</li>
- <li>Emit an RDF triple: <span class="ntriple"><code><...rdf#ericP></code> <code><.../givenName></code> <code>"Eric"</code> .</span></li>
-
- <li>Assign <code class="curPredicate">curPredicate</code> the IRI <code>http://xmlns.com/foaf/0.1/knows</code>.</li>
- <li>Emit an RDF triple: <span class="ntriple"><code><...rdf#ericP></code> <code><.../knows></code> <code><...who/dan-brickley></code> .</span></li>
-
- <li>Emit an RDF triple: <span class="ntriple"><code><...rdf#ericP></code> <code><.../knows></code> <code>_:1</code> .</span></li>
- <li>Save <code class="curSubject">curSubject</code> and reassign to the blank node <code>_:1</code>.</li>
-
- <li>Save <code class="curPredicate">curPredicate</code>.</li>
- <li>Assign <code class="curPredicate">curPredicate</code> the IRI <code>http://xmlns.com/foaf/0.1/mbox</code>.</li>
- <li>Emit an RDF triple: <span class="ntriple"><code>_:1</code> <code><.../mbox></code> <code><mailto:timbl@w3.org></code> .</span></li>
-
- <li>Restore <code class="curSubject">curSubject</code> and <code class="curPredicate">curPredicate</code> to their saved values (<code><...rdf#ericP></code>, <code><.../knows></code>).</li>
- <li>Emit an RDF triple: <span class="ntriple"><code><...rdf#ericP></code> <code><.../knows></code> <code><http://getopenid.com/amyvdh></code> .</span></li>
-
- </ul>
- </section>
- </section>
- <section id="sec-examples" class="informative">
- <h2>Examples (Informative)</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="examples/example1.ttl">example1.ttl</a>):
- </p>
-
- <div data-include="examples/example1.ttl" data-oninclude="updateExample"></div>
-
-
- <p>An example of an RDF collection of two literals.</p>
- <pre class="example"><script type="text/turtle">
-@prefix : <http://example.org/stuff/1.0/> .
-:a :b ( "apple" "banana" ) .
- </script></pre>
- <p>which is short for (<a href="examples/example2.ttl">example2.ttl</a>):</p>
-
- <div data-include="examples/example2.ttl" data-oninclude="updateExample"></div>
-
- <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="examples/example3.ttl">example3.ttl</a>):</p>
-
- <div data-include="examples/example3.ttl" data-oninclude="updateExample"></div>
-
- <p>As indicated by the grammar, a <a href="#prod-turtle2-collection">collection</a> can be either a <a href="#prod-turtle2-subject">subject</a> or an <a href="#prod-turtle2-object">object</a>. This subject or object will be the novel blank node for the first object, if the collection has one or more objects, or <code>rdf:nil</code> if the collection is empty.</p>
-
- <p>For example,</p>
-
- <pre class="example untested"><script type="text/turtle">(1 2.0 3E1) :p "w" .</script></pre>
-
- <p>is syntactic sugar for (noting that the blank nodes <code>b0</code>, <code>b1</code> and <code>b2</code> do not occur anywhere else in the RDF graph):</p>
-
-<pre class="example untested"><script type="text/turtle"> _: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" . </script></pre>
-
- <p>RDF collections can be nested and can involve other syntactic forms:</p>
-
- <pre class="example untested">(1 [:p :q] ( 2 ) ) .</pre>
-
- <p>is syntactic sugar for:</p><pre class="example untested"><script type="text/turtle"> _: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 .</script></pre>
- </section>
- <section id="sec-identifiers">
- <h2>Identifiers for the Turtle Language</h2>
- <p>The IRI that identifies the Turtle language is:<br />
- <code>http://www.w3.org/ns/formats/Turtle</code>
- </p>
-
- <p>The XML (Namespace name, Local name) pair that identifies
- the Turtle language is:<br />
- Namespace: <code>http://www.w3.org/ns/formats/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>
- <p class="issue">Previous versions of the Turtle specified
- <code>http://www.w3.org/2008/turtle#turtle</code> as the IRI for the Turtle language.
- This change aligns Turtle with identifiers for RDF/XML, N3, POWDER, etc</p>
-
- </section>
- <section id="sec-conformance">
- <h2>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>
- <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>
- </section>
- <section id="sec-mime">
- <h2>Media Type and Content Encoding</h2>
-
- <p>The media type of Turtle is <code>text/turtle</code>.
- The content encoding of Turtle content is always UTF-8. Charset
- parameters on the mime type are required until such time as the
- <code>text/</code> 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>
- </section>
-
- <section id="in-html">
- <h2>Turtle in HTML</h2>
- <p>HTML ([[!HTML5]]) <code>script</code> <a href="http://dev.w3.org/html5/spec/Overview.html#scripting-1">tags</a>
- can be used to embed data blocks in documents. Turtle can be easily embedded in HTML this way.</p>
- <pre class="example">
-<script type="text/turtle">
-@prefix dc: <http://purl.org/dc/terms/> .
-@prefix frbr: <http://purl.org/vocab/frbr/core#> .
-
-<http://books.example.com/works/45U8QJGZSQKDH8N> a frbr:Work ;
- dc:creator "Wil Wheaton"@en ;
- dc:title "Just a Geek"@en ;
- frbr:realization <http://books.example.com/products/9780596007683.BOOK>,
- <http://books.example.com/products/9780596802189.EBOOK> .
-
-<http://books.example.com/products/9780596007683.BOOK> a frbr:Expression ;
- dc:type <http://books.example.com/product-types/BOOK> .
-
-<http://books.example.com/products/9780596802189.EBOOK> a frbr:Expression ;
- dc:type <http://books.example.com/product-types/EBOOK> .
-</script>
- </pre>
- <p>Turtle content should be placed in a <code>script</code> tag with the
- <code>type</code> attribute set to <code>text/turtle</code>. <code><</code> and <code>></code> symbols
- do not need to be escaped inside of script tags. The character encoding of the embedded Turtle
- MUST match the HTML documents encoding.</p>
- <section>
- <h3>XHTML</h3>
- <p>
- Like JavaScript, Turtle authored for HTML (<code>text/html</code>) can break when used in an XHTML
- (<code>application/xhtml+xml</code>). The solution is the same one used for JavaScript.
- </p>
- <pre class="example">
-<script type="text/turtle">
-<strong># <![CDATA[</strong>
-@prefix frbr: <http://purl.org/vocab/frbr/core#> .
-
-<http://books.example.com/works/45U8QJGZSQKDH8N> a frbr:Work .
-<strong># ]]></strong>
-</script>
- </pre>
- <p>When embedded in XHTML Turtle data blocks MUST be enclosed in CDATA sections. Those CDATA markers MUST be
- in Turtle comments. This will also make Turtle safe in polyglot documents served as both <code>text/html</code>
- and <code>application/xhtml+xml</code>.</p>
- </section>
- <section class="informative">
- <h3>Displaying Examples</h3>
- <p>
- It is possible to display the contents of script tags containing Turtle for use in examples or other guides
- using Cascading Style Sheets Selectors Level 3 ([[SELECT]]).
- </p>
-<pre class="example">
-script[type='text/turtle'] {
- display:block;
- white-space: pre;
- font-family: monospace;
-}
-</pre>
- <p>
- However, this creates issues with polyglot documents. If you wish to display Turtle from script tags you
- SHOULD only use <code>text/html</code>.
- </p>
- </section>
- <section id="in-html-parsing">
- <h3>Parsing Turtle in HTML</h3>
- <p>There are no syntactic or grammar diffrences between parsing Turtle that has been embedded
- and normal Turtle documents. Each <code>script</code> data block is considered to be it's own
- Turtle document. <code>@prefix</code>, <code>@base</code> declarations MUST NOT effect other
- data blocks. All Turtle data blocks in a HTML document share the same document base URI as the HTML
- document. THe HTML <code>lang</code> attribute or XHTML <code>xml:lang</code> attribute have
- no effect on the parsing of the data blocks.</p>
- </section>
- </section>
- <!-- BEGIN N-TRIPLES SPEC -->
-
- <section id="sec-triples">
- <h2>N-Triples</h2>
- <p>This section defines an easy to parse line-based subset of Turtle named N-Triples.</p>
- <p>The syntax is an improved version of N-Triples as originally defined in the RDF Test Cases [[!RDF-TESTCASES]] document. Its original intent was for writing test cases, but it has proven to be popular as a dump format for RDF data.</p>
- <section id="n-triples-mediatype">
- <h2>Media Type and Content Encoding</h2>
-
- <p>The media type of N-Triples is <code>application/ntriples</code>.
- The content encoding of N-Triples is always UTF-8. N-Triples may also be provided as <code>text/plain</code>. When used in this way N-Triples MUST use the escaped form of any character outside US-ASCII. As N-Triples is a subset of Turtle it MAY also be provided as <code>text/turtle</code>.
- See <a href="#sec-mediaReg-n-triples">N-Triples Media Type</a> for the media type
- registration form.
- </p>
-
- </section>
- <section id="n-triple-changes" class="informative">
- <h3>Changes from RDF Test Cases format</h3>
- <ul>
- <li>Encoding is UTF-8 rather than US-ASCII
- <li>Uses IRIs rather than RDF URI References
- <li>Defines a unique media type <code>application/ntriples</code>
- <li>Subset of Turtle rather than Notation 3
- <li>Comments may occur after a triple production
- <li>Allows <code>\b</code> and <code>\f</code> for backspace and form feed
- <li>More than one way to represent a single character
- </ul>
- </section>
- <section id="n-triples-compatibility" class="informative">
- <h3>Compatibility with previous RDF Test Cases N-Triples</h3>
- <p class="issue">This section is very prescriptive and contains no information not contained above.</p>
- <p>
- Full backwards compatibility with RDF Test Cases N-Triples is supported. An RDF Test Cases document written using only absolute IRIs is a valid N-Triples document generating the same triples. Both use <code>\u</code> escape sequences for characters outside US-ASCII and processing will have turned these into the original character.
- </p>
-
- <p>N-Triples is also forwards compatible with existing RDF Test Cases format parsers. A N-Triples document that is serialized into US-ASCII and uses <code>\u</code> escape sequences for any character outside US-ASCII is equivalent to a RDF Test Cases document. In addition the backspace (<code>U+0008</code>) and form feed (<code>U+000C</code>) characters SHOULD be escaped using the <code>\u</code> sequence rather than using <code>\b</code> or <code>\f</code>. Any comments SHOULD also be removed to avoid changes in the locations that comments are allowed. Such a document provided as <code>text/plain</code> is indistinguishable from an RDF Test Cases format document.
- </p>
- </section>
- <section id="n-triple-grammar">
- <h3>Grammar</h3>
- <p>A N-Triples 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.</p>
- <p><a href="#sec-strings">Escape sequence rules</a> are the same as Turtle. However, as only the <code>STRING_LITERAL2</code> production is allowed new lines in literals MUST be escaped.</p>
- <pre data-include="n-prime.bnf" data-oninclude="esc">
- </pre>
- </section>
- </section>
-
-<!-- END N-TRIPLES SPEC -->
-
- <section id="sec-compared">
- <h2>Turtle compared</h2>
- <p>Turtle is related to a number of other languages.</p>
- <section id="sec-diff-n3" class="informative">
- <h3>Turtle compared to Notation 3 (Informative)</h3>
-
- <p>Turtle is similar to and inspired by Notation 3 (<abbr title="Notation 3">N3</abbr>).
- Please see the most recent Notation3 specification for comparison with Turtle.
-<!--
- While the syntax played a role in the creation of Turtle
- they are not strictly compatible. There are a number of differences in
- escaping, encoding and structure. 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 <code>_:Bob a foaf:Person</code> is the object of another arc:</p>
- <pre>_:Bob ex:said { _:Bob a foaf:Person } .</pre>
-
- <p>In addition, Literals are allowed in the subject position. For example:</p>
- <pre>"Bob" ex:said "Hi Bob" .</pre>
-
- <p>Following is a partial list of syntactic features in N3 which are not in Turtle:</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>=></code> implies</li>
- <li><code>=</code> equivalence</li>
-
- <li><code>@forAll</code></li>
- <li><code>@forSome</code></li>
- <li><=</li>
- </ol>
--->
- </section>
- <section id="sec-diff-rdfxml" class="informative">
- <h3>Turtle compared to RDF/XML (Informative)</h3>
- <p>
- <a href="http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/">RDF/XML</a>
- ([[RDF-SYNTAX-GRAMMAR]])
- 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>
- </section>
- <section id="sec-diff-sparql" class="informative">
- <h3>Turtle compared to SPARQL (Informative)</h3>
-
- <p>The <a href="http://www.w3.org/TR/sparql11-query/">SPARQL Query Language for RDF</a> (<abbr title="SPARQL Protocol And RDF Query Language">SPARQL</abbr>) [[RDF-SPARQL-QUERY]] uses a Turtle style syntax for its <a href="http://www.w3.org/TR/sparql11-query/#rTriplesBlock">TriplesBlock production</a>.
- This production differs from the Turtle language in that:
- </p>
-
- <ol>
- <li>SPARQL permits RDF Literals as the subject of RDF triples (per <a href="http://www.w3.org/TR/sparql11-query/#rGraphTerm">Last Call draft</a>)</li>
-
- <li>SPARQL permits variables (<code>?</code><em>name</em> or <code>$</code><em>name</em>) in any part of the triple of the form</li>
- <li>Turtle allows <a href="#prod-turtle2-directive">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/sparql11-query/#rPrologue">Prologue</a> (at the start of the SPARQL query).</li>
- <li>SPARQL uses case insensitive keywords, except for <code>a</code>. Turtle's prefix and base declarations are case sensitive.</li>
- <li><code>true</code> and <code>false</code> are case insensitive in SPARQL and case sensitive in Turtle. <code>TrUe</code> is not a valid boolean value in Turtle.</li>
-
- </ol>
-
- <p>For further information see the
- <a href="http://www.w3.org/TR/sparql11-query/#QSynIRI">Syntax for IRIs</a>
- and <a href="http://www.w3.org/TR/sparql11-query/#grammar">SPARQL Grammar</a>
- sections of the SPARQL query document [[RDF-SPARQL-QUERY]].
- </p>
- </section>
-
- </section>
-
- <section id="sec-mediaReg" class="appendix">
- <h2>Internet Media Type, File Extension and Macintosh File Type (Normative)</h2>
- <dl>
- <dt>Contact:</dt>
- <dd>Ian Davis</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 "text/turtle".</p>
- <p>It is recommended that Turtle files have the extension ".ttl" (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 "TEXT".</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><code>charset</code> — this parameter is required when transferring non-ASCII data. If present, the value of <code>charset</code> is always <code>UTF-8</code>.</dd>
-
- <dt>Encoding considerations:</dt>
- <dd>The syntax of Turtle is expressed over code points in Unicode [[!UNICODE]]. The encoding is always UTF-8 [[!UTF-8]].</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 IRIs, invoking the security considerations of the scheme for that IRI. Note in particular, the privacy issues in [[!RFC3023]] section 10 for HTTP IRIs. Data obtained from an inaccurate or malicious data source may lead to inaccurate or misleading conclusions, as well as the dereferencing of unintended IRIs. 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> [[!RFC3987]] Section 8, as well as
- <a class="norm" href="http://www.ietf.org/rfc/rfc3986.txt">Uniform Resource Identifier (URI): Generic Syntax</a> [[!RFC3986]] Section 7.</dd>
-
- <dd>Multiple IRIs may have the same appearance. Characters in different scripts may
- look similar (a Cyrillic "о" may appear similar to a Latin "o"). 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鼯code> and <code>fоо:resumé</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> [[UNISEC]] and
- <a class="norm" href="http://www.ietf.org/rfc/rfc3987.txt">Internationalized Resource
- Identifiers (IRIs)</a> [[RFC3987]] 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 <IRIref>' 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>"TEXT"</dd>
- <dt>Person & email address to contact for further information:</dt>
-
- <dd>Eric Prud'hommeaux <eric@w3.org></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>
- </section>
-
-
- <section id="sec-acks" class="appendix">
- <h2>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>
-
- </section>
- <section id="sec-changelog" class="appendix">
- <h2>Changes (Informative)</h2>
-
- <p>Changes since the last publication of this document
- <a href="http://www.w3.org/TeamSubmission/2008/SUBM-turtle-20080114">W3C Turtle Submission 2008-01-14</a>
- . See the
- <a href="http://www.w3.org/TeamSubmission/2008/SUBM-turtle-20080114#sec-changelog">Previous changelog for further information</a>
- </p>
-
-
- <ul>
-
- <li>Adopted three additional string syntaxes from SPARQL: <a href="#term-turtle2-STRING_LITERAL2">STRING_LITERAL2</a>, <a href="#term-turtle2-STRING_LITERAL_LONG1">STRING_LITERAL_LONG1</a>, <a href="#term-turtle2-STRING_LITERAL_LONG2">STRING_LITERAL_LONG2</a></li>
-
- <li>Adopted SPARQL's syntax for prefixed names (see <a href="http://www.w3.org/TR/sparql11-query/#rPrefixedName">editor's draft</a>):
- <ul>
- <li>'.'s in names in all positions of a local name apart from the first or last, e.g. <code>ex:first.name</code>.</li>
-
- <li>digits in the first character of the <a href="http://www.w3.org/TR/rdf-sparql-query/#rPN_LOCAL">PN_LOCAL</a> lexical token, e.g. <code>ex:7tm</code>.</li>
- </ul></li>
- <li>Made <a href="#sec-syntax">syntax section</a> normative.
- <ul>
- <li>adopted SPARQL's IRI resolution and prefix substitution text.</li>
-
- <li>explicitly allowed re-use of the same prefix.</li>
- </ul></li>
- <li>Added <a href="#sec-parsing">parsing rules</a>.</li>
- </ul>
- </section>
-
-
-
- </body>
-
-</html>
-
-
--- a/rdf-turtle/index.html Mon Mar 26 12:11:36 2012 -0700
+++ b/rdf-turtle/index.html Mon Mar 26 12:18:40 2012 -0700
@@ -75,6 +75,8 @@
company: "W3C", companyURL: "http://www.w3.org/" },
{ name: "Eric Prud'hommeaux", url: "http://www.w3.org/People/Eric/",
company: "W3C", companyURL: "http://www.w3.org/" },
+ { name: "Gavin Carothers", url: "http://gavin.carothers.name/",
+ company: "TopQuadrant, Inc", companyURL: "http://topquadrant.com/" },
],
// name of the WG
@@ -149,207 +151,206 @@
<section id="sec-intro">
<h2>Introduction</h2>
- <p>This document defines Turtle, the Terse RDF Triple Language,
- a concrete syntax for RDF as defined in the
- <a href="../rdf-concepts/index.html">RDF Concepts and Abstract Syntax</a> ([[!RDF-CONCEPTS]]) W3C Recommendation.
- Turtle is an extension of the
- <a href="http://www.w3.org/TR/rdf-testcases/#ntriples">RDF Test Cases format</a>
- ([[!N-TRIPLES]])
- carefully taking the most useful and appropriate things added from
- <a href="http://www.w3.org/DesignIssues/Notation3">Notation 3</a>
- ([[N3]])
- while staying within the RDF model.</p>
- <p>The Turtle grammar for <a href="#prod-turtle2-triples"><code>triples</code></a> is a subset of the
- <a href="http://www.w3.org/TR/2008/REC-rdf-sparql-query-20080115/">SPARQL Query Language for RDF</a>
- [[RDF-SPARQL-QUERY]] grammar for <a href="http://www.w3.org/TR/sparql11-query/#rTriplesBlock"><code>TriplesBlock</code></a>. The two grammars share production and terminal names where possible.</p>
- </section>
- <section class="informative">
-
- <h2>An Introduction to Turtle (Informative)</h2>
- <p>The
- <a href="#sec-syntax">Turtle Syntax</a> and <a href="#sec-grammar">Turtle Grammar</a> sections formally define the language.
- </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 and optional blank lines. Comments may be given after a <code>#</code>
- that is not part of another lexical token 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 the
- <a href="http://www.w3.org/TR/rdf-testcases/#ntriples">RDF Test Cases format</a>
- [[N-TRIPLES]].
+ <p>
+ This document defines two syntaxes for <a href="../rdf-concepts/index.html">RDF</a> ([[!RDF-CONCEPTS]]), Turtle, the Terse RDF Triple Language, and N-Triples.
+ N-Triples is a sublanguage of Turtle, which in turn borrows much of its syntax from <a href="http://www.w3.org/DesignIssues/Notation3">Notation 3</a> ([[N3]]).
</p>
- <p>There are three types of <em>RDF Term</em>:
- <a href="../rdf-concepts/index.html#dfn-iri">Internationalized Resource Identifiers</a> (IRIs for short),
- <a href="../rdf-concepts/index.html#dfn-literal">literals</a> and
- <a href="../rdf-concepts/index.html#dfn-blank-node">blank nodes</a>.</p>
-
- <section id="terms">
- <h3>RDF Terms</h3>
-
- <p>IRIs are written enclosed in '<' and '>' and may be
- absolute RDF URI References or relative to the current base IRI
- (described below).
- </p>
-
- <pre class="example"><script type="text/plain"># this is not a complete turtle document
-<http://example.org/path/>
-
-<http://example.org/path/#fragment>
-</path>
-<#fragment>
-<></script></pre>
+ <p>
+ Turtle and N-Triples documents are textual representation of a RDF graphs.
+ A Turtle document consists parsing directives and triples.
+ An N-Triples document contains no parsing directives.
+ Comments in either language may be given after a <code>#</code> that is not part of another lexical token and continue to the end of the line.
+ </p>
- <p>IRIs 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 IRIs. This is useful for many RDF vocabularies that are
- all defined with a common namespace like IRI.</p>
-
- <p class="note">While <code>@prefix</code> works somewhat like XML
- namespaces the restrictions from XML QNames do NOT apply. <code>leg:3032571</code>
- is a perfectly fine prefixed name. Some character escapes are allowed
- in the local part of prefixed names. These are the non-alphanumeric
- characters allowed in an IRI path. The characters are
- <code>~.-!$&'()*+,;=:/?#@%_</code>. <code>og:video\:height</code>
- is an example of escaping <code>:</code>.</p>
- <p>
-
- </p>
+ <p>
+ N-Triples triples are a sequence of RDF terms representing the subject, predicate and object of an RDF Triple. This sequence is terminated by a '.' and a new line (optional at the end of a document).
+ </p>
- <p>Once a prefix such as <code>@prefix foo:
- <http://example.org/ns#></code> is defined, any mention of a
- URI later in the document may use a <em>prefixed name</em> that
- starts <code>foo:</code> to stand for the longer IRI. So for
- example, the prefixed name <code>foo:bar</code> is a shorthand for
- the IRI <code><http://example.org/ns#bar></code>.</p>
-
- <pre class="example"><script type="text/turtle"># this is a complete turtle document
-@prefix foo: <http://example.org/ns#> .
-@prefix : <http://other.example.org/ns#> .
-foo:bar foo: : .
-:bar : foo:bar .
-</script></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"><script type="text/plain"># this is not a complete turtle document
-"a string"
-"""a string"""
-"""a string
-with newlines
-"""
+ <pre class="example"><script type="text/plain">
+_:subject1 <http://an.example/predicate1> "object1" .
+_:subject2 <http://an.example/predicate2> "object2" .
</script></pre>
- <p>Literals have either a language suffix or a datatype IRI
- but not both. Languages are indicated by appending the simple
- literal with <code>@</code> and the language tag. Datatype IRIs
- similarly append <code>^^</code> followed by any legal IRI form (full
- or prefixed) as described above to give the datatype IRI. <span class="non-issue">Literals
- may be written without either a language tag or a datatype IRI as a
- shortcut for a literal with the type <code>xsd:string</code>.</span>
+ <p>
+ N-Triples triples are also Turtle triples, but Turtle includes other <a href="#terms">representations of RDF Terms</a> and <a href="#groups">abbreviations of RDF Triples</a>.
+ </p>
+
+ <p>
+ The Turtle grammar for <a href="#prod-turtle2-triples"><code>triples</code></a> is a subset of the <a href="http://www.w3.org/TR/2008/REC-rdf-sparql-query-20080115/">SPARQL Query Language for RDF</a> [[RDF-SPARQL-QUERY]] grammar for <a href="http://www.w3.org/TR/sparql11-query/#rTriplesBlock"><code>TriplesBlock</code></a>.
+ The two grammars share production and terminal names where possible.
+ Likewise, the N-Triples grammar re-uses some productions and terminals from Turtle.
+ </p>
+
+ <p>
+ The <a href="#sec-grammar">Turtle Grammar</a> and <a href="#sec-parsing">Parsing</a> sections define the construction of an RDF graph from a Turtle document.
+ The RDF graph represented by an N-Triples document contains exactly each triple matching <a href="#prod-ntriples-triple">N-Triples <code>triple</code> production</a>.
+ </p>
+ </section>
+ <section id="terms">
+ <h2>RDF Terms in Turtle and N-Triples</h2>
+
+ <p>
+ There are three types of <em>RDF Term</em>:
+ <a href="../rdf-concepts/index.html#dfn-iri">IRIs</a> (Internationalized Resource Identifiers),
+ <a href="../rdf-concepts/index.html#dfn-literal">literals</a> and
+ <a href="../rdf-concepts/index.html#dfn-blank-node">blank nodes</a>.
+ </p>
+
+ <section id="IRIs">
+ <h3>RDF IRIs</h3>
+
+ <p>
+ Turtle's grammar production <a href="#prod-turtle2-IRIref">IRIref</a> designates <a href="../rdf-concepts/index.html#dfn-iri">RDF IRIs</a>.
+ These may be written as relative or absolute IRIs or prefixed names.
+ Relative and absolute IRIs are enclosed in '<' and '>' and may contain <a href="#numeric">numeric escape sequences</a> (described below).
+ The N-Triples language includes absolute IRIs but no relative IRIs or prefixed names.
</p>
- <pre class="example"><script type="text/plain"># this is not a complete turtle document
-"That Seventies Show"
-"That Seventies Show"@en
-"Cette Série des Années Soixante-dix"@fr
-"Cette Série des Années Septante"@fr-be
-"mylexicaldata"^^<http://example.org/my/datatype>
-"""10"""^^xsd:decimal
-</script></pre>
+ <section id="turtleIRIs">
+ <h3>Relative IRIs and Prefixed Names in Turtle</h3>
<p>
- The <code>"That Seventies Show"</code> above is equivalent to <code>"That Seventies Show"^^xsd:string</code>.
+ The <code>@prefix</code> directive associates a prefix label with an IRI.
+ Subsequent <code>@prefix</code> directives may re-map the same local name.
+ A prefixed name is a prefix label and a local part, separated by a colon ":".
+ A prefixed name is mapped to an IRI by concatenating the IRI associated with the prefix and the local part.
+ The local part of a prefixed name may have <a href="#reserved">reserved character escape sequences</a> (described below).
</p>
- <p>Blank nodes are written as <code>_:</code><em>BLANK_NODE_LABEL</em>
- to provide a blank node either from the given <a href="#prod-turtle2-BLANK_NODE_LABEL">BLANK_NODE_LABEL</a>.
- A generated blank node may also be made with <code>[]</code>
+ <div class="note">
+ <p>
+ Prefixed names are a superset of XML namespaces.
+ They differ in that the local part of prefixed names may include:
+ </p>
+ <ul>
+ <li>leading digits, e.g. <code>leg:3032571</code> or <code>isbn13:9780136019701</code></li>
+ <li>reserved character escape sequences, e.g. <code>og:video\:height</code> or <code>wgs:lat\-long</code></li>
+ </ul>
+ </div>
- which is useful to provide the subject of RDF triples for
- each pair from the <a href="#prod-turtle2-predicateObjectList">predicateObjectList</a>
- or the root of the <a href="#prod-turtle2-collection">collection</a>.
+ <p>
+ Relative IRIs are combined with base IRIs as per <a href="http://www.ietf.org/rfc/rfc3986.txt" class="norm">Uniform Resource Identifier (URI): Generic Syntax</a> [<a href="#rfc3986">RFC3986</a>] using only the basic algorithm in section 5.2.
+ Neither Syntax-Based Normalization nor Scheme-Based Normalization (described in sections 6.2.2 and 6.2.3 of RFC3986) are performed.
+ Characters additionally allowed in IRI references are treated in the same way that unreserved characters are treated in URI references, per section 6.5 of <a href="http://www.ietf.org/rfc/rfc3987.txt" class="norm">Internationalized Resource Identifiers (IRIs)</a> [<a href="#rfc3987">RFC3987</a>].
+ </p>
+ <p>
+ The <code>@base</code> directive defines the Base IRI used to resolve relative IRIs per RFC3986 section 5.1.1, "Base URI Embedded in Content".
+ Section 5.1.2, "Base URI from the Encapsulating Entity" defines how the In-Scope Base IRI may come from an encapsulating document, such as a SOAP envelope with an xml:base directive or a mime multipart document with a Content-Location header.
+ The "Retrieval URI" identified in 5.1.3, Base "URI from the Retrieval URI", is the URL from which a particular SPARQL query was retrieved.
+ If none of the above specifies the Base URI, the default Base URI (section 5.1.4, "Default Base URI") is used.
+ Each <code>@base</code> directive sets a new In-Scope Base URI, relative to the previous one.
</p>
- <pre class="example"><script type="text/plain"># this is not a complete turtle document
-_:me
-_:a1234
+ <p>
+ The token <code>a</code> in the predicate position of a Turtle triple represents the IRI <code>rdf:type</code> .
+ </p>
+
+ <pre class="example"><script type="text/plain">
+# A triple with all absolute IRIs (which is also a valid N-Triples triple):
+<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> .
+
+@base <http://one.example/>
+<subject2> <predicate2> <object2> . # relative IRIs, e.g. http://one.example/subject2
+
+@prefix p: <http://two.example/>
+p:subject3 p:predicate3 p:object3 . # prefixed IRIs, e.g. http://two.example/subject3
+
+@prefix p: <path/> # prefix p: now stands for http://one.example/path/
+p:subject4 p:predicate4 p:object4 . # prefixed IRIs, e.g. http://one.example/path/subject4
+
+@prefix : <http://another.example/> # empty prefix
+:subject5 :predicate5 :object5 . # prefixed IRIs, e.g. http://another.example/subject5
+
+:subject6 a :subject7 . # same as :subject6 rdf:type :subject7 .
</script></pre>
+ </section>
+ <section id="iri-summary">
+ <h3>Summary of IRI Representations in N-Triples and Turtle</h3>
- <p>Literals <span class="non-issue">, prefixed names</span> and IRIs may also contain escape sequences 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 escape sequences are:</p>
+ <table id="term2escape" class="separated" style="border-collapse:collapse;margin: 2em;">
+ <thead>
+ <tr>
+ <th></th>
+ <th>Turtle</th>
+ <th>N-Triples</th>
+ <th>example</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td class="r">absolute IRI</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td><code><http://a.example/some/path/></code></td>
+ </tr>
+ <tr>
+ <td class="r">relative IRI</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td>no</td>
+ <td><code></some/path/></code></td>
+ </tr>
+ <tr>
+ <td class="r">prefixed name</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td>no</td>
+ <td><code>foo:bar\=baz</code></td>
+ </tr>
+ <tr>
+ <td class="r"><code>a</code> for the predicate <code>rdf:type</code></td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td>no</td>
+ <td><code>a</code></td>
+ </tr>
+ </tbody>
+ </table>
+ </section>
+ </section>
+ <section id="literals">
+ <h3>RDF Literals</h3>
+
+ <p>
+ Literals in N-Triples have a lexical form followed by a bare langugae tag, a datatype IRI, or neither.
+ The representation of the lexical form consists of a delimiting <code>"</code>, a sequence of characters matching the regular expression <code>[^\"\\\n\r]</code> or <a href="#numeric">numeric escape sequence</a> or <a href="#string">string escape sequence</a>, and a final delimiting <code>"</code>.
+ The corresponding <a href="../rdf-concepts/index.html#dfn-lexical-form">RDF lexical form</a> is the characters between the <code>""</code>s, after processing the escape sequences.
+ If present, the <a href="../rdf-concepts/index.html#dfn-language-tagged-string">language tag</a> is preceded by a <code>@</code>.
+ The datatype of literals with a language tag is <code>rdf:langString</code>, though this datatype is not written in N-Triples or Turtle.
+ The datatype IRI in Turtle may be written in any valid IRI representation.
+ If there is no language tag, there may be a <a href="../rdf-concepts/index.html#dfn-datatype-URI">datatype IRI</a>, preceeded by <code>^^</code>.
+ If there is no datatype IRI and no language tag, the datatype is <code>xsd:string</code>.
+ </p>
+
+ <section id="turtle-literals">
+ <h3>Alternative Lexical Representations in Turtle</h3>
+ <p>
+ Turtle literals include N-Triples literals, as well as three other representations of the lexical form:
+ </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="#prod-turtle2-String">strings</a>)</li>
- <li><code>\></code> (U+003E, greater than - only allowed inside <a href="#prod-turtle2-IRI_REF">IRI_REFs</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>
+ <li>Literals delimited by <code>'</code>, which contain escape characters and characters matching the pattern <code>[^'\\\n\r]</code>.</li>
+ <li>Literals delimited by <code>"""</code>, which permit up to two <code>"</code>s, as well as <code>\r</code> and <code>\n</code>.</li>
+ <li>Literals delimited by <code>'''</code>, which permit up to two <code>'</code>s, as well as <code>\r</code> and <code>\n</code>.</li>
</ul>
- <p>See the <a href="#sec-strings">String escape sequences</a> section for full details.</p>
-
- </section>
- <section id="iris">
- <h3>Abbreviating IRIs</h3>
-
- <p>The current base IRI may be altered in a Turtle document using the
- <code>@base</code> directive. It allows further abbreviation of
- IRIs but is usually used for simplifying the IRIs in the data, where
- the prefix directives are used for vocabularies that describe the data.</p>
-
- <p>Whenever this directive appears, it defines the base IRI for which
- all relative IRIs are resolved against. That includes IRIs,
- qualified names, prefix directives as well as later base directives.
+ <p>
+ Turtle datatype IRIs may be represented by <a href="#iri-summary">any valid IRI form</a>.
</p>
- <pre class="example"><script type="text/turtle"># 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 .</script></pre>
-
-
- <p>The token <code>a</code> is equivalent to the IRI
- <code><http://www.w3.org/1999/02/22-rdf-syntax-ns#type></code>
- </p>
-
- <pre class="example"><script type="text/turtle"># this is a complete turtle document
-@prefix doc: <http://example.org/#ns> .
-
-<http://example.org/path> a doc:Document .
- </script></pre>
+ <pre class="example"><script type="text/plain">
+show:218 rdfs:label "That Seventies Show"^^xsd:string . # literal with XML Schema string datatype
+show:218 rdfs:label "That Seventies Show"^^<http://www.w3.org/2001/XMLSchema#string> . # same as above
+show:218 rdfs:label "That Seventies Show" . # same again
+show:218 show:localName "That Seventies Show"@en . # literal with a language tag
+show:218 show:localName 'Cette Série des Années Soixante-dix'@fr . # literal delimited by single quote
+show:218 show:localName "Cette Série des Années Septante"@fr-be . # literal with a region subtag
+show:218 show:blurb '''This is a
+multi-line, single-quoted literal.''' . # literal with embedded new line
+</script></pre>
</section>
<section id="abbrev">
- <h3 >Abbreviating common datatypes</h3>
+ <h3 >Abbreviating Common Datatypes in Turtle</h3>
<p>Integer values, arbitrary precision decimal values, double precision floating point values and boolean values may be written without quotes or datatypes as follows:</p>
<ul>
<li>
@@ -383,18 +384,157 @@
</table>
<pre class="example"><script type="text/turtle">
-# this is a complete turtle document
@prefix : <http://example.org/stats> .
<http://somecountry.example/census2007>
- :censusYear 2007 ; # xsd:integer
- :birthsPerPerson .0135 ; # xsd:decimal
- :gdpDollars 14074.2E9 ; # xsd:double
- :isLandlocked false . # xsd:boolean
+ :censusYear 2007 ; # xsd:integer
+ :birthsPerPerson .0135 ; # xsd:decimal
+ :gdpDollars 14074.2E9 ; # xsd:double
+ :isLandlocked false . # xsd:boolean
+ :series "IV"^^my:romanNumeral . # no abbreviation available
</script></pre>
</section>
+ <section id="literal-summary">
+ <h3>Summary of Literal Representations in N-Triples and Turtle</h3>
+ <table id="term2escape" class="separated" style="border-collapse:collapse;margin: 2em;">
+ <thead>
+ <tr>
+ <th></th>
+ <th>Turtle</th>
+ <th>N-Triples</th>
+ <th>example</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td class="r">single-quoted single-line lexical representation</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td>no</td>
+ <td><code>'some literal'</code></td>
+ </tr>
+ <tr>
+ <td class="r">double-quoted single-line lexical representation</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td><code>"some literal"</code></td>
+ </tr>
+ <tr>
+ <td class="r">single-quoted multi-line lexical representation</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td>no</td>
+ <td><code>'''some<br/>literal'''</code></td>
+ </tr>
+ <tr>
+ <td class="r">double-quoted multi-line lexical representation</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td>no</td>
+ <td><code>"""some<br/>literal"""</code></td>
+ </tr>
+ <tr>
+ <td class="r">abbreviated numeric</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td>no</td>
+ <td><code>13</code></td>
+ </tr>
+ <tr>
+ <td class="r">abbreviated boolean</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td>no</td>
+ <td><code>true</code></td>
+ </tr>
+ </tbody>
+ </table>
+ </section>
+ </section>
+
+ <section id="BNodes">
+ <h3>RDF Blank Nodes</h3>
+
+ <div class="issue">
+ <p>
+ documented presuming we remove %XX and \C escapes from blank node labels:
+ </p>
+ <pre>
+-[73s] BLANK_NODE_LABEL ::= "_:" PN_LOCAL
++[73s] BLANK_NODE_LABEL ::= "_:" ( PN_CHARS_U | [0-9] ) ( ( PN_CHARS | '.' )* PN_CHARS ) ? # no PLX
+ [100s] PN_LOCAL ::= ( PN_CHARS_U | [0-9] | PLX ) ( ( PN_CHARS | '.' | PLX )* ( PN_CHARS | PLX ) ) ?
+ [160s] PLX ::= PERCENT | PN_LOCAL_ESC
+ [161s] PERCENT ::= '%' HEX HEX
+ [163s] PN_LOCAL_ESC ::= '\\' ( '_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | ':' | '/' | '?' | '#' | '@' | '%' )
+ </pre>
+ </div>
+
+ <p>
+ <a href="../rdf-concepts/index.html#dfn-blank-node">RDF blank nodes</a> in N-Triples are expressed as <code>_:</code> followed by a blank node label which is a series of name characters.
+ The characters in the label are built upon <a href="#term-turtle2-PN_CHARS_BASE">PN_CHARS_BASE</a>, liberalized to allow:
+ </p>
+ <ul>
+ <li>The characters <code>_</code> and digits may appear anywhere in a blank node label.</li>
+ <li>The character <code>.</code> may appear anywhere except the first or last character.</li>
+ <li>The characters <code>-</code>, <code>\uB7</code>, <code>\u300</code> to <code>\u36F</code> and <code>\u203F</code> to <code>2040</code> are permitted anywhere except the first character.</li>
+ </ul>
+ <p>
+ A fresh RDF blank node is allocated for each unique blank node label in a Turtle or N-Triples document.
+ Repeated use of the same blank node label identifies the same RDF blank node.
+ </p>
+ <pre class="example"><script type="text/plain">
+_:alice foaf:knows _:bob .
+_:bob foaf:knows _:alice .
+</script></pre>
+
+ <section id="abbrev">
+ <h3>Nesting Unlabeled Blank Nodes in Turtle</h3>
+ <p>
+ In Turtle, fresh RDF blank nodes are also allocated when matching the production <a href="#prod-turtle2-blankNodePropertyList">blankNodePropertyList</a> and the terminal <a href="#term-turtle2-ANON">ANON</a>.
+ Both of these may appear in the subject or object position of a triple.
+ That subject or object is a fresh RDF blank node.
+ This blank node also serves as the subject of the triples produced by matching the <a href="#prod-turtle2-predicateObjectList">predicateObjectList</a> production embedded in a blankNodePropertyList.
+ The generation of these triples is described below in <a href="#groups">Predicate Object Lists in Turtle</a>.
+ Blank nodes are also allocated for <a href="#collections">Turtle Collections</a> (below).
+ </p>
+ <pre class="example"><script type="text/plain">
+# Someone knows someone else, who has the name "Bob".
+[] foaf:knows [ foaf:name "Bob" ] .
+</script></pre>
+ </section>
+ <section id="bnode-summary">
+ <h3>Summary of Blank Node Representations in N-Triples and Turtle</h3>
+
+ <table id="term2escape" class="separated" style="border-collapse:collapse;margin: 2em;">
+ <thead>
+ <tr>
+ <th></th>
+ <th>Turtle</th>
+ <th>N-Triples</th>
+ <th>example</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td class="r">labeled blank node</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td><code><http://a.example/who#Alice> foaf:knows _:bob .</code></td>
+ </tr>
+ <tr>
+ <td class="r">anonymous node</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td>no</td>
+ <td><code><http://a.example/who#Alice> foaf:knows [] .</code></td>
+ </tr>
+ <tr>
+ <td class="r">blank node property list</td>
+ <td style="background-color: green; border:1px solid black;">yes</td>
+ <td>no</td>
+ <td><code><http://a.example/who#Alice> foaf:knows [ foaf:name "Bob" ] .</code></td>
+ </tr>
+ </tbody>
+ </table>
+ </section>
+ </section>
+ </section>
<section id="groups">
- <h3>Abbreviating groups of triples</h3>
+ <h3>Predicate Object Lists in Turtle</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>
@@ -416,7 +556,7 @@
</section>
<section id="collections">
- <h3>Abbreviating RDF Collections</h3>
+ <h3>Turtle Collections</h3>
<p>An RDF Collection may be abbreviated using a sequence of
RDF Terms enclosed in <code>( )</code> brackets. Whitespace may
@@ -434,13 +574,9 @@
# an empty collection value - rdf:nil
:subject :predicate2 () .
</script></pre>
-
- <p>See section <a href="#sec-collections">Collections</a> for
- the details on the long form of the generated triples.
- </p>
</section>
</section>
- <section id="sec-syntax">
+ <!-- section id="sec-syntax">
<h3>Syntax for IRIs, Literals and Blank Nodes</h3>
<p>Turtle is a language for an <a href="../rdf-concepts/index.html#dfn-rdf-graph">RDF graph</a>,
a set of <a href="../rdf-concepts/index.html#dfn-rdf-triple">RDF triple</a>s. An RDF graph is
@@ -471,7 +607,7 @@
</div>
<p>The Turtle syntax for literals and blank nodes are defined by <a href="http://www.w3.org/TR/rdf-sparql-query/#QSynLiterals">SPARQL Query section 4.1.2</a> and <a href="http://www.w3.org/TR/rdf-sparql-query/#QSynBlankNodes">SPARQL Query section 4.1.4</a> respectively.</p>
- </section>
+ </section -->
<section id="sec-grammar">
<h2>Turtle Grammar</h2>
@@ -640,7 +776,7 @@
<td>no</td>
</tr>
<tr>
- <td class="r"><a href="#term-turtle2-BLANK_NODE_LABEL"><span style="font-weight:bold;">Blank node label</span>s</a> and <a href="#term-turtle2-PN_LOCAL"><span style="font-weight:bold;">local name</span>s</a></td>
+ <td class="r"><del><a href="#term-turtle2-BLANK_NODE_LABEL"><span style="font-weight:bold;">Blank node label</span>s</a> and </del><a href="#term-turtle2-PN_LOCAL"><span style="font-weight:bold;">local name</span>s</a></td>
<td>no</td>
<td>no</td>
<td style="background-color: green; border:1px solid black;">yes</td>
@@ -653,7 +789,7 @@
</tr>
</tbody>
</table>
- <p class="note">%-encoded sequences are in the <a href="#term-turtle2-IRI_REF">character range for IRIs</a> and are <a href="#term-turtle2-PERCENT">explicitly allowed</a> in blank node labels and local names. These appear as a '%' followed by two hex characters and represent that same sequence of three characters. These sequences are <em>not</em> decoded during processing. A term written as <code><http://a.example/%66oo-bar></code> in Turtle designates the RDF IRI <code>http://a.example/%66oo-bar</code> and not RDF IRI <code>http://a.example/foo-bar</code>. A term written as <code>ex:%66oo-bar</code> with a prefix <code>@prefix ex: <http://a.example/></code> also designates the RDF IRI <code>http://a.example/%66oo-bar</code>.</p>
+ <p class="note">%-encoded sequences are in the <a href="#term-turtle2-IRI_REF">character range for IRIs</a> and are <a href="#term-turtle2-PERCENT">explicitly allowed</a> in <del>blank node labels and </del>local names. These appear as a '%' followed by two hex characters and represent that same sequence of three characters. These sequences are <em>not</em> decoded during processing. A term written as <code><http://a.example/%66oo-bar></code> in Turtle designates the RDF IRI <code>http://a.example/%66oo-bar</code> and not RDF IRI <code>http://a.example/foo-bar</code>. A term written as <code>ex:%66oo-bar</code> with a prefix <code>@prefix ex: <http://a.example/></code> also designates the RDF IRI <code>http://a.example/%66oo-bar</code>.</p>
</section>
<section id="sec-grammar-grammar">
@@ -1223,7 +1359,7 @@
<li>explicitly allowed re-use of the same prefix.</li>
</ul></li>
- <li>Added <a href="#sec-grammar-parsing">parsing rules</a>.</li>
+ <li>Added <a href="#sec-parsing">parsing rules</a>.</li>
</ul>
</section>