{Bracket}: a minimal substitution language
for use with RDF N-triples

(yet another simplified human-oriented syntax for RDF)
Chris Goad


Bracket is intended to provide a way of including abreviations in text files in the simplest possible manner. Bracket can be applied to any kind of text file, but the immediate motivation is to transform the RDF N-triple syntax into a viable alternative for human composers and readers of RDF. The following observation gave rise to this idea.

The XML namespace and base mechanisms are used to abreviate URIs in the standard RDF syntax based on XML. These mechanisms are among the culprits in the widely lamented complexity of this syntax, and as long as they remain, the underlying radical simplicity of RDF cannot be fully exposed to a doubting world. On the other hand, omitting any abreviation mechanism (as in the RDF N-triple syntax) makes the resulting syntax too verbose for routine human use. Hence the current proposal of applying the simplest possible abreviation mechanism to the simplest possible non-abreviated syntax (N-triples).

Other syntactic constructs in RDF are also devoted primarily to abreviation. For example, in the standard XML syntax, several properties can be asserted of a single resource via the nesting structure. This may be considered another variety of abreviation, and occurs in N3 and Tim Bray's RPV syntax as well. Specifically, one can write something with the structure

... resource ...
   ... property0 ... value0 ...
   ... property1 ...  value1 ...

where either the tag hierarchy (XML variants) or punctuation details (N3) indicate that both properties apply to the same resource.

In bracket, instead of a nesting construct, one writes

{x} property0 value0 .
{x} property1 value1 .

This is as concise, and as easy to read. It is simpler in the sense that only one kind of abreviation construct is used rather than many separate mechanisms.

Bracket defined

A bracket file asssigns special meaning to text surrounded by curly brackets ({}). There are three kinds of bracketed expressions:

  1. Definitions of the form

    {variable0 = "text0"; variable1 = "text1";... variablen = "textn"}

  2. Variable occurences of the form


  3. Comments of the form

    {* comment *}

The rules for transforming a bracket file into the text that it denotes are:

  1. Definitions and comments are omitted

  2. Variable occurences are replaced by their values

  3. Blank lines are removed
It is also required that every bracket file start with a comment. Variables may be redefined; the most recent value assigned is used for substitution.

Here's an example:

{* example *}
{greeting = "hello"; person = "Keith";
where="down there";twogreetings = "{greeting}, {greeting}"}

After I fell, I heard {person} call:
"{twogreetings}, {where} - {greeting}, are you alright?"

This denotes the text

After I fell, I heard Keith call: 
"hello, hello, down there - hello, are you alright?"

Note that bracket variables can appear within the definition text of other bracket variables.

And here is an N-triple example:

ntriples = "<http://www.w3.org/2001/sw/RDFCore/ntriples/>";
dc = "http://purl.org/dc/elements/1.1/";
{ntriples} <{dc}creator> "Dave Becket" .
{ntriples} <{dc}creator> "Art Barstow" .
{ntriples} <{dc}publisher> <http://www.w3.org/> .

This denotes the N-triple text file

<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://purl.org/dc/elements/1.1/creator> "Dave Beckett" .
<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://purl.org/dc/elements/1.1/creator> "Art Barstow" .
<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://purl.org/dc/elements/1.1/publisher> <http://www.w3.org/> .

which in turn has the same meaning as the standard RDF syntax:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  <rdf:Description rdf:about="http://www.w3.org/2001/sw/RDFCore/ntriples/">
    <dc:creator>Art Barstow</dc:creator>
    <dc:creator>Dave Beckett</dc:creator>
    <dc:publisher rdf:resource="http://www.w3.org/"/>

(The N-triple examples are borrowed from the N-triple document.)

Escape sequences

To allow the appearance of the brackets { and } in the output, and to allow inclusion of the double quote symbol " within definitions of variables, three escape sequences are defined:


The rules covering escape sequences are:

  1. When processing the file, brackets preceded by a backslash (\{ or \}) are treated as normal text.

  2. When processing the definition text of a variable, a double quote preceded by a backslash (\") is treated as normal text.

  3. After processing all substitutions in a file, the backslashes preceding brackets are removed (transforming \{ to { and \} to }).

  4. After processing all substitions in a file, the backslashes preceding double quotes (\") are removed, but only in the text that resulted from substitution.

So, a bracket may be included anywhere in the file by preceding it with a backslash. Double quotes need only be preceded by a backslash when they appear inside variable definitions.


{a = "\"\{ \}\"";
b = "Here are two pairs of brackets: {a} {a}";
Here are some more: "\{\{\}\}"

This denotes the following text:

Here are two pairs of brackets: "{}" "{}"
Here are some more: "{{}}"


Any application that understands N-triples can be made bracket-aware by interposing the simple bracket interpretation step for those files that start with "{*". A bracket web service could also be provided, eg


would turn the possibly bracketed file myfile.nt into a standard debracketed triple file.