This section defines an easy to parse line-based subset of Turtle named N-Triples.
The syntax is a revised 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 exchange format for RDF data.
An N-Triples document contains no parsing directives.
N-Triples triples are a sequence of RDF terms representing the subject, predicate and object of an RDF Triple. These may be seperated by white space (spaces #x20
or tabs #x9
). This sequence is terminated by a '.
' and a new line (optional at the end of a document).
N-Triples triples are also Turtle simple triples, but Turtle includes other representations of RDF Terms and abbreviations of RDF Triples. When parsed by a Turtle parser, data in the N-Triples format will produce exactly the same triples as a parser for the restricted N-triples language.
The RDF graph represented by an N-Triples document contains exactly each triple matching N-Triples N-Triples only allows for simple triple statements which MUST NOT contain new lines. A single triple is always a single line of the document. 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. The EBNF used here is defined in XML 1.0
[[!EBNF-NOTATION]]. Escape sequence rules are the same as Turtle. However, as only the The media type of N-Triples is N-Triples has been historically provided with other media types. N-Triples may also be provided as triple
production.
Summary of diffrences in N-Triples and Turtle
Triples
IRI Representations
Turtle
N-Triples
example
absolute IRI
yes
yes
<http://a.example/some/path/>
relative IRI
yes
no
</some/path/>
prefixed name
yes
no
rdfs:label
a
for the predicate rdf:type
yes
no
a
Literal Representations
Turtle
N-Triples
example
single-quoted single-line lexical representation
yes
no
'some literal'
double-quoted single-line lexical representation
yes
yes
"some literal"
single-quoted multi-line lexical representation
yes
no
'''some
literal'''
double-quoted multi-line lexical representation
yes
no
"""some
literal"""
abbreviated numeric
yes
no
13
abbreviated boolean
yes
no
true
Summary of Blank Node Representations in N-Triples and Turtle
Turtle
N-Triples
example
labeled blank node
yes
yes
<http://a.example/who#Alice> foaf:knows _:bob .
anonymous node
yes
no
<http://a.example/who#Alice> foaf:knows [] .
blank node property list
yes
no
<http://a.example/who#Alice> foaf:knows [ foaf:name "Bob" ] .
Changes from RDF Test Cases format
application/n-triples
\b
and \f
for backspace and form feed
Grammar
STRING_LITERAL2
production is allowed new lines in literals MUST be escaped.Media Type and Content Encoding
application/n-triples
.
The content encoding of N-Triples is always UTF-8.
See N-Triples Media Type for the media type
registration form.
Other Media Types
text/plain
. 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 a N-Triples document MAY also be provided as text/turtle
. In both of these cases the document is not an N-Triples document as an N-Triples document is only provided as application/n-triples
.
The Internet Media Type / MIME Type for N-Triples is "application/n-triples".
It is recommended that N-Triples files have the extension ".nt" (all lowercase) on all platforms.
It is recommended that N-Triples files stored on Macintosh HFS file systems be given a file type of "TEXT".
This information that follows will be submitted to the IESG for review, approval, and registration with IANA.