ldpatch.html
author Alexandre Bertails <bertails@gmail.com>
Thu, 20 Nov 2014 23:52:28 -0500
branchldpatch
changeset 896 1cfafcb13507
parent 895 9e83f2d8b056
child 897 b8f83a85dd5c
permissions -rw-r--r--
Added new errors.
<!DOCTYPE html>
<html>
  <head>
    <title>Linked Data Patch Format</title>
    <meta charset='utf-8'>
    <script src='//www.w3.org/Tools/respec/respec-w3c-common'
            async class='remove'></script>
    <script class='remove'>
      var preProc = {
        apply: function(c) {
                  // terms definitions
                  refs = document.querySelectorAll('tdef') ;
                  for (var i = 0; i < refs.length; i++) {
                      var item = refs[i];
                      if (!item) continue ;
                      var p = item.parentNode ;
                      var con = item.innerHTML ;
                      var ref = item.getAttribute('title') ;
                      if (!ref) {
                          ref = item.textContent ;
                      }
                      if (ref) {
                          ref = ref.replace(/\n/g, '_') ;
                          ref = ref.replace(/\s+/g, '_') ;
                      }
                      var sp = document.createElement( 'dfn' ) ;
                      sp.title = ref ;
                      sp.innerHTML = con ;
                      p.replaceChild(sp, item) ;
                  }
                  // term references
                  refs = document.querySelectorAll('tref') ;
                  for (var i = 0; i < refs.length; i++) {
                      var item = refs[i];
                      if (!item) continue ;
                      var p = item.parentNode ;
                      var con = item.innerHTML ;
                      var ref = item.getAttribute('title') ;
                      if (!ref) {
                          ref = item.textContent ;
                      }
                      if (ref) {
                          ref = ref.replace(/\n/g, '_') ;
                          ref = ref.replace(/\s+/g, '_') ;
                      }

                      var sp = document.createElement( 'a' ) ;
                      var id = item.textContent ;
                      sp.className = 'tref' ;
                      sp.title = ref ;
                      sp.innerHTML = con ;
                      p.replaceChild(sp, item) ;
                  }
              }
      };

      function updateExample(doc, content) {
        // perform transformations to make it render and prettier
        content = content.replace(/<!--/, '');
        content = content.replace(/-->/, '');
        content = doc._esc(content);
        content = content.replace(/\*\*\*\*([^*]*)\*\*\*\*/g, '<span class="hilite">$1</span>') ;
        return content ;
      };

      function updateDTD(doc, content) {
        // perform transformations to
        // make it render and prettier
        content = '<pre class="dtd">' + doc._esc(content) + '</pre>';
        content = content.replace(/!ENTITY % ([^ \t\r\n]*)/g, '!ENTITY <span class="entity">% $1</span>');
        content = content.replace(/!ELEMENT ([^ \t$]*)/mg, '!ELEMENT <span class="element">$1</span>');
        return content;
      };

      function updateSchema(doc, content) {
        // perform transformations to
        // make it render and prettier
        content = '<pre class="dtd">' + doc._esc(content) + '</pre>';
        content = content.replace(/&lt;xs:element\s+name=&quot;([^&]*)&quot;/g, '&lt;xs:element name="<span class="element" id="schema_element_$1">$1</span>"') ;
        return content;
      };

      function updateTTL(doc, content) {
        // perform transformations to
        // make it render and prettier
        content = '<pre class="sh_sourceCode">' + doc._esc(content) + '</pre>';
        content = content.replace(/@prefix/g, '<span class="sh_keyword">@prefix</span>');
        return content;
      };

      var respecConfig = {
          // specification status (e.g. WD, LCWD, WG-NOTE, etc.). If in doubt use ED.
          specStatus:           "ED",
          
          // the specification's short name, as in http://www.w3.org/TR/short-name/
          shortName:            "ldpatch",

          // if your specification has a subtitle that goes below the main
          // formal title, define it here
          // subtitle   :  "an excellent document",

          // if you wish the publication date to be other than the last modification, set this
          // publishDate:  "2009-08-06",

          // if the specification's copyright date is a range of years, specify
          // the start date here:
          // copyrightStart: "2005"

          // if there is a previously published draft, uncomment this and set its YYYY-MM-DD date
          // and its maturity status
          // previousPublishDate:  "1977-03-15",
          // previousMaturity:  "WD",

          // if there a publicly available Editor's Draft, this is the link
          edDraftURI:           "https://dvcs.w3.org/hg/ldpwg/raw-file/ldpatch/ldpatch.html",

          // if this is a LCWD, uncomment and set the end of its review period
          // lcEnd: "2009-08-05",

          // editors, add as many as you like
          // only "name" is required
          editors:  [
              {
                  name:       "Alexandre Bertails"
              ,   url:        "http://bertails.org/"
              ,   mailto:     "alexandre@bertails.org"
              ,   company:    "Pellucid Analytics"
              ,   companyURL: "http://www.pellucid.com"
              },
              {
                  name:       "Pierre-Antoine Champin"
              ,   url:        "http://liris.cnrs.fr/~pchampin/en/"
              ,   mailto:     "pchampin@liris.cnrs.fr"
              ,   company:    "Université de Lyon"
              ,   companyURL: "http://www.universite-lyon.fr/"
              },
              {
                  name:       "Andrei Sambra"
              ,   url:        "https://deiu.rww.io/profile/card#me"
              ,   mailto:     "asambra@mit.edu"
              ,   company:    "MIT"
              ,   companyURL: "http://web.mit.edu"
              },
          ],

          // name of the WG
          wg:           "Linked Data Platform Working Group",
          
          // URI of the public WG page
          wgURI:        "http://www.w3.org/2012/ldp",
          
          // name (without the @w3c.org) of the public mailing to which comments are due
          wgPublicList: "public-ldp-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/Consortium/Patent-Policy-20040205/",
          // !!!! IMPORTANT !!!! MAKE THE ABOVE BLINK IN YOUR HEAD
          preProcess: [ preProc ]
      };
    </script>
    <style type="text/css">
.atrisk {
  padding:    1em;
  margin: 1em 0em 0em;
  border: 1px solid #f00;
  background: #ffc;
}
.atrisktext {
  /* content:    "Feature At Risk"; */
  display:    block;
  width:  150px;
  margin: -1.5em 0 0.5em 0;
  font-weight:    bold;
  border: 1px solid #f00;
  background: #fff;
  padding:    3px 1em;
}

div.rule {padding-top: 1em;}
div.ldp-issue {
  border-color: #E05252;
  background: #FBE9E9;
  padding: 0.5em;
  margin: 1em 0;
  position: relative;
  clear: both;
  border-left-width: .5em;
  border-left-style: solid;
}
div.ldp-issue-title {
  color: #E05252;
  padding-right: 1em;
  min-width: 7.5em;
}
#updatelist-algo img {
  width: 70%;
  display: block;
  margin:0 auto;
}
    </style>
  </head>
  <body>
    <section id='abstract'>
      <p>
Linked Data Patch Format (LD Patch) defines a language for expressing a sequence of operations to apply to Linked Data resources; it is suitable for use with the HTTP PATCH method. <!-- The "text/ldpatch" media type is used to identify such Patch documents.-->
      </p>
    </section>
    
    <section id='sotd'>

      <p id="alternative-designs">
 	Although the Linked Data Platform (LDP) Working Group is currently favoring LD Patch, it seeks more input in deciding which format to promote for use in <a href="http://www.w3.org/TR/ldp/#h4_ldpr-HTTP_PATCH">LDP PATCH</a> [[!LDP]] operations on <a href="http://www.w3.org/TR/ldp/#ldprs">RDF Sources</a>.  Other viable candidates include:</p>
      
      <ul>
	<li><a href="http://www.w3.org/TR/sparql11-http-rdf-update/#http-patch">SPARQL 1.1 Update</a> &mdash; already standardized, but quite complex for LDP scenarios</li>
	<li><a href="http://www.w3.org/2001/sw/wiki/SparqlPatch">SparqlPatch</a> &mdash; restricted to a simple subset of SPARQL 1.1 Update</li>
	<li><a href="http://www.w3.org/2001/sw/wiki/TurtlePatch">TurtlePatch</a> &mdash; uses an even simpler subset, but requires unusual handling of blank nodes</li>
	<li><a href="http://afs.github.io/rdf-patch/">RDF Patch</a> &mdash; simple, but also requires unusual handling of blank nodes</li>
      </ul>

      <p>
	At this point, the advantage leans towards LD Patch in terms of simplicity, ease of implementation, and run-time performance on anticipated data.  We welcome data relevant to this decision.
      </p>

    </section>
    
    <section class='informative' id='introduction'>
      <h1>Introduction</h1>
      <p>
          Linked Data <q cite="http://en.wikipedia.org/wiki/Linked_data">describes a method of publishing structured data so that it can be interlinked and become more useful. It builds upon standard Web technologies such as HTTP, RDF and IRIs, but rather than using them to serve web pages for human readers, it extends them to share information in a way that can be read automatically by computers. This enables data from different sources to be connected and queried.</q> (source Wikipedia).
      </p>
      <p>
This document defines the Linked Data Patch Format (LD Patch), a format for describing changes to apply to Linked Data. It is suitable for use with <a href="http://tools.ietf.org/html/rfc5789">HTTP PATCH</a> [[!RFC5789]], a method to perform partial modifications to Web resources. <!-- The "text/ldpatch" media type is prospectively used to identify such LD Patch documents.-->
      </p>
      <p>
An instance of the LD Patch language (or LD Patch document) defines a list of operations to be performed against a Linked Data resource, namely the addition or removal of RDF [[!rdf11-concepts]] triples in this graph.
      </p>

      <p id="relation-sparql-update">
        The LD Patch format described in this document should be seen as a language for updating <a class="externalDFN" href="http://www.w3.org/TR/rdf11-concepts/#section-rdf-graph">RDF Graphs</a> in a resource-centric fashion. It is the intention to confine its expressive power to an RDF diff with <a class="internalDFN" href="#pathological-graph">partial support for blank nodes</a> and <code>rdf:List</code> manipulations. For more powerful operations on RDF Graphs and Quad Stores, the LDP WG recommends the reader to consider <a href="http://www.w3.org/TR/sparql11-update/">SPARQL Update</a> [[sparql11-update]].
      </p>

    </section>
      
    <section id="examples" class="informative">
      <h2>Examples</h2>

      <section id="full-example">
          <h2>Full example</h2>

          <p>
              The following RDF Graph describes the relation between a person named Tim Berners-Lee (denoted by <code>&lt;http://example.org/timbl#&gt;</code>) and two events he attended.
          </p>
          <pre class='example'>
@prefix schema: &lt;http://schema.org/&gt; .
@prefix profile: &lt;http://ogp.me/ns/profile#&gt; .
@prefix ex: &lt;http://example.org/vocab#&gt; .
@prefix rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
&lt;#&gt; a schema:Person ;
  schema:alternateName "TimBL" ;
  profile:first_name "Tim" ;
  profile:last_name "Berners-Lee" ;
  schema:workLocation [ schema:name "W3C/MIT" ] ;
  schema:performerIn _:b1, _:b2 ;
  ex:preferredLanguages ( "en" "fr" ).

_:b1 schema:name "F2F5 - Linked Data Platform" ;
  schema:url &lt;https://www.w3.org/2012/ldp/wiki/F2F5&gt; .

_:b2 a schema:Event ;
  schema:name "TED 2009" ;
  schema:startDate "2009-02-04" ;
  schema:url &lt;http://conferences.ted.com/TED2009/&gt; .
          </pre>
          <p>
              The following is an example HTTP Patch request, conveying an LD Patch document:
          </p>
          <pre class='example'>
PATCH /timbl HTTP/1.1
Host: example.org
Content-Length: 478
Content-Type: text/ldpatch
If-Match: "abc123"

@prefix rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
@prefix schema: &lt;http://schema.org/&gt; .
@prefix profile: &lt;http://ogp.me/ns/profile#&gt; .
@prefix ex: &lt;http://example.org/vocab#&gt; .

Delete { &lt;#&gt; profile:first_name "Tim" } .
Add {
  &lt;#&gt; profile:first_name "Timothy" ;
    profile:image &lt;https://example.org/timbl.jpg&gt; .
} .

Bind ?workLocation &lt;#&gt; /schema:workLocation .
Cut ?workLocation.

UpdateList &lt;#&gt; ex:preferredLanguages 1..2 ( "fr-CH" ) .

Bind ?event &lt;#&gt; /schema:attendee[/schema:url = &lt;https://www.w3.org/2012/ldp/wiki/F2F5&gt;]  .
Add { ?event rdf:type schema:Event } .

Bind ?ted &lt;http://conferences.ted.com/TED2009/&gt; /^schema:url! .
Delete { ?ted schema:startDate "2009-02-04" } .
Add {
  ?ted schema:location [
    schema:name "Long Beach, California" ;
    schema:geo [
      schema:latitude "33.7817" ;
      schema:longitude "-118.2054"
    ]
  ]
} .
          </pre>
          <p>
              This example introduces most features of the LD Patch format: <code>@prefix</code> and prefixed names, the <a>Add</a>, <a>Delete</a>, <a>Cut</a>, and <a>UpdateList</a> operations, the <a>Bind</a>-ing mechanism and blank node creation. The "text/ldpatch" media type is <a href="#media-registration">prospectively</a> used to identify such LD Patch documents.
          </p>
          <p>
              The following is the resulting (patched) document.
          </p>
          <pre class='example'>
@prefix schema: &lt;http://schema.org/&gt; .
@prefix profile: &lt;http://ogp.me/ns/profile#&gt; .
@prefix ex: &lt;http://example.org/vocab#&gt; .
@prefix rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
&lt;#&gt; a schema:Person ;
  schema:alternateName "TimBL" ;
  profile:first_name "Timothy" ;
  profile:last_name "Berners-Lee" ;
  profile:image &lt;https://example.org/timbl.jpg&gt; ;
  schema:attendee _:b1, _:b2 ;
  ex:preferredLanguages ( "en" "fr-CH" ).

_:b1 a schema:Event ;
  schema:name "F2F5 - Linked Data Platform" ;
  schema:url &lt;https://www.w3.org/2012/ldp/wiki/F2F5&gt; .

_:b2 a schema:Event ;
  schema:name "TED 2009" ;
  schema:url &lt;http://conferences.ted.com/TED2009/&gt; ;
  schema:location [
    schema:name "Long Beach, California";
    schema:geo [ schema:latitude "33.7817" ; schema:longitude "-118.2054" ]
  ] .
          </pre>
      </section>

      <section id="list-manipulation-examples">
          <h2><code>rdf:List</code> manipulation examples</h2>

          <p>
              This example shows how to <strong id="replace-elements">replace one element</strong> (here the second one) with a new one:
          </p>

          <pre class='example'>
UpdateList &lt;#&gt; ex:preferredLanguages 1..2 ( "fr-CH" ) .
          </pre>

          <p>
              This example shows how to <strong id="insert-new-elements">insert new elements</strong> at a specific index (here <code>2</code>):
          </p>

          <pre class='example'>
UpdateList &lt;#&gt; ex:preferredLanguages 2..2 ( "fr-CH" "en-US" ) .
          </pre>

          <p>
              This example shows how to <strong id="append-elements">append elements</strong> at the end of a collection:
          </p>

          <pre class='example'>
UpdateList &lt;#&gt; ex:preferredLanguages .. ( "fr-CH" "en-US" ) .
          </pre>

          <p>
              This example shows how to <strong id="replace-elements">replace all the elements</strong> after the index <code>2</code> with the provided collection:
          </p>

          <pre class='example'>
UpdateList &lt;#&gt; ex:preferredLanguages 2.. ( "fr-CH" "en-US" ) .
          </pre>

          <p>
              This example shows how to <strong id="remove-elements">remove elements</strong> (here the second and the third) from a collection:
          </p>

          <pre class='example'>
UpdateList &lt;#&gt; ex:preferredLanguages 1..3 ( ) .
          </pre>

          <p>
              Finally, this example shows how to <strong id="empty-collection">empty a collection</strong>:
          </p>

          <pre class='example'>
UpdateList &lt;#&gt; ex:preferredLanguages 0.. ( ) .
          </pre>


      </section>

    </section>


    <section class='normative' id='semantics'>
      <h1>LD Patch Semantics</h1>
      <p>
An LD Patch document is applied to a Linked Data resource identified by an IRI (the <dfn>target IRI</dfn>) and represented by an RDF graph (the <dfn>target graph</dfn>). It is made of a prologue and a list of statements, where the order <strong>must be respected</strong>. The prologue declares a number of <a>prefixes</a> used to abbreviate IRIs. Then, each statement either binds a variable to a matching node from the <a>target graph</a>, or specifies a modification on the <a>target graph</a>.
      </p>


      <section id="prefixes">
        <h2><dfn>Prefixes</dfn></h2>
        <p>
<!-- @@ TODO should defer to Turtle's syntax. Not only Prefixes, but everything in http://www.w3.org/TR/2014/REC-turtle-20140225/#language-features. Proposed section name: Inherited from (the?) Turtle language. @@ -->
An LD Patch document starts with a preamble that MAY contain a number of <code>@prefix</code> directives (similar to the <a href="http://www.w3.org/TR/turtle/#prefixed-name">same directive in Turtle</a> [[Turtle]]). They allow declaring a short prefix name for a long prefix of repeated IRIs. This is useful for many RDF vocabularies that are all defined in nearby namespace IRIs [[!rdf11-concepts]]. Note: the <code>@prefix</code> keyword is <em>case sensitive</em>.
        </p>
        <p>
A prefix directive is defined by a prefix <var>p</var> and an IRI <var>ns</var>. Any further <a class="internalDFN" href="#grammar-production-PrefixedName">PrefixedName</a> in the LD Patch document whose <a class="internalDFN" href="#grammar-production-PNAME_NS">PNAME_NS</a> is <var>p</var> MUST be interpreted as the IRI formed by concatenating <var>ns</var> with the <a class="internalDFN" href="#grammar-production-PrefixedName">PrefixedName</a>'s <a class="internalDFN" href="#grammar-production-PN_LOCAL">PN_LOCAL</a>.
        </p>
        <p>
For example, once the directive <code>@prefix foo: &lt;http://example.org/ns#&gt;</code> is defined, any <a class="internalDFN" href="#grammar-production-PrefixedName">PrefixedName</a> that starts with <code>foo:</code> can be interpreted as an IRI, <i>e.g.</i> <code>foo:bar</code> is a shorthand for the IRI <code>&lt;http://example.org/ns#bar&gt;</code>.
        </p>
      </section>

      <section id="node-matching-semantics">
        <h2><dfn>Nodes and triples Semantics</dfn></h2>
        <p>
LD Patch borrows much of its syntax and semantics from <a href="http://www.w3.org/TR/turtle/">Turtle</a> [[Turtle]] for describing nodes and triples. Especially, whenever production rules <a class="internalDFN" href="#grammar-production-triples">triples</a> or <a class="internalDFN" href="#grammar-production-collection">collection</a> are used, Turtle semantics must be applied to parse them as a set of triples that we call an <dfn>argument graph</dfn>.
        </p>
        <p>
There are however a few points that need to be highlighted in the way LD Patch parses an <a>argument graph</a> compared to Turtle:
        </p>
        <ul>
          <li>
            The base IRI used to resolve relative IRIs MUST be <a>target IRI</a>.
          </li>
          <li>
            LD Patch allows <a href="#grammar-production-Var">Var</a>iables in subject or object positions. A variable MUST be <a title="bind">bound</a> prior to its first use in the LD Patch Document, and it must be replaced by the last node to which it has been bound (in case it appears in several <a>Bind</a> statements).
          </li>
          <li>
            <dfn id="blank-node-scoping">The scope of <a class="internalDFN" href="#grammar-production-BlankNode">Blank nodes</a> identifiers is the whole LD Patch document.</dfn> Hence several argument graphs can share the same blank nodes across statements.
          </li>
        </ul>
        <p>
As IRIs and Literals have global scopes, such nodes in an <a>argument graph</a> represent the same resource as in the <a>target graph</a>. <a class="internalDFN" href="#grammar-production-BlankNode">Blank nodes</a>, on the other hand, pose a problem, as they have no global identifiers. Indeed, the scope of blank node identifiers is limited to the LD Patch document in which they appear. As a consequence, any blank node identifier appearing in an LD Patch document is understood to denote a <em>fresh</em> blank node, distinct from any node initially present in the <a>target graph</a>. Therefore blank node identifiers in LD Patch cannot interfere with pre-existing blank nodes in the <a>target graph</a>.
        </p>
        <p>
However, LD Patch provides mechanisms to address those pre-existing blank nodes: <a>bind</a>ing a variable to a blank node reachable through a <a>path expression</a>, <a>cut</a>ting a whole tree made of blank nodes, or using <a>UpdateList</a> to deal with those blank nodes that constitute RDF collections. There are cases where those mechanisms will not be able to unambiguously address a given blank node, but those cases are deemed <a href="#pathological-graph">pathological</a>, and are out of the scope of this specification.
        </p>
      </section>

      <section id="path-expression">
        <h2><dfn>Path Expression</dfn></h2>
        <p>
            A path expression can be used to locate RDF nodes within the <a>target graph</a>. A path expression consists of a series of one or more <a>Step</a>s or <a>Constraint</a>s, separated by "<code>/</code>", and optionally beginning with "<code>/</code>". The main goal is to allow addressing a blank node by “walking” the arcs of the graph from an already identified node. 
        </p>
        <p>
            A <dfn>Step</dfn> can be of three kinds:
        </p>
        <ul>
          <li>A <dfn>StepForward</dfn> is defined by an IRI <var>p</var>, and consists in following the corresponding outgoing arcs: <var>N</var> is replaced by the set of the objects of all triples from the <a>target graph</a> with predicate <var>p</a> and their subject in <var>N</var>.</li>
          <li>A <dfn>StepBackward</dfn> is defined by an IRI <var>p</var> preceded with the caret ("<code>^</code>") sign, and consists in following the corresponding incoming arcs: <var>N</var> is replaced by the set of the subjects of all triples from the <a>target graph</a> with predicate <var>p</var> and their object in <var>N</var>.</li>
          <li>A <dfn>StepAt</dfn> is defined by an integer <i>n</i>, and consists in following <var>n</var> <code>rdf:rest</code> arcs and one <code>rdf:first</code> arc in order to reach the corresponding member of an RDF collection. It is equivalent to a sequence of <var>n</var>+1 <a>StepForward</a>s with the corresponding IRIs.</li>
        </ul>
        <p>
A <dfn>Constraint</dfn> can be of two kinds:
        </p>
        <ul>
          <li>A <dfn>Unicity constraint</dfn>, described by the <em>bang</em> ("<code>!</code>") character, checks that <var>N</var> contains exactly one node. If this is not the case, <var>N</var> is replaced by the empty set (which triggers the Path Expression to fail).</li>
          <li>A <dfn>Filter</dfn>, consisting of a path <var>p</var> in square brackets ("<code>[</code>", "<code>]</code>"), keeps only nodes that “satisfy” the enclosed path, i.e. those from which the enclosed path reaches at least one node: <var>N</var> is replaced by the subset of its elements <var>n</var> such that applying <var>p</var> to {<var>n</var>} results in a non-empty set. </li>
          <li>Additionally, the path in a <a>filter</a> can be followed by the equal ("<code>=</code>") sign and a <tref>Value</tref> <var>v</var>. In that case, only the node for which that particular value is reached through the enclosed path are kept: <var>N</var> is replaced by the subset of its elements <var>n</var> such that applying <var>p</var> to {<var>n</var>} results in a set containing <var>v</var>.</li>
        </ul>

        <p>
The following path expression (taken from the <a href="#examples">Examples section</a>) will look for all the events matching the predicate <code>schema:performerIn</code>, keeping only the one matching the IRI <code>&lt;https://www.w3.org/2012/ldp/wiki/F2F5&gt;</code>.
        <pre class='example'>
/schema:performerIn[/schema:url = &lt;https://www.w3.org/2012/ldp/wiki/F2F5&gt;]
        </pre>
        </p>

      </section>

      <section id="patch-operations">
        <h2>Patch Operations</h2>

        <section id="bind-statement">
          <h2><dfn>Bind</dfn></h2>
          <p>
              The <a>Bind</a> operation is used to bind an RDF Term to a variable. The process results in the variable being bound to exactly one node. After being bound, the variable can be used in the subsequent statements. Another <a>Bind</a> can override the value of a previously bound variable.
          </p>

          <p>
              The <a>Bind</a> operation is defined by three components: <a>Var</a>, <a>Value</a> and <a title="path expression">Path</a>, the last component being optional (can be considered equivalent to the empty path).
          </p>

          <p>
              <dfn>Var</dfn> contains a unique name for the new variable. Variables are prefixed by the "<code>?</code>" character, which is not part of the variable name.
          </p>
          <p>
              <dfn>Value</dfn> is the RDF Term that will be used as starting point when following the path expression.
          </p>
          <p>
              <dfn>Path</dfn> is the expression that is used to identify the RDF Term to which the Variable will be bound. It is comprised of <a>Step</a>(s) and/or <a>Constraint</a>(s).
          </p>

          <p>
              Following the example above, the <a>Bind</a> operation creates a new variable called <code>event</code>, starting from the RDF Term <code>&lt;#&gt;</code> and following the path expression <code>/schema:performerIn[/schema:url = &lt;https://www.w3.org/2012/ldp/wiki/F2F5&gt;]</code> in order to identify the RDF Term to which this variable will be bound to – i.e. <code>_:b2</code>.
          <pre class='example'>
Bind ?event &lt;#&gt; /schema:performerIn[/schema:url = &lt;https://www.w3.org/2012/ldp/wiki/F2F5&gt;] .
          </pre>
          </p>

        </section>

        <section id="add-statement">
          <h2><dfn>Add</dfn></h2>
          <p>
The <a>Add</a> operation is used to append new RDF triples to the <a>target graph</a>.
          </p>
          <p>
It has a single argument: an <a>argument graph</a> <var>g</var>. All triples in <var>g</var> must be added to the <var>target graph</var>. Even if an argument graph contains one or more triples that already exist in the target graph, the Add operation MUST NOT fail.
          <pre class='example'>
Add { 
    &lt;#&gt; profile:first_name "Timothy" ;
        profile:image &lt;https://example.org/timbl.jpg&gt; .
} .

Add { ?event rdf:type schema:Event } .
          </pre>
          </p>
        </section>

        <section id="delete-statement">
          <h2><dfn>Delete</dfn></h2>
          <p>
The <a>Delete</a> operation is used to remove RDF triples from the <a>target graph</a>.
          </p>
          <p>
It has a single argument: an <a>argument graph</a> <var>g</var>. All triples in <var>g</var> must be removed from the <var>target graph</var>. It MUST fail if one of those triples does not exists in the <a>target graph</a>. Blank nodes identifiers are allowed in <a>Delete</a> statements but <a href="#blank-node-scoping">they remain scoped to the LD Patch document</a>, so they can only match a blank node previously added by the same LD Patch document.
          </p>
          <pre class='example'>
Delete { &lt;#&gt; profile:first_name "Tim" } .

Delete { ?ted schema:startDate "2009-02-04" } .
          </pre>
          </p>
        </section>

        <section id="cut-statement">
          <h2><dfn>Cut</dfn></h2>
          <p>
              The <a>Cut</a> operation is used to remove one or more triples from the <a>target graph</a> connected to a specific node (either an <a>IRI</a>, or a previously bound variable). The triples being removed correspond to the <a href="http://en.wikipedia.org/wiki/Connectivity_%28graph_theory%29">connected graph</a> whose nodes were accessible from the given node, as well as the triples having this node in the object position. @@ TODO @@
          <pre class='example'>
Cut ?workLocation .
          </pre>
          </p>
        </section>

        <section id="update-list-statement">
          <h2><dfn>UpdateList</dfn></h2>
          <p>
              The <a>UpdateList</a> operation is used to update the members of an <a href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF collection</a>. The first two arguments are the <a class="internalDFN" href="#grammar-production-subject">subject</a> (up to <a>var</a>iable binding) and <a class="internalDFN" href="#grammar-production-predicate">predicate</a> of the RDF triple that unambiguously identify the target collection to be updated: it is in the object position of this triple. The third argument specifies which <a>Slice</a> will be replaced by a new collection: this is the fourth argument of the statement.
          </p>

          <p>
              A <dfn>Slice</dfn> is described by two positive integers separated by "<code>..</code>". The second integer can be omitted, in that case it denotes the end of the list. If both integers are omitted (i.e. "<code>..</code>" alone), this denotes by convention the empty slice at the end of the list. Indexes start at 0.
          </p>

          <p>
              @@ TODO better explanations @@
              In the example below, <a>UpdateList</a> is used to replace the second and third member of <code>( "foo" "bar" "baz" "qux" )</code> by list <code>( 1 2 3 )</code>.
          </p>
          
          <pre class='example'>
UpdateList ex:s ex:p 2..4 ( 1 2 3 ) .
          </pre>

          <p>
              Here is an intuition of the algorithm being applied:
          </p>
          <ul>
              <li>Step 1: find the last triple sLeft/pLeft/oRight on the left side of slice (corner case: index 0, or empty list => sLeft/pLeft can be s/p)</li>
              <li>Step 2: find the first node sRight on the right side of the slice</li>
              <li>Step 3: connect the lists
                  <ul>
                      <li>remove the triples from the slice</li>
                      <li>remove last triple of the new list</li>
                      <li>remove sLeft/pLeft/oLeft</li>
                      <li>add sLeft/pLeft/headNewList</li>
                      <li>add sSlice/pSlice/sRight</li>
                  </ul>
              </li>
          </ul>

          <p>
              (TODO do we need a better picture?) Graphically, that's what it looks like:
          </p>


          <div id="updatelist-algo">
              <img src="updatelist-algo.svg" />
          </div>

        </section>
      </section>



      <section id="error-handling">
        <h2><dfn>Error Handling</dfn></h2>
        <p>
LD Patch abides to the semantics of the <a href="http://tools.ietf.org/html/rfc5789">HTTP PATCH method</a> [[!RFC5789]], in that the server <q cite="http://tools.ietf.org/html/rfc5789">MUST apply the entire set of changes atomically and never provide (e.g., in response to a GET during this operation) a partially modified representation. If the entire patch document cannot be successfully applied (e.g., one of the instructions has failed), then the server MUST NOT apply any of the changes</q>. In the case LD Patch operations fail to be applied, <a href="http://tools.ietf.org/html/rfc5789#section-2.2">Error Handling, Section 2</a> of [[!RFC5789]] specifies the error codes to be used.
        </p>

	<p>
            Here are some additional error conditions more specific to LD Patch:
        </p>

        <ul>
            <li id="bind-unique-match">If a <a>Bind</a> statement fails to match exactly one node, then a HTTP 422 (Unprocessable Entity) error status code MUST be returned.</li>
            <li id="unicity-constraint-violated">If a <a>Unicity constraint</a> is violated, then a HTTP 422 (Unprocessable Entity) error status code MUST be returned.</li>
            <li id="cut-nothing">If a <a>Cut</a> operation fails to remove any triple, then a HTTP 422 (Unprocessable Entity) error status code MUST be returned.</li>
            <li id="delete-non-existing-triple">If a <a>Delete</a> attempts to remove a non-existing triple, then a HTTP 422 (Unprocessable Entity) error status code MUST be returned.</li>
            <li id="updatelist-non-list-argument">If the <a class="internalDFN" href="#grammar-production-subject">subject</a> and <a class="internalDFN" href="#grammar-production-predicate">predicate</a> provided to a <a>UpdateList</a> operation fail to match a collection, then a HTTP 422 (Unprocessable Entity) error status code MUST be returned.</li>
            <li id="wrong-order-for-indexes">If the indexes in a <a>Slice</a> are in the wrong order (e.g. <code>2868..42</code>), then the parsing fails and a 400 (Bad Request) error status code MUST be returned.</li>
            <li id="wrong-index">If an index in a <a>Slice</a> has no corresponding element in an <code>rdf:List</code>, then a 422 (Unprocessable Entity) error status code MUST be returned.</li>
            <li id="unknown-prefix">If a prefix name (<a class="internalDFN" href="#grammar-production-PNAME_NS">PNAME_NS</a>) is used without being previously declared, then the parsing fails and a 400 (Bad Request) error status code MUST be returned.</li>
            <li id="unknown-variable">If a <a>var</a>iable is used without being previously bound, then the parsing fails and a 400 (Bad Request) error status code MUST be returned.</li>

        </ul>

        <p>
            Note: 422 (Unprocessable Entity) is defined in <a href="http://tools.ietf.org/html/rfc4918#section-11.2">422 Unprocessable Entity, Section 11.2</a> of [[!RFC4918]].

        </p>

      </section>

      <section id="pathological-graph">
        <h2><dfn>Pathological Graph</dfn></h2>
          <p>
            There exists a particular case which LD Patch is not able to address. Given an RDF graph <var>G</var>, a blank node <var>b</var> is said to be unambiguous in <var>G</var> if there exists a couple <var>(n, p)</var> where
          <ul>
            <li><var>n</var> is an IRI or a literal</li>
            <li><var>p</var> is an LD <a>Path Expression</a></li>
          </ul>
          such that applying <var>p</var> to {<var>n</var>} results in the singleton set {<var>b</var>}.
          </p>

          <p>
  It is easy to see that only the unambiguous blank nodes of a graph can be handled in LD Patch.
          </p>

          <p>
  Consider for example the following graph:
          </p>

        <pre class='example'>
&lt;#&gt; foaf:name "Alice" ; foaf:knows _:b1, _:b2 .
_:b1 a foaf:Person .
_:b2 a foaf:Person ; schema:workLocation _:b3 .
_:b3 schema:name "W3C/MIT" .
        </pre>

        <p>
          The blank nodes <code>_:b2</code> and <code>_:b3</code> are unambiguous as they can be reached unambiguoulsy from the literal <code>"W3C/MIT"</code>). The blank node <code>_:b1</code>, on the other hand, is ambigious as all <a>path expression</a>s that can can match it would also match <code>_:b2</code>.
        </p>

        <!-- p>
          This kind of node is not particularly interesting in RDF, as its presence does not change the semantics of the graph. Indeed, if we remove <code>_:b2</code> and all its triples from the graph above, the resulting graph would be semantically equivalent to the original graph.
        </p-->

        <p>
          Another example is a graph containing only blank nodes. All its nodes are therefore ambiguous as they can not be reached from an IRI or a literal. Such a graph is not interesting in the context of Linked Data as it contains no IRI to link to or from it.
        </p>

        <p>
          Therefore, ambiguous blank nodes are considered a pathological case in the context of Linked Data, and so the fact that they cannot be coped with in LD Patch is deemed acceptable. Furthermore, their presence in a graph does not prevent the other nodes of that graph to be handled by LD Patch. Most notably, all <a class="externalDFN" href="http://www.w3.org/TR/rdf11-mt/#dfn-lean">non-lean graphs</a> [[!rdf11-mt]] are also pathological.
        </p>

        </section>

      </section>
    </section>

    <section id='concrete-syntax'>
      <h1>Concrete Syntax</h1>
      <p>
          The LD Patch grammar shares most of its production rules with [[!Turtle]], which are extended to allow variables in the <a class="internalDFN" href="#grammar-production-subject">subject</a> and <a class="internalDFN" href="#grammar-production-object">object</a> positions.
      </p>
      <!-- do not edit manually, this is automatically generated -->
<table class="grammar">
  <tbody class="grammar-productions">
<tr id="grammar-production-ldpatch">
    <td>[1]</td>
    <td><a href="#grammar-production-ldpatch">ldpatch</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-prologue">prologue</a> <a href="#grammar-production-statement">statement</a>*</td>
</tr>
<tr id="grammar-production-prologue">
    <td>[2]</td>
    <td><a href="#grammar-production-prologue">prologue</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-prefixID">prefixID</a>*</td>
</tr>
<tr id="grammar-production-statement">
    <td>[3]</td>
    <td><a href="#grammar-production-statement">statement</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-bind">bind</a> | <a href="#grammar-production-add">add</a> | <a href="#grammar-production-delete">delete</a> | <a href="#grammar-production-updateList">updateList</a></td>
</tr>
<tr id="grammar-production-bind">
    <td>[4]</td>
    <td><a href="#grammar-production-bind">bind</a></td>
    <td>::=</td>
    <td>("<code class="grammar-literal">Bind</code>" | "<code class="grammar-literal">B</code>") Var <a href="#grammar-production-value">value</a> <a href="#grammar-production-path">path</a>? "<code class="grammar-literal">.</code>"</td>
</tr>
<tr id="grammar-production-add">
    <td>[5]</td>
    <td><a href="#grammar-production-add">add</a></td>
    <td>::=</td>
    <td>("<code class="grammar-literal">Add</code>" | "<code class="grammar-literal">A</code>") "<code class="grammar-literal">{</code>" <a href="#grammar-production-graph">graph</a> "<code class="grammar-literal">}</code>" "<code class="grammar-literal">.</code>"</td>
</tr>
<tr id="grammar-production-delete">
    <td>[6]</td>
    <td><a href="#grammar-production-delete">delete</a></td>
    <td>::=</td>
    <td>("<code class="grammar-literal">Delete</code>" | "<code class="grammar-literal">D</code>") "<code class="grammar-literal">{</code>" <a href="#grammar-production-graph">graph</a> "<code class="grammar-literal">}</code>" "<code class="grammar-literal">.</code>"</td>
</tr>
<tr id="grammar-production-cut">
    <td>[7]</td>
    <td><a href="#grammar-production-cut">cut</a></td>
    <td>::=</td>
    <td>("<code class="grammar-literal">Cut</code>" | "<code class="grammar-literal">C</code>") <a href="#grammar-production-varOrIRI">varOrIRI</a> "<code class="grammar-literal">.</code>"</td>
</tr>
<tr id="grammar-production-updateList">
    <td>[8]</td>
    <td><a href="#grammar-production-updateList">updateList</a></td>
    <td>::=</td>
    <td>("<code class="grammar-literal">UpdateList</code>" | "<code class="grammar-literal">UL</code>") <a href="#grammar-production-varOrIRI">varOrIRI</a> <a href="#grammar-production-predicate">predicate</a> <a href="#grammar-production-slice">slice</a> <a href="#grammar-production-collection">collection</a> "<code class="grammar-literal">.</code>"</td>
</tr>
<tr id="grammar-production-value">
    <td>[9]</td>
    <td><a href="#grammar-production-value">value</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-iri">iri</a> | <a href="#grammar-production-literal">literal</a> | Var</td>
</tr>
<tr id="grammar-production-path">
    <td>[10]</td>
    <td><a href="#grammar-production-path">path</a></td>
    <td>::=</td>
    <td>('<code class="grammar-literal">/</code>'? <a href="#grammar-production-step">step</a> | <a href="#grammar-production-constraint">constraint</a> )? ( '<code class="grammar-literal">/</code>' <a href="#grammar-production-step">step</a> | <a href="#grammar-production-constraint">constraint</a> )*</td>
</tr>
<tr id="grammar-production-step">
    <td>[11]</td>
    <td><a href="#grammar-production-step">step</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">^</code>' <a href="#grammar-production-iri">iri</a> | <a href="#grammar-production-iri">iri</a> | <a href="#grammar-production-INDEX">INDEX</a></td>
</tr>
<tr id="grammar-production-constraint">
    <td>[12]</td>
    <td><a href="#grammar-production-constraint">constraint</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">[</code>' <a href="#grammar-production-path">path</a> ( '<code class="grammar-literal">=</code>' <a href="#grammar-production-value">value</a> )? '<code class="grammar-literal">]</code>' | '<code class="grammar-literal">!</code>'</td>
</tr>
<tr id="grammar-production-slice">
    <td>[13]</td>
    <td><a href="#grammar-production-slice">slice</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-INDEX">INDEX</a>? '<code class="grammar-literal">..</code>' <a href="#grammar-production-INDEX">INDEX</a>?</td>
</tr>
<tr id="grammar-production-INDEX">
    <td>[14]</td>
    <td><a href="#grammar-production-INDEX">INDEX</a></td>
    <td>::=</td>
    <td>[0-9]+</td>
</tr>
<tr id="grammar-production-VAR1">
    <td>[143s]</td>
    <td><a href="#grammar-production-VAR1">VAR1</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">?</code>' <a href="#grammar-production-VARNAME">VARNAME</a></td>
</tr>
<tr id="grammar-production-VARNAME">
    <td>[166s]</td>
    <td><a href="#grammar-production-VARNAME">VARNAME</a></td>
    <td>::=</td>
    <td>( <a href="#grammar-production-PN_CHARS_U">PN_CHARS_U</a> | [0-9] ) ( <a href="#grammar-production-PN_CHARS_U">PN_CHARS_U</a> | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] )*</td>
</tr>
<tr id="grammar-production-prefixID">
    <td>[4t]</td>
    <td><a href="#grammar-production-prefixID">prefixID</a></td>
    <td>::=</td>
    <td>"<code class="grammar-literal">@prefix</code>" <a href="#grammar-production-PNAME_NS">PNAME_NS</a> <a href="#grammar-production-IRIREF">IRIREF</a> "<code class="grammar-literal">.</code>"</td>
</tr>
<tr id="grammar-production-graph">
    <td>[15]</td>
    <td><a href="#grammar-production-graph">graph</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-triples">triples</a> ( '<code class="grammar-literal">.</code>' <a href="#grammar-production-triples">triples</a> )* '<code class="grammar-literal">.</code>'?</td>
</tr>
<tr id="grammar-production-triples">
    <td>[6t]</td>
    <td><a href="#grammar-production-triples">triples</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-subject">subject</a> <a href="#grammar-production-predicateObjectList">predicateObjectList</a> | <a href="#grammar-production-blankNodePropertyList">blankNodePropertyList</a> <a href="#grammar-production-predicateObjectList">predicateObjectList</a>?</td>
</tr>
<tr id="grammar-production-predicateObjectList">
    <td>[7t]</td>
    <td><a href="#grammar-production-predicateObjectList">predicateObjectList</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-verb">verb</a> <a href="#grammar-production-objectList">objectList</a> ('<code class="grammar-literal">;</code>' (<a href="#grammar-production-verb">verb</a> <a href="#grammar-production-objectList">objectList</a>)?)*</td>
</tr>
<tr id="grammar-production-objectList">
    <td>[8t]</td>
    <td><a href="#grammar-production-objectList">objectList</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-object">object</a> ('<code class="grammar-literal">,</code>' <a href="#grammar-production-object">object</a>)*</td>
</tr>
<tr id="grammar-production-verb">
    <td>[9t]</td>
    <td><a href="#grammar-production-verb">verb</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-predicate">predicate</a> | '<code class="grammar-literal">a</code>'</td>
</tr>
<tr id="grammar-production-subject">
    <td>[10t]</td>
    <td><a href="#grammar-production-subject">subject</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-iri">iri</a> | <a href="#grammar-production-BlankNode">BlankNode</a> | <a href="#grammar-production-collection">collection</a> | <a href="#grammar-production-VAR1">VAR1</a></td>
</tr>
<tr id="grammar-production-predicate">
    <td>[11t]</td>
    <td><a href="#grammar-production-predicate">predicate</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-iri">iri</a></td>
</tr>
<tr id="grammar-production-object">
    <td>[12t]</td>
    <td><a href="#grammar-production-object">object</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-iri">iri</a> | <a href="#grammar-production-BlankNode">BlankNode</a> | <a href="#grammar-production-collection">collection</a> | <a href="#grammar-production-blankNodePropertyList">blankNodePropertyList</a> | <a href="#grammar-production-literal">literal</a></td>
</tr>
<tr id="grammar-production-literal">
    <td>[13t]</td>
    <td><a href="#grammar-production-literal">literal</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-RDFLiteral">RDFLiteral</a> | <a href="#grammar-production-NumericLiteral">NumericLiteral</a> | <a href="#grammar-production-BooleanLiteral">BooleanLiteral</a></td>
</tr>
<tr id="grammar-production-blankNodePropertyList">
    <td>[14t]</td>
    <td><a href="#grammar-production-blankNodePropertyList">blankNodePropertyList</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">[</code>' <a href="#grammar-production-predicateObjectList">predicateObjectList</a> '<code class="grammar-literal">]</code>'</td>
</tr>
<tr id="grammar-production-collection">
    <td>[15t]</td>
    <td><a href="#grammar-production-collection">collection</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">(</code>' <a href="#grammar-production-object">object</a>* '<code class="grammar-literal">)</code>'</td>
</tr>
<tr id="grammar-production-NumericLiteral">
    <td>[16t]</td>
    <td><a href="#grammar-production-NumericLiteral">NumericLiteral</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-INTEGER">INTEGER</a> | <a href="#grammar-production-DECIMAL">DECIMAL</a> | <a href="#grammar-production-DOUBLE">DOUBLE</a></td>
</tr>
<tr id="grammar-production-RDFLiteral">
    <td>[128s]</td>
    <td><a href="#grammar-production-RDFLiteral">RDFLiteral</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-String">String</a> (<a href="#grammar-production-LANGTAG">LANGTAG</a> | '<code class="grammar-literal">^^</code>' <a href="#grammar-production-iri">iri</a>)?</td>
</tr>
<tr id="grammar-production-BooleanLiteral">
    <td>[133s]</td>
    <td><a href="#grammar-production-BooleanLiteral">BooleanLiteral</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">true</code>' | '<code class="grammar-literal">false</code>'</td>
</tr>
<tr id="grammar-production-String">
    <td>[17]</td>
    <td><a href="#grammar-production-String">String</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-STRING_LITERAL_QUOTE">STRING_LITERAL_QUOTE</a> | <a href="#grammar-production-STRING_LITERAL_SINGLE_QUOTE">STRING_LITERAL_SINGLE_QUOTE</a> | <a href="#grammar-production-STRING_LITERAL_LONG_SINGLE_QUOTE">STRING_LITERAL_LONG_SINGLE_QUOTE</a> | <a href="#grammar-production-STRING_LITERAL_LONG_QUOTE">STRING_LITERAL_LONG_QUOTE</a></td>
</tr>
<tr id="grammar-production-iri">
    <td>[135s]</td>
    <td><a href="#grammar-production-iri">iri</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-IRIREF">IRIREF</a> | <a href="#grammar-production-PrefixedName">PrefixedName</a></td>
</tr>
<tr id="grammar-production-varOrIRI">
    <td>[143s]</td>
    <td><a href="#grammar-production-varOrIRI">varOrIRI</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-iri">iri</a> | <a href="#grammar-production-VAR1">VAR1</a></td>
</tr>
<tr id="grammar-production-PrefixedName">
    <td>[136s]</td>
    <td><a href="#grammar-production-PrefixedName">PrefixedName</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-PNAME_LN">PNAME_LN</a> | <a href="#grammar-production-PNAME_NS">PNAME_NS</a></td>
</tr>
<tr id="grammar-production-BlankNode">
    <td>[137s]</td>
    <td><a href="#grammar-production-BlankNode">BlankNode</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-BLANK_NODE_LABEL">BLANK_NODE_LABEL</a> | <a href="#grammar-production-ANON">ANON</a></td>
</tr>
<tr id="grammar-production-IRIREF">
    <td>[18]</td>
    <td><a href="#grammar-production-IRIREF">IRIREF</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal"><</code>' ([^#x00-#x20<>"{}|^`\] | <a href="#grammar-production-UCHAR">UCHAR</a>)* '<code class="grammar-literal">></code>' /* #x00=NULL #01-#x1F=control codes #x20=space */</td>
</tr>
<tr id="grammar-production-PNAME_NS">
    <td>[139s]</td>
    <td><a href="#grammar-production-PNAME_NS">PNAME_NS</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-PN_PREFIX">PN_PREFIX</a>? '<code class="grammar-literal">:</code>'</td>
</tr>
<tr id="grammar-production-PNAME_LN">
    <td>[140s]</td>
    <td><a href="#grammar-production-PNAME_LN">PNAME_LN</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-PNAME_NS">PNAME_NS</a> <a href="#grammar-production-PN_LOCAL">PN_LOCAL</a></td>
</tr>
<tr id="grammar-production-BLANK_NODE_LABEL">
    <td>[141s]</td>
    <td><a href="#grammar-production-BLANK_NODE_LABEL">BLANK_NODE_LABEL</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">_:</code>' (<a href="#grammar-production-PN_CHARS_U">PN_CHARS_U</a> | [0-9]) ((<a href="#grammar-production-PN_CHARS">PN_CHARS</a> | '<code class="grammar-literal">.</code>')* <a href="#grammar-production-PN_CHARS">PN_CHARS</a>)?</td>
</tr>
<tr id="grammar-production-LANGTAG">
    <td>[144s]</td>
    <td><a href="#grammar-production-LANGTAG">LANGTAG</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">@</code>' [a-zA-Z]+ ('<code class="grammar-literal">-</code>' [a-zA-Z0-9]+)*</td>
</tr>
<tr id="grammar-production-INTEGER">
    <td>[19]</td>
    <td><a href="#grammar-production-INTEGER">INTEGER</a></td>
    <td>::=</td>
    <td>[+-]? [0-9]+</td>
</tr>
<tr id="grammar-production-DECIMAL">
    <td>[20]</td>
    <td><a href="#grammar-production-DECIMAL">DECIMAL</a></td>
    <td>::=</td>
    <td>[+-]? [0-9]* '<code class="grammar-literal">.</code>' [0-9]+</td>
</tr>
<tr id="grammar-production-DOUBLE">
    <td>[21]</td>
    <td><a href="#grammar-production-DOUBLE">DOUBLE</a></td>
    <td>::=</td>
    <td>[+-]? ([0-9]+ '<code class="grammar-literal">.</code>' [0-9]* <a href="#grammar-production-EXPONENT">EXPONENT</a> | '<code class="grammar-literal">.</code>' [0-9]+ <a href="#grammar-production-EXPONENT">EXPONENT</a> | [0-9]+ <a href="#grammar-production-EXPONENT">EXPONENT</a>)</td>
</tr>
<tr id="grammar-production-EXPONENT">
    <td>[154s]</td>
    <td><a href="#grammar-production-EXPONENT">EXPONENT</a></td>
    <td>::=</td>
    <td>[eE] [+-]? [0-9]+</td>
</tr>
<tr id="grammar-production-STRING_LITERAL_QUOTE">
    <td>[22]</td>
    <td><a href="#grammar-production-STRING_LITERAL_QUOTE">STRING_LITERAL_QUOTE</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">"</code>' ([^#x22#x5C#xA#xD] | <a href="#grammar-production-ECHAR">ECHAR</a> | <a href="#grammar-production-UCHAR">UCHAR</a>)* '<code class="grammar-literal">"</code>'      /* #x22=" #x5C=\ #xA=new line #xD=carriage return */</td>
</tr>
<tr id="grammar-production-STRING_LITERAL_SINGLE_QUOTE">
    <td>[23]</td>
    <td><a href="#grammar-production-STRING_LITERAL_SINGLE_QUOTE">STRING_LITERAL_SINGLE_QUOTE</a></td>
    <td>::=</td>
    <td>"<code class="grammar-literal">'</code>" ([^#x27#x5C#xA#xD] | <a href="#grammar-production-ECHAR">ECHAR</a> | <a href="#grammar-production-UCHAR">UCHAR</a>)* "<code class="grammar-literal">'</code>"      /* #x27=' #x5C=\ #xA=new line #xD=carriage return */</td>
</tr>
<tr id="grammar-production-STRING_LITERAL_LONG_SINGLE_QUOTE">
    <td>[24]</td>
    <td><a href="#grammar-production-STRING_LITERAL_LONG_SINGLE_QUOTE">STRING_LITERAL_LONG_SINGLE_QUOTE</a></td>
    <td>::=</td>
    <td>"<code class="grammar-literal">'''</code>" (("<code class="grammar-literal">'</code>" | "<code class="grammar-literal">''</code>")? ([^'\] | <a href="#grammar-production-ECHAR">ECHAR</a> | <a href="#grammar-production-UCHAR">UCHAR</a>))* "<code class="grammar-literal">'''</code>"</td>
</tr>
<tr id="grammar-production-STRING_LITERAL_LONG_QUOTE">
    <td>[25]</td>
    <td><a href="#grammar-production-STRING_LITERAL_LONG_QUOTE">STRING_LITERAL_LONG_QUOTE</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">"""</code>' (('<code class="grammar-literal">"</code>' | '<code class="grammar-literal">""</code>')? ([^"\] | <a href="#grammar-production-ECHAR">ECHAR</a> | <a href="#grammar-production-UCHAR">UCHAR</a>))* '<code class="grammar-literal">"""</code>'</td>
</tr>
<tr id="grammar-production-UCHAR">
    <td>[26]</td>
    <td><a href="#grammar-production-UCHAR">UCHAR</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">\\u</code>' <a href="#grammar-production-HEX">HEX</a> <a href="#grammar-production-HEX">HEX</a> <a href="#grammar-production-HEX">HEX</a> <a href="#grammar-production-HEX">HEX</a> | '<code class="grammar-literal">\\U</code>' <a href="#grammar-production-HEX">HEX</a> <a href="#grammar-production-HEX">HEX</a> <a href="#grammar-production-HEX">HEX</a> <a href="#grammar-production-HEX">HEX</a> <a href="#grammar-production-HEX">HEX</a> <a href="#grammar-production-HEX">HEX</a> <a href="#grammar-production-HEX">HEX</a> <a href="#grammar-production-HEX">HEX</a></td>
</tr>
<tr id="grammar-production-ECHAR">
    <td>[159s]</td>
    <td><a href="#grammar-production-ECHAR">ECHAR</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">\</code>' [tbnrf"'\]</td>
</tr>
<tr id="grammar-production-WS">
    <td>[161s]</td>
    <td><a href="#grammar-production-WS">WS</a></td>
    <td>::=</td>
    <td>#x20 | #x9 | #xD | #xA</td>
</tr>
<tr id="grammar-production-ANON">
    <td>[162s]</td>
    <td><a href="#grammar-production-ANON">ANON</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">[</code>' <a href="#grammar-production-WS">WS</a>* '<code class="grammar-literal">]</code>'</td>
</tr>
<tr id="grammar-production-PN_CHARS_BASE">
    <td>[163s]</td>
    <td><a href="#grammar-production-PN_CHARS_BASE">PN_CHARS_BASE</a></td>
    <td>::=</td>
    <td>[A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]</td>
</tr>
<tr id="grammar-production-PN_CHARS_U">
    <td>[164s]</td>
    <td><a href="#grammar-production-PN_CHARS_U">PN_CHARS_U</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-PN_CHARS_BASE">PN_CHARS_BASE</a> | '<code class="grammar-literal">_</code>'</td>
</tr>
<tr id="grammar-production-PN_CHARS">
    <td>[166s]</td>
    <td><a href="#grammar-production-PN_CHARS">PN_CHARS</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-PN_CHARS_U">PN_CHARS_U</a> | '<code class="grammar-literal">-</code>' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]</td>
</tr>
<tr id="grammar-production-PN_PREFIX">
    <td>[167s]</td>
    <td><a href="#grammar-production-PN_PREFIX">PN_PREFIX</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-PN_CHARS_BASE">PN_CHARS_BASE</a> ((<a href="#grammar-production-PN_CHARS">PN_CHARS</a> | '<code class="grammar-literal">.</code>')* <a href="#grammar-production-PN_CHARS">PN_CHARS</a>)?</td>
</tr>
<tr id="grammar-production-PN_LOCAL">
    <td>[168s]</td>
    <td><a href="#grammar-production-PN_LOCAL">PN_LOCAL</a></td>
    <td>::=</td>
    <td>(<a href="#grammar-production-PN_CHARS_U">PN_CHARS_U</a> | '<code class="grammar-literal">:</code>' | [0-9] | <a href="#grammar-production-PLX">PLX</a>) ((<a href="#grammar-production-PN_CHARS">PN_CHARS</a> | '<code class="grammar-literal">.</code>' | '<code class="grammar-literal">:</code>' | <a href="#grammar-production-PLX">PLX</a>)* (<a href="#grammar-production-PN_CHARS">PN_CHARS</a> | '<code class="grammar-literal">:</code>' | <a href="#grammar-production-PLX">PLX</a>))?</td>
</tr>
<tr id="grammar-production-PLX">
    <td>[169s]</td>
    <td><a href="#grammar-production-PLX">PLX</a></td>
    <td>::=</td>
    <td><a href="#grammar-production-PERCENT">PERCENT</a> | <a href="#grammar-production-PN_LOCAL_ESC">PN_LOCAL_ESC</a></td>
</tr>
<tr id="grammar-production-PERCENT">
    <td>[170s]</td>
    <td><a href="#grammar-production-PERCENT">PERCENT</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">%</code>' <a href="#grammar-production-HEX">HEX</a> <a href="#grammar-production-HEX">HEX</a></td>
</tr>
<tr id="grammar-production-HEX">
    <td>[171s]</td>
    <td><a href="#grammar-production-HEX">HEX</a></td>
    <td>::=</td>
    <td>[0-9] | [A-F] | [a-f]</td>
</tr>
<tr id="grammar-production-PN_LOCAL_ESC">
    <td>[172s]</td>
    <td><a href="#grammar-production-PN_LOCAL_ESC">PN_LOCAL_ESC</a></td>
    <td>::=</td>
    <td>'<code class="grammar-literal">\</code>' ('<code class="grammar-literal">_</code>' | '<code class="grammar-literal">~</code>' | '<code class="grammar-literal">.</code>' | '<code class="grammar-literal">-</code>' | '<code class="grammar-literal">!</code>' | '<code class="grammar-literal">$</code>' | '<code class="grammar-literal">&</code>' | "<code class="grammar-literal">'</code>" | '<code class="grammar-literal">(</code>' | '<code class="grammar-literal">)</code>' | '<code class="grammar-literal">*</code>' | '<code class="grammar-literal">+</code>' | '<code class="grammar-literal">,</code>' | '<code class="grammar-literal">;</code>' | '<code class="grammar-literal">=</code>' | '<code class="grammar-literal">/</code>' | '<code class="grammar-literal">?</code>' | '<code class="grammar-literal">#</code>' | '<code class="grammar-literal">@</code>' | '<code class="grammar-literal">%</code>')</td>
</tr>
  </tbody>
</table>



    </section>

    <section class="appendix" id="media-registration">
      <h2>Internet Media Type, File Extension and Macintosh File Type</h2>

	    <dl>
	      <dt>Contact:</dt>
	      <dd>Andrei Vlad Sambra</dd>
	      <dt>see also:</dt>
        <dd><a href="http://www.w3.org/2002/06/registering-mediatype">How to Register a Media Type for a <abbr title="World Wide Web Consortium">W3C</abbr> 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>

        <p>The Internet Media Type / MIME Type for LD Patch is "text/ldpatch".</p>
        <div class="ldp-issue">
          Pending discussion/registration with IETF.
        </div>

        <p>It is recommended that LD Patch files have the extension ".ldp" (all lowercase) on all platforms.</p>
        <div class="ldp-issue">
          Possible namespace conflict for .ldp!
	      </div>

        <p>It is recommended that LD Patch files stored on Macintosh HFS file systems be given a file type of "TEXT".</p>
      </dl>
  
      <dl>
        <dt>Type name:</dt>
          <dd>text</dd>
        <dt>Subtype name:</dt>
          <dd>ldpatch</dd>
        <dt>Required parameters:</dt>
          <dd>None</dd>
        <dt>Optional parameters:</dt>
          <dd>charset — this parameter is required when transferring non-ASCII data. If present, the value of charset is always UTF-8 [[!UTF-8]].</dd>
        <dt>Encoding considerations:</dt>
          <dd>The syntax of LD Patch is expressed over code points in Unicode [[!UNICODE]]. The encoding is always UTF-8. Unicode code points may also be expressed using an <code>\uXXXX</code> (U+0000 to U+FFFF) or <code>\UXXXXXXXX</code> syntax (for U+10000 onwards) where <code>X</code> is a hexadecimal digit <code>[0-9A-Fa-f]</code>.</dd>
        <dt>Security considerations:</dt>
          <dd>Because of it's relation with Turtle, the same security considerations can be applied here. 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.
            <!-- 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. -->
            Application rendering strings retrieved from untrusted LD Patch sources 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.
            LD Patch uses IRIs as term identifiers. Applications interpreting data expressed in LD Patch should address the security issues of Internationalized Resource Identifiers (IRIs) [[!RFC3987]] Section 8, as well as Uniform Resource Identifier (URI): Generic Syntax [[!RFC3986]] Section 7.
            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). Any person or application that is writing or interpreting LD Patch data must take care to use the IRI that matches the intended semantics, and avoid IRIs that may look similar. Further information about matching of similar characters can be found in Unicode Security Considerations [[!UNICODE-SECURITY]] and Internationalized Resource Identifiers (IRIs) [[!RFC3987]] Section 8.</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>
        <br>
        <dt>Additional information:</dt>
        <dt>Magic number(s):</dt>
          <dd>LD Patch documents may have the string '@prefix' (case sensitive) near the beginning of the document.</dd>
        <dt>File extension(s):</dt>
          <dd>".ldp"</dd>
        <dt>Macintosh file type code(s):</dt>
          <dd>"TEXT"</dd>
        <dt>Person & email address to contact for further information:</dt>
          <dd>Andrei Vlad Sambra &lt;andrei@w3.org&gt;</dd>
        <dt>Intended usage:</dt>
          <dd>COMMON</dd>
        <dt>Restrictions on usage:</dt>
          <dd>None</dd>
        <dt>Author/Change controller:</dt>
          <dd>The LD Patch specification is the product of the LDP WG. The W3C reserves change control over this specifications.</dd>
      </dl>
    </section>

    <section id="acknowledgements" class="appendix informative">
      <h2>Acknowledgements</h2>
     
      <p>The following people (in alphabetic order) have been instrumental in providing thoughts, feedback, reviews, content, criticism and input in the creation of this specification:</p>
      
      <p style="margin-left: 3em;">Andy Seaborne, Arnaud Le Hors, Henry Story, John Arwe, Eric Prud'hommeaux, Sandro Hawke, Steve Speicher, Tim Berners-Lee</p>

    </section>

    <section id="changelog" class="appendix informative">
        <h2>Change Log</h2>
        <section>
            <h3>Changes since <a href="http://www.w3.org/TR/2014/WD-ldpatch-20140918/">September 2014 First Public Working Draft</a></h3>
            <p>@@ TODO see http://www.w3.org/TR/2014/REC-turtle-20140225/#sec-change-log-PR-REC @@</p>
        </section>
    </section>

  </body>
</html>