RDF Triples

The RDF data model is based on statements to describe and feature resources, especially web resources, in the form of subject-predicate-object (resource–property–value) expressions (RDF triples).

Definition (RDF Triple). Assume there are pairwise disjoint infinite sets ?, ?, and ? representing IRIs, blank nodes, and RDF literals, respectively. A triple (s, o, p) ∈ (? ∪ ?) × ? × (? ∪ ? ∪ ?) is called an RDF triple (or RDF statement), where s is the subject, p is the predicate, and o is the object.

The predicate (property) describes the relationship between the subject and the object. For example, the statement “Leslie’s homepage is http://www.lesliesikos.com” can be expressed as follows:

RDF data model RDF Triple
Subject Leslie http://www.lesliesikos.com/metadata/sikos.rdf#lesliesikos
Predicate the machine-readable definition of “homepage” from the Friend of a Friend (FOAF) external vocabulary http://xmlns.com/foaf/0.1/homepage
Object http://www.lesliesikos.com http://www.lesliesikos.com

All elements of the triple are resources defined by a unique URI:

<?xml version="1.0" encoding="UTF-8"?>
<foaf:Person rdf:about="http://www.lesliesikos.com/metadata/sikos.rdf#lesliesikos">
<foaf:homepage rdf:resource="http://www.lesliesikos.com" />

The about attribute of RDF declares the subject of the RDF statement, which is in this case http://www.lesliesikos.com/metadata/sikos.rdf#lesliesikos. The fragment identifier #lesliesikos is used to identify an actual person rather than a document (sikos.rdf). Those objects whose value is a web address such as the homepage of a person are declared using the resource attribute of RDF, in contrast to those that are string literals (character sequences) such as Sikos (the value of the family_name property from the FOAF vocabulary). The syntax of this example is known as the RDF/XML serialization (RDF/XML), which is the normative syntax of RDF, using the application/rdf+xml Internet media type and the .rdf or .xml file extension. Structured datasets can be written in RDF using a variety of other syntax notations and data serialization formats, for example, RDFa, JSON-LD, Notation3 (N3), Turtle, N Triples, TRiG, and TRiX, so the syntax of RDF triples varies from format to format. The N3 syntax is, for example, less verbose than the RDF/XML serialization, where the namespace prefix is declared by the @prefix directive, the URIs are delimited by the lass then (<) and greater than (>) signs, and the triples are separated by semicolons (;):

@prefix : <http://www.lesliesikos.com/metadata/sikos.rdf#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

:lesliesikos a foaf:Person ;
foaf:givenname "Leslie" ;
foaf:family_name "Sikos" ;
foaf:homepage <http://www.lesliesikos.com> .

Shorthand notation can be used for the most common predicates, including a (<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>), = (<http://www.w3.org/2002/07/owl#sameAs>), => (<http://www.w3.org/2000/10/swap/log#implies>), and <= (<http://www.w3.org/2000/10/swap/log#implies>). This is the reason why the RDF type of the person is declared using a. If the Notation 3 code is in an external file, the typical file extension is .n3. The MIME type and character encoding of N3 should be declared as text/n3; charset=utf-8. Tokenizing and whitespace handling are not specified in the N3 grammar. Base URIs to be used for the parsing of relative URIs can be set with the @base directive in the form @base <http://example.com/overview/>. Several N3 rules for string escaping are derived from Python, namely, stringliteral, stringprefix, shortstring, shortstringitem, longstring, longstringitem, shortstringchar, and longstringchar. Additionally, the \U extension, also used in another RDF serialization (N-Triples), can be applied. Legal escape sequences are \ (newline), \\ (backslash, \), \' (single quote, ‘), \" (double quote, “), \n (ASCII Linefeed, LF), \r (ASCII Carriage Return, CR), \t (ASCII Horizontal Tab, TAB), \uhhhh (Unicode character in BMP), and \U00hhhhhh (Unicode character in plane 1–16 notation). The escapes \a, \b, \f, and \v cannot be used because the corresponding characters are not allowed in RDF.

A subset of N3 is the Terse RDF Triple Language, often referred to as Turtle. Turtle provides a syntax to describe RDF graphs in a compact textual form, which is easy to develop. It is a subset of Notation 3 (N3) and a superset of N-Triples. Turtle is popular among Semantic Web developers and considered as an easy-to-read alternative to RDF/XML. The typical file extension of Turtle files is .ttl. The character encoding of Turtle files should be UTF-8. The MIME type of Turtle is text/turtle. Turtle is supported by many software frameworks that can be used for querying and analyzing RDF data, such as Jena, Redland, and Sesame. Turtle files consist of a sequence of directives, statements representing triples, and blank lines. Triples can be written in Turtle as a sequence of subject–predicate–object terms, separated by whitespace, and terminated by a period (.). URIs are written in angle brackets (<>), and string literals are delimited by double quotes ("") such as <http://www.lesliesikos.com/metadata/sikos.rdf#> <http://xmlns.com/foaf/0.1/homepage> <http://www.lesliesikos.com> . Using the URI prefix declaration @PREFIX foaf: <http://xmlns.com/foaf/0.1/> ., this can be abbreviated as <http://www.lesliesikos.com/metadata/sikos.rdf#> foaf:homepage <http://www.lesliesikos.com> . where foaf:homepage declares the concatenation of http://xmlns.com/foaf/0.1/ with homepage, revealing the original URI http://xmlns.com/foaf/0.1/homepage.