This document is part of the RDF 1.1 document suit. The N-Quads format is a line-based RDF syntax with a similar flavor as N-Triples [[N-TRIPLES]]. The main distinction is that N-Quads allows encoding multiple graphs.
This document defines N-Quads, an easy to parse, line-based, concrete syntax for RDF Datasets [[!RDF11-CONCEPTS]].
N-quads statements are a sequence of RDF terms representing the subject, predicate, object and graph label of an RDF Triple and the graph it is part of in a dataset. These may be separated 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).
The simplest statement is a sequence of (subject, predicate, object) terms forming an RDF triple and an optional blank node label or IRI labeling what graph in a dataset the triple belongs to, all are separated by whitespace and terminated by '
.' after each statement.
The graph label IRI can be omitted, in which case the triples are considered part of the default graph of the RDF dataset.
IRIs may be written only as absolute IRIs.
IRIs are enclosed in '<' and '>' and may contain numeric escape sequences (described below). For example
Literals are used to identify values such as strings, numbers, dates.
Literals (Grammar production Literal) have a lexical form followed by a language tag, a datatype IRI, or neither.
The representation of the lexical form consists of an initial delimiter
" (U+0022), a sequence of permitted characters or numeric escape sequence or string escape sequence, and a final delimiter. Literals may not contain the characters
CR. In addition '
\' (U+005C) may not appear in any quoted literal except as part of an escape sequence.
The corresponding RDF lexical form is the characters between the delimiters, after processing any escape sequences.
If present, the language tag is preceded by a '
If there is no language tag, there may be a datatype IRI, preceded by '
^^' (U+005E U+005E). If there is no datatype IRI and no language tag, the datatype is
RDF blank nodes in N-Quads are expressed as
_: followed by a blank node label which is a series of name characters.
The characters in the label are built upon PN_CHARS_BASE, liberalized as follows:
_and digits may appear anywhere in a blank node label.
.may appear anywhere except the first or last character.
U+2040are permitted anywhere except the first character.
A fresh RDF blank node is allocated for each unique blank node label in a document. Repeated use of the same blank node label identifies the same RDF blank node.
This specification defines conformance criteria for:
A conforming N-Quads document is a Unicode string that conforms to the grammar and additional constraints defined in , starting with the
nquadsDoc production. An N-Quad document serializes an RDF dataset.
N-Quads documents do not provide a way of serializing empty graphs that may be part of an RDF dataset.
A conforming N-Quads parser is a system capable of reading N-Quads documents on behalf of an application. It makes the serialized RDF graph, as defined in , available to the application, usually through some form of API.
The IRI that identifies the N-Quads language is:
The media type of N-Quads is
The content encoding of N-Quads is always UTF-8.
See N-Quads Media Type for the media type
The original specification,
N-Quads: Extending N-Triples with Context,
proposed the use of media type
text/x-nquads with an encoding
using 7-bit US-ASCII.
An N-Quads document is a Unicode[[!UNICODE]] character string encoded in UTF-8. Unicode code points only in the range U+0 to U+10FFFF inclusive are allowed.
White space (tab
U+0009 or space
U+0020) is used to separate two terminals which would otherwise be (mis-)recognized as one terminal. White space is significant in the production STRING_LITERAL_QUOTE.
Comments in N-Quads take the form of '
#', outside an
STRING_LITERAL_QUOTE, and continue to the end of line (
EOL) or end of file if there is no end of line after the comment marker. Comments are treated as white space.
The EBNF used here is defined in XML 1.0 [[!EBNF-NOTATION]].
Escape sequence rules are the same as Turtle
[[TURTLE]]. However, as only the
STRING_LITERAL_QUOTE production is allowed new lines in literals MUST be escaped.
Parsing N-Quads requires a state of one item:
bnodeLabels— A mapping from string to blank node.
This table maps productions and lexical tokens to
RDF terms or components of
RDF terms listed in :
|IRIREF||IRI||The characters between "<" and ">" are taken, with the escape sequences unescaped, to form the unicode string of the IRI.|
|STRING_LITERAL_QUOTE||lexical form||The characters between the outermost '"'s are taken, with escape sequences unescaped, to form the unicode string of a lexical form.|
|LANGTAG||language tag||The characters following the |
|literal||literal||The literal has a lexical form of the first rule argument, |
|BLANK_NODE_LABEL||blank node||The string matching the second argument, |
An N-Quads document defines an RDF dataset composed of RDF graphs composed of a set of RDF triples. The
statement production produces a triple defined by the terms constructed for
object. This RDF triple is added to the graph labeled by the production
graphLabel, if no
graphLabel is present the triple is added to the RDF datasets default graph.
The editor of the RDF 1.1 edition acknowledges valuable contributions from Gregg Kellogg, Andy Seaborne, Eric Prud'hommeaux, Dave Beckett, David Robillard, Gregory Williams, Antoine Zimmermann, Sandro Hawke, Richard Cyganiak, Pat Hayes, Henry S. Thompson, Bob Ferris, Henry Story, Andreas Harth, Lee Feigenbaum, Peter Ansell, Evan Patton and David Booth.
This specification is a product of extensive deliberations by the members of the RDF Working Group chaired by Guus Schreiber and David Wood. It draws upon the eariler specification in N-Quads: Extending N-Triples with Context, edited by Richard Cyganiak, Andreas Harth, and Aidan Hogan.
text/x-nquadshistorical media type added.
No substitutive changes.
The Internet Media Type / MIME Type for N-Quads is "application/n-quads".
It is recommended that N-Quads files have the extension ".nq" (all lowercase) on all platforms.
It is recommended that N-Quads 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.