Skip to content

Instantly share code, notes, and snippets.

@kwijibo
Last active March 21, 2017 02:50
Show Gist options
  • Save kwijibo/a1f0756ae7fd0ce9673c to your computer and use it in GitHub Desktop.
Save kwijibo/a1f0756ae7fd0ce9673c to your computer and use it in GitHub Desktop.
Although Turtle was invented as a way of serialising RDF, it can be thought of as a more general purpose data format, competing with formats like JSON, XML and YAML. It can handle dictionaries, lists, strings, numbers, local identifiers, and URIs.

#Why

##Structure

The basic structure that Turtle is built on is Entity Attribute Value. An entity can be thought of as a named set of key-value pairs.

  • entities are represented by identifiers.
  • attributes (properties) are also represented by identifiers (this allows the semantics of an attribute to be described, if so wished)
  • values may be an identifier (of an entity), a string, a number, or an ordered list.

An entity description is terminated by a full-stop (period) . character:

<entity> <attribute> "value" .

Identifiers

An identifier begins with < and ends with >

eg:

<myProductionServer>

Strings

Strings begin with " and end with " . Multiline strings begin with """ and end with """ . Optionally, a string may be tagged with a language code: "Bonjour"@fr

eg:

"a single line string"

""" a multi-line string """

###Numbers

Numbers are represented by digits 0123456789, and can contain a decimal point ..

###Booleans

Booleans are written without quotes, in lower case: true or false

Attribute value pairs

Attributes and values are separated by white space.

Attribute-value pairs are separated by semi-colons ;.

eg:

<theProductionServer> 
    <port> 4040 ; 
    <homeDir> "/var/www/public/" ;
.

Multiple values

Multiple values of an attribute are separated by a comma ,.

eg:

<jane> <friend> <sue> , <tom> , <heather> .
<bill> <nickname> "Wild Bill", "Crazy Bill", "Billy" .

Ordering values with a List

A list can represent a set of values where order is significant. A list begins with ( and ends with ). Values in a list are separated with white space.

eg:

<breakfastBananaRecipe> <instructions> (
  "buy 6 bananas"
  "peel bananas"
  "eat bananas"
) .
@timbl
Copy link

timbl commented Mar 21, 2017

An unnamed entity can be represented just by its attribute list like

<jane> <friend> [ <nickname> "Wild Bill", "Crazy Bill", "Billy"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment