Jump to content

N-Triples: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
SmackBot (talk | contribs)
m Date maintenance tags and general fixes
Expand article further.
Line 1: Line 1:
{{technical}}
{{Importance|date=December 2008}}
'''N-Triples''' is a line-based, plain text [[serialisation]] format for [[Resource Description Framework|RDF]] (Resource Description Framework) graphs. It is a subset of the [[Turtle (syntax)|Turtle]] (Terse RDF Triple Language) format.<ref name=RDFCore>{{cite web| url=http://www.w3.org/2001/sw/RDFCore/ntriples/| title=N-Triples| work=W3C RDF Core WG Internal Working Draft| publisher=www.w3.org| accessdate=2008-02-17}}</ref><ref name=rdf-testcases>{{cite web| url=http://www.w3.org/TR/rdf-testcases/#ntriples| title=RDF Test Cases - N-Triples| work=W3C Recommendation 10 Feb 2004| publisher=www.w3.org| accessdate=2008-02-17}}</ref> N-Triples should not be confused with [[Notation 3]] which is a superset of Turtle. N-Triples was primarily developed by Dave Beckett at the [[University of Bristol]] and Art Barstow at the [[W3C]].
'''N-Triples''' is a line-based, plain text [[serialisation]] format for [[Resource Description Framework|RDF]] (Resource Description Framework) graphs. It is a subset of the [[Turtle (syntax)|Turtle]] (Terse RDF Triple Language) format.<ref name=RDFCore>{{cite web| url=http://www.w3.org/2001/sw/RDFCore/ntriples/| title=N-Triples| work=W3C RDF Core WG Internal Working Draft| publisher=www.w3.org| accessdate=2008-02-17}}</ref><ref name=rdf-testcases>{{cite web| url=http://www.w3.org/TR/rdf-testcases/#ntriples| title=RDF Test Cases - N-Triples| work=W3C Recommendation 10 Feb 2004| publisher=www.w3.org| accessdate=2008-02-17}}</ref> N-Triples should not be confused with [[Notation 3]] which is a superset of Turtle. N-Triples was primarily developed by Dave Beckett at the [[University of Bristol]] and Art Barstow at the [[W3C]].


N-Triples was designed to be a simpler format than Notation 3 and Turtle, and therefore easier for software to [[Parsing|parse]] and generate. However, because it lacks some of the shortcuts provided by other RDF serialisations (such as [[CURIE|CURIEs]] and nested resources, which are provided by both RDF/XML and Turtle) it can be onerous to type out large amounts of data by hand, and difficult to read.
N-Triples was designed to be a simpler format than Notation 3 and Turtle, and therefore easier for software to [[Parsing|parse]]. Each line of the file represents a single statement of information or a comment. Each statement consists of three parts, separated by [[Whitespace (computer science)|whitespace]]: the subject, the predicate and the object, and is terminated with a [[full stop]]. Subjects may take the form of a [[URI]] or a ''named node''; predicates must be a URI; objects may be a URI, named node or a [[string literal]]. URIs are delimited with [[inequality|less-than and greater-than signs]] used as [[angle brackets]]. Named nodes are represented by an alphanumeric string, prefixed with an underscore and colon (<code>_:</code>). String literals are represented by a [[C_syntax#Backslash_escapes|C-style string]]. Comments consist of a line beginning with a [[Number sign|hash sign]]. By definition, all N-Triples files are encoded in [[UTF-8]].


== Example ==
== Usage ==

There is very little variation in how an RDF [[Graph (data structure)|graph]] can be represented in N-Triples. This makes it a very convenient format to provide "model answers" for RDF test suites <ref name=rdf-testcases />.

== Implementations ==

As N-Triples is a subset of Turtle and Notation 3, by definition all tools which support input in either of those formats will support N-Triples. In addition, some tools like [[Cwm]] have specific support for N-Triples.

== File Format ==

Each line of the file represents a single statement of information or a comment. Each statement consists of three parts, separated by [[Whitespace (computer science)|whitespace]]: the subject, the predicate and the object, and is terminated with a [[full stop]]. Subjects may take the form of a [[URI]] or a ''named node''; predicates must be a URI; objects may be a URI, named node or a [[string literal]]. URIs are delimited with [[inequality|less-than and greater-than signs]] used as [[angle brackets]]. Named nodes are represented by an alphanumeric string, prefixed with an underscore and colon (<code>_:</code>). String literals are represented by a [[C_syntax#Backslash_escapes|C-style string]]. Comments consist of a line beginning with a [[Number sign|hash sign]].

By definition, all N-Triples files are encoded in [[US-ASCII]], with characters outside the range of ASCII handled by escapes.

The [[Internet media type]] of N-Triples files is '''text/plain'''. The usual [[filename extension]] is '''".nt"'''.

=== Example ===


<pre><nowiki>
<pre><nowiki>
Line 49: Line 63:


[[Category:Metadata]]
[[Category:Metadata]]

{{tech-stub}}

Revision as of 15:44, 19 December 2008

N-Triples is a line-based, plain text serialisation format for RDF (Resource Description Framework) graphs. It is a subset of the Turtle (Terse RDF Triple Language) format.[1][2] N-Triples should not be confused with Notation 3 which is a superset of Turtle. N-Triples was primarily developed by Dave Beckett at the University of Bristol and Art Barstow at the W3C.

N-Triples was designed to be a simpler format than Notation 3 and Turtle, and therefore easier for software to parse and generate. However, because it lacks some of the shortcuts provided by other RDF serialisations (such as CURIEs and nested resources, which are provided by both RDF/XML and Turtle) it can be onerous to type out large amounts of data by hand, and difficult to read.

Usage

There is very little variation in how an RDF graph can be represented in N-Triples. This makes it a very convenient format to provide "model answers" for RDF test suites [2].

Implementations

As N-Triples is a subset of Turtle and Notation 3, by definition all tools which support input in either of those formats will support N-Triples. In addition, some tools like Cwm have specific support for N-Triples.

File Format

Each line of the file represents a single statement of information or a comment. Each statement consists of three parts, separated by whitespace: the subject, the predicate and the object, and is terminated with a full stop. Subjects may take the form of a URI or a named node; predicates must be a URI; objects may be a URI, named node or a string literal. URIs are delimited with less-than and greater-than signs used as angle brackets. Named nodes are represented by an alphanumeric string, prefixed with an underscore and colon (_:). String literals are represented by a C-style string. Comments consist of a line beginning with a hash sign.

By definition, all N-Triples files are encoded in US-ASCII, with characters outside the range of ASCII handled by escapes.

The Internet media type of N-Triples files is text/plain. The usual filename extension is ".nt".

Example

# The N-Triples statements below are equivalent to this RDF/XML:
#
# <rdf:RDF xmlns="http://xmlns.com/foaf/0.1/"
#          xmlns:dc="http://purl.org/dc/terms/"
#          xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
#   <Document rdf:about="http://www.w3.org/2001/sw/RDFCore/ntriples/">
#     <dc:title>N-Triples</dc:title>
#     <maker>
#       <Person rdf:nodeID="art">
#         <name>Art Barstow</name>
#       </Person>
#     </maker>
#     <maker>
#       <Person rdf:nodeID="dave">
#         <name>Dave Beckett</name>
#       </Person>
#     </maker>
#   </Document>
# </rdf:RDF>

<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ↵
    <http://xmlns.com/foaf/0.1/Document> .
<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://purl.org/dc/terms/title> "N-Triples" .
<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://xmlns.com/foaf/0.1/maker> _:art .
<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://xmlns.com/foaf/0.1/maker> _:dave .

_:art <http://www.w3.org/1999/02/22-rdf-syntax-ns#> <http://xmlns.com/foaf/0.1/Person> .
_:art <http://xmlns.com/foaf/0.1/name> "Art Barstow".

_:dave <http://www.w3.org/1999/02/22-rdf-syntax-ns#> <http://xmlns.com/foaf/0.1/Person> .
_:dave <http://xmlns.com/foaf/0.1/name> "Dave Beckett".

(The symbol ↵ is used to indicate a place where a line has been wrapped for legibility. N-Triples do not allow lines to be wrapped arbitrarily: the line endings indicate the end of a statement.)

References

  1. ^ "N-Triples". W3C RDF Core WG Internal Working Draft. www.w3.org. Retrieved 2008-02-17.
  2. ^ a b "RDF Test Cases - N-Triples". W3C Recommendation 10 Feb 2004. www.w3.org. Retrieved 2008-02-17.